// 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); |