BasePBR_LightingBrdf.azsli 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #pragma once
  9. // This #define magic lets you use the GetDiffuseLighting & GetSpecularLighting functions in this file without making them the final functions
  10. // used in your shader. Simply #define GetDiffuseLighting & GetSpecularLighting to your custom definition before including this file
  11. //
  12. #ifndef GetDiffuseLighting
  13. #define GetDiffuseLighting(surface, lightingData, lightIntensity, dirToLight) GetDiffuseLighting_BasePBR(surface, lightingData, lightIntensity, dirToLight)
  14. #endif
  15. #ifndef GetSpecularLighting
  16. #define GetSpecularLighting(surface, lightingData, lightIntensity, dirToLight, viewIndex) GetSpecularLighting_BasePBR(surface, lightingData, lightIntensity, dirToLight, viewIndex)
  17. #endif
  18. #include <Atom/Features/PBR/Microfacet/Brdf.azsli>
  19. #ifndef LightingData
  20. #error LightingData must be defined before including this file.
  21. #endif
  22. #ifndef Surface
  23. #error Surface must be defined before including this file.
  24. #endif
  25. real3 GetDiffuseLighting_BasePBR(Surface surface, LightingData lightingData, real3 lightIntensity, real3 dirToLight)
  26. {
  27. real3 diffuse = DiffuseLambertian(surface.albedo, surface.GetDiffuseNormal(), dirToLight, lightingData.diffuseResponse);
  28. diffuse *= lightIntensity;
  29. return diffuse;
  30. }
  31. real3 GetSpecularLighting_BasePBR(Surface surface, LightingData lightingData, const real3 lightIntensity, const real3 dirToLight, uint viewIndex)
  32. {
  33. #if ENABLE_MOBILEBRDF
  34. real3 specular = SpecularGGXMobile(lightingData.dirToCamera[viewIndex], dirToLight, surface.GetSpecularNormal(), surface.GetSpecularF0(), surface.roughnessA2, surface.roughnessA, surface.roughnessLinear);
  35. #else
  36. real3 specular = SpecularGGX(lightingData.dirToCamera[viewIndex], dirToLight, surface.GetSpecularNormal(), surface.GetSpecularF0(), lightingData.GetSpecularNdotV(viewIndex), surface.roughnessA2, lightingData.multiScatterCompensation);
  37. #endif
  38. specular *= lightIntensity;
  39. return specular;
  40. }