Matrix Composition Prebaked Ribs St Coloration Pattern Animation Fire Grass Home
Grass Shader  
   
The Grass Shader excersise is to understand the lighting effect on grass. Effects like the specular highlites and translucency of the grass material. The major part is not only observing the natural effects but to think of a concept in render man language to produce that same naturalistic lighting effect on the grass material.  
   

// Establish the true front and rear normal------------------------------
normal front =n, rear = -n;
if (nf !=n)
{ front =-n; rear =n; }

//Make two lightingcaluculations - front/rear
color frontColor = KdFront * diffuse(front);
color
rearColor = KdRear * diffuse(rear);

// Calculate brightness of rear and front lighting and extract brightness
color frontHSV = ctransform ( "rgb", "hsv", frontColor);
float
frontBrightness = frontHSV [2];
color rearHSV = ctransform ( "rgb", "hsv", rearColor);
float rearBrightness = rearHSV [2];

//Combine the front/rear colors
color
diffuseColor = mix(rearColor,frontColor,translucency)*Kd;

// Mix the glow Color and the true leaf color based on the // relative difference between the front and the rear lighting value
float T = smoothstep ( 0.0 , 1.0, rearBrightness - frontBrightness);
color finalColor = mix(Cs, glowColor, T);

On the top image we cant really see the glow color, hence i decided to throw a red on.

Just to be sure that I know its working.In this image you can see some specular highlites as well.

// specular color hilites

color specularcolor = specular (nf, normalize(-I), roughness) * Ks;
color specularHSV = ctransform ( "rgb", "hsv", specularcolor);

 

In here I just switch the Glow Color back to its correct color,

and I am pretty much ready to add the texture

 

However here is where I meet my problem.

When I throw in the texture. Somehow the textures just blow or its corrupted.

I am still in the process of solving this problem.

 

// read out texture_v02 ----------------------------------------------

color texColor = 1;if (texname != "")// "!=" is one character
{
if
(texflip == 0 ) texColor = texture (texname, s* texrepeats, t);
else
texColor = texture (texname, t* texrepeats, s);
}
finalColor =
mix ( finalColor ,texColor , texblend);

I tried to redo the txmake function in terminal, however the texture still did not show up as it suppose to be.

So currently I am still in the stage of getting the texture to work properly, then will i bake the grass as a rib file and duplicate them in maya and render them with proper lighting.

Click on the link below to see the full shader script and the test rib file.

Grass Shader.sl

GrassTest.rib

-