@babylonjs/addons 8.46.1 → 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.
- package/atmosphere/Shaders/ShadersInclude/atmosphereFunctions.js +7 -11
- package/atmosphere/Shaders/ShadersInclude/atmosphereFunctions.js.map +1 -1
- package/atmosphere/Shaders/compositeAerialPerspective.fragment.js +1 -2
- package/atmosphere/Shaders/compositeAerialPerspective.fragment.js.map +1 -1
- package/atmosphere/Shaders/compositeGlobeAtmosphere.fragment.js +2 -4
- package/atmosphere/Shaders/compositeGlobeAtmosphere.fragment.js.map +1 -1
- package/atmosphere/Shaders/compositeSky.fragment.js +2 -4
- package/atmosphere/Shaders/compositeSky.fragment.js.map +1 -1
- package/atmosphere/Shaders/diffuseSkyIrradiance.fragment.js +1 -2
- package/atmosphere/Shaders/diffuseSkyIrradiance.fragment.js.map +1 -1
- package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereFunctions.d.ts +5 -0
- package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereFunctions.js +48 -0
- package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereFunctions.js.map +1 -0
- package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereUboDeclaration.d.ts +5 -0
- package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereUboDeclaration.js +56 -0
- package/atmosphere/ShadersWGSL/ShadersInclude/atmosphereUboDeclaration.js.map +1 -0
- package/atmosphere/atmosphere.d.ts +1 -6
- package/atmosphere/atmosphere.js +32 -37
- package/atmosphere/atmosphere.js.map +1 -1
- package/atmosphere/atmospherePBRMaterialPlugin.d.ts +8 -1
- package/atmosphere/atmospherePBRMaterialPlugin.js +89 -23
- package/atmosphere/atmospherePBRMaterialPlugin.js.map +1 -1
- package/package.json +2 -2
|
@@ -5,6 +5,9 @@ import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
|
|
|
5
5
|
import { MaterialPluginBase } from "@babylonjs/core/Materials/materialPluginBase.js";
|
|
6
6
|
import type { Nullable } from "@babylonjs/core/types.js";
|
|
7
7
|
import type { UniformBuffer } from "@babylonjs/core/Materials/uniformBuffer.js";
|
|
8
|
+
import { ShaderLanguage } from "@babylonjs/core/Materials/shaderLanguage.js";
|
|
9
|
+
import "./ShadersWGSL/ShadersInclude/atmosphereFunctions.js";
|
|
10
|
+
import "./ShadersWGSL/ShadersInclude/atmosphereUboDeclaration.js";
|
|
8
11
|
declare class AtmospherePBRMaterialDefines extends MaterialDefines {
|
|
9
12
|
USE_AERIAL_PERSPECTIVE_LUT: boolean;
|
|
10
13
|
APPLY_AERIAL_PERSPECTIVE_INTENSITY: boolean;
|
|
@@ -30,6 +33,10 @@ export declare class AtmospherePBRMaterialPlugin extends MaterialPluginBase {
|
|
|
30
33
|
* @param _isAerialPerspectiveEnabled - Whether to apply aerial perspective.
|
|
31
34
|
*/
|
|
32
35
|
constructor(material: Material, _atmosphere: Atmosphere, _isAerialPerspectiveEnabled?: boolean);
|
|
36
|
+
/**
|
|
37
|
+
* @override
|
|
38
|
+
*/
|
|
39
|
+
isCompatible(): boolean;
|
|
33
40
|
/**
|
|
34
41
|
* @override
|
|
35
42
|
*/
|
|
@@ -69,6 +76,6 @@ export declare class AtmospherePBRMaterialPlugin extends MaterialPluginBase {
|
|
|
69
76
|
/**
|
|
70
77
|
* @override
|
|
71
78
|
*/
|
|
72
|
-
getCustomCode(shaderType: string): Nullable<Record<string, string>>;
|
|
79
|
+
getCustomCode(shaderType: string, shaderLanguage: ShaderLanguage): Nullable<Record<string, string>>;
|
|
73
80
|
}
|
|
74
81
|
export {};
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
|
|
4
4
|
import { MaterialPluginBase } from "@babylonjs/core/Materials/materialPluginBase.js";
|
|
5
5
|
import { Vector3FromFloatsToRef, Vector3ScaleToRef } from "@babylonjs/core/Maths/math.vector.functions.js";
|
|
6
|
+
import "./ShadersWGSL/ShadersInclude/atmosphereFunctions.js";
|
|
7
|
+
import "./ShadersWGSL/ShadersInclude/atmosphereUboDeclaration.js";
|
|
6
8
|
class AtmospherePBRMaterialDefines extends MaterialDefines {
|
|
7
9
|
/**
|
|
8
10
|
* Constructs the {@link AtmospherePBRMaterialDefines}.
|
|
@@ -10,13 +12,9 @@ class AtmospherePBRMaterialDefines extends MaterialDefines {
|
|
|
10
12
|
*/
|
|
11
13
|
constructor(useAerialPerspectiveLut) {
|
|
12
14
|
super();
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
14
15
|
this.APPLY_AERIAL_PERSPECTIVE_INTENSITY = false;
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
16
16
|
this.APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS = false;
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
18
17
|
this.SAMPLE_TRANSMITTANCE_LUT = true;
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
20
18
|
this.EXCLUDE_RAY_MARCHING_FUNCTIONS = true;
|
|
21
19
|
this.USE_AERIAL_PERSPECTIVE_LUT = useAerialPerspectiveLut;
|
|
22
20
|
}
|
|
@@ -48,19 +46,12 @@ export class AtmospherePBRMaterialPlugin extends MaterialPluginBase {
|
|
|
48
46
|
*/
|
|
49
47
|
constructor(material, _atmosphere, _isAerialPerspectiveEnabled = false) {
|
|
50
48
|
super(material, PluginName, PluginPriority, {
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
52
49
|
USE_CUSTOM_REFLECTION: _atmosphere.diffuseSkyIrradianceLut !== null,
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
54
50
|
CUSTOM_FRAGMENT_BEFORE_FOG: _isAerialPerspectiveEnabled,
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
56
51
|
USE_AERIAL_PERSPECTIVE_LUT: _isAerialPerspectiveEnabled && _atmosphere.isAerialPerspectiveLutEnabled,
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
58
52
|
APPLY_AERIAL_PERSPECTIVE_INTENSITY: _isAerialPerspectiveEnabled && _atmosphere.aerialPerspectiveIntensity !== 1.0,
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
60
53
|
APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS: _isAerialPerspectiveEnabled && _atmosphere.aerialPerspectiveRadianceBias !== 0.0,
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
62
54
|
SAMPLE_TRANSMITTANCE_LUT: true,
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
64
55
|
EXCLUDE_RAY_MARCHING_FUNCTIONS: true,
|
|
65
56
|
}, false, // addPluginToList -- false because we need to control when this is added to the list
|
|
66
57
|
true, // enable
|
|
@@ -72,13 +63,20 @@ export class AtmospherePBRMaterialPlugin extends MaterialPluginBase {
|
|
|
72
63
|
// This calls `getCode` so we need to do this after having initialized the class fields.
|
|
73
64
|
this._pluginManager._addPlugin(this);
|
|
74
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* @override
|
|
68
|
+
*/
|
|
69
|
+
isCompatible() {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
75
72
|
/**
|
|
76
73
|
* @override
|
|
77
74
|
*/
|
|
78
75
|
getUniformBuffersNames(_ubos) {
|
|
79
76
|
const uniformBuffer = this._atmosphere.uniformBuffer;
|
|
80
77
|
if (uniformBuffer.useUbo) {
|
|
81
|
-
|
|
78
|
+
const uboName = this._material.shaderLanguage === 1 /* ShaderLanguage.WGSL */ ? "atmosphere" : uniformBuffer.name;
|
|
79
|
+
_ubos.push(uboName);
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
/**
|
|
@@ -174,7 +172,7 @@ export class AtmospherePBRMaterialPlugin extends MaterialPluginBase {
|
|
|
174
172
|
/**
|
|
175
173
|
* @override
|
|
176
174
|
*/
|
|
177
|
-
getCustomCode(shaderType) {
|
|
175
|
+
getCustomCode(shaderType, shaderLanguage) {
|
|
178
176
|
// Assumed inputs are light0, vPositionW, normalW.
|
|
179
177
|
// Only works for directional lights.
|
|
180
178
|
if (shaderType !== "fragment") {
|
|
@@ -182,13 +180,14 @@ export class AtmospherePBRMaterialPlugin extends MaterialPluginBase {
|
|
|
182
180
|
}
|
|
183
181
|
const useUbo = this._atmosphere.scene.getEngine().supportsUniformBuffers;
|
|
184
182
|
const directionToLightSnippet = useUbo ? "-light0.vLightData.xyz" : "-vLightData0.xyz";
|
|
185
|
-
const useAtmosphereUbo = this._atmosphere.uniformBuffer.useUbo;
|
|
183
|
+
const useAtmosphereUbo = shaderLanguage === 1 /* ShaderLanguage.WGSL */ || this._atmosphere.uniformBuffer.useUbo;
|
|
186
184
|
const atmosphereImportSnippet = useAtmosphereUbo ? "#include<atmosphereUboDeclaration>" : "#include<atmosphereFragmentDeclaration>";
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
185
|
+
if (shaderLanguage === 0 /* ShaderLanguage.GLSL */) {
|
|
186
|
+
return {
|
|
187
|
+
CUSTOM_FRAGMENT_DEFINITIONS: this._isAerialPerspectiveEnabled && this._atmosphere.isAerialPerspectiveLutEnabled
|
|
188
|
+
? `uniform sampler2D transmittanceLut;\r\nprecision highp sampler2DArray;\r\nuniform sampler2DArray aerialPerspectiveLut;\r\n${atmosphereImportSnippet}\r\n#include<atmosphereFunctions>`
|
|
189
|
+
: `uniform sampler2D transmittanceLut;\r\n${atmosphereImportSnippet}\r\n#include<atmosphereFunctions>`,
|
|
190
|
+
CUSTOM_LIGHT0_COLOR: `
|
|
192
191
|
{
|
|
193
192
|
vec3 positionGlobal = 0.001 * vPositionW + ${OriginOffsetUniformName};
|
|
194
193
|
float positionRadius = length(positionGlobal);
|
|
@@ -198,7 +197,7 @@ export class AtmospherePBRMaterialPlugin extends MaterialPluginBase {
|
|
|
198
197
|
diffuse0 = lightIntensity * sampleTransmittanceLut(transmittanceLut, positionRadius, cosAngleLightToZenith);
|
|
199
198
|
}
|
|
200
199
|
`,
|
|
201
|
-
|
|
200
|
+
CUSTOM_REFLECTION: `
|
|
202
201
|
{
|
|
203
202
|
vec3 positionGlobal = 0.001 * vPositionW + ${OriginOffsetUniformName};
|
|
204
203
|
float positionRadius = length(positionGlobal);
|
|
@@ -227,8 +226,8 @@ export class AtmospherePBRMaterialPlugin extends MaterialPluginBase {
|
|
|
227
226
|
reflectionOut.environmentRadiance.rgb = reflectionOut.environmentIrradiance;
|
|
228
227
|
}
|
|
229
228
|
`,
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
// TODO: Support full ray marching if USE_AERIAL_PERSPECTIVE_LUT is disabled.
|
|
230
|
+
CUSTOM_FRAGMENT_BEFORE_FOG: `
|
|
232
231
|
#if USE_AERIAL_PERSPECTIVE_LUT
|
|
233
232
|
{
|
|
234
233
|
float distanceFromCameraKm = 0.001 * distance(vEyePosition.xyz, vPositionW);
|
|
@@ -246,7 +245,74 @@ export class AtmospherePBRMaterialPlugin extends MaterialPluginBase {
|
|
|
246
245
|
}
|
|
247
246
|
#endif
|
|
248
247
|
`,
|
|
249
|
-
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
// WGSL
|
|
252
|
+
return {
|
|
253
|
+
CUSTOM_FRAGMENT_DEFINITIONS: this._isAerialPerspectiveEnabled && this._atmosphere.isAerialPerspectiveLutEnabled
|
|
254
|
+
? `var transmittanceLutSampler: sampler;\r\nvar transmittanceLut: texture_2d<f32>;\r\nvar aerialPerspectiveLutSampler: sampler;\r\nvar aerialPerspectiveLut: texture_2d_array<f32>;\r\n${atmosphereImportSnippet}\r\n#include<atmosphereFunctions>`
|
|
255
|
+
: `var transmittanceLutSampler: sampler;\r\nvar transmittanceLut: texture_2d<f32>;\r\n${atmosphereImportSnippet}\r\n#include<atmosphereFunctions>`,
|
|
256
|
+
CUSTOM_LIGHT0_COLOR: `
|
|
257
|
+
{
|
|
258
|
+
var positionGlobal = 0.001 * fragmentInputs.vPositionW + uniforms.${OriginOffsetUniformName};
|
|
259
|
+
var positionRadius = length(positionGlobal);
|
|
260
|
+
var geocentricNormal = positionGlobal / positionRadius;
|
|
261
|
+
var directionToLight = ${directionToLightSnippet};
|
|
262
|
+
var cosAngleLightToZenith = dot(directionToLight, geocentricNormal);
|
|
263
|
+
diffuse0 = atmosphere.lightIntensity * sampleTransmittanceLut(transmittanceLut, positionRadius, cosAngleLightToZenith);
|
|
264
|
+
}
|
|
265
|
+
`,
|
|
266
|
+
CUSTOM_REFLECTION: `
|
|
267
|
+
{
|
|
268
|
+
var positionGlobal = 0.001 * fragmentInputs.vPositionW + uniforms.${OriginOffsetUniformName};
|
|
269
|
+
var positionRadius = length(positionGlobal);
|
|
270
|
+
var geocentricNormal = positionGlobal / positionRadius;
|
|
271
|
+
|
|
272
|
+
var directionToLight = ${directionToLightSnippet};
|
|
273
|
+
var cosAngleLightToZenith = dot(directionToLight, geocentricNormal);
|
|
274
|
+
|
|
275
|
+
var uv = vec2f(0.5 + 0.5 * cosAngleLightToZenith, (positionRadius - atmosphere.planetRadius) / atmosphere.atmosphereThickness);
|
|
276
|
+
var irradianceScaleT = 0.5 * dot(normalW, geocentricNormal) + 0.5;
|
|
277
|
+
var irradianceScale = ((-0.6652 * irradianceScaleT) + 1.5927) * irradianceScaleT + 0.1023;
|
|
278
|
+
var environmentIrradiance = atmosphere.lightIntensity * textureSample(irradianceSampler, irradianceSamplerSampler, uv).rgb;
|
|
279
|
+
|
|
280
|
+
// Add a contribution here to estimate indirect lighting.
|
|
281
|
+
const r = 0.2;
|
|
282
|
+
var indirect = getLuminance(environmentIrradiance) / max(0.00001, 1.0 - r);
|
|
283
|
+
environmentIrradiance *= irradianceScale;
|
|
284
|
+
environmentIrradiance += indirect;
|
|
285
|
+
|
|
286
|
+
environmentIrradiance += atmosphere.additionalDiffuseSkyIrradiance;
|
|
287
|
+
|
|
288
|
+
const diffuseBrdf = 1.0 / PI;
|
|
289
|
+
environmentIrradiance *= diffuseBrdf * atmosphere.diffuseSkyIrradianceIntensity;
|
|
290
|
+
|
|
291
|
+
reflectionOut.environmentIrradiance = environmentIrradiance;
|
|
292
|
+
reflectionOut.environmentRadiance = vec4f(reflectionOut.environmentIrradiance, reflectionOut.environmentRadiance.a);
|
|
293
|
+
}
|
|
294
|
+
`,
|
|
295
|
+
// TODO: Support full ray marching if USE_AERIAL_PERSPECTIVE_LUT is disabled.
|
|
296
|
+
CUSTOM_FRAGMENT_BEFORE_FOG: `
|
|
297
|
+
#if USE_AERIAL_PERSPECTIVE_LUT
|
|
298
|
+
{
|
|
299
|
+
var distanceFromCameraKm = 0.001 * distance(scene.vEyePosition.xyz, fragmentInputs.vPositionW);
|
|
300
|
+
var aerialPerspective = vec4f(0.);
|
|
301
|
+
if (sampleAerialPerspectiveLut(
|
|
302
|
+
fragmentInputs.position.xy * uniforms.${InverseViewportSizeUniformName},
|
|
303
|
+
true,
|
|
304
|
+
distanceFromCameraKm,
|
|
305
|
+
NumAerialPerspectiveLutLayers,
|
|
306
|
+
AerialPerspectiveLutKMPerSlice,
|
|
307
|
+
AerialPerspectiveLutRangeKM,
|
|
308
|
+
&aerialPerspective)) {
|
|
309
|
+
finalColor = aerialPerspective + (1. - aerialPerspective.a) * finalColor;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
#endif
|
|
313
|
+
`,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
250
316
|
}
|
|
251
317
|
}
|
|
252
318
|
//# sourceMappingURL=atmospherePBRMaterialPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atmospherePBRMaterialPlugin.js","sourceRoot":"","sources":["../../../../dev/addons/src/atmosphere/atmospherePBRMaterialPlugin.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAKlC,OAAO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AAC,oCAAoC,CAAC,CAAC,CAAC,yCAAyC,CAAC;QAEpI,OAAO;YACH,2BAA2B,EACvB,IAAI,CAAC,2BAA2B,IAAI,IAAI,CAAC,WAAW,CAAC,6BAA6B;gBAC9E,CAAC,CAAC,6HAA6H,uBAAuB,mCAAmC;gBACzL,CAAC,CAAC,0CAA0C,uBAAuB,mCAAmC;YAC9G,mBAAmB,EAAE;;6DAE4B,uBAAuB;;;0CAG1C,uBAAuB;;;;CAIhE;YACW,iBAAiB,EAAE;;8DAE+B,uBAAuB;;;;0CAI3C,uBAAuB;;;;;;;;;;;;;;;;;;;;;;CAsBhE;YACW,6EAA6E;YAC7E,0BAA0B,EAAE;;;;;;4CAMI,8BAA8B;;;;;;;;;;;CAWzE;SACQ,CAAC;IACN,CAAC;CACJ","sourcesContent":["// Copyright (c) Microsoft Corporation.\r\n// Licensed under the MIT License.\r\n\r\nimport type { Atmosphere } from \"./atmosphere\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { MaterialPluginBase } from \"core/Materials/materialPluginBase\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { UniformBuffer } from \"core/Materials/uniformBuffer\";\r\nimport { Vector3FromFloatsToRef, Vector3ScaleToRef } from \"core/Maths/math.vector.functions\";\r\n\r\nclass AtmospherePBRMaterialDefines extends MaterialDefines {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public USE_AERIAL_PERSPECTIVE_LUT: boolean;\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public APPLY_AERIAL_PERSPECTIVE_INTENSITY = false;\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS = false;\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public SAMPLE_TRANSMITTANCE_LUT = true;\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public EXCLUDE_RAY_MARCHING_FUNCTIONS = true;\r\n\r\n /**\r\n * Constructs the {@link AtmospherePBRMaterialDefines}.\r\n * @param useAerialPerspectiveLut - Whether to use the aerial perspective LUT.\r\n */\r\n constructor(useAerialPerspectiveLut: boolean) {\r\n super();\r\n this.USE_AERIAL_PERSPECTIVE_LUT = useAerialPerspectiveLut;\r\n }\r\n}\r\n\r\nconst OriginOffsetUniformName = \"originOffsetKm\";\r\nconst InverseViewportSizeUniformName = \"inverseViewportSize\";\r\n\r\nconst UboArray = [\r\n { name: OriginOffsetUniformName, size: 3, type: \"vec3\" },\r\n { name: \"_atmoPbrPadding1\", size: 1, type: \"float\" },\r\n { name: InverseViewportSizeUniformName, size: 2, type: \"vec2\" },\r\n];\r\nconst MakeUniforms = (atmosphere: Atmosphere) => ({\r\n ubo: UboArray,\r\n fragment: `uniform vec2 ${InverseViewportSizeUniformName};\\nuniform vec3 ${OriginOffsetUniformName};\\n`,\r\n externalUniforms: atmosphere.uniformBuffer.getUniformNames(),\r\n});\r\n\r\nconst PluginName = \"AtmospherePBRMaterialPlugin\";\r\nconst PluginPriority = 600;\r\nconst OriginOffsetKm = { x: 0, y: 0, z: 0 };\r\n\r\n/**\r\n * Adds shading logic to a PBRMaterial that provides radiance, diffuse sky irradiance, and aerial perspective from the atmosphere.\r\n */\r\nexport class AtmospherePBRMaterialPlugin extends MaterialPluginBase {\r\n /**\r\n * Constructs the {@link AtmospherePBRMaterialPlugin}.\r\n * @param material - The material to apply the plugin to.\r\n * @param _atmosphere - The atmosphere to use for shading.\r\n * @param _isAerialPerspectiveEnabled - Whether to apply aerial perspective.\r\n */\r\n constructor(\r\n material: Material,\r\n private readonly _atmosphere: Atmosphere,\r\n private readonly _isAerialPerspectiveEnabled = false\r\n ) {\r\n super(\r\n material,\r\n PluginName,\r\n PluginPriority,\r\n {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n USE_CUSTOM_REFLECTION: _atmosphere.diffuseSkyIrradianceLut !== null,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_FRAGMENT_BEFORE_FOG: _isAerialPerspectiveEnabled,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n USE_AERIAL_PERSPECTIVE_LUT: _isAerialPerspectiveEnabled && _atmosphere.isAerialPerspectiveLutEnabled,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n APPLY_AERIAL_PERSPECTIVE_INTENSITY: _isAerialPerspectiveEnabled && _atmosphere.aerialPerspectiveIntensity !== 1.0,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS: _isAerialPerspectiveEnabled && _atmosphere.aerialPerspectiveRadianceBias !== 0.0,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n SAMPLE_TRANSMITTANCE_LUT: true,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n EXCLUDE_RAY_MARCHING_FUNCTIONS: true,\r\n },\r\n false, // addPluginToList -- false because we need to control when this is added to the list\r\n true, // enable\r\n true // resolveIncludes\r\n );\r\n\r\n this.doNotSerialize = true;\r\n\r\n // This calls `getCode` so we need to do this after having initialized the class fields.\r\n this._pluginManager._addPlugin(this);\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getUniformBuffersNames(_ubos: string[]): void {\r\n const uniformBuffer = this._atmosphere.uniformBuffer;\r\n if (uniformBuffer.useUbo) {\r\n _ubos.push(uniformBuffer.name);\r\n }\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getUniforms() {\r\n return MakeUniforms(this._atmosphere);\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override isReadyForSubMesh(): boolean {\r\n let isReady = true;\r\n const atmosphere = this._atmosphere;\r\n if (this._isAerialPerspectiveEnabled && atmosphere.isAerialPerspectiveLutEnabled) {\r\n const aerialPerspectiveLutRenderTarget = atmosphere.aerialPerspectiveLutRenderTarget;\r\n isReady = isReady && !!aerialPerspectiveLutRenderTarget?.isReady();\r\n }\r\n const transmittanceLutRenderTarget = atmosphere.transmittanceLut?.renderTarget ?? null;\r\n isReady = isReady && !!transmittanceLutRenderTarget?.isReady();\r\n return isReady;\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getActiveTextures(_activeTextures: BaseTexture[]): void {\r\n const atmosphere = this._atmosphere;\r\n if (this._isAerialPerspectiveEnabled && atmosphere.isAerialPerspectiveLutEnabled) {\r\n const aerialPerspectiveLutRenderTarget = atmosphere.aerialPerspectiveLutRenderTarget;\r\n if (aerialPerspectiveLutRenderTarget) {\r\n _activeTextures.push(aerialPerspectiveLutRenderTarget);\r\n }\r\n }\r\n\r\n const transmittanceLutRenderTarget = atmosphere.transmittanceLut?.renderTarget ?? null;\r\n if (transmittanceLutRenderTarget) {\r\n _activeTextures.push(transmittanceLutRenderTarget);\r\n }\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override bindForSubMesh(uniformBuffer: UniformBuffer): void {\r\n const atmosphere = this._atmosphere;\r\n const scene = atmosphere.scene;\r\n const engine = scene.getEngine();\r\n\r\n // Bind the atmosphere's uniform buffer to the effect.\r\n const effect = uniformBuffer.currentEffect;\r\n if (effect) {\r\n this._atmosphere.bindUniformBufferToEffect(effect);\r\n }\r\n\r\n // Need the offset to apply which will take a world space position and convert it to a global space position in the atmosphere.\r\n // If floating origin mode is enabled, that offset is the floating origin offset.\r\n // If not, it's an offset up the Y-axis by the planet radius.\r\n uniformBuffer.updateVector3(\r\n OriginOffsetUniformName,\r\n scene.floatingOriginMode\r\n ? Vector3ScaleToRef(scene.floatingOriginOffset, 0.001, OriginOffsetKm) // Convert to kilometers\r\n : Vector3FromFloatsToRef(0, atmosphere.physicalProperties.planetRadius, 0, OriginOffsetKm) // planetRadius is already in kilometers\r\n );\r\n\r\n const width = engine.getRenderWidth();\r\n const height = engine.getRenderHeight();\r\n uniformBuffer.updateFloat2(InverseViewportSizeUniformName, 1.0 / width, 1.0 / height);\r\n\r\n if (this._isAerialPerspectiveEnabled && atmosphere.isAerialPerspectiveLutEnabled) {\r\n const aerialPerspectiveLutRenderTarget = atmosphere.aerialPerspectiveLutRenderTarget;\r\n uniformBuffer.setTexture(\"aerialPerspectiveLut\", aerialPerspectiveLutRenderTarget);\r\n }\r\n const transmittanceLutRenderTarget = atmosphere.transmittanceLut?.renderTarget ?? null;\r\n uniformBuffer.setTexture(\"transmittanceLut\", transmittanceLutRenderTarget);\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override prepareDefines(defines: AtmospherePBRMaterialDefines): void {\r\n const lastUseAerialPerspectiveLut = defines.USE_AERIAL_PERSPECTIVE_LUT;\r\n const lastApplyAerialPerspectiveIntensity = defines.APPLY_AERIAL_PERSPECTIVE_INTENSITY;\r\n const lastApplyAerialPerspectiveRadianceBias = defines.APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS;\r\n defines.USE_AERIAL_PERSPECTIVE_LUT = this._isAerialPerspectiveEnabled && this._atmosphere.isAerialPerspectiveLutEnabled;\r\n defines.APPLY_AERIAL_PERSPECTIVE_INTENSITY = this._isAerialPerspectiveEnabled && this._atmosphere.aerialPerspectiveIntensity !== 1.0;\r\n defines.APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS = this._isAerialPerspectiveEnabled && this._atmosphere.aerialPerspectiveRadianceBias !== 0.0;\r\n if (\r\n lastUseAerialPerspectiveLut !== defines.USE_AERIAL_PERSPECTIVE_LUT ||\r\n lastApplyAerialPerspectiveIntensity !== defines.APPLY_AERIAL_PERSPECTIVE_INTENSITY ||\r\n lastApplyAerialPerspectiveRadianceBias !== defines.APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS\r\n ) {\r\n defines.markAllAsDirty();\r\n }\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getSamplers(samplers: string[]): void {\r\n samplers.push(\"transmittanceLut\");\r\n if (this._isAerialPerspectiveEnabled && this._atmosphere.isAerialPerspectiveLutEnabled) {\r\n samplers.push(\"aerialPerspectiveLut\");\r\n }\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getCustomCode(shaderType: string): Nullable<Record<string, string>> {\r\n // Assumed inputs are light0, vPositionW, normalW.\r\n // Only works for directional lights.\r\n if (shaderType !== \"fragment\") {\r\n return null;\r\n }\r\n\r\n const useUbo = this._atmosphere.scene.getEngine().supportsUniformBuffers;\r\n const directionToLightSnippet = useUbo ? \"-light0.vLightData.xyz\" : \"-vLightData0.xyz\";\r\n\r\n const useAtmosphereUbo = this._atmosphere.uniformBuffer.useUbo;\r\n const atmosphereImportSnippet = useAtmosphereUbo ? \"#include<atmosphereUboDeclaration>\" : \"#include<atmosphereFragmentDeclaration>\";\r\n\r\n return {\r\n CUSTOM_FRAGMENT_DEFINITIONS:\r\n this._isAerialPerspectiveEnabled && this._atmosphere.isAerialPerspectiveLutEnabled\r\n ? `uniform sampler2D transmittanceLut;\\r\\nprecision highp sampler2DArray;\\r\\nuniform sampler2DArray aerialPerspectiveLut;\\r\\n${atmosphereImportSnippet}\\r\\n#include<atmosphereFunctions>`\r\n : `uniform sampler2D transmittanceLut;\\r\\n${atmosphereImportSnippet}\\r\\n#include<atmosphereFunctions>`,\r\n CUSTOM_LIGHT0_COLOR: `\r\n {\r\n vec3 positionGlobal = 0.001 * vPositionW + ${OriginOffsetUniformName};\r\n float positionRadius = length(positionGlobal);\r\n vec3 geocentricNormal = positionGlobal / positionRadius;\r\n vec3 directionToLight = ${directionToLightSnippet};\r\n float cosAngleLightToZenith = dot(directionToLight, geocentricNormal);\r\n diffuse0 = lightIntensity * sampleTransmittanceLut(transmittanceLut, positionRadius, cosAngleLightToZenith);\r\n }\r\n`,\r\n CUSTOM_REFLECTION: `\r\n {\r\n vec3 positionGlobal = 0.001 * vPositionW + ${OriginOffsetUniformName};\r\n float positionRadius = length(positionGlobal);\r\n vec3 geocentricNormal = positionGlobal / positionRadius;\r\n\r\n vec3 directionToLight = ${directionToLightSnippet};\r\n float cosAngleLightToZenith = dot(directionToLight, geocentricNormal);\r\n\r\n vec2 uv = vec2(0.5 + 0.5 * cosAngleLightToZenith, (positionRadius - planetRadius) / atmosphereThickness);\r\n float irradianceScaleT = 0.5 * dot(normalW, geocentricNormal) + 0.5;\r\n float irradianceScale = ((-0.6652 * irradianceScaleT) + 1.5927) * irradianceScaleT + 0.1023;\r\n vec3 environmentIrradiance = lightIntensity * sampleReflection(irradianceSampler, uv).rgb;\r\n\r\n // Add a contribution here to estimate indirect lighting.\r\n const float r = 0.2;\r\n float indirect = getLuminance(environmentIrradiance) / max(0.00001, 1. - r);\r\n environmentIrradiance *= irradianceScale;\r\n environmentIrradiance += indirect;\r\n\r\n environmentIrradiance += additionalDiffuseSkyIrradiance;\r\n\r\n const float diffuseBrdf = 1. / PI;\r\n environmentIrradiance *= diffuseBrdf * diffuseSkyIrradianceIntensity;\r\n\r\n reflectionOut.environmentIrradiance = environmentIrradiance;\r\n reflectionOut.environmentRadiance.rgb = reflectionOut.environmentIrradiance;\r\n }\r\n`,\r\n // TODO: Support full ray marching if USE_AERIAL_PERSPECTIVE_LUT is disabled.\r\n CUSTOM_FRAGMENT_BEFORE_FOG: `\r\n #if USE_AERIAL_PERSPECTIVE_LUT\r\n {\r\n float distanceFromCameraKm = 0.001 * distance(vEyePosition.xyz, vPositionW);\r\n vec4 aerialPerspective = vec4(0.);\r\n if (sampleAerialPerspectiveLut(\r\n gl_FragCoord.xy * ${InverseViewportSizeUniformName},\r\n true,\r\n distanceFromCameraKm,\r\n NumAerialPerspectiveLutLayers,\r\n AerialPerspectiveLutKMPerSlice,\r\n AerialPerspectiveLutRangeKM,\r\n aerialPerspective)) {\r\n finalColor = aerialPerspective + (1. - aerialPerspective.a) * finalColor;\r\n }\r\n }\r\n #endif\r\n`,\r\n };\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"atmospherePBRMaterialPlugin.js","sourceRoot":"","sources":["../../../../dev/addons/src/atmosphere/atmospherePBRMaterialPlugin.ts"],"names":[],"m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{ Atmosphere } from \"./atmosphere\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { MaterialPluginBase } from \"core/Materials/materialPluginBase\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { UniformBuffer } from \"core/Materials/uniformBuffer\";\r\nimport { Vector3FromFloatsToRef, Vector3ScaleToRef } from \"core/Maths/math.vector.functions\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport \"./ShadersWGSL/ShadersInclude/atmosphereFunctions\";\r\nimport \"./ShadersWGSL/ShadersInclude/atmosphereUboDeclaration\";\r\n\r\nclass AtmospherePBRMaterialDefines extends MaterialDefines {\r\n public USE_AERIAL_PERSPECTIVE_LUT: boolean;\r\n public APPLY_AERIAL_PERSPECTIVE_INTENSITY = false;\r\n public APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS = false;\r\n public SAMPLE_TRANSMITTANCE_LUT = true;\r\n public EXCLUDE_RAY_MARCHING_FUNCTIONS = true;\r\n\r\n /**\r\n * Constructs the {@link AtmospherePBRMaterialDefines}.\r\n * @param useAerialPerspectiveLut - Whether to use the aerial perspective LUT.\r\n */\r\n constructor(useAerialPerspectiveLut: boolean) {\r\n super();\r\n this.USE_AERIAL_PERSPECTIVE_LUT = useAerialPerspectiveLut;\r\n }\r\n}\r\n\r\nconst OriginOffsetUniformName = \"originOffsetKm\";\r\nconst InverseViewportSizeUniformName = \"inverseViewportSize\";\r\n\r\nconst UboArray = [\r\n { name: OriginOffsetUniformName, size: 3, type: \"vec3\" },\r\n { name: \"_atmoPbrPadding1\", size: 1, type: \"float\" },\r\n { name: InverseViewportSizeUniformName, size: 2, type: \"vec2\" },\r\n];\r\nconst MakeUniforms = (atmosphere: Atmosphere) => ({\r\n ubo: UboArray,\r\n fragment: `uniform vec2 ${InverseViewportSizeUniformName};\\nuniform vec3 ${OriginOffsetUniformName};\\n`,\r\n externalUniforms: atmosphere.uniformBuffer.getUniformNames(),\r\n});\r\n\r\nconst PluginName = \"AtmospherePBRMaterialPlugin\";\r\nconst PluginPriority = 600;\r\nconst OriginOffsetKm = { x: 0, y: 0, z: 0 };\r\n\r\n/**\r\n * Adds shading logic to a PBRMaterial that provides radiance, diffuse sky irradiance, and aerial perspective from the atmosphere.\r\n */\r\nexport class AtmospherePBRMaterialPlugin extends MaterialPluginBase {\r\n /**\r\n * Constructs the {@link AtmospherePBRMaterialPlugin}.\r\n * @param material - The material to apply the plugin to.\r\n * @param _atmosphere - The atmosphere to use for shading.\r\n * @param _isAerialPerspectiveEnabled - Whether to apply aerial perspective.\r\n */\r\n constructor(\r\n material: Material,\r\n private readonly _atmosphere: Atmosphere,\r\n private readonly _isAerialPerspectiveEnabled = false\r\n ) {\r\n super(\r\n material,\r\n PluginName,\r\n PluginPriority,\r\n {\r\n USE_CUSTOM_REFLECTION: _atmosphere.diffuseSkyIrradianceLut !== null,\r\n CUSTOM_FRAGMENT_BEFORE_FOG: _isAerialPerspectiveEnabled,\r\n USE_AERIAL_PERSPECTIVE_LUT: _isAerialPerspectiveEnabled && _atmosphere.isAerialPerspectiveLutEnabled,\r\n APPLY_AERIAL_PERSPECTIVE_INTENSITY: _isAerialPerspectiveEnabled && _atmosphere.aerialPerspectiveIntensity !== 1.0,\r\n APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS: _isAerialPerspectiveEnabled && _atmosphere.aerialPerspectiveRadianceBias !== 0.0,\r\n SAMPLE_TRANSMITTANCE_LUT: true,\r\n EXCLUDE_RAY_MARCHING_FUNCTIONS: true,\r\n },\r\n false, // addPluginToList -- false because we need to control when this is added to the list\r\n true, // enable\r\n true // resolveIncludes\r\n );\r\n\r\n this.doNotSerialize = true;\r\n\r\n // This calls `getCode` so we need to do this after having initialized the class fields.\r\n this._pluginManager._addPlugin(this);\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override isCompatible(): boolean {\r\n return true;\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getUniformBuffersNames(_ubos: string[]): void {\r\n const uniformBuffer = this._atmosphere.uniformBuffer;\r\n if (uniformBuffer.useUbo) {\r\n const uboName = this._material.shaderLanguage === ShaderLanguage.WGSL ? \"atmosphere\" : uniformBuffer.name;\r\n _ubos.push(uboName);\r\n }\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getUniforms() {\r\n return MakeUniforms(this._atmosphere);\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override isReadyForSubMesh(): boolean {\r\n let isReady = true;\r\n const atmosphere = this._atmosphere;\r\n if (this._isAerialPerspectiveEnabled && atmosphere.isAerialPerspectiveLutEnabled) {\r\n const aerialPerspectiveLutRenderTarget = atmosphere.aerialPerspectiveLutRenderTarget;\r\n isReady = isReady && !!aerialPerspectiveLutRenderTarget?.isReady();\r\n }\r\n const transmittanceLutRenderTarget = atmosphere.transmittanceLut?.renderTarget ?? null;\r\n isReady = isReady && !!transmittanceLutRenderTarget?.isReady();\r\n return isReady;\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getActiveTextures(_activeTextures: BaseTexture[]): void {\r\n const atmosphere = this._atmosphere;\r\n if (this._isAerialPerspectiveEnabled && atmosphere.isAerialPerspectiveLutEnabled) {\r\n const aerialPerspectiveLutRenderTarget = atmosphere.aerialPerspectiveLutRenderTarget;\r\n if (aerialPerspectiveLutRenderTarget) {\r\n _activeTextures.push(aerialPerspectiveLutRenderTarget);\r\n }\r\n }\r\n\r\n const transmittanceLutRenderTarget = atmosphere.transmittanceLut?.renderTarget ?? null;\r\n if (transmittanceLutRenderTarget) {\r\n _activeTextures.push(transmittanceLutRenderTarget);\r\n }\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override bindForSubMesh(uniformBuffer: UniformBuffer): void {\r\n const atmosphere = this._atmosphere;\r\n const scene = atmosphere.scene;\r\n const engine = scene.getEngine();\r\n\r\n // Bind the atmosphere's uniform buffer to the effect.\r\n const effect = uniformBuffer.currentEffect;\r\n if (effect) {\r\n this._atmosphere.bindUniformBufferToEffect(effect);\r\n }\r\n\r\n // Need the offset to apply which will take a world space position and convert it to a global space position in the atmosphere.\r\n // If floating origin mode is enabled, that offset is the floating origin offset.\r\n // If not, it's an offset up the Y-axis by the planet radius.\r\n uniformBuffer.updateVector3(\r\n OriginOffsetUniformName,\r\n scene.floatingOriginMode\r\n ? Vector3ScaleToRef(scene.floatingOriginOffset, 0.001, OriginOffsetKm) // Convert to kilometers\r\n : Vector3FromFloatsToRef(0, atmosphere.physicalProperties.planetRadius, 0, OriginOffsetKm) // planetRadius is already in kilometers\r\n );\r\n\r\n const width = engine.getRenderWidth();\r\n const height = engine.getRenderHeight();\r\n uniformBuffer.updateFloat2(InverseViewportSizeUniformName, 1.0 / width, 1.0 / height);\r\n\r\n if (this._isAerialPerspectiveEnabled && atmosphere.isAerialPerspectiveLutEnabled) {\r\n const aerialPerspectiveLutRenderTarget = atmosphere.aerialPerspectiveLutRenderTarget;\r\n uniformBuffer.setTexture(\"aerialPerspectiveLut\", aerialPerspectiveLutRenderTarget);\r\n }\r\n const transmittanceLutRenderTarget = atmosphere.transmittanceLut?.renderTarget ?? null;\r\n uniformBuffer.setTexture(\"transmittanceLut\", transmittanceLutRenderTarget);\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override prepareDefines(defines: AtmospherePBRMaterialDefines): void {\r\n const lastUseAerialPerspectiveLut = defines.USE_AERIAL_PERSPECTIVE_LUT;\r\n const lastApplyAerialPerspectiveIntensity = defines.APPLY_AERIAL_PERSPECTIVE_INTENSITY;\r\n const lastApplyAerialPerspectiveRadianceBias = defines.APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS;\r\n defines.USE_AERIAL_PERSPECTIVE_LUT = this._isAerialPerspectiveEnabled && this._atmosphere.isAerialPerspectiveLutEnabled;\r\n defines.APPLY_AERIAL_PERSPECTIVE_INTENSITY = this._isAerialPerspectiveEnabled && this._atmosphere.aerialPerspectiveIntensity !== 1.0;\r\n defines.APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS = this._isAerialPerspectiveEnabled && this._atmosphere.aerialPerspectiveRadianceBias !== 0.0;\r\n if (\r\n lastUseAerialPerspectiveLut !== defines.USE_AERIAL_PERSPECTIVE_LUT ||\r\n lastApplyAerialPerspectiveIntensity !== defines.APPLY_AERIAL_PERSPECTIVE_INTENSITY ||\r\n lastApplyAerialPerspectiveRadianceBias !== defines.APPLY_AERIAL_PERSPECTIVE_RADIANCE_BIAS\r\n ) {\r\n defines.markAllAsDirty();\r\n }\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getSamplers(samplers: string[]): void {\r\n samplers.push(\"transmittanceLut\");\r\n if (this._isAerialPerspectiveEnabled && this._atmosphere.isAerialPerspectiveLutEnabled) {\r\n samplers.push(\"aerialPerspectiveLut\");\r\n }\r\n }\r\n\r\n /**\r\n * @override\r\n */\r\n public override getCustomCode(shaderType: string, shaderLanguage: ShaderLanguage): Nullable<Record<string, string>> {\r\n // Assumed inputs are light0, vPositionW, normalW.\r\n // Only works for directional lights.\r\n if (shaderType !== \"fragment\") {\r\n return null;\r\n }\r\n\r\n const useUbo = this._atmosphere.scene.getEngine().supportsUniformBuffers;\r\n const directionToLightSnippet = useUbo ? \"-light0.vLightData.xyz\" : \"-vLightData0.xyz\";\r\n\r\n const useAtmosphereUbo = shaderLanguage === ShaderLanguage.WGSL || this._atmosphere.uniformBuffer.useUbo;\r\n const atmosphereImportSnippet = useAtmosphereUbo ? \"#include<atmosphereUboDeclaration>\" : \"#include<atmosphereFragmentDeclaration>\";\r\n\r\n if (shaderLanguage === ShaderLanguage.GLSL) {\r\n return {\r\n CUSTOM_FRAGMENT_DEFINITIONS:\r\n this._isAerialPerspectiveEnabled && this._atmosphere.isAerialPerspectiveLutEnabled\r\n ? `uniform sampler2D transmittanceLut;\\r\\nprecision highp sampler2DArray;\\r\\nuniform sampler2DArray aerialPerspectiveLut;\\r\\n${atmosphereImportSnippet}\\r\\n#include<atmosphereFunctions>`\r\n : `uniform sampler2D transmittanceLut;\\r\\n${atmosphereImportSnippet}\\r\\n#include<atmosphereFunctions>`,\r\n CUSTOM_LIGHT0_COLOR: `\r\n {\r\n vec3 positionGlobal = 0.001 * vPositionW + ${OriginOffsetUniformName};\r\n float positionRadius = length(positionGlobal);\r\n vec3 geocentricNormal = positionGlobal / positionRadius;\r\n vec3 directionToLight = ${directionToLightSnippet};\r\n float cosAngleLightToZenith = dot(directionToLight, geocentricNormal);\r\n diffuse0 = lightIntensity * sampleTransmittanceLut(transmittanceLut, positionRadius, cosAngleLightToZenith);\r\n }\r\n`,\r\n CUSTOM_REFLECTION: `\r\n {\r\n vec3 positionGlobal = 0.001 * vPositionW + ${OriginOffsetUniformName};\r\n float positionRadius = length(positionGlobal);\r\n vec3 geocentricNormal = positionGlobal / positionRadius;\r\n\r\n vec3 directionToLight = ${directionToLightSnippet};\r\n float cosAngleLightToZenith = dot(directionToLight, geocentricNormal);\r\n\r\n vec2 uv = vec2(0.5 + 0.5 * cosAngleLightToZenith, (positionRadius - planetRadius) / atmosphereThickness);\r\n float irradianceScaleT = 0.5 * dot(normalW, geocentricNormal) + 0.5;\r\n float irradianceScale = ((-0.6652 * irradianceScaleT) + 1.5927) * irradianceScaleT + 0.1023;\r\n vec3 environmentIrradiance = lightIntensity * sampleReflection(irradianceSampler, uv).rgb;\r\n\r\n // Add a contribution here to estimate indirect lighting.\r\n const float r = 0.2;\r\n float indirect = getLuminance(environmentIrradiance) / max(0.00001, 1. - r);\r\n environmentIrradiance *= irradianceScale;\r\n environmentIrradiance += indirect;\r\n\r\n environmentIrradiance += additionalDiffuseSkyIrradiance;\r\n\r\n const float diffuseBrdf = 1. / PI;\r\n environmentIrradiance *= diffuseBrdf * diffuseSkyIrradianceIntensity;\r\n\r\n reflectionOut.environmentIrradiance = environmentIrradiance;\r\n reflectionOut.environmentRadiance.rgb = reflectionOut.environmentIrradiance;\r\n }\r\n`,\r\n // TODO: Support full ray marching if USE_AERIAL_PERSPECTIVE_LUT is disabled.\r\n CUSTOM_FRAGMENT_BEFORE_FOG: `\r\n #if USE_AERIAL_PERSPECTIVE_LUT\r\n {\r\n float distanceFromCameraKm = 0.001 * distance(vEyePosition.xyz, vPositionW);\r\n vec4 aerialPerspective = vec4(0.);\r\n if (sampleAerialPerspectiveLut(\r\n gl_FragCoord.xy * ${InverseViewportSizeUniformName},\r\n true,\r\n distanceFromCameraKm,\r\n NumAerialPerspectiveLutLayers,\r\n AerialPerspectiveLutKMPerSlice,\r\n AerialPerspectiveLutRangeKM,\r\n aerialPerspective)) {\r\n finalColor = aerialPerspective + (1. - aerialPerspective.a) * finalColor;\r\n }\r\n }\r\n #endif\r\n`,\r\n };\r\n } else {\r\n // WGSL\r\n return {\r\n CUSTOM_FRAGMENT_DEFINITIONS:\r\n this._isAerialPerspectiveEnabled && this._atmosphere.isAerialPerspectiveLutEnabled\r\n ? `var transmittanceLutSampler: sampler;\\r\\nvar transmittanceLut: texture_2d<f32>;\\r\\nvar aerialPerspectiveLutSampler: sampler;\\r\\nvar aerialPerspectiveLut: texture_2d_array<f32>;\\r\\n${atmosphereImportSnippet}\\r\\n#include<atmosphereFunctions>`\r\n : `var transmittanceLutSampler: sampler;\\r\\nvar transmittanceLut: texture_2d<f32>;\\r\\n${atmosphereImportSnippet}\\r\\n#include<atmosphereFunctions>`,\r\n CUSTOM_LIGHT0_COLOR: `\r\n {\r\n var positionGlobal = 0.001 * fragmentInputs.vPositionW + uniforms.${OriginOffsetUniformName};\r\n var positionRadius = length(positionGlobal);\r\n var geocentricNormal = positionGlobal / positionRadius;\r\n var directionToLight = ${directionToLightSnippet};\r\n var cosAngleLightToZenith = dot(directionToLight, geocentricNormal);\r\n diffuse0 = atmosphere.lightIntensity * sampleTransmittanceLut(transmittanceLut, positionRadius, cosAngleLightToZenith);\r\n }\r\n`,\r\n CUSTOM_REFLECTION: `\r\n {\r\n var positionGlobal = 0.001 * fragmentInputs.vPositionW + uniforms.${OriginOffsetUniformName};\r\n var positionRadius = length(positionGlobal);\r\n var geocentricNormal = positionGlobal / positionRadius;\r\n\r\n var directionToLight = ${directionToLightSnippet};\r\n var cosAngleLightToZenith = dot(directionToLight, geocentricNormal);\r\n\r\n var uv = vec2f(0.5 + 0.5 * cosAngleLightToZenith, (positionRadius - atmosphere.planetRadius) / atmosphere.atmosphereThickness);\r\n var irradianceScaleT = 0.5 * dot(normalW, geocentricNormal) + 0.5;\r\n var irradianceScale = ((-0.6652 * irradianceScaleT) + 1.5927) * irradianceScaleT + 0.1023;\r\n var environmentIrradiance = atmosphere.lightIntensity * textureSample(irradianceSampler, irradianceSamplerSampler, uv).rgb;\r\n\r\n // Add a contribution here to estimate indirect lighting.\r\n const r = 0.2;\r\n var indirect = getLuminance(environmentIrradiance) / max(0.00001, 1.0 - r);\r\n environmentIrradiance *= irradianceScale;\r\n environmentIrradiance += indirect;\r\n\r\n environmentIrradiance += atmosphere.additionalDiffuseSkyIrradiance;\r\n\r\n const diffuseBrdf = 1.0 / PI;\r\n environmentIrradiance *= diffuseBrdf * atmosphere.diffuseSkyIrradianceIntensity;\r\n\r\n reflectionOut.environmentIrradiance = environmentIrradiance;\r\n reflectionOut.environmentRadiance = vec4f(reflectionOut.environmentIrradiance, reflectionOut.environmentRadiance.a);\r\n }\r\n`,\r\n // TODO: Support full ray marching if USE_AERIAL_PERSPECTIVE_LUT is disabled.\r\n CUSTOM_FRAGMENT_BEFORE_FOG: `\r\n #if USE_AERIAL_PERSPECTIVE_LUT\r\n {\r\n var distanceFromCameraKm = 0.001 * distance(scene.vEyePosition.xyz, fragmentInputs.vPositionW);\r\n var aerialPerspective = vec4f(0.);\r\n if (sampleAerialPerspectiveLut(\r\n fragmentInputs.position.xy * uniforms.${InverseViewportSizeUniformName},\r\n true,\r\n distanceFromCameraKm,\r\n NumAerialPerspectiveLutLayers,\r\n AerialPerspectiveLutKMPerSlice,\r\n AerialPerspectiveLutRangeKM,\r\n &aerialPerspective)) {\r\n finalColor = aerialPerspective + (1. - aerialPerspective.a) * finalColor;\r\n }\r\n }\r\n #endif\r\n`,\r\n };\r\n }\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babylonjs/addons",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.47.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"postcompile": "build-tools -c add-js-to-es6"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@babylonjs/core": "^8.
|
|
22
|
+
"@babylonjs/core": "^8.47.0",
|
|
23
23
|
"@dev/addons": "^1.0.0",
|
|
24
24
|
"@dev/build-tools": "^1.0.0"
|
|
25
25
|
},
|