| ////////////////////////////////////////////////// |
| // Normal debugging shader |
| ////////////////////////////////////////////////// |
| |
| struct VertexIn |
| { |
| float4 position : POSITION0; |
| float2 texCoords : TEXCOORD0; |
| float3 normal : NORMAL0; |
| float3 tangent : TANGENT0; |
| float3 binormal : BINORMAL0; |
| }; |
| |
| struct VertexToPixelBuggedNormal |
| { |
| float4 position : POSITION; |
| float2 texCoords : TEXCOORD0; |
| float3 viewVector : TEXCOORD1; |
| float3 normal : TEXCOORD2; |
| |
| float3x3 tangentToWorld : TEXCOORD3; |
| }; |
| |
| VertexToPixelBuggedNormal BuggedNormalVertexShader(VertexIn input) |
| { |
| VertexToPixelBuggedNormal output = (VertexToPixelBuggedNormal)0; |
| |
| output.position = mul(input.position, CameraTransform); |
| |
| output.texCoords = input.texCoords; |
| |
| output.normal = normalize(mul(float4(input.normal,1.0f), WorldTransform)); |
| |
| output.viewVector = -(DirectionalLightDirection.xyz*50) - mul(input.position, WorldTransform); |
| |
| output.tangentToWorld[0] = mul(float4(input.tangent,1.0f),WorldTransform).xyz; |
| output.tangentToWorld[1] = mul(float4(input.binormal,1.0f),WorldTransform).xyz; |
| output.tangentToWorld[2] = mul(float4(input.normal,1.0f), WorldTransform).xyz; |
| |
| return output; |
| } |
| |
| PixelToFrame BuggedNormalPixelShader(VertexToPixelBuggedNormal input) |
| { |
| PixelToFrame output = (PixelToFrame)0; |
| |
| // clean up our inputs a bit |
| input.viewVector = normalize(input.viewVector); |
| |
| // bump map |
| float3 bumpNorm = (2 * (tex2D(BumpSampler, input.texCoords).rgb-0.5f)); |
| bumpNorm = normalize(mul(bumpNorm,input.tangentToWorld)); |
| |
| // directional light |
| float4 DirectionalLighting = (dot(bumpNorm, input.viewVector)) * DirectionalLightColor; |
| |
| // base color |
| float4 baseColor = tex2D(TextureSampler, input.texCoords); |
| |
| // adjust for lighting |
| baseColor.xyz *= saturate(DirectionalLighting + AmbientColor).xyz; |
| |
| output.Color = baseColor; |
| |
| return output; |
| } |
| |
| technique BuggedNormal |
| { |
| pass Pass0 |
| { |
| VertexShader = compile vs_2_0 BuggedNormalVertexShader(); |
| PixelShader = compile ps_2_0 BuggedNormalPixelShader(); |
| } |
| } |
| |