/* * stars * * Lawson Wade * * A surface shader which creates a plastic like surface * which has a navy blue background and many white stars. * * stars.sl is based upon Steve May's rotblocks.4.sl */ #include "rmannotes.sl" #include "colors.sl" surface stars( float minlayer = 2, maxlayer = 18, seed = 0.36, hfreq = 1, vfreq = 1; float Ka = 1, Kd = 0.3, Ks = 0.3, roughness = 0.1; color specularcolor = 1; ) { point Nf, V; color surface_color, layer_color; color layer_opac; float ss, tt, tmps, tmpt; float col, row; float percentage; float sfreq, tfreq; float noi, choice; float i; float d; surface_color = Navy; for (i = minlayer; i <= maxlayer; i += 1) { /* set freq and fuzz of pattern based on layer # */ sfreq = i * hfreq; tfreq = i * vfreq; percentage = 0.5 * (maxlayer - i + 1) / (maxlayer - minlayer + 1); /* base seed to udn on current row and column of tile */ col = whichtile(s, sfreq); row = whichtile(t, tfreq); noi = 0.5 * (noise(col * 100 * seed + 0.513 + seed, row * 100 * seed + 0.579 + seed) + noise(i * 100 * seed + 0.527 + seed)); /* repeat texture coords, jitter tiles by plus or minus 0.4, and rotate by random amount (0-360) */ tmps = repeat(s, sfreq) + udn(noi * (1183 + 7 * seed), -0.4, 0.4); tmpt = repeat(t, tfreq) + udn(noi * (999 + 5 * seed), -0.4, 0.4); rotate2d(tmps, tmpt, radians(udn(noi * (777 + 3 * seed), 0, 360)), 0.5, 0.5, ss, tt); /* generate tiles with a decreasing percentage per layer */ if (udn(noi * (314 + 9 * seed), 0, 1) < percentage) { layer_color = White; d = distance((0.5, 0.5, 0), (ss, tt, 0)); layer_opac = 1 - smoothstep(0.0, 0.1, d); surface_color = blend(surface_color, layer_color, layer_opac); } } /* illumination vectors */ Nf = faceforward(normalize(N), I); V = normalize(-I); /*** ambient light ***/ surface_color = surface_color * (Ka * ambient() + Kd * diffuse(Nf)) + specularcolor * Ks * specular(Nf, V, roughness); /* output */ Oi = Os; Ci = Os * surface_color; }