/* * 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 #include #include #include ShaderResourceGroup PassSrg : SRG_PerPass { Texture2DMS 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; }