1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- /*
- * 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_all.srgi>
- #include <Atom/Features/Debug.azsli>
- #include <Atom/Features/PostProcessing/FullscreenVertexUtil.azsli>
- #include <Atom/Features/PostProcessing/FullscreenVertexInfo.azsli>
- #include <Atom/Features/PostProcessing/FullscreenPixelInfo.azsli>
- ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
- {
- 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)
- {
- if(!IsSpecularLightingEnabled() || !IsIndirectLightingEnabled())
- {
- PSOutput OUT;
- OUT.m_color = float4(0, 0, 0, 0);
- return OUT;
- }
- // 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;
- }
|