67 lines
2.2 KiB
Plaintext
67 lines
2.2 KiB
Plaintext
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
// 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 <viewsrg.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;
|
|
}
|
|
|
|
#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
|
|
|
|
// 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;
|
|
}
|