Darwyn Peachey introduces a simple brick texture on pg 40. An excerpt follows:
#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)
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);
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 */
At this point the author says that "the new coordinates ss and tt vary from 0 to 1 within a single brick."
What gives? ss and tt are just linear....they are not peroidic at all as far as I can tell, unless I don't understand the global's s and t! It seems to me that mod(tt*0.5,1) is going to be greater then .5 for the vast majority of the texture space.
I mean the #defines are static, right? You just add the measurement to get ss = s/.26 and tt= t/.09.
The rest follows:
sbrick = floor(ss); /* which brick? */
tbrick = floor(tt); /* 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));
I am having problems plotting it out by running thru it with sample points.
I feel like there is a typo! maybe his comments are in the wrong place.
Paul the confused.