@babylonjs/addons 8.46.2 → 8.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/atmosphere/Shaders/ShadersInclude/atmosphereFunctions.js +7 -11
  2. package/atmosphere/Shaders/ShadersInclude/atmosphereFunctions.js.map +1 -1
  3. package/atmosphere/Shaders/compositeAerialPerspective.fragment.js +1 -2
  4. package/atmosphere/Shaders/compositeAerialPerspective.fragment.js.map +1 -1
  5. package/atmosphere/Shaders/compositeGlobeAtmosphere.fragment.js +2 -4
  6. package/atmosphere/Shaders/compositeGlobeAtmosphere.fragment.js.map +1 -1
  7. package/atmosphere/Shaders/compositeSky.fragment.js +2 -4
  8. package/atmosphere/Shaders/compositeSky.fragment.js.map +1 -1
  9. package/atmosphere/Shaders/diffuseSkyIrradiance.fragment.js +1 -2
  10. package/atmosphere/Shaders/diffuseSkyIrradiance.fragment.js.map +1 -1
  11. package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereFunctions.d.ts +5 -0
  12. package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereFunctions.js +48 -0
  13. package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereFunctions.js.map +1 -0
  14. package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereUboDeclaration.d.ts +5 -0
  15. package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereUboDeclaration.js +56 -0
  16. package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereUboDeclaration.js.map +1 -0
  17. package/atmosphere/atmosphere.d.ts +1 -6
  18. package/atmosphere/atmosphere.js +32 -37
  19. package/atmosphere/atmosphere.js.map +1 -1
  20. package/atmosphere/atmospherePBRMaterialPlugin.d.ts +8 -1
  21. package/atmosphere/atmospherePBRMaterialPlugin.js +89 -23
  22. package/atmosphere/atmospherePBRMaterialPlugin.js.map +1 -1
  23. package/package.json +2 -2
@@ -40,7 +40,7 @@ export class Atmosphere {
40
40
  * @returns True if the atmosphere is supported, false otherwise.
41
41
  */
42
42
  static IsSupported(engine) {
43
- return !engine._badOS && !engine.isWebGPU && engine.version >= 2;
43
+ return !engine._badOS && (engine.isWebGPU || engine.version >= 2);
44
44
  }
45
45
  /**
46
46
  * Controls the overall brightness of the atmosphere rendering.
@@ -563,10 +563,7 @@ export class Atmosphere {
563
563
  this.getDiffuseSkyIrradianceToRef = (directionToLight, pointRadius, pointGeocentricNormal, lightIrradiance, result) => this._diffuseSkyIrradianceLut?.getDiffuseSkyIrradianceToRef(directionToLight, pointRadius, pointGeocentricNormal, lightIrradiance, result) ??
564
564
  ((result.r = 0), (result.g = 0), (result.b = 0), result);
565
565
  const engine = (this._engine = scene.getEngine());
566
- if (engine.isWebGPU) {
567
- throw new Error("Atmosphere is not supported on WebGPU.");
568
- }
569
- if (engine.version < 2) {
566
+ if (!engine.isWebGPU && engine.version < 2) {
570
567
  throw new Error(`Atmosphere is not supported on WebGL ${engine.version}.`);
571
568
  }
572
569
  this._physicalProperties = options?.physicalProperties ?? new AtmospherePhysicalProperties();
@@ -615,6 +612,7 @@ export class Atmosphere {
615
612
  });
616
613
  this._transmittanceLut = new TransmittanceLut(this);
617
614
  this._multiScatteringLutRenderTarget = CreateRenderTargetTexture("atmo-multiScattering", { width: 32, height: 32 }, scene);
615
+ this._multiScatteringEffectWrapper = CreateMultiScatteringEffectWrapper(engine, this.uniformBuffer, this._groundAlbedo);
618
616
  if (options?.isDiffuseSkyIrradianceLutEnabled ?? true) {
619
617
  this._diffuseSkyIrradianceLut = new DiffuseSkyIrradianceLut(this);
620
618
  }
@@ -753,32 +751,6 @@ export class Atmosphere {
753
751
  getClassName() {
754
752
  return "Atmosphere";
755
753
  }
756
- /**
757
- * Creates a new {@link EffectWrapper} for the multiple scattering LUT
758
- * @returns The newly created {@link EffectWrapper}.
759
- */
760
- _createMultiScatteringEffectWrapper() {
761
- const engine = this._engine;
762
- const name = "atmo-multiScattering";
763
- const ubo = this.uniformBuffer;
764
- const useUbo = ubo.useUbo;
765
- const defines = ["#define POSITION_VEC2"];
766
- if (!this._groundAlbedo.equals(Color3.BlackReadOnly)) {
767
- defines.push("#define USE_GROUND_ALBEDO");
768
- }
769
- return new EffectWrapper({
770
- engine,
771
- name,
772
- vertexShader: "fullscreenTriangle",
773
- fragmentShader: "multiScattering",
774
- attributeNames: ["position"],
775
- uniformNames: ["depth", ...(useUbo ? [] : ubo.getUniformNames())],
776
- uniformBuffers: useUbo ? [ubo.name] : [],
777
- samplerNames: ["transmittanceLut"],
778
- defines,
779
- useShaderStore: true,
780
- });
781
- }
782
754
  /**
783
755
  * Draws the multiple scattering LUT using {@link EffectWrapper} and {@link EffectRenderer}.
784
756
  */
@@ -1022,7 +994,7 @@ export class Atmosphere {
1022
994
  this._diffuseSkyIrradianceLut?.markDirty();
1023
995
  }
1024
996
  if (!this._transmittanceLut.isDirty && !this._hasRenderedMultiScatteringLut) {
1025
- this._multiScatteringEffectWrapper ?? (this._multiScatteringEffectWrapper = this._createMultiScatteringEffectWrapper());
997
+ this._multiScatteringEffectWrapper ?? (this._multiScatteringEffectWrapper = CreateMultiScatteringEffectWrapper(this._engine, this.uniformBuffer, this._groundAlbedo));
1026
998
  if (this._multiScatteringEffectWrapper?.isReady() && this._multiScatteringLutRenderTarget?.isReady()) {
1027
999
  this._drawMultiScatteringLut();
1028
1000
  this._hasRenderedMultiScatteringLut = true;
@@ -1038,17 +1010,18 @@ export class Atmosphere {
1038
1010
  */
1039
1011
  bindUniformBufferToEffect(effect) {
1040
1012
  const uniformBuffer = this.uniformBuffer;
1041
- const name = uniformBuffer.name;
1042
- uniformBuffer.bindToEffect(effect, name);
1013
+ const isWGSL = effect.shaderLanguage === 1 /* ShaderLanguage.WGSL */;
1014
+ const blockName = isWGSL ? "atmosphere" : uniformBuffer.name;
1015
+ uniformBuffer.bindToEffect(effect, blockName);
1043
1016
  if (uniformBuffer.useUbo) {
1044
- uniformBuffer.bindUniformBuffer();
1017
+ uniformBuffer.update();
1045
1018
  }
1046
1019
  else {
1047
1020
  this.updateUniformBuffer();
1048
1021
  }
1049
1022
  }
1050
1023
  /**
1051
- * Updates the atmosphere's uniform buffer.
1024
+ * Updates the values in the atmosphere's uniform buffer.
1052
1025
  */
1053
1026
  updateUniformBuffer() {
1054
1027
  const physicalProperties = this._physicalProperties;
@@ -1099,7 +1072,6 @@ export class Atmosphere {
1099
1072
  ubo.updateFloat("originHeight", this._originHeight);
1100
1073
  ubo.updateFloat("sinCameraAtmosphereHorizonAngleFromNadir", cameraAtmosphereVariables.sinCameraAtmosphereHorizonAngleFromNadir);
1101
1074
  ubo.updateFloat("atmosphereExposure", this._exposure);
1102
- ubo.update();
1103
1075
  }
1104
1076
  /**
1105
1077
  * Draws the aerial perspective LUT using {@link EffectWrapper} and {@link EffectRenderer}.
@@ -1172,6 +1144,26 @@ const CreateEffectWrapper = (engine, name, fragmentShader, uniformNames, sampler
1172
1144
  useShaderStore: true,
1173
1145
  });
1174
1146
  };
1147
+ const CreateMultiScatteringEffectWrapper = (engine, uniformBuffer, groundAlbedo) => {
1148
+ const name = "atmo-multiScattering";
1149
+ const useUbo = uniformBuffer.useUbo;
1150
+ const defines = ["#define POSITION_VEC2"];
1151
+ if (!groundAlbedo.equals(Color3.BlackReadOnly)) {
1152
+ defines.push("#define USE_GROUND_ALBEDO");
1153
+ }
1154
+ return new EffectWrapper({
1155
+ engine,
1156
+ name,
1157
+ vertexShader: "fullscreenTriangle",
1158
+ fragmentShader: "multiScattering",
1159
+ attributeNames: ["position"],
1160
+ uniformNames: ["depth", ...(useUbo ? [] : uniformBuffer.getUniformNames())],
1161
+ uniformBuffers: useUbo ? [uniformBuffer.name] : [],
1162
+ samplerNames: ["transmittanceLut"],
1163
+ defines,
1164
+ useShaderStore: true,
1165
+ });
1166
+ };
1175
1167
  const CreateRenderTargetTexture = (name, size, scene, options) => {
1176
1168
  const caps = scene.getEngine().getCaps();
1177
1169
  const textureType = caps.textureHalfFloatRender
@@ -1229,11 +1221,14 @@ const DrawEffect = (engine, effectRenderer, effectWrapper, renderTarget, drawCal
1229
1221
  effectRenderer.saveStates();
1230
1222
  effectRenderer.setViewport();
1231
1223
  effectRenderer.applyEffectWrapper(effectWrapper, depthTest); // Note, stencil is false by default.
1224
+ const currentCull = engine.depthCullingState.cull;
1225
+ engine.depthCullingState.cull = false;
1232
1226
  const effect = effectWrapper.effect;
1233
1227
  effect.setFloat("depth", depth);
1234
1228
  // Call the specific drawing logic.
1235
1229
  drawCallback(effectRenderer, renderTarget?.renderTarget, effect, engine);
1236
1230
  // Restore state (order matters!)
1231
+ engine.depthCullingState.cull = currentCull;
1237
1232
  engine.setAlphaMode(currentAlphaMode);
1238
1233
  if (currentDepthWrite !== undefined) {
1239
1234
  engine.setDepthWrite(currentDepthWrite);