TerrainTracks.fx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2006 Electronic Arts Inc
  3. //
  4. // FX Shader for rendering the terrain tracks left by vehicle
  5. //////////////////////////////////////////////////////////////////////////////
  6. #include "Common.fxh"
  7. #include "Gamma.fxh"
  8. // ----------------------------------------------------------------------------
  9. // Transformations
  10. // ----------------------------------------------------------------------------
  11. #if defined(_WW3D_)
  12. #if !defined(USE_INDIRECT_CONSTANT)
  13. float4x4 ViewProjection
  14. <
  15. string UIWidget = "None";
  16. string SasBindAddress = "Sas.Camera.WorldToProjection";
  17. >;
  18. #endif // #if !defined(USE_INDIRECT_CONSTANT)
  19. float4x4 GetViewProjection()
  20. {
  21. return ViewProjection;
  22. }
  23. #else
  24. float4x4 View : View;
  25. float4x4 Projection : Projection;
  26. float4x4 GetViewProjection()
  27. {
  28. return mul(View, Projection);
  29. }
  30. #endif
  31. // ----------------------------------------------------------------------------
  32. // Textures declaration
  33. // ----------------------------------------------------------------------------
  34. SAMPLER_2D_BEGIN(Texture_0,
  35. string UIWidget = "None";
  36. string SasBindAddress = "WW3D.MiscTexture";
  37. int WW3DDynamicSet = DS_CUSTOM_FIRST;
  38. )
  39. AddressU = Clamp;
  40. AddressV = Clamp;
  41. MinFilter = Linear;
  42. MagFilter = Linear;
  43. MipFilter = Linear;
  44. SAMPLER_2D_END
  45. // ---------------------------------------------------------------------------
  46. struct VSOutput
  47. {
  48. float4 Position : POSITION;
  49. float4 DiffuseColor : COLOR0;
  50. float2 BaseTexCoord : TEXCOORD0;
  51. };
  52. // ---------------------------------------------------------------------------
  53. VSOutput VS(float3 Position : POSITION, float2 TexCoord0 : TEXCOORD0, float4 color : COLOR0 )
  54. {
  55. VSOutput Out;
  56. Out.Position = mul(float4(Position, 1), GetViewProjection());
  57. Out.DiffuseColor = color;
  58. Out.BaseTexCoord = TexCoord0;
  59. return Out;
  60. }
  61. // ---------------------------------------------------------------------------
  62. float4 PS(VSOutput In) : COLOR
  63. {
  64. // Get vertex color
  65. float4 color = In.DiffuseColor;
  66. // Apply texture
  67. float4 baseTextureColor = tex2D(SAMPLER(Texture_0), In.BaseTexCoord);
  68. baseTextureColor.xyz = GammaToLinear(baseTextureColor.xyz);
  69. color *= baseTextureColor;
  70. return color;
  71. }
  72. // ---------------------------------------------------------------------------
  73. technique Default
  74. {
  75. pass P0
  76. {
  77. VertexShader = compile VS_2_0 VS();
  78. PixelShader = compile PS_2_0 PS();
  79. ZEnable = true;
  80. ZFunc = ZFUNC_INFRONT;
  81. ZWriteEnable = false;
  82. CullMode = CW;
  83. ColorWriteEnable = RGB;
  84. AlphaBlendEnable = true;
  85. SrcBlend = SrcAlpha;
  86. DestBlend = InvSrcAlpha;
  87. AlphaTestEnable = false;
  88. }
  89. }
  90. // ---------------------------------------------------------------------------
  91. float4 PS_M(VSOutput In) : COLOR
  92. {
  93. // Get vertex color
  94. float4 color = In.DiffuseColor;
  95. // Apply texture
  96. float4 baseTextureColor = tex2D(SAMPLER(Texture_0), In.BaseTexCoord);
  97. color *= baseTextureColor;
  98. return color;
  99. }
  100. // ---------------------------------------------------------------------------
  101. technique Default_M
  102. {
  103. pass P0
  104. {
  105. VertexShader = compile VS_2_0 VS();
  106. PixelShader = compile PS_2_0 PS_M();
  107. ZEnable = true;
  108. ZFunc = ZFUNC_INFRONT;
  109. ZWriteEnable = false;
  110. CullMode = CW;
  111. ColorWriteEnable = RGB;
  112. AlphaBlendEnable = true;
  113. SrcBlend = SrcAlpha;
  114. DestBlend = InvSrcAlpha;
  115. AlphaTestEnable = false;
  116. }
  117. }