LaserAlpha.fx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //-----------------------------------------------------------------------------
  2. // ©2006 Electronic Arts Inc
  3. //-----------------------------------------------------------------------------
  4. #include "Common.fxh"
  5. #include "Gamma.fxh"
  6. float4x4 World : World;
  7. float4x4 WorldViewProjection : WorldViewProjection;
  8. // ----------------------------------------------------------------------------
  9. // Texture1
  10. // ----------------------------------------------------------------------------
  11. SAMPLER_2D_BEGIN( Texture1,
  12. string UIWidget = "None";
  13. )
  14. MinFilter = Linear;
  15. MagFilter = Linear;
  16. MipFilter = Linear;
  17. AddressU = Wrap;
  18. AddressV = Wrap;
  19. SAMPLER_2D_END
  20. // ----------------------------------------------------------------------------
  21. // Texture2
  22. // ----------------------------------------------------------------------------
  23. SAMPLER_2D_BEGIN( Texture2,
  24. string UIWidget = "None";
  25. )
  26. MinFilter = Linear;
  27. MagFilter = Linear;
  28. MipFilter = Linear;
  29. AddressU = Wrap;
  30. AddressV = Wrap;
  31. SAMPLER_2D_END
  32. // ----------------------------------------------------------------------------
  33. // Shroud
  34. // ----------------------------------------------------------------------------
  35. ShroudSetup Shroud
  36. <
  37. string UIWidget = "None";
  38. string SasBindAddress = "Terrain.Shroud";
  39. > = DEFAULT_SHROUD;
  40. SAMPLER_2D_BEGIN( ShroudTexture,
  41. string UIWidget = "None";
  42. string SasBindAddress = "Terrain.Shroud.Texture";
  43. string ResourceName = "ShaderPreviewShroud.dds";
  44. )
  45. MinFilter = Linear;
  46. MagFilter = Linear;
  47. MipFilter = Linear;
  48. AddressU = Clamp;
  49. AddressV = Clamp;
  50. SAMPLER_2D_END
  51. //-----------------------------------------------------------------------------
  52. // Vertex Shader structure
  53. //-----------------------------------------------------------------------------
  54. struct VSInput
  55. {
  56. float3 Position : POSITION;
  57. float2 UV0 : TEXCOORD0;
  58. float2 UV1 : TEXCOORD1;
  59. };
  60. struct VSOutput
  61. {
  62. float4 Position : POSITION;
  63. float2 UV0 : TEXCOORD0;
  64. float2 UV1 : TEXCOORD1;
  65. float2 ShroudTexCoord : TEXCOORD2;
  66. };
  67. //-----------------------------------------------------------------------------
  68. // Pixel Shader structures
  69. //-----------------------------------------------------------------------------
  70. struct PSOutput
  71. {
  72. float4 Color : COLOR0;
  73. };
  74. //-----------------------------------------------------------------------------
  75. // Vertex Shader
  76. //-----------------------------------------------------------------------------
  77. VSOutput VS( VSInput Input )
  78. {
  79. VSOutput Output;
  80. Output.Position = mul( float4( Input.Position, 1 ), WorldViewProjection );
  81. Output.UV0 = Input.UV0;
  82. Output.UV1 = Input.UV1;
  83. // Calculate Shroud UVs
  84. float3 worldPosition = mul( float4( Input.Position, 1), World );
  85. Output.ShroudTexCoord = CalculateShroudTexCoord( Shroud, worldPosition );
  86. return Output;
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Pixel Shader
  90. //-----------------------------------------------------------------------------
  91. PSOutput PS( VSOutput Input, uniform bool applyGammaCorrection )
  92. {
  93. PSOutput Output;
  94. float4 texture1 = tex2D( SAMPLER(Texture1), Input.UV0 );
  95. float4 texture2 = tex2D( SAMPLER(Texture2), Input.UV1 );
  96. Output.Color = texture1 * texture2;
  97. if (applyGammaCorrection)
  98. {
  99. Output.Color.xyz = GammaToLinear(Output.Color.xyz);
  100. }
  101. // Apply shroud
  102. float shroud = tex2D( SAMPLER(ShroudTexture), Input.ShroudTexCoord ).x;
  103. shroud = BiasShroudValueForEffects( shroud );
  104. Output.Color.xyz *= shroud;
  105. return Output;
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Techniques
  109. //-----------------------------------------------------------------------------
  110. technique Default
  111. {
  112. pass pass0
  113. {
  114. VertexShader = compile VS_2_0 VS();
  115. PixelShader = compile PS_2_0 PS(true);
  116. ZEnable = true;
  117. ZWriteEnable = false;
  118. ZFunc = ZFUNC_INFRONT;
  119. AlphaBlendEnable = true;
  120. CullMode = none;
  121. SrcBlend = SrcAlpha; //One;
  122. DestBlend = InvSrcAlpha;
  123. }
  124. }
  125. technique Default_M
  126. {
  127. pass pass0
  128. {
  129. VertexShader = compile VS_2_0 VS();
  130. PixelShader = compile PS_2_0 PS(false);
  131. ZEnable = true;
  132. ZWriteEnable = false;
  133. ZFunc = ZFUNC_INFRONT;
  134. AlphaBlendEnable = true;
  135. CullMode = none;
  136. SrcBlend = SrcAlpha; //One;
  137. DestBlend = InvSrcAlpha;
  138. }
  139. }