123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <viewsrg_all.srgi>
- #include <Atom/Features/PostProcessing/FullscreenPixelInfo.azsli>
- #include <Atom/Features/PostProcessing/FullscreenVertex.azsli>
- #include <Atom/Features/PostProcessing/PostProcessUtil.azsli>
- #include <Atom/Features/PostProcessing/Aces.azsli>
- #include <Atom/Features/PostProcessing/Tonemap.azsli>
- #include <Atom/Features/PostProcessing/Shapers.azsli>
- #include <Atom/Features/ColorManagement/TransformColor.azsli>
- ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
- {
- [[input_attachment_index(0)]]
- SubpassInput m_framebuffer;
- Texture3D<float4> m_lut;
- Sampler LinearSampler
- {
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- AddressW = Clamp;
- };
- // Reference white and black luminance values
- float2 m_cinemaLimits;
- // LDR color grading
- int m_shaperType;
- float m_shaperBias;
- float m_shaperScale;
- }
- // Option shader variable to select tone mapper feature.
- option enum class ToneMapperType {None, Reinhard, AcesFitted, AcesFilmic, Filmic} o_tonemapperType = ToneMapperType::None;
- // Option shader variable to select transfer function.
- option enum class TransferFunctionType {None, Gamma22, PerceptualQuantizer} o_transferFunctionType = TransferFunctionType::None;
- // Option to enable color grading
- option bool o_colorGradingEnabled = false;
- float3 NormalizedToCinemaLimits(const float3 inputColor)
- {
- float3 linearColor;
- // Scale from normalized range to the proper range
- linearColor.r = LinearCVToY(inputColor.r, PassSrg::m_cinemaLimits.y, PassSrg::m_cinemaLimits.x);
- linearColor.g = LinearCVToY(inputColor.g, PassSrg::m_cinemaLimits.y, PassSrg::m_cinemaLimits.x);
- linearColor.b = LinearCVToY(inputColor.b, PassSrg::m_cinemaLimits.y, PassSrg::m_cinemaLimits.x);
- linearColor = max(linearColor, 0.);
- return linearColor;
- }
- PSOutput MainPS(VSOutput IN)
- {
- PSOutput OUT;
- // Fetch the pixel color from the input texture
- float3 color = PassSrg::m_framebuffer.SubpassLoad(int3(IN.m_position.x, IN.m_position.y, 0)).rgb;
- #if MERGE_MANUAL_EXPOSURE
- // Apply manual exposure compensation
- color = ApplyManualExposure(color, float(ViewSrg::GetExposureValueCompensation()));
- #endif
- // Applying tone mapper.
- switch (o_tonemapperType)
- {
- case ToneMapperType::Reinhard:
- color = TonemapReinhard(AcesCg_To_LinearSrgb(color));
- break;
- case ToneMapperType::AcesFitted:
- color = AcesCg_To_LinearSrgb(TonemapAcesFitted(color));
- break;
- case ToneMapperType::AcesFilmic:
- color = TonemapAcesFilmic(AcesCg_To_LinearSrgb(color));
- break;
- case ToneMapperType::Filmic:
- color = TonemapFilmic(AcesCg_To_LinearSrgb(color));
- break;
- default:
- break;
- }
- // Aplying transfer function to go from linear srgb to gamma srgb
- switch (o_transferFunctionType)
- {
- case TransferFunctionType::Gamma22:
- color = pow(color, 1.0 / 2.2);
- break;
- case TransferFunctionType::PerceptualQuantizer:
- if (o_tonemapperType == ToneMapperType::Reinhard ||
- o_tonemapperType == ToneMapperType::AcesFitted ||
- o_tonemapperType == ToneMapperType::AcesFilmic)
- {
- color = NormalizedToCinemaLimits(color);
- }
- // Encode with PQ transfer function
- color = PerceptualQuantizerRevF3(color);
- break;
- default:
- break;
- }
- if(o_colorGradingEnabled)
- {
- color.rgb = ApplyShaperLookupTable(ShaperType::ShaperLinear, color, PassSrg::m_shaperBias, PassSrg::m_shaperScale, PassSrg::m_lut, PassSrg::LinearSampler);
- }
- OUT.m_color.rgb = color;
- OUT.m_color.w = 1;
- return OUT;
- }
|