You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Gems/Atom/Feature/Common/Assets/Shaders/Reflections/ReflectionComposite.azsl

60 lines
1.8 KiB
Plaintext

/*
* 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
*
*/
// Specular IBL reflection pipeline:
// Stencil -> BlendWeight -> GlobalFullscreen -> RenderOuter -> RenderInner -> Composite
// ---------
//
// This shader composites the final reflection texture onto the specular texture using a
// fullscreen pass, for pixels that have a non-zero stencil value. Output values are
// box-filtered from the MSAA sub-pixels of the reflection texture.
#include <scenesrg.srgi>
#include <Atom/Features/PostProcessing/FullscreenVertexUtil.azsli>
#include <Atom/Features/PostProcessing/FullscreenVertexInfo.azsli>
#include <Atom/Features/PostProcessing/FullscreenPixelInfo.azsli>
ShaderResourceGroup PassSrg : SRG_PerPass
{
Texture2DMS<float4> m_reflection;
}
// Vertex Shader
VSOutput MainVS(VSInput input)
{
VSOutput OUT;
float4 posTex = GetVertexPositionAndTexCoords(input.m_vertexID);
OUT.m_texCoord = float2(posTex.z, posTex.w);
OUT.m_position = float4(posTex.x, posTex.y, 0.0, 1.0);
return OUT;
}
// Pixel Shader
PSOutput MainPS(VSOutput IN)
{
// read reflection image, box filter samples for MSAA
// Note: output will only be written to the sub-pixel samples that pass the stencil test
float3 reflection = float3(0.0f, 0.0f, 0.0f);
uint width, height, samples;
PassSrg::m_reflection.GetDimensions(width, height, samples);
for (uint sampleIndex = 0; sampleIndex < samples; ++sampleIndex)
{
reflection += PassSrg::m_reflection.Load(IN.m_position.xy, sampleIndex).rgb;
}
reflection /= samples;
PSOutput OUT;
OUT.m_color = float4(reflection, 1.0f);
return OUT;
}