DebugShaderPBR_ForwardPass.azsl 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #include <viewsrg.srgi>
  9. #include <Atom/Features/InstancedTransforms.azsli>
  10. #include <Atom/Features/PBR/DefaultObjectSrg.azsli>
  11. #include <Atom/Features/PBR/ForwardPassSrg.azsli>
  12. #include <Atom/Features/PBR/ForwardPassOutput.azsli>
  13. #include <Atom/Features/PBR/AlphaUtils.azsli>
  14. #include <Atom/Features/SrgSemantics.azsli>
  15. #include <Atom/Features/ColorManagement/TransformColor.azsli>
  16. #include <Atom/Features/PBR/Lighting/StandardLighting.azsli>
  17. #include <Atom/Features/PBR/Lights/IblForward.azsli>
  18. #include <Atom/Features/PBR/Decals.azsli>
  19. ShaderResourceGroup DebugShaderPBRSrg : SRG_PerMaterial
  20. {
  21. float3 m_baseColor;
  22. float m_metallic;
  23. float m_roughness;
  24. }
  25. /*
  26. * For better understanding of the meshlet data please review MeshletsData.h and
  27. * specifically review MeshletDescriptor for understanding.
  28. * MESHLETS: meshlets descriptor structure containing vertices and indices offsets
  29. * MESHLETS_TRIANGLES: compressed indices of the local triangles per meshlet - each byte is a local index, 4th is not used.
  30. * MESHLETS_LOOKUP: vertices indirect index look up table.
  31. */
  32. struct VSInput
  33. {
  34. float3 m_position : POSITION;
  35. float3 m_normal : NORMAL;
  36. float4 m_tangent : TANGENT;
  37. float3 m_bitangent : BITANGENT;
  38. float2 m_uv : UV0;
  39. uint4 m_meshlets : MESHLETS;
  40. uint m_meshletsTriangles : MESHLETS_TRIANGLES;
  41. uint m_meshletsVtxLookup : MESHLETS_LOOKUP;
  42. };
  43. struct VSOutput
  44. {
  45. float4 m_position : SV_Position;
  46. float3 m_normal: NORMAL;
  47. float3 m_tangent : TANGENT;
  48. float3 m_bitangent : BITANGENT;
  49. float3 m_worldPosition : UV0;
  50. float2 m_uv : UV1;
  51. };
  52. #include <Atom/Features/Vertex/VertexHelper.azsli>
  53. VSOutput DebugShaderPBR_MainPassVS(VSInput IN, uint instanceId : SV_InstanceID)
  54. {
  55. VSOutput OUT;
  56. float3 worldPosition = mul(GetObjectToWorldMatrix(instanceId), float4(IN.m_position, 1.0)).xyz;
  57. VertexHelper(IN, OUT, worldPosition);
  58. OUT.m_uv = IN.m_uv;
  59. return OUT;
  60. }
  61. ForwardPassOutput DebugShaderPBR_MainPassPS(VSOutput IN)
  62. {
  63. // ------- Surface -------
  64. Surface surface;
  65. // Position, Normal, Roughness
  66. surface.position = IN.m_worldPosition.xyz;
  67. surface.normal = normalize(IN.m_normal);
  68. surface.vertexNormal = normalize(IN.m_normal);
  69. surface.roughnessLinear = DebugShaderPBRSrg::m_roughness;
  70. surface.CalculateRoughnessA();
  71. // Albedo, SpecularF0
  72. const float specularF0Factor = 0.5f;
  73. surface.SetAlbedoAndSpecularF0(DebugShaderPBRSrg::m_baseColor, specularF0Factor, DebugShaderPBRSrg::m_metallic);
  74. // Clear Coat, Transmission
  75. surface.clearCoat.InitializeToZero();
  76. // ------- LightingData -------
  77. LightingData lightingData;
  78. // Light iterator
  79. lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData);
  80. lightingData.Init(surface.position, surface.normal, surface.roughnessLinear);
  81. // Diffuse and Specular response
  82. lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear);
  83. lightingData.diffuseResponse = 1.0f - lightingData.specularResponse;
  84. const float alpha = 1.0f;
  85. // ------- Lighting Calculation -------
  86. // Apply Decals
  87. ApplyDecals(lightingData.tileIterator, surface);
  88. // Apply Direct Lighting
  89. ApplyDirectLighting(surface, lightingData, IN.m_position);
  90. // Apply Image Based Lighting (IBL)
  91. ApplyIBL(surface, lightingData);
  92. // Finalize Lighting
  93. lightingData.FinalizeLighting();
  94. PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha);
  95. // ------- Output -------
  96. ForwardPassOutput OUT;
  97. OUT.m_diffuseColor = lightingOutput.m_diffuseColor;
  98. OUT.m_diffuseColor.w = -1; // Subsurface scattering is disabled
  99. OUT.m_specularColor = lightingOutput.m_specularColor;
  100. OUT.m_specularF0 = lightingOutput.m_specularF0;
  101. OUT.m_albedo = lightingOutput.m_albedo;
  102. OUT.m_normal = lightingOutput.m_normal;
  103. // Debug purposes - displays UV coordiantes as color. For meshlets this will
  104. // display the different meshlets groups.
  105. OUT.m_diffuseColor = float4(IN.m_uv.rg, 0, 1);
  106. return OUT;
  107. }