PostFX_Distortion.fx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //////////////////////////////////////////////////////////////////////////////
  2. // ©2005 Electronic Arts Inc
  3. //
  4. // Image post processing effect performing a color conversion through a lookup table
  5. //////////////////////////////////////////////////////////////////////////////
  6. //#define DEBUG_DISTORTION_TEXTURE 1
  7. #include "Common.fxh"
  8. #include "CommonPostFX.fxh"
  9. SAMPLER_2D_BEGIN( FrameBufferSampler,
  10. string SasBindAddress = "PostEffect.FrameBufferTexture";
  11. )
  12. MinFilter = Linear;
  13. MagFilter = Linear;
  14. MipFilter = Point;
  15. AddressU = Clamp;
  16. AddressV = Clamp;
  17. SAMPLER_2D_END
  18. SAMPLER_2D_BEGIN( DistortionOffsetSampler,
  19. string SasBindAddress = "PostEffect.Distortion.DistortionOffsetTexture";
  20. )
  21. MinFilter = Linear;
  22. MagFilter = Linear;
  23. MipFilter = Point;
  24. AddressU = Clamp;
  25. AddressV = Clamp;
  26. AddressW = Clamp;
  27. SAMPLER_2D_END
  28. // ----------------------------------------------------------------------------
  29. struct VSOutput
  30. {
  31. float4 Position : POSITION;
  32. float2 TexCoord : TEXCOORD0;
  33. };
  34. // ----------------------------------------------------------------------------
  35. VSOutput DefaultVS(float3 Position : POSITION, float2 TexCoord : TEXCOORD0)
  36. {
  37. VSOutput Out;
  38. Out.Position = float4(Position, 1);
  39. Out.TexCoord = TexCoord;
  40. #if defined(DEBUG_DISTORTION_TEXTURE)
  41. float scale = 0.4;
  42. Out.Position = float4(Position * scale + float3(1 - scale, 1 - scale, 0), 1);
  43. #endif
  44. return Out;
  45. }
  46. // ----------------------------------------------------------------------------
  47. float4 DefaultPS_H(float2 TexCoord : TEXCOORD0) : COLOR
  48. {
  49. #if defined(DEBUG_DISTORTION_TEXTURE)
  50. return tex2D( SAMPLER(DistortionOffsetSampler), TexCoord);
  51. #endif
  52. float2 offset = tex2D( SAMPLER(DistortionOffsetSampler), TexCoord) * 2 - 1;
  53. // The neutral color (127, 127) comes out one step below 0. Correct for that.
  54. offset += 1.0 / 255.0;
  55. static const float maxOffset = 0.08;
  56. float4 color = tex2D( SAMPLER(FrameBufferSampler), TexCoord + offset * maxOffset);
  57. color.xyz = UncompressRenderTargetColor(color);
  58. return color;
  59. }
  60. // ----------------------------------------------------------------------------
  61. float4 DefaultPS_M(float2 TexCoord : TEXCOORD0) : COLOR
  62. {
  63. #if defined(DEBUG_DISTORTION_TEXTURE)
  64. return tex2D( SAMPLER(DistortionOffsetSampler), TexCoord);
  65. #endif
  66. float2 offset = tex2D( SAMPLER(DistortionOffsetSampler), TexCoord) * 2 - 1;
  67. // The neutral color (127, 127) comes out one step below 0. Correct for that.
  68. offset += 1.0 / 255.0;
  69. static const float maxOffset = 0.08;
  70. float4 color = tex2D( SAMPLER(FrameBufferSampler), TexCoord + offset * maxOffset);
  71. return color;
  72. }
  73. // ----------------------------------------------------------------------------
  74. // Technique: Default (High and up)
  75. // ----------------------------------------------------------------------------
  76. technique Default
  77. {
  78. pass P0
  79. {
  80. VertexShader = compile VS_2_0 DefaultVS();
  81. PixelShader = compile PS_2_0 DefaultPS_H();
  82. ZEnable = false;
  83. ZWriteEnable = false;
  84. CullMode = None;
  85. AlphaBlendEnable = false;
  86. AlphaTestEnable = false;
  87. #if !defined(EA_PLATFORM_PS3)
  88. FillMode = Solid;
  89. #endif
  90. }
  91. }
  92. // ----------------------------------------------------------------------------
  93. // Technique: Default (Medium)
  94. // ----------------------------------------------------------------------------
  95. technique Default_M
  96. {
  97. pass P0
  98. {
  99. VertexShader = compile VS_2_0 DefaultVS();
  100. PixelShader = compile PS_2_0 DefaultPS_M();
  101. ZEnable = false;
  102. ZWriteEnable = false;
  103. CullMode = None;
  104. AlphaBlendEnable = false;
  105. AlphaTestEnable = false;
  106. #if !defined(EA_PLATFORM_PS3)
  107. FillMode = Solid;
  108. #endif
  109. }
  110. }
  111. // ----------------------------------------------------------------------------
  112. // Technique: Default (Low)
  113. // ----------------------------------------------------------------------------
  114. technique Default_L
  115. {
  116. // No passes. Indicates technique disabled.
  117. }