ShadowMap.fxh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2008 Electronic Arts Inc
  3. //
  4. // Shadowmap header
  5. //////////////////////////////////////////////////////////////////////////////
  6. #ifndef _SHADOWMAP_FXH_
  7. #define _SHADOWMAP_FXH_
  8. #include "RegisterMap.fxh"
  9. // ----------------------------------------------------------------------------
  10. // Shadow mapping variables
  11. // ----------------------------------------------------------------------------
  12. // If we use indirect constant, this should be declared in GlobalParamaters.fxh already
  13. #if !defined(USE_INDIRECT_CONSTANT) || defined(EA_PLATFORM_WINDOWS)
  14. bool HasShadow
  15. <
  16. string UIWidget = "None";
  17. string SasBindAddress = "Sas.HasShadow";
  18. > = false;
  19. #endif
  20. #if !defined(USE_INDIRECT_CONSTANT)
  21. float4x4 ShadowMapWorldToShadow
  22. <
  23. string UIWidget = "None";
  24. string SasBindAddress = "Sas.Shadow[0].WorldToShadow";
  25. >;
  26. #endif // #if !defined(USE_INDIRECT_CONSTANT)
  27. SAMPLER_2D_BEGIN( ShadowMap,
  28. string UIWidget = "None";
  29. string SasBindAddress = "Sas.Shadow[0].ShadowMap";
  30. )
  31. MinFilter = Point;
  32. MagFilter = Point;
  33. MipFilter = None;
  34. AddressU = Clamp;
  35. AddressV = Clamp;
  36. SAMPLER_2D_END
  37. // ----------------------------------------------------------------------------
  38. // Shadow mapping constants
  39. // ----------------------------------------------------------------------------
  40. static const float shadowZBias = 0.0015; // Can use 0.001 with post processing pass
  41. // ----------------------------------------------------------------------------
  42. // Functions declaration, should be implemented in platform specific file
  43. // ----------------------------------------------------------------------------
  44. float shadow(sampler2D shadowSampler, float4 shadowTexCoord);
  45. // ----------------------------------------------------------------------------
  46. // Utility functions
  47. // ----------------------------------------------------------------------------
  48. float4 CalculateShadowMapTexCoord(float3 worldPosition)
  49. {
  50. float4 shadowTexCoord = mul(float4(worldPosition, 1), ShadowMapWorldToShadow);
  51. shadowTexCoord.xyz /= shadowTexCoord.w;
  52. shadowTexCoord.z -= shadowZBias;
  53. return shadowTexCoord;
  54. }
  55. float4 CalculateShadowMapTexCoord_PerspectiveCorrect(float3 worldPosition)
  56. {
  57. float4 shadowTexCoord = mul(float4(worldPosition, 1), ShadowMapWorldToShadow);
  58. return shadowTexCoord;
  59. }
  60. // ----------------------------------------------------------------------------
  61. // Include platform specific implementations
  62. // ----------------------------------------------------------------------------
  63. #if defined(EA_PLATFORM_XENON)
  64. #include "ShadowMap_xenon.fxh"
  65. #else // #if defined(EA_PLATFORM_XENON)
  66. #include "ShadowMap_win32.fxh"
  67. #endif // #if defined(EA_PLATFORM_XENON)
  68. float shadow_PerspectiveCorrect(sampler2D shadowSampler, float4 shadowTexCoord)
  69. {
  70. shadowTexCoord.xyz /= shadowTexCoord.w;
  71. shadowTexCoord.z -= shadowZBias;
  72. return shadow(shadowSampler, shadowTexCoord);
  73. }
  74. #endif // #define _SHADOWMAP_FXH_