/* * ass6_5.sl * * Description: * Shader that has a procedurally generated regular pattern using polar * coordinate and ring technique. * * Parameters: Ka, Kd, Ks, roughness, specularcolor, freq, background, foreground, ringcolor, radiuslength, num. * * Author: Akanee Mahasith */ #include "rmannotes.sl" surface ass6_5(float Ka = 0.5, Kd = 0.5, Ks = 0.5, roughness = 0.15; color specularcolor = 1; float freq = 10; float num = 2; color background = color (1,0,0); color foreground = color (1,1,0); color ringcolor = color (1,1,0); float radiuslength = .45; ) { color surface_color, layer_color; color surface_opac, layer_opac; float ss, tt; float theta, r; float fuzz = 0.05; float radius, half_width; point center; point Nf, V; float d; /* background */ surface_color = background; surface_opac = 1; ss = repeat(s, num); tt = repeat(t, num); /* ring */ layer_color = ringcolor; center = (0.5, 0.5, 0); radius = radiuslength; half_width = 0.02; d = distance(center, (ss, tt, 0)); layer_opac = pulse(radius - half_width, radius + half_width, fuzz, d); layer_opac -= .8; surface_color = blend(surface_color, layer_color, layer_opac); /* 4 x 4 tiles, ss and tt go from -0.5 to 0.5 (instead of 0-1) */ ss -= 0.5; tt -= 0.5; /* compute r & theta: r = distance from (ss,tt) = (0,0) theta = angle (0 to 1) */ topolar2d(ss, tt, r, theta); theta = (theta + PI) / (2 * PI); /* repeat theta to make pie slices */ theta = repeat(theta, freq); /* polar coordinate patterns */ layer_color = foreground; layer_opac = pulse(0.4, 0.5, 0.3,theta) + (clamp(0.4 - r, 0, 1) * 2.5); layer_opac *= 0.9; surface_color = blend(surface_color, layer_color, layer_opac); /* illumunation for all layers */ Nf = faceforward(normalize(N), I); V = -normalize(I); surface_color = surface_color * (Ka * ambient() + Kd * diffuse(Nf)) + specularcolor * Ks * specular(Nf, V, roughness); /* output */ Oi = surface_opac; Ci = surface_color * surface_opac; }