Simple.fx 4.0 KB

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