PostFX_LinearDepth.fx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2005 Electronic Arts Inc
  3. //
  4. // Image post processing effect performing a glow by selective color blurring
  5. //////////////////////////////////////////////////////////////////////////////
  6. #include "Common.fxh"
  7. // ----------------------------------------------------------------------------
  8. // Transformations
  9. // ----------------------------------------------------------------------------
  10. float4x4 ProjectionI : ProjectionInverse;
  11. // ----------------------------------------------------------------------------
  12. SAMPLER_2D_BEGIN( DepthBufferSampler,
  13. string SasBindAddress = "PostEffect.DepthBufferTexture";
  14. )
  15. MinFilter = Point;
  16. MagFilter = Point;
  17. MipFilter = Point;
  18. AddressU = Clamp;
  19. AddressV = Clamp;
  20. SAMPLER_2D_END
  21. // ----------------------------------------------------------------------------
  22. struct VSOutput
  23. {
  24. float4 Position : POSITION;
  25. float2 TexCoord : TEXCOORD0;
  26. };
  27. // ----------------------------------------------------------------------------
  28. VSOutput DefaultVS(float3 Position : POSITION, float2 TexCoord : TEXCOORD0)
  29. {
  30. VSOutput Out;
  31. Out.Position = float4(Position, 1);
  32. Out.TexCoord = TexCoord;
  33. return Out;
  34. }
  35. // ----------------------------------------------------------------------------
  36. float4 DefaultPS(float2 TexCoord : TEXCOORD0) : COLOR
  37. {
  38. #if defined(EA_PLATFORM_XENON)
  39. float depth = 1.0f - tex2D( SAMPLER(DepthBufferSampler), TexCoord).x;
  40. #else
  41. float depth = tex2D( SAMPLER(DepthBufferSampler), TexCoord).x;
  42. #endif
  43. float4 clipPos = float4(TexCoord.x * 2 - 1, -TexCoord.y * 2 + 1, depth, 1);
  44. float4 viewPos = mul(clipPos, ProjectionI);
  45. viewPos.xyz /= viewPos.w;
  46. return float4( viewPos.zzz, 1.0f );
  47. }
  48. // ----------------------------------------------------------------------------
  49. technique LinearDepth
  50. {
  51. pass p0
  52. {
  53. VertexShader = compile VS_2_0 DefaultVS();
  54. PixelShader = compile PS_2_0 DefaultPS();
  55. ZEnable = false;
  56. ZWriteEnable = false;
  57. CullMode = None;
  58. AlphaBlendEnable = false;
  59. AlphaTestEnable = false;
  60. }
  61. }