EnhancedPBR_SurfaceData.azsli 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #ifndef Surface
  10. #define Surface SurfaceData_EnhancedPBR
  11. #endif
  12. #include "../StandardPBR/StandardPBR_SurfaceData.azsli"
  13. #include <Atom/Features/PBR/Surfaces/AnisotropicSurfaceData.azsli>
  14. #include <Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli>
  15. // Class inheritance doesn't seem to be working
  16. #define DOES_CLASS_INHERITANCE_WORK_IN_ASZL 0
  17. #if DOES_CLASS_INHERITANCE_WORK_IN_ASZL
  18. class SurfaceData_EnhancedPBR : SurfaceData_StandardPBR
  19. {
  20. AnisotropicSurfaceData anisotropy;
  21. #if ENABLE_TRANSMISSION
  22. TransmissionSurfaceData transmission;
  23. #endif
  24. //! Subsurface scattering parameters
  25. real subsurfaceScatteringFactor;
  26. real subsurfaceScatteringQuality;
  27. real3 scatterDistance;
  28. }
  29. #else
  30. class SurfaceData_EnhancedPBR
  31. {
  32. #if ENABLE_CLEAR_COAT
  33. ClearCoatSurfaceData clearCoat;
  34. #endif
  35. AnisotropicSurfaceData anisotropy;
  36. #if ENABLE_TRANSMISSION
  37. TransmissionSurfaceData transmission;
  38. #endif
  39. uint lightingChannels; //!< Lightingchannel of the object
  40. // ------- BasePbrSurfaceData -------
  41. float3 position; //!< Position in world-space
  42. real3 normal; //!< Normal in world-space
  43. real3 vertexNormal; //!< Vertex normal in world-space
  44. real3 baseColor; //!< Surface base color
  45. real metallic; //!< Surface metallic property
  46. real roughnessLinear; //!< Perceptually linear roughness value authored by artists. Must be remapped to roughnessA before use
  47. real roughnessA; //!< Actual roughness value ( a.k.a. "alpha roughness") to be used in microfacet calculations
  48. float roughnessA2; //!< Alpha roughness ^ 2 (i.e. roughnessA * roughnessA), used in GGX, cached here for perfromance. Float precision is needed as values can get very close to 0
  49. real alpha;
  50. // Increase opacity at grazing angles for surfaces with a low m_opacityAffectsSpecularFactor.
  51. // For m_opacityAffectsSpecularFactor values close to 0, that indicates a transparent surface
  52. // like glass, so it becomes less transparent at grazing angles. For m_opacityAffectsSpecularFactor
  53. // values close to 1.0, that indicates the absence of a surface entirely, so this effect should
  54. // not apply.
  55. real opacityAffectsSpecularFactor;
  56. //! Subsurface scattering parameters
  57. real subsurfaceScatteringFactor;
  58. real subsurfaceScatteringQuality;
  59. real3 scatterDistance;
  60. //! Surface lighting inputs
  61. real3 albedo; //!< Albedo color of the non-metallic material, will be multiplied against the diffuse lighting value
  62. real3 specularF0; //!< Fresnel f0 spectral value of the surface
  63. real3 emissiveLighting; //!< Emissive lighting
  64. real diffuseAmbientOcclusion; //!< Diffuse ambient occlusion factor - [0, 1] :: [Dark, Bright]
  65. real specularOcclusion; //!< Specular occlusion factor - [0, 1] :: [Dark, Bright]
  66. //! Calculates roughnessA and roughnessA2 after roughness has been set
  67. void CalculateRoughnessA();
  68. //! Sets albedo and specularF0 using metallic workflow
  69. void SetAlbedoAndSpecularF0(real3 baseColor, real specularF0Factor, real metallic);
  70. real3 GetDiffuseNormal() { return normal; }
  71. real3 GetSpecularNormal() { return normal; }
  72. real3 GetDefaultNormal() { return normal; }
  73. real3 GetVertexNormal() { return vertexNormal; }
  74. real3 GetSpecularF0() { return specularF0; }
  75. };
  76. void SurfaceData_EnhancedPBR::CalculateRoughnessA()
  77. {
  78. CalculateRoughnessValues(normal, roughnessLinear, roughnessA, roughnessA2);
  79. }
  80. void SurfaceData_EnhancedPBR::SetAlbedoAndSpecularF0(real3 newBaseColor, real specularF0Factor, real newMetallic)
  81. {
  82. baseColor = newBaseColor;
  83. metallic = newMetallic;
  84. albedo = GetAlbedo(baseColor, metallic);
  85. specularF0 = CalculateSpecularF0(baseColor, metallic, specularF0Factor);
  86. }
  87. #endif