default_ForwardPass.azsl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/PBR/DefaultObjectSrg.azsli>
  10. #include <Atom/Features/PBR/ForwardPassSrg.azsli>
  11. #include <Atom/Features/PBR/ForwardPassOutput.azsli>
  12. #include <Atom/Features/PBR/AlphaUtils.azsli>
  13. #include <Atom/Features/SrgSemantics.azsli>
  14. #include <Atom/Features/ColorManagement/TransformColor.azsli>
  15. #include <Atom/Features/PBR/Lighting/StandardLighting.azsli>
  16. #include <Atom/Features/PBR/Decals.azsli>
  17. // Everything inside of the generated blocks will eventually be replaced in the generated files as the material graph is compiled.
  18. // O3DE_GENERATED_INCLUDES_BEGIN
  19. // O3DE_GENERATED_INCLUDES_END
  20. struct VSInput
  21. {
  22. float3 m_position : POSITION;
  23. float3 m_normal : NORMAL;
  24. float4 m_tangent : TANGENT;
  25. float3 m_bitangent : BITANGENT;
  26. // O3DE_GENERATED_VSINPUT_BEGIN
  27. // O3DE_GENERATED_VSINPUT_END
  28. };
  29. struct VSOutput
  30. {
  31. precise linear centroid float4 m_position : SV_Position;
  32. float3 m_normal: NORMAL;
  33. float3 m_tangent : TANGENT;
  34. float3 m_bitangent : BITANGENT;
  35. float3 m_worldPosition : UV0;
  36. };
  37. #include <Atom/Features/Vertex/VertexHelper.azsli>
  38. ShaderResourceGroup MaterialSrg : SRG_PerMaterial
  39. {
  40. // O3DE_GENERATED_MATERIAL_SRG_BEGIN
  41. // O3DE_GENERATED_MATERIAL_SRG_END
  42. }
  43. // O3DE_GENERATED_CLASSES_BEGIN
  44. // O3DE_GENERATED_CLASSES_END
  45. // O3DE_GENERATED_FUNCTIONS_BEGIN
  46. // O3DE_GENERATED_FUNCTIONS_END
  47. VSOutput default_MainPassVS(VSInput IN)
  48. {
  49. VSOutput OUT;
  50. float3 worldPosition = mul(ObjectSrg::GetWorldMatrix(), float4(IN.m_position, 1.0)).xyz;
  51. // O3DE_GENERATED_INSTRUCTIONS_BEGIN: inPositionOffset
  52. float4 inPositionOffset = float4(0.0, 0.0, 0.0, 0.0);
  53. // O3DE_GENERATED_INSTRUCTIONS_END
  54. VertexHelper(IN, OUT, worldPosition + inPositionOffset.xyz);
  55. return OUT;
  56. }
  57. ForwardPassOutput default_MainPassPS(VSOutput IN)
  58. {
  59. // O3DE_GENERATED_INSTRUCTIONS_BEGIN: inBaseColor, inEmissive, inMetallic, inRoughness, inSpecularF0Factor
  60. float node7_inValue = 0;
  61. float node7_outValue = node7_inValue;
  62. float node5_outTime = SceneSrg::m_time;
  63. float4 node6_inValue1 = node5_outTime;
  64. float4 node6_inValue2 = node7_outValue;
  65. float4 node6_outValue = node6_inValue1 + node6_inValue2;
  66. float4 node4_inValue = node6_outValue;
  67. float4 node4_outValue = sin(node4_inValue);
  68. float2 node3_inUV = float2(0, 0);
  69. float4 node3_outColor = 1.0;
  70. float4 node18_inValue1 = node4_outValue;
  71. float4 node18_inValue2 = node3_outColor;
  72. float4 node18_outValue = mul(node18_inValue1, node18_inValue2);
  73. float4 inBaseColor = node18_outValue;
  74. float inMetallic = 0;
  75. float inSpecularF0Factor = 0;
  76. float inRoughness = node3_outColor;
  77. float4 inEmissive = float4(0, 0, 0, 1);
  78. // O3DE_GENERATED_INSTRUCTIONS_END
  79. // ------- Surface -------
  80. Surface surface;
  81. surface.position = IN.m_worldPosition.xyz;
  82. surface.normal = normalize(IN.m_normal);
  83. surface.vertexNormal = normalize(IN.m_normal);
  84. surface.roughnessLinear = inRoughness;
  85. surface.CalculateRoughnessA();
  86. surface.SetAlbedoAndSpecularF0(inBaseColor.rgb, inSpecularF0Factor, inMetallic);
  87. surface.clearCoat.InitializeToZero();
  88. // ------- LightingData -------
  89. LightingData lightingData;
  90. lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData);
  91. lightingData.Init(surface.position, surface.normal, surface.roughnessLinear);
  92. lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear);
  93. lightingData.diffuseResponse = 1.0f - lightingData.specularResponse;
  94. lightingData.emissiveLighting = inEmissive;
  95. // ------- Lighting Calculation -------
  96. // Apply Decals
  97. ApplyDecals(lightingData.tileIterator, surface);
  98. // Apply Direct Lighting
  99. ApplyDirectLighting(surface, lightingData, IN.m_position);
  100. // Apply Image Based Lighting (IBL)
  101. ApplyIBL(surface, lightingData);
  102. // Finalize Lighting
  103. lightingData.FinalizeLighting();
  104. PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, inBaseColor.a);
  105. // ------- Output -------
  106. ForwardPassOutput OUT;
  107. OUT.m_diffuseColor = lightingOutput.m_diffuseColor;
  108. OUT.m_diffuseColor.w = -1; // Subsurface scattering is disabled
  109. OUT.m_specularColor = lightingOutput.m_specularColor;
  110. OUT.m_specularF0 = lightingOutput.m_specularF0;
  111. OUT.m_albedo = lightingOutput.m_albedo;
  112. OUT.m_normal = lightingOutput.m_normal;
  113. return OUT;
  114. }