Stream.fx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //-----------------------------------------------------------------------------
  2. // ©2008 Electronic Arts Inc
  3. // Never do this, this is a hard coded shader for the Desolator Toxic Streams.
  4. //-----------------------------------------------------------------------------
  5. #include "Common.fxh"
  6. #include "Gamma.fxh"
  7. // ----------------------------------------------------------------------------
  8. // Texture1
  9. // ----------------------------------------------------------------------------
  10. SAMPLER_2D_BEGIN( Texture1,
  11. string UIWidget = "None";
  12. )
  13. MinFilter = Linear;
  14. MagFilter = Linear;
  15. MipFilter = Linear;
  16. AddressU = Wrap;
  17. AddressV = Wrap;
  18. SAMPLER_2D_END
  19. // ----------------------------------------------------------------------------
  20. // Texture2
  21. // ----------------------------------------------------------------------------
  22. SAMPLER_2D_BEGIN( Texture2,
  23. string UIWidget = "None";
  24. )
  25. MinFilter = Linear;
  26. MagFilter = Linear;
  27. MipFilter = Linear;
  28. AddressU = Wrap;
  29. AddressV = Wrap;
  30. SAMPLER_2D_END
  31. // ----------------------------------------------------------------------------
  32. // Shroud
  33. // ----------------------------------------------------------------------------
  34. ShroudSetup Shroud
  35. <
  36. string UIWidget = "None";
  37. string SasBindAddress = "Terrain.Shroud";
  38. > = DEFAULT_SHROUD;
  39. SAMPLER_2D_BEGIN( ShroudTexture,
  40. string UIWidget = "None";
  41. string SasBindAddress = "Terrain.Shroud.Texture";
  42. string ResourceName = "ShaderPreviewShroud.dds";
  43. )
  44. MinFilter = Linear;
  45. MagFilter = Linear;
  46. MipFilter = Linear;
  47. AddressU = Clamp;
  48. AddressV = Clamp;
  49. SAMPLER_2D_END
  50. // ----------------------------------------------------------------------------
  51. // Transformations
  52. // ----------------------------------------------------------------------------
  53. float4x3 World : World;
  54. #if defined(_WW3D_)
  55. #if !defined(USE_INDIRECT_CONSTANT)
  56. float4x4 ViewProjection
  57. <
  58. string UIWidget = "None";
  59. string SasBindAddress = "Sas.Camera.WorldToProjection";
  60. >;
  61. float3 EyePosition
  62. <
  63. string UIWidget = "None";
  64. string SasBindAddress = "Sas.Camera.Position";
  65. >;
  66. #endif // #if !defined(USE_INDIRECT_CONSTANT)
  67. float4x4 GetViewProjection()
  68. {
  69. return ViewProjection;
  70. }
  71. float3 GetEyePosition()
  72. {
  73. return EyePosition;
  74. }
  75. #else // #if defined(_WW3D_)
  76. float4x4 View : View;
  77. float4x3 ViewI : ViewInverse;
  78. float4x4 Projection : Projection;
  79. float4x4 GetViewProjection()
  80. {
  81. return mul(View, Projection);
  82. }
  83. float3 GetEyePosition()
  84. {
  85. return ViewI[3];
  86. }
  87. #endif // #if defined(_WW3D_)
  88. float Time : Time;
  89. //-----------------------------------------------------------------------------
  90. // Vertex Shader structure
  91. //-----------------------------------------------------------------------------
  92. struct VSInput
  93. {
  94. float3 Position : POSITION;
  95. float2 DiffuseTexCoord : TEXCOORD0;
  96. float3 Normal : NORMAL;
  97. };
  98. struct VSOutput
  99. {
  100. float4 Position : POSITION;
  101. float4 DiffuseTexCoord : TEXCOORD0;
  102. float2 ShroudTexCoord : TEXCOORD3;
  103. };
  104. //-----------------------------------------------------------------------------
  105. // Vertex Shader
  106. //-----------------------------------------------------------------------------
  107. VSOutput VS( VSInput Input )
  108. {
  109. VSOutput Output;
  110. // Position is already in world space
  111. Output.Position = mul( float4( Input.Position, 1 ), GetViewProjection() );
  112. // Copy UVs
  113. Output.DiffuseTexCoord.xy = float2(Input.DiffuseTexCoord.x + Time, Input.DiffuseTexCoord.y + Time);
  114. Output.DiffuseTexCoord.zw = float2(Input.DiffuseTexCoord.x * .5 - Time, Input.DiffuseTexCoord.y * .5 + Time);
  115. // Calculate Shroud UVs
  116. // Note: Input is already in world space
  117. Output.ShroudTexCoord = CalculateShroudTexCoord( Shroud, Input.Position );
  118. return Output;
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Pixel Shader
  122. //-----------------------------------------------------------------------------
  123. float4 PS( VSOutput Input, uniform bool applyGammaCorrection ) : Color
  124. {
  125. float4 texture1 = tex2D( SAMPLER(Texture1), Input.DiffuseTexCoord.xy );
  126. float4 texture2 = tex2D( SAMPLER(Texture1), Input.DiffuseTexCoord.zw);
  127. if (applyGammaCorrection)
  128. {
  129. texture1.xyz = GammaToLinear(texture1.xyz);
  130. texture2.xyz = GammaToLinear(texture2.xyz);
  131. }
  132. float4 color = min(texture1 * texture2,1);
  133. // Apply shroud
  134. float shroud = tex2D( SAMPLER(ShroudTexture), Input.ShroudTexCoord ).x;
  135. shroud = BiasShroudValueForEffects( shroud );
  136. color.xyz *= shroud;
  137. return color;
  138. }
  139. //-----------------------------------------------------------------------------
  140. // Techniques
  141. //-----------------------------------------------------------------------------
  142. technique Multiply
  143. {
  144. pass pass0
  145. {
  146. VertexShader = compile VS_2_0 VS();
  147. PixelShader = compile PS_2_0 PS(true);
  148. ZEnable = true;
  149. ZWriteEnable = false;
  150. ZFunc = ZFUNC_INFRONT;
  151. AlphaBlendEnable = true;
  152. CullMode = CCW;
  153. SrcBlend = Zero;
  154. DestBlend = InvSrcColor;
  155. }
  156. }
  157. technique Additive
  158. {
  159. pass pass0
  160. {
  161. VertexShader = compile VS_2_0 VS();
  162. PixelShader = compile PS_2_0 PS(true);
  163. ZEnable = true;
  164. ZWriteEnable = false;
  165. ZFunc = ZFUNC_INFRONT;
  166. AlphaBlendEnable = true;
  167. CullMode = CCW;
  168. SrcBlend = One;
  169. DestBlend = One;
  170. }
  171. }
  172. #if ENABLE_LOD
  173. technique Multiply_M
  174. {
  175. pass pass0
  176. {
  177. VertexShader = compile VS_2_0 VS();
  178. PixelShader = compile PS_2_0 PS(false);
  179. ZEnable = true;
  180. ZWriteEnable = false;
  181. ZFunc = ZFUNC_INFRONT;
  182. AlphaBlendEnable = true;
  183. CullMode = CCW;
  184. SrcBlend = Zero;
  185. DestBlend = InvSrcColor;
  186. }
  187. }
  188. technique Additive_M
  189. {
  190. pass pass0
  191. {
  192. VertexShader = compile VS_2_0 VS();
  193. PixelShader = compile PS_2_0 PS(false);
  194. ZEnable = true;
  195. ZWriteEnable = false;
  196. ZFunc = ZFUNC_INFRONT;
  197. AlphaBlendEnable = true;
  198. CullMode = CCW;
  199. SrcBlend = One;
  200. DestBlend = One;
  201. }
  202. }
  203. #endif // if ENABLE_LOD