Advertisement
Guest User

terrain.fx

a guest
Jan 6th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include "lighthelper.fx"
  2.  
  3. cbuffer cbPerFrame
  4. {
  5. float4x4 gWorld;
  6. float4x4 gWVP;
  7. float4 gDirToSunW;
  8. };
  9.  
  10. cbuffer cbFixed
  11. {
  12. float gTexScale = 20;
  13. };
  14.  
  15. // Nonnumeric values cannot be added to a cbuffer.
  16. Texture2D gLayer0;
  17. Texture2D gLayer1;
  18. Texture2D gLayer2;
  19. Texture2D gLayer3;
  20. Texture2D gLayer4;
  21. Texture2D gBlendMap;
  22.  
  23. SamplerState gTriLinearSam
  24. {
  25. Filter = MIN_MAG_MIP_LINEAR;
  26. AddressU = Wrap;
  27. AddressV = Wrap;
  28. };
  29.  
  30. struct VS_IN
  31. {
  32. float3 posL : POSITION;
  33. float3 normalL : NORMAL;
  34. float2 texC : TEXCOORD;
  35. };
  36.  
  37. struct VS_OUT
  38. {
  39. float4 posH : SV_POSITION;
  40. float shade : SHADE;
  41. float2 tiledUV : TEXCOORD0;
  42. float2 stretchedUV : TEXCOORD1;
  43. };
  44.  
  45. VS_OUT VS(VS_IN vIn)
  46. {
  47. VS_OUT vOut;
  48.  
  49. vOut.posH = mul(float4(vIn.posL, 1.0f), gWVP);
  50.  
  51. float4 normalW = mul(float4(vIn.normalL, 0.0f), gWorld);
  52.  
  53. vOut.shade = saturate(max(dot(normalW, gDirToSunW), 0.0f) + 0.1f);
  54.  
  55. vOut.tiledUV = gTexScale * vIn.texC;
  56. vOut.stretchedUV = vIn.texC;
  57.  
  58. return vOut;
  59. }
  60.  
  61. float4 PS(VS_OUT pIn) : SV_Target
  62. {
  63. float4 c0 = gLayer0.Sample( gTriLinearSam, pIn.tiledUV );
  64. float4 c1 = gLayer1.Sample( gTriLinearSam, pIn.tiledUV );
  65. float4 c2 = gLayer2.Sample( gTriLinearSam, pIn.tiledUV );
  66. float4 c3 = gLayer3.Sample( gTriLinearSam, pIn.tiledUV );
  67. float4 c4 = gLayer4.Sample( gTriLinearSam, pIn.tiledUV );
  68.  
  69. float4 t = gBlendMap.Sample( gTriLinearSam, pIn.stretchedUV );
  70.  
  71. float4 C = c0;
  72. C = lerp(C, c1, t.r);
  73. C = lerp(C, c2, t.g);
  74. C = lerp(C, c3, t.b);
  75. C = lerp(C, c4, t.a);
  76.  
  77. C *= pIn.shade;
  78.  
  79. return C;
  80. }
  81.  
  82.  
  83. technique11 TerrainTech
  84. {
  85. pass P0
  86. {
  87. SetVertexShader( CompileShader( vs_4_0, VS() ) );
  88. SetGeometryShader( NULL );
  89. SetPixelShader( CompileShader( ps_4_0, PS() ) );
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement