ReflectionComposite.azsl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // Specular IBL reflection pipeline:
  9. // Stencil -> BlendWeight -> GlobalFullscreen -> RenderOuter -> RenderInner -> Composite
  10. // ---------
  11. //
  12. // This shader composites the final reflection texture onto the specular texture using a
  13. // fullscreen pass, for pixels that have a non-zero stencil value. Output values are
  14. // box-filtered from the MSAA sub-pixels of the reflection texture.
  15. #include <scenesrg_all.srgi>
  16. #include <Atom/Features/Debug.azsli>
  17. #include <Atom/Features/PostProcessing/FullscreenVertexUtil.azsli>
  18. #include <Atom/Features/PostProcessing/FullscreenVertexInfo.azsli>
  19. #include <Atom/Features/PostProcessing/FullscreenPixelInfo.azsli>
  20. ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
  21. {
  22. Texture2DMS<float4> m_reflection;
  23. }
  24. // Vertex Shader
  25. VSOutput MainVS(VSInput input)
  26. {
  27. VSOutput OUT;
  28. float4 posTex = GetVertexPositionAndTexCoords(input.m_vertexID);
  29. OUT.m_texCoord = float2(posTex.z, posTex.w);
  30. OUT.m_position = float4(posTex.x, posTex.y, 0.0, 1.0);
  31. return OUT;
  32. }
  33. // Pixel Shader
  34. PSOutput MainPS(VSOutput IN)
  35. {
  36. if(!IsSpecularLightingEnabled() || !IsIndirectLightingEnabled())
  37. {
  38. PSOutput OUT;
  39. OUT.m_color = float4(0, 0, 0, 0);
  40. return OUT;
  41. }
  42. // read reflection image, box filter samples for MSAA
  43. // Note: output will only be written to the sub-pixel samples that pass the stencil test
  44. float3 reflection = float3(0.0f, 0.0f, 0.0f);
  45. uint width, height, samples;
  46. PassSrg::m_reflection.GetDimensions(width, height, samples);
  47. for (uint sampleIndex = 0; sampleIndex < samples; ++sampleIndex)
  48. {
  49. reflection += PassSrg::m_reflection.Load(IN.m_position.xy, sampleIndex).rgb;
  50. }
  51. reflection /= samples;
  52. PSOutput OUT;
  53. OUT.m_color = float4(reflection, 1.0f);
  54. return OUT;
  55. }