Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************************/
- /*! DopeShader settings available in \file APB-DopeShader-Settings.usf
- ****************************************************************************************/
- #include "Common.usf"
- #include "PostProcessCommon.usf"
- #include "APB-DopeShader-Settings.usf"
- // Tone-mapping parameters.
- sampler2D AdaptedLuminance;
- float MiddleGrey;
- float Lwhite;
- #if SET_BLOOM
- sampler2D BlurredImage;
- float BloomAlpha;
- float BloomPostScale;
- #endif
- // Colour adjustment parameters.
- #if SET_ADJUSTMENT
- float Brightness;
- float Contrast;
- float Saturation;
- float3 DesaturatedColour;
- #endif
- // The per-color weighting to be used for luminance calculations in RGB order.
- static const float3 LuminanceVector = float3(0.3, 0.59, 0.11);
- // SJT: Perform tone mapping on a pixel.
- float3 ToneMap(float3 WorldColour)
- {
- float fAdaptedLuminance = tex2D(AdaptedLuminance, float2(0.5f, 0.5f)).r;
- float Lworld = dot(WorldColour, LuminanceVector);
- float Exposure = MiddleGrey / (fAdaptedLuminance + 0.2f);
- float Ladapted = Lworld * Exposure;
- float Ldisplay = (Ladapted * (1.4 + Ladapted / (Lwhite * Lwhite))) / (1.0f + Ladapted);
- return WorldColour * Ldisplay / (Lworld + 0.0016);
- }
- // SJT: Basic colour adjustment.
- #if SET_ADJUSTMENT
- float3 ColourAdjust(float3 InColour)
- {
- float3 Result = InColour;
- // Saturate before we do anything to prevent whackiness from values outside [0,1]
- Result = saturate(Result);
- // (De)saturate.
- Result = lerp(dot(Result, LuminanceVector) * DesaturatedColour, Result, Saturation);
- // Contrast adjustment (cubic).
- Result = Result - Contrast * (Result - 1) * Result * (Result - 0.5);
- // Brightness adjustment (addition).
- Result = Result + Brightness;
- return Result;
- }
- #endif
- void Main(
- in float2 UV : TEXCOORD0,
- in float2 SceneUV : TEXCOORD1,
- out float4 OutColor : COLOR0
- )
- {
- float4 sceneColor=tex2D(SceneColorTexture,SceneUV);
- #if SET_BLOOM
- float4 rawColor = tex2D(BlurredImage,UV);
- float3 filteredColor = MAX_SCENE_COLOR * rawColor.rgb * BloomPostScale;
- float3 RTWBloom = 1-(saturate(1-(filteredColor.rgb*BloomAlpha*0.2))*saturate(1-lerp(sceneColor.rgb, 0, BloomAlpha*saturate(rawColor.a*4)*0.2)));
- float3 ToneMappedColour = ToneMap(RTWBloom);
- #else
- float3 ToneMappedColour = ToneMap(sceneColor);
- #endif
- #if SET_ADJUSTMENT
- float3 AdjustedColour = ColourAdjust(ToneMappedColour);
- OutColor = float4(AdjustedColour.rgb, sceneColor.a);
- #else
- OutColor = float4(ToneMappedColour.rgb, sceneColor.a);
- #endif
- #if SET_DESATURATE
- float luminance = dot(OutColor, LuminanceVector);
- float4 eColor = lerp(luminance, OutColor, 0.9) ; // 1.0 no desaturation, while 0.0 is full desaturation
- OutColor = float4(eColor.rgb, OutColor.a);
- #endif
- OutColor *= 2.15;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement