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

0 Responses to “Morphing Gradient Oscillators”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Twitter

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

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

Links

Blog Stats

  • 476,450 hits

%d bloggers like this: