pbrBRDFConfiguration.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { __decorate } from "../../tslib.es6.js";
  2. /* eslint-disable @typescript-eslint/naming-convention */
  3. import { serialize, expandToProperty } from "../../Misc/decorators.js";
  4. import { MaterialDefines } from "../materialDefines.js";
  5. import { MaterialPluginBase } from "../materialPluginBase.js";
  6. /**
  7. * @internal
  8. */
  9. export class MaterialBRDFDefines extends MaterialDefines {
  10. constructor() {
  11. super(...arguments);
  12. this.BRDF_V_HEIGHT_CORRELATED = false;
  13. this.MS_BRDF_ENERGY_CONSERVATION = false;
  14. this.SPHERICAL_HARMONICS = false;
  15. this.SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = false;
  16. }
  17. }
  18. /**
  19. * Plugin that implements the BRDF component of the PBR material
  20. */
  21. export class PBRBRDFConfiguration extends MaterialPluginBase {
  22. /** @internal */
  23. _markAllSubMeshesAsMiscDirty() {
  24. this._internalMarkAllSubMeshesAsMiscDirty();
  25. }
  26. constructor(material, addToPluginList = true) {
  27. super(material, "PBRBRDF", 90, new MaterialBRDFDefines(), addToPluginList);
  28. this._useEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_ENERGY_CONSERVATION;
  29. /**
  30. * Defines if the material uses energy conservation.
  31. */
  32. this.useEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_ENERGY_CONSERVATION;
  33. this._useSmithVisibilityHeightCorrelated = PBRBRDFConfiguration.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED;
  34. /**
  35. * LEGACY Mode set to false
  36. * Defines if the material uses height smith correlated visibility term.
  37. * If you intent to not use our default BRDF, you need to load a separate BRDF Texture for the PBR
  38. * You can either load https://assets.babylonjs.com/environments/uncorrelatedBRDF.png
  39. * or https://assets.babylonjs.com/environments/uncorrelatedBRDF.dds to have more precision
  40. * Not relying on height correlated will also disable energy conservation.
  41. */
  42. this.useSmithVisibilityHeightCorrelated = PBRBRDFConfiguration.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED;
  43. this._useSphericalHarmonics = PBRBRDFConfiguration.DEFAULT_USE_SPHERICAL_HARMONICS;
  44. /**
  45. * LEGACY Mode set to false
  46. * Defines if the material uses spherical harmonics vs spherical polynomials for the
  47. * diffuse part of the IBL.
  48. * The harmonics despite a tiny bigger cost has been proven to provide closer results
  49. * to the ground truth.
  50. */
  51. this.useSphericalHarmonics = PBRBRDFConfiguration.DEFAULT_USE_SPHERICAL_HARMONICS;
  52. this._useSpecularGlossinessInputEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION;
  53. /**
  54. * Defines if the material uses energy conservation, when the specular workflow is active.
  55. * If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).
  56. * If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.
  57. * In the deactivated case, the material author has to ensure energy conservation, for a physically plausible rendering.
  58. */
  59. this.useSpecularGlossinessInputEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION;
  60. this._internalMarkAllSubMeshesAsMiscDirty = material._dirtyCallbacks[16];
  61. this._enable(true);
  62. }
  63. prepareDefines(defines) {
  64. defines.BRDF_V_HEIGHT_CORRELATED = this._useSmithVisibilityHeightCorrelated;
  65. defines.MS_BRDF_ENERGY_CONSERVATION = this._useEnergyConservation && this._useSmithVisibilityHeightCorrelated;
  66. defines.SPHERICAL_HARMONICS = this._useSphericalHarmonics;
  67. defines.SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = this._useSpecularGlossinessInputEnergyConservation;
  68. }
  69. getClassName() {
  70. return "PBRBRDFConfiguration";
  71. }
  72. }
  73. /**
  74. * Default value used for the energy conservation.
  75. * This should only be changed to adapt to the type of texture in scene.environmentBRDFTexture.
  76. */
  77. PBRBRDFConfiguration.DEFAULT_USE_ENERGY_CONSERVATION = true;
  78. /**
  79. * Default value used for the Smith Visibility Height Correlated mode.
  80. * This should only be changed to adapt to the type of texture in scene.environmentBRDFTexture.
  81. */
  82. PBRBRDFConfiguration.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED = true;
  83. /**
  84. * Default value used for the IBL diffuse part.
  85. * This can help switching back to the polynomials mode globally which is a tiny bit
  86. * less GPU intensive at the drawback of a lower quality.
  87. */
  88. PBRBRDFConfiguration.DEFAULT_USE_SPHERICAL_HARMONICS = true;
  89. /**
  90. * Default value used for activating energy conservation for the specular workflow.
  91. * If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).
  92. * If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.
  93. */
  94. PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION = true;
  95. __decorate([
  96. serialize(),
  97. expandToProperty("_markAllSubMeshesAsMiscDirty")
  98. ], PBRBRDFConfiguration.prototype, "useEnergyConservation", void 0);
  99. __decorate([
  100. serialize(),
  101. expandToProperty("_markAllSubMeshesAsMiscDirty")
  102. ], PBRBRDFConfiguration.prototype, "useSmithVisibilityHeightCorrelated", void 0);
  103. __decorate([
  104. serialize(),
  105. expandToProperty("_markAllSubMeshesAsMiscDirty")
  106. ], PBRBRDFConfiguration.prototype, "useSphericalHarmonics", void 0);
  107. __decorate([
  108. serialize(),
  109. expandToProperty("_markAllSubMeshesAsMiscDirty")
  110. ], PBRBRDFConfiguration.prototype, "useSpecularGlossinessInputEnergyConservation", void 0);
  111. //# sourceMappingURL=pbrBRDFConfiguration.js.map