/******************************************************************************* * * Simple GLSL FX file * *******************************************************************************/ #pragma language GLSL // un-tweakables // structures and shaders ///////////////////// varying vec3 eyeNormal; varying vec4 eyePos; varying vec3 eyeView; void mainVS() { // Must write gl_Position for rasterization to be defined.... // gl_Position = ftransform(); // Transform to shading space (we are going to shade in eyespace) // // eyeNormal = gl_NormalMatrix * gl_Normal; eyeView = -vec3(gl_ModelViewMatrix * gl_Vertex); } uniform vec3 lightDir = vec3( 0.57735, 0.57735, 0.57735); uniform vec3 warmColor = vec3( 0.3, 0.3, 0.0); uniform vec3 coolColor = vec3( 0.0, 0.3, 0.6); uniform vec3 baseColor = vec3( 0.8, 0.8, 0.8); uniform float alpha = 0.25; uniform float beta = 0.5; uniform float factor = 0.6; void mainPS() { vec3 norm; vec4 SurfColor; vec3 Cool; vec3 Warm; float Intensity; vec3 hvec; vec3 lightDirection = normalize(lightDir); // // Since the EyeNormal is getting interpolated, we // have to first restore it by normalizing it. // norm = normalize( eyeNormal ); vec3 view = normalize(eyeView); // // Per fragment gooch lighting Intensity = dot ( norm, lightDirection ); // Gooch maps Intensity from (-1,1) to (0,1) Intensity = Intensity * 0.5 + 0.5; Cool = alpha * baseColor + coolColor; Warm = beta * baseColor + warmColor; SurfColor.rgb = factor * mix( Cool, Warm, Intensity); // // Now, specular light.... hvec = normalize(lightDirection + view); Intensity = dot ( norm, hvec ); Intensity = max ( Intensity, 0.0 ); Intensity = pow ( Intensity, 32.0 ); SurfColor += 0.8* Intensity; SurfColor.a = 1.0; gl_FragColor = SurfColor; } //////// techniques //////////////////////////// technique Gooch { pass p0 { VertexShader = compile vs_2_0 mainVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LEqual; CullMode = Back; PixelShader = compile ps_2_0 mainPS(); } } technique Bad { pass p0 { VertexShader = compile vs_2_0 mainVS(); ZEnable = true; ZWriteEnable = true; ZFunc = Always; CullMode = Back; PixelShader = compile ps_2_0 mainPS(); } }