| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- //////////////////////////////////////////////////////////////////////////////
- // ©2005 Electronic Arts Inc
- //
- // Image post processing effect performing a color conversion through a lookup table
- //////////////////////////////////////////////////////////////////////////////
- #include "Common.fxh"
- #include "CommonPostFX.fxh"
- #include "Gamma.fxh"
- SAMPLER_2D_BEGIN( FrameBufferSampler,
- string SasBindAddress = "PostEffect.FrameBufferTexture";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Point;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- SAMPLER_3D_BEGIN( LookupTexture,
- string SasBindAddress = "PostEffect.LookupTable.LookupTexture";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Point;
- AddressU = Clamp;
- AddressV = Clamp;
- AddressW = Clamp;
- SAMPLER_3D_END
- SAMPLER_2D_BEGIN( FilmTonemappingLookupTexture,
- string SasBindAddress = "PostEffect.LookupTable.FilmTonemapping";
- )
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Point;
- AddressU = Clamp;
- AddressV = Clamp;
- SAMPLER_2D_END
- float4 BlendFactor
- <
- string SasBindAddress = "PostEffect.LookupTable.BlendFactor";
- > = float4(1.0, 1.0, 1.0, 1.0);
- float3 ExposureLevel
- <
- string SasBindAddress = "PostEffect.LookupTable.ExposureLevel";
- > = float3(1.0, 1.0, 1.0);
- // ----------------------------------------------------------------------------
- struct VSOutput
- {
- float4 Position : POSITION;
- float2 TexCoord : TEXCOORD0;
- };
- // ----------------------------------------------------------------------------
- VSOutput DefaultVS(float3 Position : POSITION, float2 TexCoord : TEXCOORD0)
- {
- VSOutput Out;
- Out.Position = float4(Position, 1);
- Out.TexCoord = TexCoord;
- return Out;
- }
- // ----------------------------------------------------------------------------
- #if defined(EA_PLATFORM_PS3)
- float4 DefaultPS(float2 TexCoord : TEXCOORD0, uniform bool applyLUT, uniform bool applyGammaCorrection)
- #else // #if defined(EA_PLATFORM_PS3)
- float4 DefaultPS(float2 TexCoord : TEXCOORD0, uniform bool applyLUT, uniform bool applyGammaCorrection) : COLOR
- #endif // #if defined(EA_PLATFORM_PS3)
- {
- float4 color = tex2D(SAMPLER(FrameBufferSampler), TexCoord);
-
- color.xyz = UncompressRenderTargetColor(color.xyz);
-
- color.xyz *= ExposureLevel;
-
- #if defined(ENABLE_GAMMA_CONVERSION)
- if (applyGammaCorrection)
- {
- #define TONEMAPPER 2
- #if TONEMAPPER == 0
- color.xyz = LinearToGamma(color.xyz);
- #elif TONEMAPPER == 1
- color.xyz /= 1 + color.xyz;
- #elif TONEMAPPER == 2
- float3 white = 6.0;
- color.xyz *= white;
- color.xyz = color.xyz * (1 + color.xyz / (white * white)) / (1 + color.xyz);
- #else
- float3 ld = 0.002;
- float linReference = 0.18;
- float logReference = 444;
- float logGamma = 0.45;
-
- color.xyz = (log10(0.4 * color.xyz / linReference) / ld * logGamma + logReference) / 1023.0;
- //color.xyz = clamp(color.xyz, 0, 1);
-
- float FilmLutWidth = 256;
- float Padding = .5/FilmLutWidth;
- //color.xyz = lerp(Padding,1-Padding,color.xyz);
- // apply response lookup and color grading for target display
- color.x = tex2D(SAMPLER(FilmTonemappingLookupTexture), float2(color.x, .5)).r;
- color.y = tex2D(SAMPLER(FilmTonemappingLookupTexture), float2(color.y, .5)).r;
- color.z = tex2D(SAMPLER(FilmTonemappingLookupTexture), float2(color.z, .5)).r;
- #endif
- }
- #endif
-
- if (applyLUT)
- {
- #if defined (EA_PLATFORM_XENON)
- // TODO: LLatta 2008-09-13
- // This is a workaround for a Xenon pipeline bug.
- // This fix here is a less risky fix at this stage of the project.
- // At the earliest convenience fix the actual issue in CVolumeTexture::SaveImage
- // See the comment in code\AssetCompilers\0.0-dev\Modules\TextureCompiler\Source\xenon\VolumeTexture.cpp
- float4 tableColor = tex3D(SAMPLER(LookupTexture), color.xzy).xzyw;
- #else
- float4 tableColor = tex3D(SAMPLER(LookupTexture), color.xyz);
- #endif
- color = lerp(color, tableColor, BlendFactor.x);
- }
- return color;
- }
- #if defined(EA_PLATFORM_PS3)
- float4 DefaultPS_Default(float2 TexCoord : TEXCOORD0) : COLOR
- {
- return DefaultPS(TexCoord, true, true);
- }
- float4 DefaultPS_Default_M(float2 TexCoord : TEXCOORD0) : COLOR
- {
- return DefaultPS(TexCoord, true, false);
- }
- float4 DefaultPS_ResolveOnly(float2 TexCoord : TEXCOORD0) : COLOR
- {
- return DefaultPS(TexCoord, false, true);
- }
- float4 DefaultPS_ResolveOnly_M(float2 TexCoord : TEXCOORD0) : COLOR
- {
- return DefaultPS(TexCoord, false, false);
- }
- #endif // #if defined(EA_PLATFORM_PS3)
- // ----------------------------------------------------------------------------
- technique Default
- {
- pass P0
- {
- VertexShader = compile VS_2_0 DefaultVS();
- #if defined(EA_PLATFORM_PS3)
- PixelShader = compile PS_2_0 DefaultPS_Default();
- #else // #if defined(EA_PLATFORM_PS3)
- PixelShader = compile PS_2_0 DefaultPS(true, true);
- #endif // #if defined(EA_PLATFORM_PS3)
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = false;
- AlphaTestEnable = false;
- }
- }
- // ----------------------------------------------------------------------------
- technique Default_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 DefaultVS();
- #if defined(EA_PLATFORM_PS3)
- PixelShader = compile PS_2_0 DefaultPS_Default_M();
- #else // #if defined(EA_PLATFORM_PS3)
- PixelShader = compile PS_2_0 DefaultPS(true, false);
- #endif // #if defined(EA_PLATFORM_PS3)
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = false;
- AlphaTestEnable = false;
- }
- }
- // ----------------------------------------------------------------------------
- technique ResolveOnly
- {
- pass P0
- {
- VertexShader = compile VS_2_0 DefaultVS();
- #if defined(EA_PLATFORM_PS3)
- PixelShader = compile PS_2_0 DefaultPS_ResolveOnly();
- #else // #if defined(EA_PLATFORM_PS3)
- PixelShader = compile PS_2_0 DefaultPS(false, true);
- #endif // #if defined(EA_PLATFORM_PS3)
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = false;
- AlphaTestEnable = false;
- }
- }
- // ----------------------------------------------------------------------------
- technique ResolveOnly_M
- {
- pass P0
- {
- VertexShader = compile VS_2_0 DefaultVS();
- #if defined(EA_PLATFORM_PS3)
- PixelShader = compile PS_2_0 DefaultPS_ResolveOnly_M();
- #else // #if defined(EA_PLATFORM_PS3)
- PixelShader = compile PS_2_0 DefaultPS(false, false);
- #endif // #if defined(EA_PLATFORM_PS3)
- ZEnable = false;
- ZWriteEnable = false;
- CullMode = None;
- AlphaBlendEnable = false;
- AlphaTestEnable = false;
- }
- }
|