Render2D.fx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2006 Electronic Arts Inc
  3. //
  4. // FX Shader for Render2D
  5. //////////////////////////////////////////////////////////////////////////////
  6. #include "Common.fxh"
  7. // ----------------------------------------------------------------------------
  8. // Textures declaration
  9. // ----------------------------------------------------------------------------
  10. SAMPLER_2D_BEGIN(BaseTexture,
  11. string SasBindAddress = "WW3D.MiscTexture";
  12. int WW3DDynamicSet = DS_CUSTOM_FIRST;
  13. )
  14. AddressU = Clamp;
  15. AddressV = Clamp;
  16. MinFilter = Linear;
  17. MagFilter = Linear;
  18. MipFilter = Linear;
  19. SAMPLER_2D_END
  20. // ----------------------------------------------------------------------------
  21. // Transformations
  22. // ----------------------------------------------------------------------------
  23. float4x4 World : World;
  24. // ---------------------------------------------------------------------------
  25. struct VSOutput
  26. {
  27. float4 Position : POSITION;
  28. float4 Color : COLOR0;
  29. float2 BaseTexCoord : TEXCOORD0;
  30. };
  31. // ---------------------------------------------------------------------------
  32. VSOutput VS(float3 Position : POSITION, float2 TexCoord0 : TEXCOORD0, float4 color : COLOR0 )
  33. {
  34. VSOutput Out;
  35. Out.Position = mul(float4(Position, 1), World);
  36. Out.Color = color;
  37. Out.BaseTexCoord = TexCoord0;
  38. return Out;
  39. }
  40. // ---------------------------------------------------------------------------
  41. float4 PS(VSOutput In) : COLOR
  42. {
  43. // Get vertex color
  44. float4 color = In.Color;
  45. // Apply texture
  46. color *= tex2D(SAMPLER(BaseTexture), In.BaseTexCoord);
  47. return color;
  48. }
  49. // ---------------------------------------------------------------------------
  50. float4 PSGray(VSOutput In) : COLOR
  51. {
  52. // Get vertex color
  53. float4 color = In.Color;
  54. // Get texture
  55. float4 textureSample = tex2D(SAMPLER(BaseTexture), In.BaseTexCoord);
  56. // Convert texture to gray scale
  57. float3 grayMix = float3(0.30, 0.59, 0.11);
  58. color.xyz *= dot(textureSample.xyz, grayMix);
  59. // Multiply alpha
  60. color.w *= textureSample.w;
  61. return color;
  62. }
  63. // ---------------------------------------------------------------------------
  64. float4 PSIgnoreTextureAlpha(VSOutput In) : COLOR
  65. {
  66. // Get vertex color
  67. float4 color = In.Color;
  68. // Apply texture
  69. color.xyz *= tex2D(SAMPLER(BaseTexture), In.BaseTexCoord);
  70. return color;
  71. }
  72. // ---------------------------------------------------------------------------
  73. technique Copy
  74. {
  75. pass P0
  76. {
  77. VertexShader = compile VS_2_0 VS();
  78. PixelShader = compile PS_2_0 PS();
  79. ZEnable = false;
  80. ZWriteEnable = false;
  81. CullMode = None;
  82. AlphaBlendEnable = false;
  83. AlphaTestEnable = false;
  84. }
  85. }
  86. technique Additive
  87. {
  88. pass P0
  89. {
  90. VertexShader = compile VS_2_0 VS();
  91. PixelShader = compile PS_2_0 PS();
  92. ZEnable = false;
  93. ZWriteEnable = false;
  94. CullMode = None;
  95. AlphaBlendEnable = true;
  96. SrcBlend = One;
  97. DestBlend = One;
  98. AlphaTestEnable = false;
  99. }
  100. }
  101. technique AlphaBlend
  102. {
  103. pass P0
  104. {
  105. VertexShader = compile VS_2_0 VS();
  106. PixelShader = compile PS_2_0 PS();
  107. ZEnable = false;
  108. ZWriteEnable = false;
  109. CullMode = None;
  110. AlphaBlendEnable = true;
  111. SrcBlend = SrcAlpha;
  112. DestBlend = InvSrcAlpha;
  113. AlphaTestEnable = false;
  114. }
  115. }
  116. technique Gray
  117. {
  118. pass P0
  119. {
  120. VertexShader = compile VS_2_0 VS();
  121. PixelShader = compile PS_2_0 PSGray();
  122. ZEnable = false;
  123. ZWriteEnable = false;
  124. CullMode = None;
  125. AlphaBlendEnable = true;
  126. SrcBlend = SrcAlpha;
  127. DestBlend = InvSrcAlpha;
  128. AlphaTestEnable = false;
  129. }
  130. }
  131. technique GrayCopy
  132. {
  133. pass P0
  134. {
  135. VertexShader = compile VS_2_0 VS();
  136. PixelShader = compile PS_2_0 PSGray();
  137. ZEnable = false;
  138. ZWriteEnable = false;
  139. CullMode = None;
  140. AlphaBlendEnable = false;
  141. AlphaTestEnable = false;
  142. }
  143. }
  144. technique AlphaTestCopy
  145. {
  146. pass P0
  147. {
  148. VertexShader = compile VS_2_0 VS();
  149. PixelShader = compile PS_2_0 PS();
  150. ZEnable = false;
  151. ZWriteEnable = false;
  152. CullMode = None;
  153. AlphaBlendEnable = false;
  154. AlphaTestEnable = true;
  155. AlphaFunc = GreaterEqual;
  156. AlphaRef = DEFAULT_ALPHATEST_THRESHOLD;
  157. }
  158. }
  159. technique AlphaWithSolidTexture
  160. {
  161. pass P0
  162. {
  163. VertexShader = compile VS_2_0 VS();
  164. PixelShader = compile PS_2_0 PSIgnoreTextureAlpha();
  165. ZEnable = false;
  166. ZWriteEnable = false;
  167. CullMode = None;
  168. AlphaBlendEnable = false;
  169. SrcBlend = SrcAlpha;
  170. DestBlend = InvSrcAlpha;
  171. AlphaTestEnable = false;
  172. }
  173. }
  174. technique AptRenderer
  175. {
  176. pass P0
  177. {
  178. VertexShader = compile VS_2_0 VS();
  179. PixelShader = compile PS_2_0 PS();
  180. ZEnable = false;
  181. ZWriteEnable = false;
  182. CullMode = None;
  183. AlphaBlendEnable = true;
  184. SrcBlend = SrcAlpha;
  185. DestBlend = InvSrcAlpha;
  186. AlphaTestEnable = false;
  187. }
  188. }