Laser.fx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 = Clamp;
  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 = Clamp;
  30. AddressV = Wrap;
  31. SAMPLER_2D_END
  32. float3 ColorEmissive
  33. <
  34. string UIName = "Emissive Material Color";
  35. string UIWidget = "Color";
  36. > = float3(1.0, 1.0, 1.0);
  37. // ----------------------------------------------------------------------------
  38. // Shroud
  39. // ----------------------------------------------------------------------------
  40. ShroudSetup Shroud
  41. <
  42. string UIWidget = "None";
  43. string SasBindAddress = "Terrain.Shroud";
  44. > = DEFAULT_SHROUD;
  45. SAMPLER_2D_BEGIN( ShroudTexture,
  46. string UIWidget = "None";
  47. string SasBindAddress = "Terrain.Shroud.Texture";
  48. string ResourceName = "ShaderPreviewShroud.dds";
  49. )
  50. MinFilter = Linear;
  51. MagFilter = Linear;
  52. MipFilter = Linear;
  53. AddressU = Clamp;
  54. AddressV = Clamp;
  55. SAMPLER_2D_END
  56. //-----------------------------------------------------------------------------
  57. // Vertex Shader structure
  58. //-----------------------------------------------------------------------------
  59. struct VSInput
  60. {
  61. float3 Position : POSITION;
  62. float2 UV0 : TEXCOORD0;
  63. float2 UV1 : TEXCOORD1;
  64. float Opacity : COLOR0;
  65. };
  66. struct VSOutput
  67. {
  68. float4 Position : POSITION;
  69. float2 UV0 : TEXCOORD0;
  70. float2 UV1 : TEXCOORD1;
  71. float2 ShroudTexCoord : TEXCOORD2;
  72. float Opacity : COLOR0;
  73. };
  74. //-----------------------------------------------------------------------------
  75. // Pixel Shader structures
  76. //-----------------------------------------------------------------------------
  77. struct PSOutput
  78. {
  79. float4 Color : COLOR0;
  80. };
  81. //-----------------------------------------------------------------------------
  82. // Vertex Shader
  83. //-----------------------------------------------------------------------------
  84. VSOutput VS( VSInput Input )
  85. {
  86. VSOutput Output;
  87. Output.Position = mul( float4( Input.Position, 1 ), WorldViewProjection );
  88. Output.UV0 = Input.UV0;
  89. Output.UV1 = Input.UV1;
  90. Output.Opacity = Input.Opacity;
  91. // Calculate Shroud UVs
  92. float3 worldPosition = mul( float4( Input.Position, 1), World );
  93. Output.ShroudTexCoord = CalculateShroudTexCoord( Shroud, worldPosition );
  94. return Output;
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Pixel Shader
  98. //-----------------------------------------------------------------------------
  99. PSOutput PS( VSOutput Input, uniform bool applyGammaCorrection )
  100. {
  101. PSOutput Output;
  102. float4 texture1 = tex2D( SAMPLER(Texture1), Input.UV0 );
  103. float4 texture2 = tex2D( SAMPLER(Texture2), Input.UV1 );
  104. Output.Color = texture1 * texture2;
  105. Output.Color.xyz *= ColorEmissive;
  106. Output.Color.w *= Input.Opacity;
  107. if (applyGammaCorrection)
  108. {
  109. Output.Color.xyz = GammaToLinear(Output.Color.xyz);
  110. }
  111. // Apply shroud
  112. float shroud = tex2D( SAMPLER(ShroudTexture), Input.ShroudTexCoord ).x;
  113. shroud = BiasShroudValueForEffects( shroud );
  114. Output.Color.xyz *= shroud;
  115. return Output;
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Techniques
  119. //-----------------------------------------------------------------------------
  120. technique Default
  121. {
  122. pass pass0
  123. {
  124. VertexShader = compile VS_2_0 VS();
  125. PixelShader = compile PS_2_0 PS(true);
  126. ZEnable = true;
  127. ZWriteEnable = false;
  128. ZFunc = ZFUNC_INFRONT;
  129. AlphaTestEnable = false;
  130. AlphaBlendEnable = true;
  131. CullMode = none;
  132. SrcBlend = SrcAlpha; //One;
  133. DestBlend = One;
  134. }
  135. }
  136. technique Default_M
  137. {
  138. pass pass0
  139. {
  140. VertexShader = compile VS_2_0 VS();
  141. PixelShader = compile PS_2_0 PS(false);
  142. ZEnable = true;
  143. ZWriteEnable = false;
  144. ZFunc = ZFUNC_INFRONT;
  145. AlphaTestEnable = false;
  146. AlphaBlendEnable = true;
  147. CullMode = none;
  148. SrcBlend = SrcAlpha; //One;
  149. DestBlend = One;
  150. }
  151. }