Archive for January 7th, 2008

07
Jan
08

Morphing Gradient Oscillators

Smoothstep is good!

This CUKernel code produces a kind of skewed sinewave. With the breakPoint at 0.5. you get a perfect sine, with lower of higher breakPoint values, you get something nearer to a sawtooth wave (albeit a curvy one).

// Variable-geometry wave
float variSawWave(float phase, float shape) {
float aa = 0.01; // Antialias width
float breakPoint = clamp(shape, aa, 1.0-aa);
return smoothstep(0.0,breakPoint,phase)*smoothstep(1.0,breakPoint,phase);
}

// Main function
/*
Inputs:
Image: input image
Width: width of waveform. Range 0.x to 1.0
Shape: shape of wave from falling sawtooth to triangle to rising sawtooth. 0.0 to 1.0
*/
kernel vec4 waveSkew(sampler Image, float Width, float Shape)
{
vec2 dims = samplerSize(Image); // Input image dimensions
vec2 xyNorm = samplerCoord(Image) / dims; // Normalised pixel coord
float phase = fract(xyNorm.x / Width); // 0.0 to 1.0 across each wave cycle
float val = variSawWave(phase, Shape); // Output value
return vec4(1.0,1.0,1.0,val); // Output
}

My intention was to create a variable sawtooth/triangle waveform, but I forget that smoothstep produces a curved, exponential rather than a linear output. It looks like that’s actually going to be a bit more complicated to produce a linear saw/triangle wave.

Advertisements



Twitter

January 2008
M T W T F S S
« Dec   Feb »
 123456
78910111213
14151617181920
21222324252627
28293031  

Links

Blog Stats

  • 487,906 hits
Advertisements