/* * nick_screen * * DESCRIPTION: * Makes a surface that looks like a metal screen. Strips of metal run * parallel to lines of two dimensions. You can adjust the Ka, Kd, Ks, etc. * to change the material appearance. This texture antialiases pretty * well, even with only one sample per pixel. * * PARAMETERS: * Ka, Kd, Ks, roughness, specularcolor - work just like the plastic shader * frequency - how many cycles of screen in st space * density - how much of each cycle is opaque? * dimensions - x = 1, y = 2, z = 4, add the two you want * i.e x+y = 3, x+z = 5, y+z = 6 * AUTHOR: Nick Meshes * * * * The RenderMan (R) Interface Procedures and RIB Protocol are: * Copyright 1988, 1989, Pixar. All rights reserved. * RenderMan (R) is a registered trademark of Pixar. */ #define boxstep(a,b,x) (clamp(((x)-(a))/((b)-(a)),0,1)) #define MINFILTERWIDTH 1.0e-7 surface nick_screen2 (float Ka = 1, Kd = 0.75, Ks = 0.4, roughness = 0.1; color specularcolor = 1; color screencolor = color(1, 0, 0); float density = 0.25, frequency = 20, dimensions = 3;) { float swidth, twidth; float d; normal Nf; vector V; color Ct; float astrip, bstrip; float apart; float bpart; float sum; float hcomp = density; float vcomp = density; if (dimensions == 5){ apart = xcomp(P); bpart = ycomp(P); } else if (dimensions == 6){ apart = ycomp(P); bpart = zcomp(P); } else{ apart = xcomp(P); bpart = ycomp(P); } swidth = max (abs(Du(s)*du) + abs(Dv(s)*dv), MINFILTERWIDTH) * frequency; twidth = max (abs(Du(t)*du) + abs(Dv(t)*dv), MINFILTERWIDTH) * frequency; Cs = screencolor; astrip = clamp(boxstep(.5-(hcomp+twidth),.5-hcomp,t) - boxstep(.5+hcomp, .5+(hcomp+twidth),t),0,1); bstrip = clamp(boxstep(.5-(vcomp+swidth),.5-vcomp,t) - boxstep(.5+vcomp, .5+(vcomp+swidth),t),0,1); sum = astrip + bstrip; /* Let's just test this apart = mod(apart, 2); bpart = mod(bpart, 2); sum = 0; if (apart > 1) sum = sum + 1; if (bpart > 1) sum = sum + 1; if (sum < 1) Os = 0; */ Nf = faceforward(normalize(N),I); V = -normalize(I); Oi = color(sum/2); Ci = Oi * ( Cs * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * Ks*specular(Nf,V,roughness)); }