/******************************************************************************* * * Simple HLSL FX file * *******************************************************************************/ // un-tweakables // structures and shaders ///////////////////// float4x4 wvIT : WorldViewInverseTranspose; float4x4 wvp : WorldViewProjection; float4x4 wv : WorldView; void mainVS( float4 vertex : POSITION0, float3 normal : NORMAL0, float3 tangent : TEXCOORD1, float3 binormal : TEXCOORD2, out float4 position : POSITION0, out float3 eyeNormal : TEXCOORD0, out float3 eyeView : TEXCOORD1, out float3 eyeTangent : TEXCOORD2, out float3 eyeBinormal : TEXCOORD3) { // Must write gl_Position for rasterization to be defined.... // position = mul( vertex, wvp); // Transform to shading space (we are going to shade in eyespace) // // eyeNormal = mul( normal, float3x3(wvIT)); eyeTangent = mul( tangent, float3x3(wvIT)); eyeBinormal = mul( binormal, float3x3(wvIT)); eyeView = -mul( vertex, wv).xyz; } float3 lightDir = float3( 0.57735, 0.57735, 0.57735); float3 lightColor = float3( 1.0, 1.0, 1.0); float xRoughness = 0.5; float yRoughness = 0.15; float4 mainPS( float3 eyeNormal : TEXCOORD0, float3 eyeView : TEXCOORD1, float3 eyeTangent : TEXCOORD2, float3 eyeBinormal : TEXCOORD3) : COLOR0 { // // Since the EyeNormal is getting interpolated, we // have to first restore it by normalizing it. // float3 norm = normalize( eyeNormal ); float3 view = normalize(eyeView); float3 hvec = normalize(view+lightDir); float3 tan = normalize(eyeTangent) / xRoughness; float3 binorm = normalize(cross(norm,tan)) / yRoughness; float cos_theta_r = clamp( dot( norm, view), 0.0, 1.0); float cos_theta_i = clamp( dot( norm, lightDir), 0.0, 1.0); float xDotH = dot( tan, hvec); float yDotH = dot( binorm, hvec); float rho = exp( -2.0*(xDotH*xDotH + yDotH*yDotH) / (1.0 + dot(hvec, norm))); rho = rho * rsqrt( cos_theta_i * cos_theta_r); float illum = ( cos_theta_i > 0.0) ? cos_theta_i * rho : 0.0; illum /= 4.0*xRoughness*yRoughness; return float4( illum*lightColor, 1.0); } //////// techniques //////////////////////////// technique aniso { pass p0 { VertexShader = compile vs_2_0 mainVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LEqual; CullMode = Back; PixelShader = compile ps_2_0 mainPS(); } }