PDA

View Full Version : s and t in RenderMan shading language


tbaypaul
10-22-2005, 03:34 AM
I am reading "Texturing and Modeling a Procedural Approach.
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)

surface
brick(
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 */


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.

Thankx,

Paul the confused.

-Vormav-
10-22-2005, 06:28 AM
Don't forget a very important part of the line where ss and tt are defined:
ss = scoord / BMWIDTH;
tt = tcoord / BMHEIGHT;

Now, take a look at the values that you get by those static values for BMWIDTH and BMHEIGHT: 0.26 and .01 respectively.
So, when you divide scoord and tcoord (which are in the range of 0 to 1) by these <0 values to get ss and tt, this is going to throw the texture coordinates into a larger range such that mod(tt*0.5, 1) will be periodic (and how periodic it is is defined by the values given for brick and mortar sizes, as would be expected). In this case, (tt*0.5) is really in the range of 0 to 5.56.

Hope that helps.

tbaypaul
10-22-2005, 04:05 PM
Yeah Thanks. The main problem was the text is a little outta sync with the actual code so it confused me for a bit. Thanks

CGTalk Moderation
10-22-2005, 04:05 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.