/* I took wave's lead and renamed brickper to DPBrickperturb.sl -- tal AT renderman DOT org */ /* * brickper.sl * * AUTHOR: Darwyn Peachy * * REFERENCES: * _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed., * F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley. * Academic Press, 1994. ISBN 0-12-228760-6. */ #include "DPProctext.h" #define BRICKWIDTH 0.25 #define BRICKHEIGHT 0.08 #define MORTARTHICKNESS 0.01 #define BMWIDTH (BRICKWIDTH+MORTARTHICKNESS) #define BMHEIGHT (BRICKHEIGHT+MORTARTHICKNESS) #define MWF (MORTARTHICKNESS*0.5/BMWIDTH) #define MHF (MORTARTHICKNESS*0.5/BMHEIGHT) surface DPBrickperturb( uniform float Ka = 1; uniform float Kd = 1; uniform color Cbrick = color (0.5, 0.15, 0.14); uniform color Cmortar = color (0.5, 0.5, 0.5); ) { color Ct; point Nf; float ss, tt, sbrick, tbrick, w, h; float scoord = s; float tcoord = t; Nf = normalize(faceforward(N, I)); ss = scoord / BMWIDTH; tt = tcoord / BMHEIGHT; if (mod(tt*0.5,1) > 0.5) ss += 0.5; /* shift alternate rows */ tbrick = floor(tt); /* which brick? */ ss += 0.1 * snoise(tbrick+0.5); sbrick = floor(ss); /* which brick? */ ss -= sbrick; tt -= tbrick; w = step(MWF,ss) - step(1-MWF,ss); h = step(MHF,tt) - step(1-MHF,tt); Ct = mix(Cmortar, Cbrick, w*h); /* diffuse reflection model */ Oi = Os; Ci = Os * Ct * (Ka * ambient() + Kd * diffuse(Nf)); }