/**************************************************************************** * noisylight.sl - colored light with noise. * * Basic color/brightness controls: * intensity - overall intensity scaling of the light * lightcolor - overall color filtering for the light * * Projected noise on the light: * noiseamp - amplitude of the noise. A value of 0 (the default) * means not to use noise. Larger values increase the blotchiness * of the projected noise. * noisefreq - frequency of the noise. * noiseoffset - spatial offset of the noise. This can be animated, * for example, you can use the noise to simulate the * attenuation of light as it passes through a window with * water drops dripping down it. * * Shadow mapped shadows. * shadowmap - the name of the texture containing the shadow map. If * this value is "" (the default), no shadow map will be used. * shadowblur - how soft to make the shadow edge, expressed as a * percentage of the width of the entire shadow map. * shadowbias - the amount of shadow bias to add to the lookup. * shadownsamps - the number of samples to use. * ****************************************************************************/ light noisylight ( /* Basic intensity and color of the light */ float intensity = 1; color lightcolor = color (1,1,1); /* Noisy light */ float noiseamp = 0, noisefreq = 4; vector noiseoffset = 0; /* Shadow mapped shadows */ string shadowmap = ""; float shadowblur = 0.01, shadowbias = .01, shadownsamps = 16; color shadowcolor = 0 ) { /* For simplicity, assume that the light is at the origin of shader * space and aimed in the +z direction. */ point PL = transform ("shader", Ps); point from = point "shader" (0,0,0); vector axis = normalize(vector "shader" (0,0,1)); float angle = PI; illuminate (from, axis, angle) { /* Determine attenuation of the light */ float atten = 1.0; color lcol = lightcolor; /* Apply noise */ if (noiseamp > 0) { float n = noise (noisefreq * (PL+noiseoffset) * point(1,1,0)); n = smoothstep (0, 1, 0.5 + noiseamp * (n-0.5)); atten *= n;} /* Apply shadow mapped shadows */ float unoccluded = 1; if (shadowmap != "") unoccluded *= 1 - shadow (shadowmap, Ps, "blur", shadowblur, "samples", shadownsamps, "bias", shadowbias); point shadoworigin; shadoworigin = from; lcol = mix (shadowcolor, lcol, unoccluded); Cl = (atten*intensity) * lcol; } }