123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- /*
- * 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/SrgSemantics.azsli>
- #include <Atom/Features/PostProcessing/FullscreenPixelInfo.azsli>
- #include <Atom/Features/PostProcessing/FullscreenVertex.azsli>
- //! Returns the linear depth value of the specified non-linear depth value.
- float CalculateLinearDepth(const float zDepth)
- {
- return abs(((ViewSrg::GetFarZTimesNearZ()) / (ViewSrg::GetFarZMinusNearZ() * zDepth - ViewSrg::GetFarZ())));
- }
- //! Returns the calculated color after blending original framebuffer color with the calculated feedback effect.
- float4 CalculateOutputColor(const float3 inColor, const float3 finalEffect, const float t)
- {
- float4 outColor;
- outColor.rgb = lerp(inColor, finalEffect, t);
- outColor.a = 1.0;
- return outColor;
- }
- ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
- {
- //! The color buffer to apply the editor mode feedback effects to.
- Texture2D<float4> m_framebuffer;
- //! The non-linear depth buffer data for fragments in the color buffer.
- Texture2D<float4> m_depth;
- //! The entity mask containing the visible fragments of entities of interest.
- //! @note Red channel contains the visible fragments, green channel contains the visible and occluded fragments.
- Texture2D<float2> m_entityMask;
- //! Dimensions of mask texture (xy is width and height, zw is 1/width and 1/height).
- float4 m_maskDimensions;
- //! The final blend amount that is used to scale the calculated blend values.
- float m_finalBlendAmount;
-
- ///////////////////////////////////
- //! EditorModeDesaturation related data
- //! Amount of desaturation to apply.
- float m_desaturationAmount;
- ///////////////////////////////////
-
- ///////////////////////////////////
- //! EditorModeOutline related data
- //! Outline line thickness.
- float m_lineThickness;
- //! Outline line color.
- float4 m_lineColor;
- //! Outline style to use (0 = OutlineStyle::Always, 1 = OutlineStyle::Visible)
- uint m_outlineStyle;
- ///////////////////////////////////
-
- ///////////////////////////////////
- //! EditorModeBlur related data
- //! Width of kernel to apply box blur effect.
- float m_kernelHalfWidth;
- //! The direction to perform the blur (0 = horizontal, 1 = vertical).
- uint m_direction;
- ///////////////////////////////////
-
- ///////////////////////////////////
- //! EditorModeTint related data
- //! Amount of tint to apply.
- float m_tintAmount;
- //! Color of tint to apply.
- float4 m_tintColor;
- ///////////////////////////////////
-
- ///////////////////////////////////
- //! EditorModeDepthTransition related data
- /* -----------------
- \ E /
- \#####|#####/
- \####|####/
- \###|###/
- \##|##/
- \-S-/
- \ /
- V
- V = View position
- S = Depth transition start
- E = Depth transition end
- When E is a non-zero value, the binary mask value will be transformed into a value from [m_minDepthTransitionValue, 1.0]
- according to the fragment's depth position in the transition band (#) spanning from S to E. This is to allow feedback
- effects to be scaled according to the distance of non-mask fragments to the viewer.
- */
- //! The minimum blend amount that will be calculated through depth transitioning.
- float m_minDepthTransitionValue;
-
- //! Start of depth transtion for non-mask effect blending.
- //! @note S in the diagram above.
- float m_depthTransitionStart;
- //! The duration (depth) of the depth transition band (0.0 = no depth transitioning will be applied).
- //! @note E - S in the diagram above.
- float m_depthTransitionDuration;
- ///////////////////////////////////
-
- Sampler LinearSampler
- {
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- AddressW = Clamp;
- };
- Sampler PointSampler
- {
- MinFilter = Point;
- MagFilter = Point;
- MipFilter = Point;
- AddressU = Clamp;
- AddressV = Clamp;
- AddressW = Clamp;
- };
- //! Returns the final blend amount after the final blend amount scale is applied.
- float CalculateFinalBlendAmount(const float t)
- {
- // Apply the final blend amount modifier
- return lerp(0.0, t, PassSrg::m_finalBlendAmount);
- }
- //! Calculates the final blend anount and returns the blended output color.
- float4 CalculateFinalBlendAmountAndOutputColor(const float3 inColor, const float3 finalEffect, const float t)
- {
- return CalculateOutputColor(inColor, finalEffect, PassSrg::CalculateFinalBlendAmount(t));
- }
-
- //! Calculates the blend amount (0.0 = input color, 1.0 = final effect) as scaled by the fragment's linear depth according to the depth transition values.
- float CalculateTransitionBlendAmountFromLinearDepth(const float linearDepth, const float maskValue)
- {
- if(PassSrg::m_depthTransitionDuration > 0.0)
- {
- const float depthTransition = clamp((linearDepth - PassSrg::m_depthTransitionStart) / (PassSrg::m_depthTransitionDuration), PassSrg::m_minDepthTransitionValue, 1.0);
- return clamp((1.0 - maskValue) * depthTransition, 0.0, 1.0);
- }
- return 1.0 - maskValue;
- }
- //! Calculates the blend amount (0.0 = input color, 1.0 = final effect) as scaled by the fragment's non-linear depth according to the depth transition values.
- float CalculateTransitionBlendAmountFromDepth(const float zDepth, const float maskValue)
- {
- const float linearDepth = CalculateLinearDepth(zDepth);
- return CalculateTransitionBlendAmountFromLinearDepth(linearDepth, maskValue);
- }
- }
|