/******************************************************************************* * * Simple HLSL FX file * *******************************************************************************/ // un-tweakables // structures and shaders ///////////////////// float4x4 wvIT : WorldViewInverseTranspose; float4x4 wvp : WorldViewProjection; void mainVS( float4 vertex : POSITION0, float3 normal : NORMAL0, float4 tex : TEXCOORD0, out float4 Position : POSITION0, out float3 eyeNormal : TEXCOORD0, out float4 texCoord : TEXCOORD1 ) { // // Position = mul( vertex, wvp); // Transform to shading space (we are going to shade in eyespace) // // eyeNormal = mul( normal, float3x3(wvIT)); texCoord = tex; } // hatching parameters sampler2D hatch0; sampler2D hatch1; sampler2D weight0; sampler2D weight1; float3 strokeColor = float3( 0.15, 0.05, 0.05); float3 surfaceColor = float3( 0.9, 0.9, 0.9); float3 lightDir = float3( 0.57735, 0.57735, 0.57735); float4 mainPS( float3 eyeNormal : TEXCOORD0, float4 texCoord : TEXCOORD1 ) : COLOR0 { float3 norm; float3 color; float illum; float3 lightDirection = normalize(lightDir); float4 Intensity; // // Since the EyeNormal is getting interpolated, we // have to first restore it by normalizing it. // norm = normalize( eyeNormal); //compute diffuse illumination illum = saturate( dot(norm, lightDirection)); float3 h0 = float3( tex2D( hatch0, texCoord)); float3 h1 = float3( tex2D( hatch1, texCoord)); float3 w0 = float3( tex2D( weight0, float2(illum))); float3 w1 = float3( tex2D( weight1, float2(illum))); // compute the weighting for the different hatching directions float weight = saturate( saturate(dot(1.0-h0,w0)) + saturate(dot(1.0-h1,w1)) ); // blend between dark and light colors color = lerp(surfaceColor, strokeColor, weight); float4 result = float4(color, 1.0); return result; } //////// 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(); } }