Simple.fx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2005 Electronic Arts Inc
  3. //
  4. // FX Shader for simple unlit rendering
  5. //////////////////////////////////////////////////////////////////////////////
  6. #include "Common.fxh"
  7. #if defined(EA_PLATFORM_WINDOWS)
  8. // ----------------------------------------------------------------------------
  9. // SAMPLER : nhendricks : had to pull these in here for MAX to compile
  10. // ----------------------------------------------------------------------------
  11. #define SAMPLER_2D_BEGIN(samplerName, annotations) \
  12. texture samplerName \
  13. < \
  14. annotations \
  15. >; \
  16. sampler2D samplerName##Sampler = sampler_state \
  17. { \
  18. Texture = < samplerName >;
  19. #define SAMPLER_2D_END };
  20. #define SAMPLER( samplerName ) samplerName##Sampler
  21. #define SAMPLER_CUBE_BEGIN(samplerName, annotations) \
  22. texture samplerName \
  23. < \
  24. annotations \
  25. >; \
  26. samplerCUBE samplerName##Sampler = sampler_state \
  27. { \
  28. Texture = < samplerName >;
  29. #define SAMPLER_CUBE_END };
  30. #endif
  31. // ----------------------------------------------------------------------------
  32. // Material parameters
  33. // ----------------------------------------------------------------------------
  34. float3 ColorEmissive
  35. <
  36. string UIName = "Emissive Material Color";
  37. string UIWidget = "Color";
  38. > = float3(1.0, 1.0, 1.0);
  39. SAMPLER_2D_BEGIN( Texture_0,
  40. string UIName = "Base Texture";
  41. )
  42. MinFilter = MinFilterBest;
  43. MagFilter = MagFilterBest;
  44. MipFilter = MipFilterBest;
  45. AddressU = Wrap;
  46. AddressV = Wrap;
  47. SAMPLER_2D_END
  48. float4 TexCoordTransform_0
  49. <
  50. string UIName = "UV0 Scl/Move";
  51. string UIWidget = "Spinner";
  52. float UIMin = -100;
  53. float UIMax = 100;
  54. > = float4(1.0, 1.0, 0.0, 0.0);
  55. bool DepthWriteEnable
  56. <
  57. string UIName = "Depth Write Enable";
  58. > = true;
  59. bool AlphaBlendingEnable
  60. <
  61. string UIName = "Alpha Blend Enable";
  62. > = false;
  63. bool FogEnable
  64. <
  65. string UIName = "Fog Enable";
  66. > = true;
  67. WW3DFog Fog
  68. <
  69. string UIWidget = "None";
  70. string SasBindAddress = "WW3D.Fog";
  71. > = DEFAULT_FOG_DISABLED;
  72. // ----------------------------------------------------------------------------
  73. // Transformations
  74. // ----------------------------------------------------------------------------
  75. float4x4 WorldViewProjection : WorldViewProjection;
  76. float4x3 World : World;
  77. float4x3 ViewI : ViewInverse;
  78. float Time : Time;
  79. // ----------------------------------------------------------------------------
  80. // SHADER: VS
  81. // ----------------------------------------------------------------------------
  82. struct VSOutput
  83. {
  84. float4 Position : POSITION;
  85. float3 DiffuseColor : COLOR0;
  86. float Fog : COLOR1;
  87. float2 BaseTexCoord : TEXCOORD0;
  88. };
  89. // ----------------------------------------------------------------------------
  90. VSOutput VS(float3 Position : POSITION, float2 TexCoord0 : TEXCOORD0)
  91. {
  92. VSOutput Out;
  93. Out.Position = mul(float4(Position, 1), WorldViewProjection);
  94. float3 worldPosition = mul(float4(Position, 1), World);
  95. Out.DiffuseColor = ColorEmissive;
  96. Out.BaseTexCoord = TexCoord0 * TexCoordTransform_0.xy + Time * TexCoordTransform_0.zw;
  97. Fog.IsEnabled = Fog.IsEnabled && FogEnable;
  98. Out.Fog = CalculateFog(Fog, worldPosition, ViewI[3]);
  99. return Out;
  100. }
  101. // ----------------------------------------------------------------------------
  102. float4 PS(VSOutput In) : COLOR
  103. {
  104. float4 color = float4(In.DiffuseColor, 1.0);
  105. color *= tex2D( SAMPLER(Texture_0), In.BaseTexCoord);
  106. color.xyz = lerp(Fog.Color, color.xyz, In.Fog);
  107. return color;
  108. }
  109. technique Default
  110. {
  111. pass P0
  112. {
  113. VertexShader = compile VS_VERSION_LOW VS();
  114. PixelShader = compile PS_VERSION_LOW PS();
  115. ZEnable = true;
  116. ZFunc = ZFUNC_INFRONT;
  117. ZWriteEnable = ( DepthWriteEnable );
  118. CullMode = CW;
  119. AlphaTestEnable = false;
  120. AlphaBlendEnable = ( AlphaBlendingEnable );
  121. SrcBlend = SrcAlpha;
  122. DestBlend = InvSrcAlpha;
  123. }
  124. }