Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float4x4 World;
- float4x4 View;
- float4x4 Projection;
- float3 LightDir;
- texture DiffuseMap;
- texture HeightMap;
- texture NormalMap;
- sampler Diffuse = sampler_state {
- texture = (DiffuseMap);
- MinFilter = Anisotropic;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Wrap;
- AddressV = Wrap;
- };
- sampler Height = sampler_state {
- texture = (HeightMap);
- MinFilter = Anisotropic;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Wrap;
- AddressV = Wrap;
- };
- sampler Normal = sampler_state {
- texture = (NormalMap);
- MinFilter = Anisotropic;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Wrap;
- AddressV = Wrap;
- };
- struct VertexShaderInput
- {
- float4 Position : POSITION0;
- float3 Normal : NORMAL0;
- float3 Tangent : Tangent0;
- float2 UV : TEXCOORD0;
- };
- struct VertexShaderOutput
- {
- float4 Position : POSITION0;
- float3 LightPosition : TexCoord1;
- float3 Normal : TexCoord2;
- float3 Tangent : TexCoord3;
- float3 Bitangent : TexCoord4;
- float2 UV : TEXCOORD0;
- };
- struct PixelShaderInput
- {
- float3 LightPosition : TexCoord1;
- float3 Normal : TexCoord2;
- float3 Tangent : TexCoord3;
- float3 Bitangent : TexCoord4;
- float2 UV : TEXCOORD0;
- };
- VertexShaderOutput VertexShaderFunction(VertexShaderInput i)
- {
- VertexShaderOutput o;
- o.LightPosition = mul(i.Position, mul(World, View));
- o.Position = mul(float4(o.LightPosition, 1), Projection);
- o.Normal = mul(i.Normal, (float3x3)World);
- o.Tangent = mul(i.Tangent, (float3x3)World);
- o.Bitangent = cross(o.Normal, o.Tangent);
- o.UV = i.UV;
- return o;
- }
- float SpecValue(float2 uv)
- {
- float h = tex2D(Height, uv).x;
- if (h < 0.6)
- return 1.0;
- else if (h < 0.75)
- return 0.0;
- else
- return saturate((h - 0.75) * 3);
- }
- float4 PixelShaderFunction(PixelShaderInput i) : COLOR0
- {
- float2 uv = i.UV;
- float3 wp = i.LightPosition;
- float4 diffuse = tex2D(Diffuse, uv);
- float3 N = tex2D(Normal, uv) * 2 - 1;
- N = normalize(N.r * i.Tangent + N.g * i.Bitangent + N.b * i.Normal);
- float NdotL = saturate(dot(N, LightDir));
- // the camera is at 0, 0, 0, so I don't need to reconstruct the lightspace ray explicitly
- float3 R = normalize(wp - N * (dot(wp, N) * 2));
- float RdotL = saturate(dot(R, LightDir));
- float4 lightColor = diffuse * lerp(float4(0.25, 0.25, 0.25, 1), float4(1, 1, 1, 1), NdotL);
- lightColor += float4(1, 1, 1, 0) * (pow(RdotL, 80) * SpecValue(uv));
- return lightColor;
- }
- technique Technique1
- {
- pass Pass1
- {
- ZEnable = TRUE;
- ZWriteEnable = TRUE;
- ZFunc = LessEqual;
- AlphaBlendEnable = False;
- CullMode = CCW;
- VertexShader = compile vs_3_0 VertexShaderFunction();
- PixelShader = compile ps_3_0 PixelShaderFunction();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement