| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /*
- * 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 writes 100% of the probe IBL to this location, as it is fully covered
- // by the inner probe volume so there is no blending. Note that this shader only considers
- // pixels stenciled to the inner volume.
- #include <scenesrg.srgi>
- #include <viewsrg.srgi>
- #include "ReflectionProbeRenderObjectSrg.azsli"
- ShaderResourceGroup PassSrg : SRG_PerPass
- {
- Texture2DMS<float> m_depth;
- Texture2DMS<float4> m_normal;
- Texture2DMS<float4> m_specularF0;
- Texture2D<float2> m_brdfMap;
- Sampler LinearSampler
- {
- MinFilter = Linear;
- MagFilter = Linear;
- MipFilter = Linear;
- AddressU = Clamp;
- AddressV = Clamp;
- AddressW = Clamp;
- };
- }
- #include "ReflectionCommon.azsli"
- #include "ReflectionProbeRenderCommon.azsli"
- // Vertex Shader
- struct VSInput
- {
- float3 m_position : POSITION;
- };
- struct VSOutput
- {
- float4 m_position : SV_Position;
- };
- VSOutput MainVS(VSInput vsInput)
- {
- VSOutput OUT;
- float3 positionWS = mul(ObjectSrg::GetWorldMatrix(), float4(vsInput.m_position, 1.0)).xyz;
- OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(positionWS, 1.0));
- return OUT;
- }
- // Pixel Shader
- struct PSOutput
- {
- float4 m_color : SV_Target0;
- };
- PSOutput MainPS(VSOutput IN, in uint sampleIndex : SV_SampleIndex)
- {
- // reconstruct world space position from the depth at this location in screenspace
- // Note: this is the world position of the rendered object covered by the probe volume, not the volume itself
- uint2 dimensions;
- uint samples;
- PassSrg::m_depth.GetDimensions(dimensions.x, dimensions.y, samples);
- float depth = PassSrg::m_depth.Load(IN.m_position.xy, sampleIndex).r;
- float3 positionWS = ReconstructWorldPositionFromDepth(IN.m_position.xy, depth, dimensions, sampleIndex).xyz;
- // compute specular using the probe cubemap and the roughness, normals, and specularF0 for the surface
- float3 specular = float3(0.0f, 0.0f, 0.0f);
- if (!ComputeProbeSpecular(IN.m_position.xy, positionWS, ObjectSrg::GetWorldMatrixInverse(), ObjectSrg::m_innerObbHalfLengths, sampleIndex, specular))
- {
- discard;
- }
- // apply exposure setting
- specular *= pow(2.0, ObjectSrg::m_exposure);
- PSOutput OUT;
- OUT.m_color = float4(specular, 1.0f);
- return OUT;
- }
|