/* Solidwave.sl * * Description * A shader that generates solid wave pattern using Perturbed Regular * Pattern and Bombing techniques. * * Parameter * Kd: diffuse illumination. * Ka: ambient illumination. * noifreq: to change the size of noise. * background: background color. * foreground: foreground color. * Author * Akanee Mahasith */ #include "rmannotes.sl" surface Solidwave(float Kd = 0.8, Ka = 0.2; float noifreq = 2; color background = color(0.976, 0.946, 0.493); color foreground = color(1, 0.364, 0.003)) { color surface_color, layer_color; color surface_opac, layer_opac; float fuzz = 0.1; point center; float radius; float d; float noi; float noiscale = .02; float ss, tt, tmps, tmpt; float col, row; float freq = 8; float i, layers = 5; point Nf, V; surface_color = background; Nf = faceforward(normalize(N), I); V = -normalize(I); for (i = 1; i <= layers; i += 1) { /* set freq and fuzz of pattern based on layer # */ freq = i; fuzz = 0.005 * freq; /* compute base noise based on texture coordinates */ noi = noise(s * noifreq, t * noifreq); /* base seed to udn on current row and column of tile */ col = whichtile(s, freq); row = whichtile(t, freq); noi *= noise(col * 10 + 0.5, row * 10 + 0.5); /* perturb ss, tt */ ss = s + snoise(noi + 999) * noiscale; tt = t + snoise(noi + 999) * noiscale; /* repeat texture coordinates, jitter tiles by plus or minus 0.15, and rotate by random amount (0-360) */ tmps = repeat(ss, freq) + udn(noi * 111, -0.15, 0.15); tmpt = repeat(tt, freq) + udn(noi * 917, -0.15, 0.15); rotate2d(tmps, tmpt, radians(udn(noi * 333, 0, 360)), 0.5, 0.5, ss, tt); /* generate tile 15% of the time & choose random value */ if (udn(noi * 314, 0, 1) > 0.15) { layer_color = color "hsv" (.5, .5, udn(noi * 234, 0, 1)); layer_color *= foreground; center = (0.5, 0.5, 0); /* location of center of disk */ radius = 0.35; /* radius of disk */ d = distance(center, (ss, tt, 0)); layer_opac = 1 - smoothstep(radius - fuzz, radius, d); surface_color = blend(surface_color, layer_color, layer_opac); } } /* illumination for all layers */ surface_color = surface_color * (Ka * ambient() + Kd * diffuse(Nf)); /* output */ Oi = Os; Ci = Os * surface_color; }