/***************************************************************************** * * Sine Noise v1.0 * Last Change: Oct 3 2007 * * Author: Mario Klingemann * http://www.quasimondo.com * Contact: mario@quasimondo.com * * This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License * http://creativecommons.org/licenses/by-sa/3.0/ * * Due to the lack of a rnd() function and no binary operators it is a bit * more difficult than ususal to create random noise. This method uses nested * high frequency sine waves which look pretty "noisy" to me. * *****************************************************************************/ kernel sineNoise { parameter float4 rgbaSeed < minValue:float4(0.0,0.0,0.0,0.0); maxValue:float4(1000.0,1000.0,1000.0,1000.0); defaultValue:float4(0.0,0.0,0.0,0.0); description: "Seeds for the RGBA channels"; >; parameter bool alpha < minValue: false; maxValue: true; defaultValue: false; >; parameter bool red < minValue: false; maxValue: true; defaultValue: true; >; parameter bool green < minValue: false; maxValue: true; defaultValue: true; >; parameter bool blue < minValue: false; maxValue: true; defaultValue: true; >; // these values can be varied. Some numbers will result in artifacts or regular patterns though. const float f1 = 11.2; const float f2 = 65.0332; const float f3 = 8899.2289; const float f4 = 32921.333; const float f5 = 13.333; const float f6 = 7.321; const float f7 = 3333.773; const float f8 = 3733.1125; void evaluatePixel(in image4 image, out float4 dst) { float2 pos = outCoord(); float4 posx = float4( pos.x ) + sin( rgbaSeed * f7 ) + f5; float4 posy = float4( pos.y ) + sin( rgbaSeed * f8 ) + f6; float4 noise = 0.5 * ( 1.0 + sin( posx * ( f1 + sin( posy * f2 ) ) + posy * ( f3 + sin( posx * f4 )))); dst = noise; dst.a = alpha ? dst.a : 1.0; dst.r = red ? dst.r : 0.0; dst.g = green ? dst.g : 0.0; dst.b = blue ? dst.b : 0.0; } }