@zephyr3d/scene 0.9.23 → 0.9.24
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/dist/index.d.ts +2 -8
- package/dist/index.js +1 -1
- package/dist/material/shader/helper.js +440 -437
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/render/cluster_light.js +10 -10
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/sky.js +123 -123
- package/dist/render/sky.js.map +1 -1
- package/dist/shaders/atmosphere.js.map +1 -1
- package/dist/shaders/shadow.js +54 -12
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/esm.js +5 -5
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcss.js +6 -5
- package/dist/shadow/pcss.js.map +1 -1
- package/dist/shadow/shadow_impl.js +12 -4
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/values.js +57 -62
- package/dist/values.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Vector3, Vector4, Vector2, REVERSE_Z, DEPTH_FARTHEST, DEPTH_REDUCE_CLOSER, DEPTH_REDUCE_FARTHER } from '@zephyr3d/base';
|
|
2
|
-
import { RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_SHADOWMAP, RENDER_PASS_TYPE_OBJECT_COLOR, RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags,
|
|
2
|
+
import { RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_SHADOWMAP, RENDER_PASS_TYPE_OBJECT_COLOR, RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags, MORPH_WEIGHTS_VECTOR_COUNT, MORPH_TARGET_POSITION, MORPH_TARGET_NORMAL, MORPH_TARGET_TANGENT, MORPH_ATTRIBUTE_VECTOR_COUNT } from '../../values.js';
|
|
3
3
|
import { ProgramBuilder } from '@zephyr3d/device';
|
|
4
4
|
import { decodeNormalizedFloatFromRGBA, linearToGamma } from '../../shaders/misc.js';
|
|
5
5
|
import { getSamplerOptions, fetchSampler } from '../../utility/misc.js';
|
|
@@ -34,9 +34,9 @@ const UNIFORM_NAME_BONE_TEXTURE_SIZE = 'Z_UniformBoneTexSize';
|
|
|
34
34
|
const UNIFORM_NAME_BONE_INV_BIND_MATRIX = 'Z_UniformBoneInvBindMatrix';
|
|
35
35
|
const UNIFORM_NAME_MORPH_DATA = 'Z_UniformMorphData';
|
|
36
36
|
const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
37
|
-
/**
|
|
38
|
-
* Helper shader functions for the builtin material system
|
|
39
|
-
* @public
|
|
37
|
+
/**
|
|
38
|
+
* Helper shader functions for the builtin material system
|
|
39
|
+
* @public
|
|
40
40
|
*/ class ShaderHelper {
|
|
41
41
|
static BILLBOARD_SPHERICAL = 1;
|
|
42
42
|
static BILLBOARD_SYLINDRAL = 2;
|
|
@@ -129,25 +129,25 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
129
129
|
}
|
|
130
130
|
return bindGroupLayout;
|
|
131
131
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Prepares the fragment shader which is going to be used in our material system
|
|
134
|
-
*
|
|
135
|
-
* @remarks
|
|
136
|
-
* This function will setup all nessesary uniforms acoording to the drawing context
|
|
137
|
-
*
|
|
138
|
-
* @param pb - The program builder
|
|
139
|
-
* @param ctx - The drawing context
|
|
132
|
+
/**
|
|
133
|
+
* Prepares the fragment shader which is going to be used in our material system
|
|
134
|
+
*
|
|
135
|
+
* @remarks
|
|
136
|
+
* This function will setup all nessesary uniforms acoording to the drawing context
|
|
137
|
+
*
|
|
138
|
+
* @param pb - The program builder
|
|
139
|
+
* @param ctx - The drawing context
|
|
140
140
|
*/ static prepareFragmentShader(pb, ctx) {
|
|
141
141
|
this.setupGlobalUniforms(pb, ctx);
|
|
142
142
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Prepares the vertex shader which is going to be used in our material system
|
|
145
|
-
*
|
|
146
|
-
* @remarks
|
|
147
|
-
* This function will setup all nessesary uniforms according to the drawing context
|
|
148
|
-
*
|
|
149
|
-
* @param pb - The program builder
|
|
150
|
-
* @param ctx - The drawing context
|
|
143
|
+
/**
|
|
144
|
+
* Prepares the vertex shader which is going to be used in our material system
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* This function will setup all nessesary uniforms according to the drawing context
|
|
148
|
+
*
|
|
149
|
+
* @param pb - The program builder
|
|
150
|
+
* @param ctx - The drawing context
|
|
151
151
|
*/ static prepareVertexShader(pb, ctx) {
|
|
152
152
|
this.setupGlobalUniforms(pb, ctx);
|
|
153
153
|
this.prepareVertexShaderCommon(pb, ctx);
|
|
@@ -239,7 +239,7 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
239
239
|
scope.camera = cameraStruct().uniform(0);
|
|
240
240
|
scope.light = lightStruct().uniform(0);
|
|
241
241
|
if (useClusteredLighting) {
|
|
242
|
-
scope[UNIFORM_NAME_LIGHT_BUFFER] = pb.vec4[(
|
|
242
|
+
scope[UNIFORM_NAME_LIGHT_BUFFER] = pb.vec4[(this.getMaxClusterLights() + 1) * 4]().uniformBuffer(0);
|
|
243
243
|
// Non-WebGL1 devices fetch the light index texture with textureLoad
|
|
244
244
|
scope[UNIFORM_NAME_LIGHT_INDEX_TEXTURE] = (pb.getDevice().type === 'webgl' ? pb.tex2D() : pb.utex2D().noSampler()).uniform(0);
|
|
245
245
|
// Screen-space shadow mask array (rgba8unorm, 4 shadow lights per layer).
|
|
@@ -293,30 +293,30 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
|
-
/**
|
|
297
|
-
* This function checks if the shader needs to process skeletal animation.
|
|
298
|
-
*
|
|
299
|
-
* @param scope - Current shader scope
|
|
300
|
-
*
|
|
301
|
-
* @returns true if the shader needs to process skeletal animation, otherwise false.
|
|
296
|
+
/**
|
|
297
|
+
* This function checks if the shader needs to process skeletal animation.
|
|
298
|
+
*
|
|
299
|
+
* @param scope - Current shader scope
|
|
300
|
+
*
|
|
301
|
+
* @returns true if the shader needs to process skeletal animation, otherwise false.
|
|
302
302
|
*/ static hasSkinning(scope) {
|
|
303
303
|
return !!scope[UNIFORM_NAME_BONE_MATRICES];
|
|
304
304
|
}
|
|
305
|
-
/**
|
|
306
|
-
* This function checks if the shader needs to process morph target animation.
|
|
307
|
-
*
|
|
308
|
-
* @param scope - Current shader scope
|
|
309
|
-
*
|
|
310
|
-
* @returns true if the shader needs to process morph target animation, otherwise false.
|
|
305
|
+
/**
|
|
306
|
+
* This function checks if the shader needs to process morph target animation.
|
|
307
|
+
*
|
|
308
|
+
* @param scope - Current shader scope
|
|
309
|
+
*
|
|
310
|
+
* @returns true if the shader needs to process morph target animation, otherwise false.
|
|
311
311
|
*/ static hasMorphing(scope) {
|
|
312
312
|
return !!scope[UNIFORM_NAME_MORPH_DATA];
|
|
313
313
|
}
|
|
314
|
-
/**
|
|
315
|
-
* Calculate skinning matrix for current vertex
|
|
316
|
-
*
|
|
317
|
-
* @param scope - Current shader scope
|
|
318
|
-
*
|
|
319
|
-
* @returns Skinning matrix for current vertex, or null if there is not skeletal animation
|
|
314
|
+
/**
|
|
315
|
+
* Calculate skinning matrix for current vertex
|
|
316
|
+
*
|
|
317
|
+
* @param scope - Current shader scope
|
|
318
|
+
*
|
|
319
|
+
* @returns Skinning matrix for current vertex, or null if there is not skeletal animation
|
|
320
320
|
*/ static calculateSkinMatrix(scope) {
|
|
321
321
|
if (!this.hasSkinning(scope)) {
|
|
322
322
|
return null;
|
|
@@ -471,12 +471,12 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
471
471
|
scope.$l[that.SKIN_PREV_MATRIX_NAME] = scope[funcNameGetSkinningMatrix](scope[that.SKIN_BONE_OFFSET].y);
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
|
-
/**
|
|
475
|
-
* Calculates the vertex position of type vec3 in object space
|
|
476
|
-
*
|
|
477
|
-
* @param scope - Current shader scope
|
|
478
|
-
* @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
|
|
479
|
-
* @returns The calculated vertex position in object space, or null if pos is null
|
|
474
|
+
/**
|
|
475
|
+
* Calculates the vertex position of type vec3 in object space
|
|
476
|
+
*
|
|
477
|
+
* @param scope - Current shader scope
|
|
478
|
+
* @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
|
|
479
|
+
* @returns The calculated vertex position in object space, or null if pos is null
|
|
480
480
|
*/ static resolveVertexPosition(scope) {
|
|
481
481
|
const pb = scope.$builder;
|
|
482
482
|
if (pb.shaderKind !== 'vertex') {
|
|
@@ -518,12 +518,12 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
518
518
|
});
|
|
519
519
|
return scope[that.SKIN_MATRIX_NAME] && scope[that.SKIN_PREV_MATRIX_NAME] ? scope.Z_resolveVertexPosition(scope[that.SKIN_MATRIX_NAME], scope[that.SKIN_PREV_MATRIX_NAME]) : scope[that.SKIN_MATRIX_NAME] ? scope.Z_resolveVertexPosition(scope[that.SKIN_MATRIX_NAME]) : scope.Z_resolveVertexPosition();
|
|
520
520
|
}
|
|
521
|
-
/**
|
|
522
|
-
* Resolve motion vector
|
|
523
|
-
*
|
|
524
|
-
* @param scope - Current shader scope
|
|
525
|
-
* @param worldPos - Current object position in world space
|
|
526
|
-
* @param prevWorldPos - Previous object position in world space
|
|
521
|
+
/**
|
|
522
|
+
* Resolve motion vector
|
|
523
|
+
*
|
|
524
|
+
* @param scope - Current shader scope
|
|
525
|
+
* @param worldPos - Current object position in world space
|
|
526
|
+
* @param prevWorldPos - Previous object position in world space
|
|
527
527
|
*/ static resolveMotionVector(scope, worldPos, prevWorldPos) {
|
|
528
528
|
const that = this;
|
|
529
529
|
const pb = scope.$builder;
|
|
@@ -534,13 +534,13 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
534
534
|
scope.$outputs.zMotionVectorPosPrev = pb.mul(prevUnjitteredVPMatrix, pb.vec4(prevWorldPos.xyz, 1));
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
|
-
/**
|
|
538
|
-
* Calculates the normal vector of type vec3 in object space
|
|
539
|
-
*
|
|
540
|
-
* @param scope - Current shader scope
|
|
541
|
-
* @param normal - Vertex normal input, must be type of vec3, null if no vertex normal input
|
|
542
|
-
* @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
|
|
543
|
-
* @returns The calculated normal vector in object space, or null if normal is null
|
|
537
|
+
/**
|
|
538
|
+
* Calculates the normal vector of type vec3 in object space
|
|
539
|
+
*
|
|
540
|
+
* @param scope - Current shader scope
|
|
541
|
+
* @param normal - Vertex normal input, must be type of vec3, null if no vertex normal input
|
|
542
|
+
* @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
|
|
543
|
+
* @returns The calculated normal vector in object space, or null if normal is null
|
|
544
544
|
*/ static resolveVertexNormal(scope, normal) {
|
|
545
545
|
const pb = scope.$builder;
|
|
546
546
|
if (pb.shaderKind !== 'vertex') {
|
|
@@ -565,13 +565,13 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
565
565
|
return normal;
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
|
-
/**
|
|
569
|
-
* Calculates the tangent vector of type vec3 in object space
|
|
570
|
-
*
|
|
571
|
-
* @param scope - Current shader scope
|
|
572
|
-
* @param tangent - Vertex tangent input, must be type of vec4, null if no vertex tangent input
|
|
573
|
-
* @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
|
|
574
|
-
* @returns The calculated tangent vector of type vec4 in object space, or null if tangent is null
|
|
568
|
+
/**
|
|
569
|
+
* Calculates the tangent vector of type vec3 in object space
|
|
570
|
+
*
|
|
571
|
+
* @param scope - Current shader scope
|
|
572
|
+
* @param tangent - Vertex tangent input, must be type of vec4, null if no vertex tangent input
|
|
573
|
+
* @param skinMatrix - The skinning matrix if there is skeletal animation, otherwise null
|
|
574
|
+
* @returns The calculated tangent vector of type vec4 in object space, or null if tangent is null
|
|
575
575
|
*/ static resolveVertexTangent(scope, tangent) {
|
|
576
576
|
const pb = scope.$builder;
|
|
577
577
|
if (pb.shaderKind !== 'vertex') {
|
|
@@ -596,18 +596,18 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
596
596
|
return tangent;
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
|
-
/**
|
|
600
|
-
* Gets the uniform variable of type mat4 which holds the world matrix of current object to be drawn
|
|
601
|
-
* @param scope - Current shader scope
|
|
602
|
-
* @returns The world matrix of current object to be drawn
|
|
599
|
+
/**
|
|
600
|
+
* Gets the uniform variable of type mat4 which holds the world matrix of current object to be drawn
|
|
601
|
+
* @param scope - Current shader scope
|
|
602
|
+
* @returns The world matrix of current object to be drawn
|
|
603
603
|
*/ static getWorldMatrix(scope) {
|
|
604
604
|
const pb = scope.$builder;
|
|
605
605
|
return scope[UNIFORM_NAME_WORLD_MATRIX] ?? pb.mat4(this.getInstancedUniform(scope, 0), this.getInstancedUniform(scope, 1), this.getInstancedUniform(scope, 2), this.getInstancedUniform(scope, 3));
|
|
606
606
|
}
|
|
607
|
-
/**
|
|
608
|
-
* Gets the uniform variable of type mat4 which holds the world matrix at previous frame of current object to be drawn
|
|
609
|
-
* @param scope - Current shader scope
|
|
610
|
-
* @returns The world matrix at previous frame of current object to be drawn
|
|
607
|
+
/**
|
|
608
|
+
* Gets the uniform variable of type mat4 which holds the world matrix at previous frame of current object to be drawn
|
|
609
|
+
* @param scope - Current shader scope
|
|
610
|
+
* @returns The world matrix at previous frame of current object to be drawn
|
|
611
611
|
*/ static getPrevWorldMatrix(scope) {
|
|
612
612
|
const pb = scope.$builder;
|
|
613
613
|
const that = this;
|
|
@@ -638,28 +638,28 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
638
638
|
return scope.Z_getPrevWorldMatrix(framestamp);
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
|
-
/**
|
|
642
|
-
* Gets the instance uniform value of type vec4 by uniform index
|
|
643
|
-
* @param scope - Current shader scope
|
|
644
|
-
* @returns instance uniform value
|
|
641
|
+
/**
|
|
642
|
+
* Gets the instance uniform value of type vec4 by uniform index
|
|
643
|
+
* @param scope - Current shader scope
|
|
644
|
+
* @returns instance uniform value
|
|
645
645
|
*/ static getInstancedUniform(scope, uniformIndex) {
|
|
646
646
|
const pb = scope.$builder;
|
|
647
647
|
return scope[UNIFORM_NAME_INSTANCE_DATA].at(pb.add(pb.mul(scope[UNIFORM_NAME_INSTANCE_DATA_STRIDE], pb.uint(scope.$builtins.instanceIndex)), scope[UNIFORM_NAME_INSTANCE_DATA_OFFSET], pb.uint(uniformIndex)));
|
|
648
648
|
}
|
|
649
|
-
/**
|
|
650
|
-
* Gets the uniform variable of type mat4 which holds the normal matrix of current object to be drawn
|
|
651
|
-
*
|
|
652
|
-
* @param scope - Current shader scope
|
|
653
|
-
* @returns The normal matrix of current object to be drawn
|
|
649
|
+
/**
|
|
650
|
+
* Gets the uniform variable of type mat4 which holds the normal matrix of current object to be drawn
|
|
651
|
+
*
|
|
652
|
+
* @param scope - Current shader scope
|
|
653
|
+
* @returns The normal matrix of current object to be drawn
|
|
654
654
|
*/ static getNormalMatrix(scope) {
|
|
655
655
|
return this.getWorldMatrix(scope);
|
|
656
656
|
}
|
|
657
|
-
/**
|
|
658
|
-
* Vertex shader drawable stuff
|
|
659
|
-
*
|
|
660
|
-
* @param scope - Current shader scope
|
|
661
|
-
* @param skinning - true if skinning is used, otherwise false.
|
|
662
|
-
* @param instanced - true if instancing is used, otherwise false.
|
|
657
|
+
/**
|
|
658
|
+
* Vertex shader drawable stuff
|
|
659
|
+
*
|
|
660
|
+
* @param scope - Current shader scope
|
|
661
|
+
* @param skinning - true if skinning is used, otherwise false.
|
|
662
|
+
* @param instanced - true if instancing is used, otherwise false.
|
|
663
663
|
*/ static vertexShaderDrawableStuff(scope, skinning, morphing, instanced) {
|
|
664
664
|
const pb = scope.$builder;
|
|
665
665
|
if (instanced) {
|
|
@@ -749,57 +749,57 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
749
749
|
bindGroup.setTexture(UNIFORM_NAME_AERIALPERSPECTIVE_LUT, aerialPerspectiveLUT);
|
|
750
750
|
bindGroup.setTexture(UNIFORM_NAME_SKYDISTANTLIGHT_LUT, skyDistantLightLUT);
|
|
751
751
|
}
|
|
752
|
-
/**
|
|
753
|
-
* @internal
|
|
754
|
-
*
|
|
755
|
-
* Camera pre-exposure factor for scene-linear lighting quantities.
|
|
756
|
-
*
|
|
757
|
-
* @remarks
|
|
758
|
-
* Physical lighting authors light intensities in photometric units (lux, candela, cd/m²), whose
|
|
759
|
-
* magnitudes (~1e5 for daylight) neither fit an rgba16f render target nor leave usable headroom
|
|
760
|
-
* for specular highlights. Following Filament, the camera exposure is folded into every light
|
|
761
|
-
* quantity on the CPU so the HDR target stays near 1.0 and downstream passes need no unit
|
|
762
|
-
* awareness. Legacy returns 1 so its uploads stay byte-identical.
|
|
752
|
+
/**
|
|
753
|
+
* @internal
|
|
754
|
+
*
|
|
755
|
+
* Camera pre-exposure factor for scene-linear lighting quantities.
|
|
756
|
+
*
|
|
757
|
+
* @remarks
|
|
758
|
+
* Physical lighting authors light intensities in photometric units (lux, candela, cd/m²), whose
|
|
759
|
+
* magnitudes (~1e5 for daylight) neither fit an rgba16f render target nor leave usable headroom
|
|
760
|
+
* for specular highlights. Following Filament, the camera exposure is folded into every light
|
|
761
|
+
* quantity on the CPU so the HDR target stays near 1.0 and downstream passes need no unit
|
|
762
|
+
* awareness. Legacy returns 1 so its uploads stay byte-identical.
|
|
763
763
|
*/ static getPreExposure(ctx) {
|
|
764
764
|
return ctx.scene.lightingMode === 'physical' ? ctx.camera.exposure : 1;
|
|
765
765
|
}
|
|
766
|
-
/**
|
|
767
|
-
* @internal
|
|
768
|
-
*
|
|
769
|
-
* Light color/intensity vector with the camera pre-exposure folded into the intensity component.
|
|
770
|
-
*
|
|
771
|
-
* @remarks
|
|
772
|
-
* Only the intensity (`w`) is scaled; the color stays untouched, matching Filament's
|
|
773
|
-
* `FScene::prepareDynamicLights`. The light's own cached vector is never mutated because it is
|
|
774
|
-
* shared across every camera rendering the scene.
|
|
766
|
+
/**
|
|
767
|
+
* @internal
|
|
768
|
+
*
|
|
769
|
+
* Light color/intensity vector with the camera pre-exposure folded into the intensity component.
|
|
770
|
+
*
|
|
771
|
+
* @remarks
|
|
772
|
+
* Only the intensity (`w`) is scaled; the color stays untouched, matching Filament's
|
|
773
|
+
* `FScene::prepareDynamicLights`. The light's own cached vector is never mutated because it is
|
|
774
|
+
* shared across every camera rendering the scene.
|
|
775
775
|
*/ static getPreExposedColorIntensity(light, ctx, out) {
|
|
776
776
|
const src = light.diffuseAndIntensity;
|
|
777
777
|
const result = out ?? new Vector4();
|
|
778
778
|
result.setXYZW(src.x, src.y, src.z, src.w * this.getPreExposure(ctx));
|
|
779
779
|
return result;
|
|
780
780
|
}
|
|
781
|
-
/**
|
|
782
|
-
* @internal
|
|
783
|
-
*
|
|
784
|
-
* Environment lighting scale uploaded as `light.envLightStrength`.
|
|
785
|
-
*
|
|
786
|
-
* @remarks
|
|
787
|
-
* Legacy uses the unitless {@link EnvLightWrapper.strength}.
|
|
788
|
-
*
|
|
789
|
-
* Physical returns the ratio that converts the cached sky bake from its fixed storage exposure
|
|
790
|
-
* (`SkyRenderer.PHYSICAL_BAKE_EXPOSURE`) to the live camera exposure. Every environment source is
|
|
791
|
-
* normalized into that one space before it reaches the IBL -- the scattering atmosphere emits
|
|
792
|
-
* photometric luminance, authored 0..1 skyboxes/panoramas are lifted by
|
|
793
|
-
* {@link EnvLightWrapper.intensity} -- so no pass consuming `envLightStrength` has to know the
|
|
794
|
-
* sky type.
|
|
795
|
-
*
|
|
796
|
-
* The bake cannot simply hold raw cd/m²: the environment cubemap is `rg11b10uf`/`rgba16f` and a
|
|
797
|
-
* daylight sun overflows it to Inf, which `prefilterCubemap` then spreads across the whole IBL.
|
|
798
|
-
*
|
|
799
|
-
* {@link EnvLightWrapper.strength} multiplies the result in both modes. It is the only per-frame
|
|
800
|
-
* dimmer for environment lighting: the photometric `intensity` reaches the image solely through
|
|
801
|
-
* the cached bake, and a `scatter` sky does not even consult it (its brightness comes from the
|
|
802
|
-
* sun), so without this factor there would be no way to turn the IBL down without re-baking.
|
|
781
|
+
/**
|
|
782
|
+
* @internal
|
|
783
|
+
*
|
|
784
|
+
* Environment lighting scale uploaded as `light.envLightStrength`.
|
|
785
|
+
*
|
|
786
|
+
* @remarks
|
|
787
|
+
* Legacy uses the unitless {@link EnvLightWrapper.strength}.
|
|
788
|
+
*
|
|
789
|
+
* Physical returns the ratio that converts the cached sky bake from its fixed storage exposure
|
|
790
|
+
* (`SkyRenderer.PHYSICAL_BAKE_EXPOSURE`) to the live camera exposure. Every environment source is
|
|
791
|
+
* normalized into that one space before it reaches the IBL -- the scattering atmosphere emits
|
|
792
|
+
* photometric luminance, authored 0..1 skyboxes/panoramas are lifted by
|
|
793
|
+
* {@link EnvLightWrapper.intensity} -- so no pass consuming `envLightStrength` has to know the
|
|
794
|
+
* sky type.
|
|
795
|
+
*
|
|
796
|
+
* The bake cannot simply hold raw cd/m²: the environment cubemap is `rg11b10uf`/`rgba16f` and a
|
|
797
|
+
* daylight sun overflows it to Inf, which `prefilterCubemap` then spreads across the whole IBL.
|
|
798
|
+
*
|
|
799
|
+
* {@link EnvLightWrapper.strength} multiplies the result in both modes. It is the only per-frame
|
|
800
|
+
* dimmer for environment lighting: the photometric `intensity` reaches the image solely through
|
|
801
|
+
* the cached bake, and a `scatter` sky does not even consult it (its brightness comes from the
|
|
802
|
+
* sun), so without this factor there would be no way to turn the IBL down without re-baking.
|
|
803
803
|
*/ static getEnvLightLuminance(ctx) {
|
|
804
804
|
const env = ctx.env;
|
|
805
805
|
if (!env) {
|
|
@@ -862,174 +862,174 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
862
862
|
ctx.env.light.envLight.updateBindGroup(bindGroup, ctx);
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
|
-
/**
|
|
866
|
-
* Gets the uniform variable of type float which holds the strength of the environment light
|
|
867
|
-
*
|
|
868
|
-
* @remarks
|
|
869
|
-
* This function can only be used in the fragment shader
|
|
870
|
-
*
|
|
871
|
-
* @param scope - Current shader scope
|
|
872
|
-
* @returns The uniform variable of which presents the strength of the environment light
|
|
865
|
+
/**
|
|
866
|
+
* Gets the uniform variable of type float which holds the strength of the environment light
|
|
867
|
+
*
|
|
868
|
+
* @remarks
|
|
869
|
+
* This function can only be used in the fragment shader
|
|
870
|
+
*
|
|
871
|
+
* @param scope - Current shader scope
|
|
872
|
+
* @returns The uniform variable of which presents the strength of the environment light
|
|
873
873
|
*/ static getEnvLightStrength(scope) {
|
|
874
874
|
return scope.light.envLightStrength;
|
|
875
875
|
}
|
|
876
|
-
/**
|
|
877
|
-
* Gets the uniform variable of type float which holds the specular strength of the environment light
|
|
878
|
-
*
|
|
879
|
-
* @remarks
|
|
880
|
-
* This function can only be used in the fragment shader
|
|
881
|
-
*
|
|
882
|
-
* @param scope - Current shader scope
|
|
883
|
-
* @returns The uniform variable which presents the specular strength of the environment light
|
|
876
|
+
/**
|
|
877
|
+
* Gets the uniform variable of type float which holds the specular strength of the environment light
|
|
878
|
+
*
|
|
879
|
+
* @remarks
|
|
880
|
+
* This function can only be used in the fragment shader
|
|
881
|
+
*
|
|
882
|
+
* @param scope - Current shader scope
|
|
883
|
+
* @returns The uniform variable which presents the specular strength of the environment light
|
|
884
884
|
*/ static getEnvLightSpecularStrength(scope) {
|
|
885
885
|
return scope.light.envLightSpecularStrength ?? scope.$builder.float(1);
|
|
886
886
|
}
|
|
887
|
-
/**
|
|
888
|
-
* Gets current scene color texture
|
|
889
|
-
* @param scope - Current shader scope
|
|
890
|
-
* @returns current scene color texture
|
|
887
|
+
/**
|
|
888
|
+
* Gets current scene color texture
|
|
889
|
+
* @param scope - Current shader scope
|
|
890
|
+
* @returns current scene color texture
|
|
891
891
|
*/ static getSceneColorTexture(scope) {
|
|
892
892
|
return scope[UNIFORM_NAME_SCENE_COLOR_MAP];
|
|
893
893
|
}
|
|
894
|
-
/**
|
|
895
|
-
* Gets the size of current scene color texture
|
|
896
|
-
* @param scope - Current shader scope
|
|
897
|
-
* @returns The size of current scene color texture
|
|
894
|
+
/**
|
|
895
|
+
* Gets the size of current scene color texture
|
|
896
|
+
* @param scope - Current shader scope
|
|
897
|
+
* @returns The size of current scene color texture
|
|
898
898
|
*/ static getSceneColorTextureSize(scope) {
|
|
899
899
|
return scope[UNIFORM_NAME_SCENE_COLOR_MAP_SIZE];
|
|
900
900
|
}
|
|
901
|
-
/**
|
|
902
|
-
* Gets current linear depth texture
|
|
903
|
-
* @param scope - Current shader scope
|
|
904
|
-
* @returns current linear depth texture
|
|
901
|
+
/**
|
|
902
|
+
* Gets current linear depth texture
|
|
903
|
+
* @param scope - Current shader scope
|
|
904
|
+
* @returns current linear depth texture
|
|
905
905
|
*/ static getLinearDepthTexture(scope) {
|
|
906
906
|
return scope[UNIFORM_NAME_LINEAR_DEPTH_MAP];
|
|
907
907
|
}
|
|
908
|
-
/**
|
|
909
|
-
* Gets the size of current linear depth texture
|
|
910
|
-
* @param scope - Current shader scope
|
|
911
|
-
* @returns The size of current linear depth texture
|
|
908
|
+
/**
|
|
909
|
+
* Gets the size of current linear depth texture
|
|
910
|
+
* @param scope - Current shader scope
|
|
911
|
+
* @returns The size of current linear depth texture
|
|
912
912
|
*/ static getLinearDepthTextureSize(scope) {
|
|
913
913
|
return scope[UNIFORM_NAME_LINEAR_DEPTH_MAP_SIZE];
|
|
914
914
|
}
|
|
915
|
-
/**
|
|
916
|
-
* Gets current HiZ depth texture
|
|
917
|
-
* @param scope - Current shader scope
|
|
918
|
-
* @returns current HiZ depth texture
|
|
915
|
+
/**
|
|
916
|
+
* Gets current HiZ depth texture
|
|
917
|
+
* @param scope - Current shader scope
|
|
918
|
+
* @returns current HiZ depth texture
|
|
919
919
|
*/ static getHiZDepthTexture(scope) {
|
|
920
920
|
return scope[UNIFORM_NAME_HIZ_DEPTH_MAP];
|
|
921
921
|
}
|
|
922
|
-
/**
|
|
923
|
-
* Gets the size of current HiZ depth texture
|
|
924
|
-
* @param scope - Current shader scope
|
|
925
|
-
* @returns The size of current HiZ depth texture
|
|
922
|
+
/**
|
|
923
|
+
* Gets the size of current HiZ depth texture
|
|
924
|
+
* @param scope - Current shader scope
|
|
925
|
+
* @returns The size of current HiZ depth texture
|
|
926
926
|
*/ static getHiZDepthTextureSize(scope) {
|
|
927
927
|
return scope[UNIFORM_NAME_HIZ_DEPTH_MAP_INFO].xy;
|
|
928
928
|
}
|
|
929
|
-
/**
|
|
930
|
-
* Gets the mipmap levels count of current HiZ depth texture
|
|
931
|
-
* @param scope - Current shader scope
|
|
932
|
-
* @returns The mipmap levels count of current HiZ depth texture
|
|
929
|
+
/**
|
|
930
|
+
* Gets the mipmap levels count of current HiZ depth texture
|
|
931
|
+
* @param scope - Current shader scope
|
|
932
|
+
* @returns The mipmap levels count of current HiZ depth texture
|
|
933
933
|
*/ static getHiZDepthTextureMipLevelCount(scope) {
|
|
934
934
|
return scope[UNIFORM_NAME_HIZ_DEPTH_MAP_INFO].z;
|
|
935
935
|
}
|
|
936
|
-
/**
|
|
937
|
-
* Gets current baked skybox texture
|
|
938
|
-
* @param scope - Current shader scope
|
|
939
|
-
* @returns current baked skybox texture
|
|
936
|
+
/**
|
|
937
|
+
* Gets current baked skybox texture
|
|
938
|
+
* @param scope - Current shader scope
|
|
939
|
+
* @returns current baked skybox texture
|
|
940
940
|
*/ static getBakedSkyTexture(scope) {
|
|
941
941
|
return scope[UNIFORM_NAME_BAKED_SKY_MAP];
|
|
942
942
|
}
|
|
943
|
-
/**
|
|
944
|
-
* Samples the baked sky cubemap in the same pre-exposed space as the scene color buffer.
|
|
945
|
-
*
|
|
946
|
-
* @remarks
|
|
947
|
-
* The bake is cached and therefore exposure-independent, stored at the fixed
|
|
948
|
-
* `PHYSICAL_BAKE_EXPOSURE`. Anything that blends it against already-pre-exposed lit color (water
|
|
949
|
-
* reflection, blueprint sky lookups) must first convert it to the live exposure.
|
|
950
|
-
* `envLightStrength` carries exactly that ratio in physical mode, and the legacy environment
|
|
951
|
-
* strength (its established meaning) otherwise.
|
|
952
|
-
*
|
|
953
|
-
* @param scope - Current shader scope
|
|
954
|
-
* @param direction - Sampling direction
|
|
955
|
-
* @returns Pre-exposed sky radiance
|
|
943
|
+
/**
|
|
944
|
+
* Samples the baked sky cubemap in the same pre-exposed space as the scene color buffer.
|
|
945
|
+
*
|
|
946
|
+
* @remarks
|
|
947
|
+
* The bake is cached and therefore exposure-independent, stored at the fixed
|
|
948
|
+
* `PHYSICAL_BAKE_EXPOSURE`. Anything that blends it against already-pre-exposed lit color (water
|
|
949
|
+
* reflection, blueprint sky lookups) must first convert it to the live exposure.
|
|
950
|
+
* `envLightStrength` carries exactly that ratio in physical mode, and the legacy environment
|
|
951
|
+
* strength (its established meaning) otherwise.
|
|
952
|
+
*
|
|
953
|
+
* @param scope - Current shader scope
|
|
954
|
+
* @param direction - Sampling direction
|
|
955
|
+
* @returns Pre-exposed sky radiance
|
|
956
956
|
*/ static sampleBakedSkyPreExposed(scope, direction) {
|
|
957
957
|
const pb = scope.$builder;
|
|
958
958
|
return pb.mul(pb.textureSampleLevel(this.getBakedSkyTexture(scope), direction, 0).rgb, this.getEnvLightStrength(scope));
|
|
959
959
|
}
|
|
960
|
-
/**
|
|
961
|
-
* Gets the camera pre-exposure factor.
|
|
962
|
-
*
|
|
963
|
-
* @remarks
|
|
964
|
-
* The multiplier every photometric quantity is scaled by before it reaches the HDR target. 1 in
|
|
965
|
-
* legacy. Use it for material-authored emitters (emissive), which are not covered by the CPU-side
|
|
966
|
-
* light pre-exposure.
|
|
967
|
-
*
|
|
968
|
-
* @param scope - Current shader scope
|
|
969
|
-
* @returns The pre-exposure factor
|
|
960
|
+
/**
|
|
961
|
+
* Gets the camera pre-exposure factor.
|
|
962
|
+
*
|
|
963
|
+
* @remarks
|
|
964
|
+
* The multiplier every photometric quantity is scaled by before it reaches the HDR target. 1 in
|
|
965
|
+
* legacy. Use it for material-authored emitters (emissive), which are not covered by the CPU-side
|
|
966
|
+
* light pre-exposure.
|
|
967
|
+
*
|
|
968
|
+
* @param scope - Current shader scope
|
|
969
|
+
* @returns The pre-exposure factor
|
|
970
970
|
*/ static getPreExposureUniform(scope) {
|
|
971
971
|
return scope.camera.preExposure;
|
|
972
972
|
}
|
|
973
|
-
/**
|
|
974
|
-
* Gets the elapsed time in seconds
|
|
975
|
-
* @param scope - Current shader scope
|
|
976
|
-
* @returns The elapsed time in seconds
|
|
973
|
+
/**
|
|
974
|
+
* Gets the elapsed time in seconds
|
|
975
|
+
* @param scope - Current shader scope
|
|
976
|
+
* @returns The elapsed time in seconds
|
|
977
977
|
*/ static getElapsedTime(scope) {
|
|
978
978
|
return scope.camera.elapsedTime;
|
|
979
979
|
}
|
|
980
|
-
/**
|
|
981
|
-
* Gets the elapsed time since last frame in seconds
|
|
982
|
-
* @param scope - Current shader scope
|
|
983
|
-
* @returns The elapsed time since last frame in seconds
|
|
980
|
+
/**
|
|
981
|
+
* Gets the elapsed time since last frame in seconds
|
|
982
|
+
* @param scope - Current shader scope
|
|
983
|
+
* @returns The elapsed time since last frame in seconds
|
|
984
984
|
*/ static getElapsedTimeFrame(scope) {
|
|
985
985
|
return scope.camera.frameDeltaTime;
|
|
986
986
|
}
|
|
987
|
-
/**
|
|
988
|
-
* Gets the uniform variable of type vec3 which holds the camera position
|
|
989
|
-
* @param scope - Current shader scope
|
|
990
|
-
* @returns The camera position
|
|
987
|
+
/**
|
|
988
|
+
* Gets the uniform variable of type vec3 which holds the camera position
|
|
989
|
+
* @param scope - Current shader scope
|
|
990
|
+
* @returns The camera position
|
|
991
991
|
*/ static getCameraPosition(scope) {
|
|
992
992
|
return scope.camera.position.xyz;
|
|
993
993
|
}
|
|
994
|
-
/**
|
|
995
|
-
* Gets the uniform variable of type float which holds the roughness factor
|
|
996
|
-
* @param scope - Current shader scope
|
|
997
|
-
* @returns The roughness factor
|
|
994
|
+
/**
|
|
995
|
+
* Gets the uniform variable of type float which holds the roughness factor
|
|
996
|
+
* @param scope - Current shader scope
|
|
997
|
+
* @returns The roughness factor
|
|
998
998
|
*/ static getCameraRoughnessFactor(scope) {
|
|
999
999
|
return scope.camera.roughnessFactor;
|
|
1000
1000
|
}
|
|
1001
|
-
/**
|
|
1002
|
-
* Gets framebuffer size for rendering
|
|
1003
|
-
* @param scope - Current shader scope
|
|
1004
|
-
* @returns The roughness factor
|
|
1001
|
+
/**
|
|
1002
|
+
* Gets framebuffer size for rendering
|
|
1003
|
+
* @param scope - Current shader scope
|
|
1004
|
+
* @returns The roughness factor
|
|
1005
1005
|
*/ static getRenderSize(scope) {
|
|
1006
1006
|
return scope.camera.renderSize;
|
|
1007
1007
|
}
|
|
1008
|
-
/**
|
|
1009
|
-
* Gets the uniform variable of type uint which holds the framestamp
|
|
1010
|
-
* @param scope - Current shader scope
|
|
1011
|
-
* @returns The framestamp
|
|
1008
|
+
/**
|
|
1009
|
+
* Gets the uniform variable of type uint which holds the framestamp
|
|
1010
|
+
* @param scope - Current shader scope
|
|
1011
|
+
* @returns The framestamp
|
|
1012
1012
|
*/ static getFramestamp(scope) {
|
|
1013
1013
|
return scope.camera.framestamp;
|
|
1014
1014
|
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Gets the clip plane flag
|
|
1017
|
-
* @param scope - Current shader scope
|
|
1018
|
-
* @returns A float value of 1 indices the clip plane presents, otherwise 0
|
|
1015
|
+
/**
|
|
1016
|
+
* Gets the clip plane flag
|
|
1017
|
+
* @param scope - Current shader scope
|
|
1018
|
+
* @returns A float value of 1 indices the clip plane presents, otherwise 0
|
|
1019
1019
|
*/ static getCameraClipPlaneFlag(scope) {
|
|
1020
1020
|
return scope.camera.position.w;
|
|
1021
1021
|
}
|
|
1022
|
-
/**
|
|
1023
|
-
* Gets the clip plane
|
|
1024
|
-
* @param scope - Current shader scope
|
|
1025
|
-
* @returns A vec4 presents the clip plane
|
|
1022
|
+
/**
|
|
1023
|
+
* Gets the clip plane
|
|
1024
|
+
* @param scope - Current shader scope
|
|
1025
|
+
* @returns A vec4 presents the clip plane
|
|
1026
1026
|
*/ static getCameraClipPlane(scope) {
|
|
1027
1027
|
return scope.camera.clipPlane;
|
|
1028
1028
|
}
|
|
1029
|
-
/**
|
|
1030
|
-
* Gets the uniform variable of type vec4 which holds the camera parameters
|
|
1031
|
-
* @param scope - Current shader scope
|
|
1032
|
-
* @returns The camera parameters
|
|
1029
|
+
/**
|
|
1030
|
+
* Gets the uniform variable of type vec4 which holds the camera parameters
|
|
1031
|
+
* @param scope - Current shader scope
|
|
1032
|
+
* @returns The camera parameters
|
|
1033
1033
|
*/ static getCameraParams(scope) {
|
|
1034
1034
|
return scope.camera.params;
|
|
1035
1035
|
}
|
|
@@ -1039,36 +1039,36 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1039
1039
|
/** @internal */ static getCountParams(scope) {
|
|
1040
1040
|
return scope.light.countParams;
|
|
1041
1041
|
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Number of shadow-casting lights at the head of the clustered light buffer.
|
|
1044
|
-
* Only defined on the screen-space shadow mask path (ctx.screenSpaceShadowMask);
|
|
1045
|
-
* a clustered light whose buffer index is `<= N` samples the shadow mask.
|
|
1046
|
-
* @internal
|
|
1042
|
+
/**
|
|
1043
|
+
* Number of shadow-casting lights at the head of the clustered light buffer.
|
|
1044
|
+
* Only defined on the screen-space shadow mask path (ctx.screenSpaceShadowMask);
|
|
1045
|
+
* a clustered light whose buffer index is `<= N` samples the shadow mask.
|
|
1046
|
+
* @internal
|
|
1047
1047
|
*/ static getNumShadowLights(scope) {
|
|
1048
1048
|
return scope.light.numShadowLights;
|
|
1049
1049
|
}
|
|
1050
|
-
/**
|
|
1051
|
-
* Cluster shadow-mask mode for the current queue: 1 = sample the opaque shadow
|
|
1052
|
-
* mask for shadow lights; 0 = skip shadow lights (they are lit inline by the
|
|
1053
|
-
* additive passes, used for the transparent queue). Only defined on the
|
|
1054
|
-
* screen-space shadow mask path.
|
|
1055
|
-
* @internal
|
|
1050
|
+
/**
|
|
1051
|
+
* Cluster shadow-mask mode for the current queue: 1 = sample the opaque shadow
|
|
1052
|
+
* mask for shadow lights; 0 = skip shadow lights (they are lit inline by the
|
|
1053
|
+
* additive passes, used for the transparent queue). Only defined on the
|
|
1054
|
+
* screen-space shadow mask path.
|
|
1055
|
+
* @internal
|
|
1056
1056
|
*/ static getShadowMaskMode(scope) {
|
|
1057
1057
|
return scope[UNIFORM_NAME_SHADOW_MASK_MODE];
|
|
1058
1058
|
}
|
|
1059
|
-
/**
|
|
1060
|
-
* Bind the per-queue cluster shadow-mask mode. Call in the clustered light pass
|
|
1061
|
-
* only when the screen-space shadow mask path is active.
|
|
1062
|
-
* @internal
|
|
1059
|
+
/**
|
|
1060
|
+
* Bind the per-queue cluster shadow-mask mode. Call in the clustered light pass
|
|
1061
|
+
* only when the screen-space shadow mask path is active.
|
|
1062
|
+
* @internal
|
|
1063
1063
|
*/ static setShadowMaskMode(bindGroup, sampleMask) {
|
|
1064
1064
|
bindGroup.setValue(UNIFORM_NAME_SHADOW_MASK_MODE, sampleMask ? 1 : 0);
|
|
1065
1065
|
}
|
|
1066
|
-
/**
|
|
1067
|
-
* Lazily-created 1x1x1 rgba8unorm array texture used as the shadow-mask binding
|
|
1068
|
-
* fallback when the screen-space shadow mask path is enabled but no mask was
|
|
1069
|
-
* produced this frame (no shadow-casting lights). It is never sampled in that
|
|
1070
|
-
* case, but the declared uniform still requires a valid binding.
|
|
1071
|
-
* @internal
|
|
1066
|
+
/**
|
|
1067
|
+
* Lazily-created 1x1x1 rgba8unorm array texture used as the shadow-mask binding
|
|
1068
|
+
* fallback when the screen-space shadow mask path is enabled but no mask was
|
|
1069
|
+
* produced this frame (no shadow-casting lights). It is never sampled in that
|
|
1070
|
+
* case, but the declared uniform still requires a valid binding.
|
|
1071
|
+
* @internal
|
|
1072
1072
|
*/ static getDummyShadowMask(device) {
|
|
1073
1073
|
let tex = this._dummyShadowMask;
|
|
1074
1074
|
if (!tex || tex.disposed) {
|
|
@@ -1083,22 +1083,22 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1083
1083
|
/** @internal */ static getClusteredLightIndexTexture(scope) {
|
|
1084
1084
|
return scope[UNIFORM_NAME_LIGHT_INDEX_TEXTURE];
|
|
1085
1085
|
}
|
|
1086
|
-
/**
|
|
1087
|
-
* Clustered shadow factor for a light, in `[0,1]` (1 = fully lit).
|
|
1088
|
-
*
|
|
1089
|
-
* - Lights whose clustered buffer index is greater than `numShadowLights` are not
|
|
1090
|
-
* shadow-casters and return 1.0.
|
|
1091
|
-
* - Shadow-casting lights on the opaque queue (shadow mask mode 1) return the
|
|
1092
|
-
* screen-space mask value. Layer/channel are derived from the zero-based light
|
|
1093
|
-
* ordinal `s = index-1`: `layer = s >> 2`, `channel = s & 3`, matching the
|
|
1094
|
-
* ShadowMaskPass packing.
|
|
1095
|
-
* - Shadow-casting lights on a transparent queue (mode 0) return 0: their clustered
|
|
1096
|
-
* contribution is suppressed because they are lit inline by the additive passes,
|
|
1097
|
-
* where shadows are sampled at the true (transparent) surface depth rather than
|
|
1098
|
-
* from the opaque-depth mask.
|
|
1099
|
-
*
|
|
1100
|
-
* Only valid on the screen-space shadow mask path (ctx.screenSpaceShadowMask).
|
|
1101
|
-
* @internal
|
|
1086
|
+
/**
|
|
1087
|
+
* Clustered shadow factor for a light, in `[0,1]` (1 = fully lit).
|
|
1088
|
+
*
|
|
1089
|
+
* - Lights whose clustered buffer index is greater than `numShadowLights` are not
|
|
1090
|
+
* shadow-casters and return 1.0.
|
|
1091
|
+
* - Shadow-casting lights on the opaque queue (shadow mask mode 1) return the
|
|
1092
|
+
* screen-space mask value. Layer/channel are derived from the zero-based light
|
|
1093
|
+
* ordinal `s = index-1`: `layer = s >> 2`, `channel = s & 3`, matching the
|
|
1094
|
+
* ShadowMaskPass packing.
|
|
1095
|
+
* - Shadow-casting lights on a transparent queue (mode 0) return 0: their clustered
|
|
1096
|
+
* contribution is suppressed because they are lit inline by the additive passes,
|
|
1097
|
+
* where shadows are sampled at the true (transparent) surface depth rather than
|
|
1098
|
+
* from the opaque-depth mask.
|
|
1099
|
+
*
|
|
1100
|
+
* Only valid on the screen-space shadow mask path (ctx.screenSpaceShadowMask).
|
|
1101
|
+
* @internal
|
|
1102
1102
|
*/ static sampleShadowMask(scope, lightIndex) {
|
|
1103
1103
|
const pb = scope.$builder;
|
|
1104
1104
|
const that = this;
|
|
@@ -1125,87 +1125,87 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1125
1125
|
});
|
|
1126
1126
|
return pb.getGlobalScope()[funcName](lightIndex);
|
|
1127
1127
|
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Gets the uniform variable that contains atmosphere parameters
|
|
1130
|
-
* @param scope - Current shader scope
|
|
1131
|
-
* @returns The atmosphere parameters
|
|
1128
|
+
/**
|
|
1129
|
+
* Gets the uniform variable that contains atmosphere parameters
|
|
1130
|
+
* @param scope - Current shader scope
|
|
1131
|
+
* @returns The atmosphere parameters
|
|
1132
1132
|
*/ static getAtmosphereParams(scope) {
|
|
1133
1133
|
return scope.fog.atmosphereParams;
|
|
1134
1134
|
}
|
|
1135
|
-
/**
|
|
1136
|
-
* Gets the aerial perspective LUT
|
|
1137
|
-
* @param scope - Current shader scope
|
|
1138
|
-
* @returns The aerial perspective LUT texture
|
|
1135
|
+
/**
|
|
1136
|
+
* Gets the aerial perspective LUT
|
|
1137
|
+
* @param scope - Current shader scope
|
|
1138
|
+
* @returns The aerial perspective LUT texture
|
|
1139
1139
|
*/ static getAerialPerspectiveLUT(scope) {
|
|
1140
1140
|
return scope[UNIFORM_NAME_AERIALPERSPECTIVE_LUT];
|
|
1141
1141
|
}
|
|
1142
|
-
/**
|
|
1143
|
-
* Gets the uniform variable of type mat4 which holds the view projection matrix of current camera
|
|
1144
|
-
* @param scope - Current shader scope
|
|
1145
|
-
* @returns The view projection matrix of current camera
|
|
1142
|
+
/**
|
|
1143
|
+
* Gets the uniform variable of type mat4 which holds the view projection matrix of current camera
|
|
1144
|
+
* @param scope - Current shader scope
|
|
1145
|
+
* @returns The view projection matrix of current camera
|
|
1146
1146
|
*/ static getViewProjectionMatrix(scope) {
|
|
1147
1147
|
return scope.camera.viewProjectionMatrix;
|
|
1148
1148
|
}
|
|
1149
|
-
/**
|
|
1150
|
-
* Gets the uniform variable of type mat4 which holds the inversed view projection matrix of current camera
|
|
1151
|
-
* @param scope - Current shader scope
|
|
1152
|
-
* @returns The inversed view projection matrix of current camera
|
|
1149
|
+
/**
|
|
1150
|
+
* Gets the uniform variable of type mat4 which holds the inversed view projection matrix of current camera
|
|
1151
|
+
* @param scope - Current shader scope
|
|
1152
|
+
* @returns The inversed view projection matrix of current camera
|
|
1153
1153
|
*/ static getInvViewProjectionMatrix(scope) {
|
|
1154
1154
|
return scope.camera.invViewProjectionMatrix;
|
|
1155
1155
|
}
|
|
1156
|
-
/**
|
|
1157
|
-
* Gets the uniform variable of type mat4 which holds the projection matrix of current camera
|
|
1158
|
-
* @param scope - Current shader scope
|
|
1159
|
-
* @returns The projection matrix of current camera
|
|
1156
|
+
/**
|
|
1157
|
+
* Gets the uniform variable of type mat4 which holds the projection matrix of current camera
|
|
1158
|
+
* @param scope - Current shader scope
|
|
1159
|
+
* @returns The projection matrix of current camera
|
|
1160
1160
|
*/ static getProjectionMatrix(scope) {
|
|
1161
1161
|
return scope.camera.projectionMatrix;
|
|
1162
1162
|
}
|
|
1163
|
-
/**
|
|
1164
|
-
* Gets the uniform variable of type mat4 which holds the inversed projection matrix of current camera
|
|
1165
|
-
* @param scope - Current shader scope
|
|
1166
|
-
* @returns The inversed projection matrix of current camera
|
|
1163
|
+
/**
|
|
1164
|
+
* Gets the uniform variable of type mat4 which holds the inversed projection matrix of current camera
|
|
1165
|
+
* @param scope - Current shader scope
|
|
1166
|
+
* @returns The inversed projection matrix of current camera
|
|
1167
1167
|
*/ static getInvProjectionMatrix(scope) {
|
|
1168
1168
|
return scope.camera.invProjectionMatrix;
|
|
1169
1169
|
}
|
|
1170
|
-
/**
|
|
1171
|
-
* Gets the uniform variable of type mat4 which holds the unjittered view projection matrix of current camera
|
|
1172
|
-
* @param scope - Current shader scope
|
|
1173
|
-
* @returns The unjittered view projection matrix of current camera
|
|
1170
|
+
/**
|
|
1171
|
+
* Gets the uniform variable of type mat4 which holds the unjittered view projection matrix of current camera
|
|
1172
|
+
* @param scope - Current shader scope
|
|
1173
|
+
* @returns The unjittered view projection matrix of current camera
|
|
1174
1174
|
*/ static getUnjitteredViewProjectionMatrix(scope) {
|
|
1175
1175
|
return scope.camera.unjitteredVPMatrix;
|
|
1176
1176
|
}
|
|
1177
|
-
/**
|
|
1178
|
-
* Gets the uniform variable of type vec2 which holds the jitter value of the projection matrix of current camera
|
|
1179
|
-
* @param scope - Current shader scope
|
|
1180
|
-
* @returns The jitter value of projection matrix of current camera
|
|
1177
|
+
/**
|
|
1178
|
+
* Gets the uniform variable of type vec2 which holds the jitter value of the projection matrix of current camera
|
|
1179
|
+
* @param scope - Current shader scope
|
|
1180
|
+
* @returns The jitter value of projection matrix of current camera
|
|
1181
1181
|
*/ static getProjectionMatrixJitterValue(scope) {
|
|
1182
1182
|
return scope.camera.jitterValue;
|
|
1183
1183
|
}
|
|
1184
|
-
/**
|
|
1185
|
-
* Gets the uniform variable of type mat4 which holds the jittered inversed view-projection matrix
|
|
1186
|
-
* @param scope - Current shader scope
|
|
1187
|
-
* @returns The jittered inversed view-projection matrix
|
|
1184
|
+
/**
|
|
1185
|
+
* Gets the uniform variable of type mat4 which holds the jittered inversed view-projection matrix
|
|
1186
|
+
* @param scope - Current shader scope
|
|
1187
|
+
* @returns The jittered inversed view-projection matrix
|
|
1188
1188
|
*/ static getJitteredInvVPMatrix(scope) {
|
|
1189
1189
|
return scope.camera.jitteredInvVPMatrix;
|
|
1190
1190
|
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Gets the uniform variable of type mat4 which holds the unjittered view projection at previous frame matrix of current camera
|
|
1193
|
-
* @param scope - Current shader scope
|
|
1194
|
-
* @returns The unjittered view projection matrix at previous frame of current camera
|
|
1191
|
+
/**
|
|
1192
|
+
* Gets the uniform variable of type mat4 which holds the unjittered view projection at previous frame matrix of current camera
|
|
1193
|
+
* @param scope - Current shader scope
|
|
1194
|
+
* @returns The unjittered view projection matrix at previous frame of current camera
|
|
1195
1195
|
*/ static getPrevUnjitteredViewProjectionMatrix(scope) {
|
|
1196
1196
|
return scope.camera.prevUnjitteredVPMatrix;
|
|
1197
1197
|
}
|
|
1198
|
-
/**
|
|
1199
|
-
* Gets the uniform variable of type mat4 which holds the view matrix of current camera (world space to camera space)
|
|
1200
|
-
* @param scope - Current shader scope
|
|
1201
|
-
* @returns The view matrix of current camera
|
|
1198
|
+
/**
|
|
1199
|
+
* Gets the uniform variable of type mat4 which holds the view matrix of current camera (world space to camera space)
|
|
1200
|
+
* @param scope - Current shader scope
|
|
1201
|
+
* @returns The view matrix of current camera
|
|
1202
1202
|
*/ static getViewMatrix(scope) {
|
|
1203
1203
|
return scope.camera.viewMatrix;
|
|
1204
1204
|
}
|
|
1205
|
-
/**
|
|
1206
|
-
* Gets the uniform variable of type mat4 which holds the inv-view matrix of current camera (camera space to world space)
|
|
1207
|
-
* @param scope - Current shader scope
|
|
1208
|
-
* @returns The inv-view matrix of current camera
|
|
1205
|
+
/**
|
|
1206
|
+
* Gets the uniform variable of type mat4 which holds the inv-view matrix of current camera (camera space to world space)
|
|
1207
|
+
* @param scope - Current shader scope
|
|
1208
|
+
* @returns The inv-view matrix of current camera
|
|
1209
1209
|
*/ static getInvViewMatrix(scope) {
|
|
1210
1210
|
return scope.camera.worldMatrix;
|
|
1211
1211
|
}
|
|
@@ -1259,20 +1259,20 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1259
1259
|
/** @internal */ static getLightExtra(scope, lightIndex) {
|
|
1260
1260
|
return scope[UNIFORM_NAME_LIGHT_BUFFER].at(scope.$builder.add(scope.$builder.mul(lightIndex, 4), 3));
|
|
1261
1261
|
}
|
|
1262
|
-
/**
|
|
1263
|
-
* Sets the clip space position in vertex shader
|
|
1264
|
-
*
|
|
1265
|
-
* @remarks
|
|
1266
|
-
* Use this function instead of using
|
|
1267
|
-
* <pre>
|
|
1268
|
-
* // Do not use this
|
|
1269
|
-
* this.$builtins.position = some_value;
|
|
1270
|
-
* // Use this
|
|
1271
|
-
* ShaderFramework.setClipSpacePosition(some_value);
|
|
1272
|
-
* </pre>,
|
|
1273
|
-
*
|
|
1274
|
-
* @param scope - Current shader scope
|
|
1275
|
-
* @param pos - The clip space position to be set
|
|
1262
|
+
/**
|
|
1263
|
+
* Sets the clip space position in vertex shader
|
|
1264
|
+
*
|
|
1265
|
+
* @remarks
|
|
1266
|
+
* Use this function instead of using
|
|
1267
|
+
* <pre>
|
|
1268
|
+
* // Do not use this
|
|
1269
|
+
* this.$builtins.position = some_value;
|
|
1270
|
+
* // Use this
|
|
1271
|
+
* ShaderFramework.setClipSpacePosition(some_value);
|
|
1272
|
+
* </pre>,
|
|
1273
|
+
*
|
|
1274
|
+
* @param scope - Current shader scope
|
|
1275
|
+
* @param pos - The clip space position to be set
|
|
1276
1276
|
*/ static setClipSpacePosition(scope, pos) {
|
|
1277
1277
|
const pb = scope.$builder;
|
|
1278
1278
|
const cameraParams = this.getCameraParams(scope);
|
|
@@ -1282,20 +1282,20 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1282
1282
|
scope.$builtins.position = pos;
|
|
1283
1283
|
}
|
|
1284
1284
|
}
|
|
1285
|
-
/**
|
|
1286
|
-
* Get shadow map uniform value
|
|
1287
|
-
*
|
|
1288
|
-
* @param scope - Shader scope
|
|
1289
|
-
* @returns The shadow map texture uniform
|
|
1285
|
+
/**
|
|
1286
|
+
* Get shadow map uniform value
|
|
1287
|
+
*
|
|
1288
|
+
* @param scope - Shader scope
|
|
1289
|
+
* @returns The shadow map texture uniform
|
|
1290
1290
|
*/ static getShadowMap(scope) {
|
|
1291
1291
|
return scope[UNIFORM_NAME_SHADOW_MAP];
|
|
1292
1292
|
}
|
|
1293
|
-
/**
|
|
1294
|
-
* Calculates shadow of current fragment
|
|
1295
|
-
*
|
|
1296
|
-
* @param scope - Shader scope
|
|
1297
|
-
* @param NoL - NdotL vector
|
|
1298
|
-
* @returns Shadow of current fragment, 1 means no shadow and 0 means full shadowed.
|
|
1293
|
+
/**
|
|
1294
|
+
* Calculates shadow of current fragment
|
|
1295
|
+
*
|
|
1296
|
+
* @param scope - Shader scope
|
|
1297
|
+
* @param NoL - NdotL vector
|
|
1298
|
+
* @returns Shadow of current fragment, 1 means no shadow and 0 means full shadowed.
|
|
1299
1299
|
*/ static calculateShadow(scope, worldPos, NoL, ctx) {
|
|
1300
1300
|
const pb = scope.$builder;
|
|
1301
1301
|
const that = this;
|
|
@@ -1371,13 +1371,13 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1371
1371
|
scope[funcName](worldPos, color);
|
|
1372
1372
|
}
|
|
1373
1373
|
}
|
|
1374
|
-
/**
|
|
1375
|
-
* Calculates the non-linear depth from linear depth
|
|
1376
|
-
*
|
|
1377
|
-
* @param scope - Current shader scope
|
|
1378
|
-
* @param depth - The linear depth
|
|
1379
|
-
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
1380
|
-
* @returns The calculated non-linear depth
|
|
1374
|
+
/**
|
|
1375
|
+
* Calculates the non-linear depth from linear depth
|
|
1376
|
+
*
|
|
1377
|
+
* @param scope - Current shader scope
|
|
1378
|
+
* @param depth - The linear depth
|
|
1379
|
+
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
1380
|
+
* @returns The calculated non-linear depth
|
|
1381
1381
|
*/ static linearDepthToNonLinear(scope, depth, nearFar) {
|
|
1382
1382
|
const pb = scope.$builder;
|
|
1383
1383
|
nearFar = nearFar ?? this.getCameraParams(scope);
|
|
@@ -1386,13 +1386,13 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1386
1386
|
}
|
|
1387
1387
|
return pb.div(pb.sub(nearFar.y, pb.div(pb.mul(nearFar.x, nearFar.y), depth)), pb.sub(nearFar.y, nearFar.x));
|
|
1388
1388
|
}
|
|
1389
|
-
/**
|
|
1390
|
-
* Calculates the linear depth from non-linear depth
|
|
1391
|
-
*
|
|
1392
|
-
* @param scope - Current shader scope
|
|
1393
|
-
* @param depth - The non-linear depth
|
|
1394
|
-
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
1395
|
-
* @returns The calculated linear depth
|
|
1389
|
+
/**
|
|
1390
|
+
* Calculates the linear depth from non-linear depth
|
|
1391
|
+
*
|
|
1392
|
+
* @param scope - Current shader scope
|
|
1393
|
+
* @param depth - The non-linear depth
|
|
1394
|
+
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
1395
|
+
* @returns The calculated linear depth
|
|
1396
1396
|
*/ static nonLinearDepthToLinear(scope, depth, nearFar) {
|
|
1397
1397
|
const pb = scope.$builder;
|
|
1398
1398
|
nearFar = nearFar ?? this.getCameraParams(scope);
|
|
@@ -1401,13 +1401,13 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1401
1401
|
}
|
|
1402
1402
|
return pb.div(pb.mul(nearFar.x, nearFar.y), pb.mix(nearFar.y, nearFar.x, depth));
|
|
1403
1403
|
}
|
|
1404
|
-
/**
|
|
1405
|
-
* Calculates the normalized linear depth from non-linear depth
|
|
1406
|
-
*
|
|
1407
|
-
* @param scope - Current shader scope
|
|
1408
|
-
* @param depth - The non-linear depth
|
|
1409
|
-
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
1410
|
-
* @returns The calculated normalized linear depth
|
|
1404
|
+
/**
|
|
1405
|
+
* Calculates the normalized linear depth from non-linear depth
|
|
1406
|
+
*
|
|
1407
|
+
* @param scope - Current shader scope
|
|
1408
|
+
* @param depth - The non-linear depth
|
|
1409
|
+
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
1410
|
+
* @returns The calculated normalized linear depth
|
|
1411
1411
|
*/ static nonLinearDepthToLinearNormalized(scope, depth, nearFar) {
|
|
1412
1412
|
const pb = scope.$builder;
|
|
1413
1413
|
nearFar = nearFar ?? this.getCameraParams(scope);
|
|
@@ -1416,19 +1416,19 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1416
1416
|
}
|
|
1417
1417
|
return pb.div(nearFar.x, pb.mix(nearFar.y, nearFar.x, depth));
|
|
1418
1418
|
}
|
|
1419
|
-
/**
|
|
1420
|
-
* Converts normalized linear depth back to device non-linear depth.
|
|
1421
|
-
*
|
|
1422
|
-
* @remarks
|
|
1423
|
-
* The normalized linear depth convention (range [near/far, 1] with 1 at
|
|
1424
|
-
* the far plane, as produced by {@link ShaderHelper.nonLinearDepthToLinearNormalized})
|
|
1425
|
-
* is independent of the engine depth convention; only the mapping to
|
|
1426
|
-
* device depth flips under reverse-Z.
|
|
1427
|
-
*
|
|
1428
|
-
* @param scope - Current shader scope
|
|
1429
|
-
* @param depth - The normalized linear depth
|
|
1430
|
-
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
1431
|
-
* @returns The device non-linear depth
|
|
1419
|
+
/**
|
|
1420
|
+
* Converts normalized linear depth back to device non-linear depth.
|
|
1421
|
+
*
|
|
1422
|
+
* @remarks
|
|
1423
|
+
* The normalized linear depth convention (range [near/far, 1] with 1 at
|
|
1424
|
+
* the far plane, as produced by {@link ShaderHelper.nonLinearDepthToLinearNormalized})
|
|
1425
|
+
* is independent of the engine depth convention; only the mapping to
|
|
1426
|
+
* device depth flips under reverse-Z.
|
|
1427
|
+
*
|
|
1428
|
+
* @param scope - Current shader scope
|
|
1429
|
+
* @param depth - The normalized linear depth
|
|
1430
|
+
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
1431
|
+
* @returns The device non-linear depth
|
|
1432
1432
|
*/ static linearNormalizedToNonLinearDepth(scope, depth, nearFar) {
|
|
1433
1433
|
const pb = scope.$builder;
|
|
1434
1434
|
nearFar = nearFar ?? this.getCameraParams(scope);
|
|
@@ -1437,65 +1437,65 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1437
1437
|
}
|
|
1438
1438
|
return pb.div(pb.sub(pb.div(nearFar.x, depth), nearFar.y), pb.sub(nearFar.x, nearFar.y));
|
|
1439
1439
|
}
|
|
1440
|
-
/**
|
|
1441
|
-
* Maps a device depth value to the canonical clip-space z coordinate
|
|
1442
|
-
* (GL [-1,1] under standard-Z, zero-to-one under reverse-Z), suitable for
|
|
1443
|
-
* unprojection with the engine's inverse projection matrices.
|
|
1444
|
-
*
|
|
1445
|
-
* @param scope - Current shader scope
|
|
1446
|
-
* @param depth - The device depth value
|
|
1447
|
-
* @returns The canonical clip-space z
|
|
1440
|
+
/**
|
|
1441
|
+
* Maps a device depth value to the canonical clip-space z coordinate
|
|
1442
|
+
* (GL [-1,1] under standard-Z, zero-to-one under reverse-Z), suitable for
|
|
1443
|
+
* unprojection with the engine's inverse projection matrices.
|
|
1444
|
+
*
|
|
1445
|
+
* @param scope - Current shader scope
|
|
1446
|
+
* @param depth - The device depth value
|
|
1447
|
+
* @returns The canonical clip-space z
|
|
1448
1448
|
*/ static deviceDepthToClipZ(scope, depth) {
|
|
1449
1449
|
const pb = scope.$builder;
|
|
1450
1450
|
return REVERSE_Z ? depth : pb.sub(pb.mul(depth, 2), 1);
|
|
1451
1451
|
}
|
|
1452
|
-
/**
|
|
1453
|
-
* Clip-space z that places a vertex exactly on the far plane (sky domes,
|
|
1454
|
-
* background geometry).
|
|
1455
|
-
*
|
|
1456
|
-
* @param scope - Current shader scope
|
|
1457
|
-
* @param w - The clip-space w coordinate of the vertex
|
|
1458
|
-
* @returns The clip-space z value for the far plane
|
|
1452
|
+
/**
|
|
1453
|
+
* Clip-space z that places a vertex exactly on the far plane (sky domes,
|
|
1454
|
+
* background geometry).
|
|
1455
|
+
*
|
|
1456
|
+
* @param scope - Current shader scope
|
|
1457
|
+
* @param w - The clip-space w coordinate of the vertex
|
|
1458
|
+
* @returns The clip-space z value for the far plane
|
|
1459
1459
|
*/ static farthestClipZ(scope, w) {
|
|
1460
1460
|
return REVERSE_Z ? 0 : w;
|
|
1461
1461
|
}
|
|
1462
|
-
/**
|
|
1463
|
-
* Tests whether a device depth value equals the cleared (farthest) depth,
|
|
1464
|
-
* i.e. no geometry was rendered at this position.
|
|
1465
|
-
*
|
|
1466
|
-
* @param scope - Current shader scope
|
|
1467
|
-
* @param depth - The device depth value
|
|
1468
|
-
* @returns Boolean expression, true for background pixels
|
|
1462
|
+
/**
|
|
1463
|
+
* Tests whether a device depth value equals the cleared (farthest) depth,
|
|
1464
|
+
* i.e. no geometry was rendered at this position.
|
|
1465
|
+
*
|
|
1466
|
+
* @param scope - Current shader scope
|
|
1467
|
+
* @param depth - The device depth value
|
|
1468
|
+
* @returns Boolean expression, true for background pixels
|
|
1469
1469
|
*/ static isFarthestDepth(scope, depth) {
|
|
1470
1470
|
return scope.$builder.equal(depth, DEPTH_FARTHEST);
|
|
1471
1471
|
}
|
|
1472
|
-
/**
|
|
1473
|
-
* Selects the closer of two device depth values.
|
|
1474
|
-
*
|
|
1475
|
-
* @param scope - Current shader scope
|
|
1476
|
-
* @param a - First device depth value
|
|
1477
|
-
* @param b - Second device depth value
|
|
1478
|
-
* @returns The value closer to the camera
|
|
1472
|
+
/**
|
|
1473
|
+
* Selects the closer of two device depth values.
|
|
1474
|
+
*
|
|
1475
|
+
* @param scope - Current shader scope
|
|
1476
|
+
* @param a - First device depth value
|
|
1477
|
+
* @param b - Second device depth value
|
|
1478
|
+
* @returns The value closer to the camera
|
|
1479
1479
|
*/ static closerDepth(scope, a, b) {
|
|
1480
1480
|
return scope.$builder[DEPTH_REDUCE_CLOSER](a, b);
|
|
1481
1481
|
}
|
|
1482
|
-
/**
|
|
1483
|
-
* Selects the farther of two device depth values.
|
|
1484
|
-
*
|
|
1485
|
-
* @param scope - Current shader scope
|
|
1486
|
-
* @param a - First device depth value
|
|
1487
|
-
* @param b - Second device depth value
|
|
1488
|
-
* @returns The value farther from the camera
|
|
1482
|
+
/**
|
|
1483
|
+
* Selects the farther of two device depth values.
|
|
1484
|
+
*
|
|
1485
|
+
* @param scope - Current shader scope
|
|
1486
|
+
* @param a - First device depth value
|
|
1487
|
+
* @param b - Second device depth value
|
|
1488
|
+
* @returns The value farther from the camera
|
|
1489
1489
|
*/ static fartherDepth(scope, a, b) {
|
|
1490
1490
|
return scope.$builder[DEPTH_REDUCE_FARTHER](a, b);
|
|
1491
1491
|
}
|
|
1492
|
-
/**
|
|
1493
|
-
* Sample linear depth from linear depth texture
|
|
1494
|
-
* @param scope - Current shader scope
|
|
1495
|
-
* @param tex - The linear depth texture
|
|
1496
|
-
* @param uv - The uv coordinates
|
|
1497
|
-
* @param level - The mipmap level to sample
|
|
1498
|
-
* @returns Linear depth value
|
|
1492
|
+
/**
|
|
1493
|
+
* Sample linear depth from linear depth texture
|
|
1494
|
+
* @param scope - Current shader scope
|
|
1495
|
+
* @param tex - The linear depth texture
|
|
1496
|
+
* @param uv - The uv coordinates
|
|
1497
|
+
* @param level - The mipmap level to sample
|
|
1498
|
+
* @returns Linear depth value
|
|
1499
1499
|
*/ static sampleLinearDepth(scope, tex, uv, level) {
|
|
1500
1500
|
const pb = scope.$builder;
|
|
1501
1501
|
const depth = pb.textureSampleLevel(tex, uv, level);
|
|
@@ -1517,23 +1517,23 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1517
1517
|
});
|
|
1518
1518
|
return scope.zSamplePositionFromDepth(uv, cameraNearFar, mat);
|
|
1519
1519
|
}
|
|
1520
|
-
/**
|
|
1521
|
-
* Sample linear depth from linear depth texture with backface
|
|
1522
|
-
* @param scope - Current shader scope
|
|
1523
|
-
* @param tex - The linear depth texture
|
|
1524
|
-
* @param uv - The uv coordinates
|
|
1525
|
-
* @param level - The mipmap level to sample
|
|
1526
|
-
* @returns Linear depth value
|
|
1520
|
+
/**
|
|
1521
|
+
* Sample linear depth from linear depth texture with backface
|
|
1522
|
+
* @param scope - Current shader scope
|
|
1523
|
+
* @param tex - The linear depth texture
|
|
1524
|
+
* @param uv - The uv coordinates
|
|
1525
|
+
* @param level - The mipmap level to sample
|
|
1526
|
+
* @returns Linear depth value
|
|
1527
1527
|
*/ static sampleLinearDepthWithBackface(scope, tex, uv, level) {
|
|
1528
1528
|
const pb = scope.$builder;
|
|
1529
1529
|
return pb.textureSampleLevel(tex, uv, level).rg;
|
|
1530
1530
|
}
|
|
1531
|
-
/**
|
|
1532
|
-
* Transform color to sRGB color space if nessesary
|
|
1533
|
-
*
|
|
1534
|
-
* @param scope - Current shader scope
|
|
1535
|
-
* @param outputColor - The color to be transformed
|
|
1536
|
-
* @returns The transformed color
|
|
1531
|
+
/**
|
|
1532
|
+
* Transform color to sRGB color space if nessesary
|
|
1533
|
+
*
|
|
1534
|
+
* @param scope - Current shader scope
|
|
1535
|
+
* @param outputColor - The color to be transformed
|
|
1536
|
+
* @returns The transformed color
|
|
1537
1537
|
*/ static encodeColorOutput(scope, outputColor) {
|
|
1538
1538
|
const pb = scope.$builder;
|
|
1539
1539
|
const that = this;
|
|
@@ -1550,6 +1550,9 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
|
|
|
1550
1550
|
});
|
|
1551
1551
|
return pb.getGlobalScope()[funcName](outputColor);
|
|
1552
1552
|
}
|
|
1553
|
+
/** @internal */ static getMaxClusterLights() {
|
|
1554
|
+
return getDevice().type === 'webgl' ? 64 : 255;
|
|
1555
|
+
}
|
|
1553
1556
|
}
|
|
1554
1557
|
|
|
1555
1558
|
export { ShaderHelper };
|