Bonus NoiseShader

And for those of you testing the limits of GPU processing, here is a
dissolve shader I threw together that demonstrates a handy way of
generating noise on the GPU precedurally.  Have fun!
Happy Shading!

Andrew B.

<jittershader name=”sine_noise”>
<description>
cascading sinusoidal noise wipe
</description>
<param name=”amt” type=”float” default=”1.” />
<param name=”freq” type=”float” default=”1.” />
<param name=”xsize” type=”float” default=”320.” />
<param name=”ysize” type=”float” default=”240.” />
<param name=”tex0″ type=”int” default=”0″ />
<param name=”tex1″ type=”int” default=”1″ />
<language name=”glsl” version=”1.0″>
<bind param=”amt” program=”fp” />
<bind param=”freq” program=”fp” />
<bind param=”xsize” program=”fp” />
<bind param=”ysize” program=”fp” />
<bind param=”tex0″ program=”fp” />
<bind param=”tex1″ program=”fp” />
<program name=”vp” type=”vertex” source=”sh.passthru.xform.vp.glsl” />
<program name=”fp” type=”fragment”>
<![CDATA[

//setup for 2 texture
varying vec2 texcoord0;
varying vec2 texcoord1;
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;
uniform float amt;
uniform float freq;
uniform float xsize;
uniform float ysize;

void main()
{
vec4 a = texture2DRect(tex0, texcoord0);
vec4 b = texture2DRect(tex1, texcoord1);

//pseudo-random noise function, using cascaded sine-functions
float ax = mod(texcoord0.x,xsize);
float ay = mod(texcoord0.y,ysize);
float xs1 = sin(ax*ay/(abs(freq)+1.));
float xs2 = sin(xs1*533.);
float xs3 = abs(sin(xs2*1013.));

vec4 mixa = mix(a,b,vec4 (xs3<amt));

// output texture
gl_FragColor = mixa;
}
]]>
</program>
</language>
</jittershader>

Leave a Comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.