ReflectionProbeRenderInner.azsl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 writes 100% of the probe IBL to this location, as it is fully covered
  13. // by the inner probe volume so there is no blending. Note that this shader only considers
  14. // pixels stenciled to the inner volume.
  15. #include <scenesrg.srgi>
  16. #include <viewsrg.srgi>
  17. #include "ReflectionProbeRenderObjectSrg.azsli"
  18. ShaderResourceGroup PassSrg : SRG_PerPass
  19. {
  20. Texture2DMS<float> m_depth;
  21. Texture2DMS<float4> m_normal;
  22. Texture2DMS<float4> m_specularF0;
  23. Texture2D<float2> m_brdfMap;
  24. Sampler LinearSampler
  25. {
  26. MinFilter = Linear;
  27. MagFilter = Linear;
  28. MipFilter = Linear;
  29. AddressU = Clamp;
  30. AddressV = Clamp;
  31. AddressW = Clamp;
  32. };
  33. }
  34. #include "ReflectionCommon.azsli"
  35. #include "ReflectionProbeRenderCommon.azsli"
  36. // Vertex Shader
  37. struct VSInput
  38. {
  39. float3 m_position : POSITION;
  40. };
  41. struct VSOutput
  42. {
  43. float4 m_position : SV_Position;
  44. };
  45. VSOutput MainVS(VSInput vsInput)
  46. {
  47. VSOutput OUT;
  48. float3 positionWS = mul(ObjectSrg::GetWorldMatrix(), float4(vsInput.m_position, 1.0)).xyz;
  49. OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(positionWS, 1.0));
  50. return OUT;
  51. }
  52. // Pixel Shader
  53. struct PSOutput
  54. {
  55. float4 m_color : SV_Target0;
  56. };
  57. PSOutput MainPS(VSOutput IN, in uint sampleIndex : SV_SampleIndex)
  58. {
  59. // reconstruct world space position from the depth at this location in screenspace
  60. // Note: this is the world position of the rendered object covered by the probe volume, not the volume itself
  61. uint2 dimensions;
  62. uint samples;
  63. PassSrg::m_depth.GetDimensions(dimensions.x, dimensions.y, samples);
  64. float depth = PassSrg::m_depth.Load(IN.m_position.xy, sampleIndex).r;
  65. float3 positionWS = ReconstructWorldPositionFromDepth(IN.m_position.xy, depth, dimensions, sampleIndex).xyz;
  66. // compute specular using the probe cubemap and the roughness, normals, and specularF0 for the surface
  67. float3 specular = float3(0.0f, 0.0f, 0.0f);
  68. if (!ComputeProbeSpecular(IN.m_position.xy, positionWS, ObjectSrg::GetWorldMatrixInverse(), ObjectSrg::m_innerObbHalfLengths, sampleIndex, specular))
  69. {
  70. discard;
  71. }
  72. // apply exposure setting
  73. specular *= pow(2.0, ObjectSrg::m_exposure);
  74. PSOutput OUT;
  75. OUT.m_color = float4(specular, 1.0f);
  76. return OUT;
  77. }