Stream.fx 6.1 KB

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