Advertisement
Guest User

Untitled

a guest
Apr 24th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. float4x4 World;
  2. float4x4 View;
  3. float4x4 Projection;
  4. float3 LightDir;
  5.  
  6. texture DiffuseMap;
  7. texture HeightMap;
  8. texture NormalMap;
  9.  
  10. sampler Diffuse = sampler_state {
  11. texture = (DiffuseMap);
  12. MinFilter = Anisotropic;
  13. MagFilter = Linear;
  14. MipFilter = Linear;
  15. AddressU = Wrap;
  16. AddressV = Wrap;
  17. };
  18.  
  19. sampler Height = sampler_state {
  20. texture = (HeightMap);
  21. MinFilter = Anisotropic;
  22. MagFilter = Linear;
  23. MipFilter = Linear;
  24. AddressU = Wrap;
  25. AddressV = Wrap;
  26. };
  27.  
  28. sampler Normal = sampler_state {
  29. texture = (NormalMap);
  30. MinFilter = Anisotropic;
  31. MagFilter = Linear;
  32. MipFilter = Linear;
  33. AddressU = Wrap;
  34. AddressV = Wrap;
  35. };
  36.  
  37.  
  38. struct VertexShaderInput
  39. {
  40. float4 Position : POSITION0;
  41. float3 Normal : NORMAL0;
  42. float3 Tangent : Tangent0;
  43. float2 UV : TEXCOORD0;
  44. };
  45.  
  46. struct VertexShaderOutput
  47. {
  48. float4 Position : POSITION0;
  49. float3 LightPosition : TexCoord1;
  50. float3 Normal : TexCoord2;
  51. float3 Tangent : TexCoord3;
  52. float3 Bitangent : TexCoord4;
  53. float2 UV : TEXCOORD0;
  54. };
  55.  
  56. struct PixelShaderInput
  57. {
  58. float3 LightPosition : TexCoord1;
  59. float3 Normal : TexCoord2;
  60. float3 Tangent : TexCoord3;
  61. float3 Bitangent : TexCoord4;
  62. float2 UV : TEXCOORD0;
  63. };
  64.  
  65. VertexShaderOutput VertexShaderFunction(VertexShaderInput i)
  66. {
  67. VertexShaderOutput o;
  68.  
  69. o.LightPosition = mul(i.Position, mul(World, View));
  70. o.Position = mul(float4(o.LightPosition, 1), Projection);
  71. o.Normal = mul(i.Normal, (float3x3)World);
  72. o.Tangent = mul(i.Tangent, (float3x3)World);
  73. o.Bitangent = cross(o.Normal, o.Tangent);
  74. o.UV = i.UV;
  75.  
  76. return o;
  77. }
  78.  
  79. float SpecValue(float2 uv)
  80. {
  81. float h = tex2D(Height, uv).x;
  82. if (h < 0.6)
  83. return 1.0;
  84. else if (h < 0.75)
  85. return 0.0;
  86. else
  87. return saturate((h - 0.75) * 3);
  88. }
  89.  
  90. float4 PixelShaderFunction(PixelShaderInput i) : COLOR0
  91. {
  92. float2 uv = i.UV;
  93. float3 wp = i.LightPosition;
  94. float4 diffuse = tex2D(Diffuse, uv);
  95. float3 N = tex2D(Normal, uv) * 2 - 1;
  96. N = normalize(N.r * i.Tangent + N.g * i.Bitangent + N.b * i.Normal);
  97. float NdotL = saturate(dot(N, LightDir));
  98. // the camera is at 0, 0, 0, so I don't need to reconstruct the lightspace ray explicitly
  99. float3 R = normalize(wp - N * (dot(wp, N) * 2));
  100. float RdotL = saturate(dot(R, LightDir));
  101. float4 lightColor = diffuse * lerp(float4(0.25, 0.25, 0.25, 1), float4(1, 1, 1, 1), NdotL);
  102. lightColor += float4(1, 1, 1, 0) * (pow(RdotL, 80) * SpecValue(uv));
  103. return lightColor;
  104. }
  105.  
  106. technique Technique1
  107. {
  108. pass Pass1
  109. {
  110. ZEnable = TRUE;
  111. ZWriteEnable = TRUE;
  112. ZFunc = LessEqual;
  113. AlphaBlendEnable = False;
  114. CullMode = CCW;
  115.  
  116. VertexShader = compile vs_3_0 VertexShaderFunction();
  117. PixelShader = compile ps_3_0 PixelShaderFunction();
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement