/******************************************************************************* * * Simple GLSL FX file * *******************************************************************************/ #pragma language GLSL // un-tweakables // structures and shaders ///////////////////// varying vec3 eyeNormal; varying vec4 v_EyePos; void mainVS() { vec4 ObjNormal; vec4 ObjPos; vec3 EyeNormal; vec4 EyePos; // 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; gl_TexCoord[0] = gl_MultiTexCoord0; } // hatching parameters uniform sampler2D hatch0; uniform sampler2D hatch1; uniform sampler2D weight0; uniform sampler2D weight1; uniform vec3 strokeColor = vec3( 0.15, 0.05, 0.05); uniform vec3 surfaceColor = vec3( 0.9, 0.9, 0.9); uniform vec3 lightDir = vec3( 0.57735, 0.57735, 0.57735); void mainPS() { vec3 norm; vec4 tex; vec3 color; float turb; float illum; float s0,t0; vec3 lightDirection = normalize(lightDir); vec4 Intensity; // // Since the EyeNormal is getting interpolated, we // have to first restore it by normalizing it. // norm = normalize( eyeNormal); //compute diffuse illumination illum = clamp( dot(norm, lightDirection), 0.0, 1.0); vec3 h0=vec3(texture2D(hatch0,vec2(gl_TexCoord[0]))); vec3 h1=vec3(texture2D(hatch1,vec2(gl_TexCoord[0]))); vec3 w0=vec3(texture2D(weight0,vec2(illum))); vec3 w1=vec3(texture2D(weight1,vec2(illum))); // compute the weighting for the different hatching directions float weight = clamp( clamp(dot(1.0-h0,w0),0.0,1.0)+clamp(dot(1.0-h1,w1),0.0,1.0), 0.0, 1.0); // blend between dark and light colors color = mix(surfaceColor, strokeColor, weight); gl_FragColor = vec4( color, 1.0); } //////// techniques //////////////////////////// technique BumpReflect0 { pass p0 { VertexShader = compile vs_2_0 mainVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LEqual; CullMode = None; PixelShader = compile ps_2_0 mainPS(); } }