/* * checktrans.sl * * Lawson Wade * * A surface shader that simulates a chessboard in * which the white squares are translucent. * */ #include "rmannotes.sl" #include "colors.sl" surface checktrans( color light_color = White, dark_color = Black; float freq = 20; float eta = 0.6; float Ka = 1, Kd = 0.5, Ks = 0.5, roughness = 0.1; ) { point Nf, V, R, Lf, Lnorm; color surface_color, layer_color; color surface_opac, layer_opac; float fuzz = 0.005; float ss, tt; float row, col; float count; ss = repeat(s, freq); tt = repeat(t, freq); col = whichtile(s, freq); row = whichtile(t, freq); /* illumination */ Nf = faceforward(normalize(N), I); V = normalize(-I); /*** background layer ***/ if ((odd(row) && even(col)) || (even(row) && odd(col))) { /* dark square */ surface_opac = 1; surface_color = dark_color * (Ka * ambient() + Kd * diffuse(Nf)); } else { /* light square */ surface_opac = 0.9; surface_color = 0; count = 0; illuminance(P) { Lnorm = normalize(L); Lf = normalize(faceforward(Nf, L)); if (Lnorm . Nf >= 0.0) { surface_color += Cl * (Lnorm . Nf); /* / (L . L)); */ count += 1; } else if (Lnorm . Nf < -0.8) { surface_color += Cl * ((Lf . Nf) / (L . L)); count += 1; } } surface_color /= count; surface_color += light_color * (Ka * ambient() + Kd * diffuse(Nf)); } /* output */ Oi = surface_opac; Ci = surface_opac * surface_color; }