Decal.fx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2005 Electronic Arts Inc
  3. //
  4. // FX Shader for decal rendering
  5. //////////////////////////////////////////////////////////////////////////////
  6. #include "Common.fxh"
  7. #if !HIZ_CULLING
  8. #define DECAL_Z_BIAS -0.0001
  9. #else
  10. #define DECAL_Z_BIAS 0.0001
  11. #endif
  12. SAMPLER_2D_BEGIN( BaseSampler,
  13. string UIWidget = "None";
  14. string SasBindAddress = "Decal.BaseTexture";
  15. )
  16. AddressU = Clamp;
  17. AddressV = Clamp;
  18. MinFilter = Linear;
  19. MagFilter = Linear;
  20. MipFilter = Linear;
  21. SAMPLER_2D_END
  22. SAMPLER_2D_BEGIN( MaskSampler,
  23. string UIWidget = "None";
  24. string SasBindAddress = "Decal.MaskTexture";
  25. )
  26. AddressU = Clamp;
  27. AddressV = Clamp;
  28. MinFilter = Linear;
  29. MagFilter = Linear;
  30. MipFilter = Linear;
  31. SAMPLER_2D_END
  32. // ----------------------------------------------------------------------------
  33. // Transformations
  34. // ----------------------------------------------------------------------------
  35. float4x4 WorldViewProjection : WorldViewProjection;
  36. float4x3 World : World;
  37. #if defined(_WW3D_)
  38. #if !defined(USE_INDIRECT_CONSTANT)
  39. float3 EyePosition
  40. <
  41. string UIWidget = "None";
  42. string SasBindAddress = "Sas.Camera.Position";
  43. >;
  44. #endif // #if !defined(USE_INDIRECT_CONSTANT)
  45. float3 GetEyePosition()
  46. {
  47. return EyePosition;
  48. }
  49. #else // #if defined(_WW3D_)
  50. float4x3 ViewI : ViewInverse;
  51. float3 GetEyePosition()
  52. {
  53. return ViewI[3];
  54. }
  55. #endif // #if defined(_WW3D_)
  56. float Time : Time;
  57. // ----------------------------------------------------------------------------
  58. struct VSOutput
  59. {
  60. float4 Position : POSITION;
  61. float4 DiffuseColor : COLOR0;
  62. float2 BaseTexCoord : TEXCOORD0;
  63. };
  64. // ----------------------------------------------------------------------------
  65. VSOutput VS(float3 Position : POSITION, float2 TexCoord0 : TEXCOORD0, float4 color : COLOR0 )
  66. {
  67. VSOutput Out;
  68. Out.Position = mul(float4(Position, 1), WorldViewProjection);
  69. Out.DiffuseColor = color;
  70. Out.BaseTexCoord = TexCoord0;
  71. return Out;
  72. }
  73. // ----------------------------------------------------------------------------
  74. float4 PS(VSOutput In) : COLOR
  75. {
  76. float4 color = In.DiffuseColor;
  77. color *= tex2D( SAMPLER(BaseSampler), In.BaseTexCoord);
  78. return color;
  79. }
  80. // ----------------------------------------------------------------------------
  81. float4 MaskPS(VSOutput In) : COLOR
  82. {
  83. float4 color = In.DiffuseColor;
  84. color *= tex2D( SAMPLER(MaskSampler), In.BaseTexCoord);
  85. return color;
  86. }
  87. // ----------------------------------------------------------------------------
  88. technique Alpha
  89. {
  90. pass P0
  91. {
  92. VertexShader = compile VS_2_0 VS();
  93. PixelShader = compile PS_2_0 PS();
  94. ZEnable = true;
  95. ZFunc = ZFUNC_INFRONT;
  96. ZWriteEnable = false;
  97. CullMode = None;
  98. AlphaBlendEnable = true;
  99. SrcBlend = SrcAlpha;
  100. DestBlend = InvSrcAlpha;
  101. AlphaTestEnable = false;
  102. DepthBias = DECAL_Z_BIAS;
  103. }
  104. }
  105. // ----------------------------------------------------------------------------
  106. technique Add
  107. {
  108. pass P0
  109. {
  110. VertexShader = compile VS_2_0 VS();
  111. PixelShader = compile PS_2_0 PS();
  112. ZEnable = true;
  113. ZFunc = ZFUNC_INFRONT;
  114. ZWriteEnable = false;
  115. CullMode = None;
  116. AlphaBlendEnable = true;
  117. SrcBlend = One;
  118. DestBlend = One;
  119. AlphaTestEnable = false;
  120. DepthBias = DECAL_Z_BIAS;
  121. }
  122. }
  123. // ----------------------------------------------------------------------------
  124. technique Multiply
  125. {
  126. pass P0
  127. {
  128. VertexShader = compile VS_2_0 VS();
  129. PixelShader = compile PS_2_0 PS();
  130. ZEnable = true;
  131. ZFunc = ZFUNC_INFRONT;
  132. ZWriteEnable = false;
  133. CullMode = CW;
  134. AlphaBlendEnable = true;
  135. SrcBlend = Zero;
  136. DestBlend = SrcColor;
  137. AlphaTestEnable = false;
  138. DepthBias = DECAL_Z_BIAS;
  139. }
  140. }
  141. // ----------------------------------------------------------------------------
  142. technique MergeStencilPass
  143. {
  144. pass P0
  145. {
  146. VertexShader = compile VS_2_0 VS();
  147. PixelShader = compile PS_2_0 MaskPS();
  148. ZEnable = true;
  149. ZFunc = ZFUNC_INFRONT;
  150. ZWriteEnable = false;
  151. CullMode = CW;
  152. ColorWriteEnable = 0;
  153. AlphaBlendEnable = true;
  154. SrcBlend = Zero;
  155. DestBlend = One;
  156. AlphaTestEnable = true;
  157. AlphaFunc = GreaterEqual;
  158. AlphaRef = 0x60;
  159. StencilFunc = Always;
  160. StencilPass = Replace;
  161. StencilEnable = true;
  162. StencilRef = 0xff;
  163. StencilMask = 0x4;
  164. StencilWriteMask = 0x4;
  165. StencilZFail = Keep;
  166. StencilFail = Keep;
  167. DepthBias = DECAL_Z_BIAS;
  168. }
  169. }
  170. technique MergeCombinePass
  171. {
  172. pass P0
  173. {
  174. VertexShader = compile VS_2_0 VS();
  175. PixelShader = compile PS_2_0 PS();
  176. ZEnable = true;
  177. ZFunc = ZFUNC_INFRONT;
  178. ZWriteEnable = false;
  179. CullMode = CW;
  180. AlphaBlendEnable = true;
  181. SrcBlend = SrcAlpha; //One;
  182. DestBlend = InvSrcAlpha;
  183. ColorWriteEnable = RGBA;
  184. AlphaTestEnable = true;
  185. AlphaFunc = GreaterEqual;
  186. AlphaRef = 0x60;
  187. StencilFunc = NotEqual;
  188. StencilPass = Keep;
  189. StencilEnable = true;
  190. StencilRef = 0xff;
  191. StencilMask = 0x4;
  192. StencilWriteMask = 0x4;
  193. StencilZFail = Keep;
  194. StencilFail = Keep;
  195. DepthBias = DECAL_Z_BIAS;
  196. }
  197. }