@zephyr3d/scene 0.9.22 → 0.9.23
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/animation/joint_dynamics/collision.js +1 -7
- package/dist/animation/joint_dynamics/collision.js.map +1 -1
- package/dist/animation/joint_dynamics/constraints.js +2 -17
- package/dist/animation/joint_dynamics/constraints.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +2 -20
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +1 -3
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +14 -60
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics/types.js +3 -3
- package/dist/animation/joint_dynamics/types.js.map +1 -1
- package/dist/app/app.js +23 -0
- package/dist/app/app.js.map +1 -1
- package/dist/app/scriptregistry.js +16 -53
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +2 -0
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +22 -0
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/bilateralblur.js +3 -1
- package/dist/blitter/bilateralblur.js.map +1 -1
- package/dist/blitter/blitter.js +3 -3
- package/dist/blitter/blitter.js.map +1 -1
- package/dist/camera/camera.js +398 -45
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/perspectivecamera.js +69 -2
- package/dist/camera/perspectivecamera.js.map +1 -1
- package/dist/index.d.ts +9113 -8734
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +1 -1
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +3 -3
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +8 -5
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +17 -10
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +1 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +21 -6
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +33 -11
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/brdf.js +44 -12
- package/dist/material/mixins/pbr/brdf.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +149 -14
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mtoon.js +7 -4
- package/dist/material/mtoon.js.map +1 -1
- package/dist/material/pbrblueprint.js +5 -1
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +1 -1
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +1 -1
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +186 -11
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/skin.js +2 -2
- package/dist/material/skin.js.map +1 -1
- package/dist/material/terrain-cm.js +5 -5
- package/dist/material/terrain-cm.js.map +1 -1
- package/dist/material/water.js +6 -4
- package/dist/material/water.js.map +1 -1
- package/dist/posteffect/bloom.js +54 -4
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +41 -0
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/posteffect.js +35 -0
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +7 -6
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/skinsss.js +3 -3
- package/dist/posteffect/skinsss.js.map +1 -1
- package/dist/posteffect/ssgi.js +988 -436
- package/dist/posteffect/ssgi.js.map +1 -1
- package/dist/posteffect/ssr.js +83 -45
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +18 -15
- package/dist/posteffect/sss.js.map +1 -1
- package/dist/posteffect/taa.js +5 -4
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/posteffect/tonemap.js +15 -3
- package/dist/posteffect/tonemap.js.map +1 -1
- package/dist/render/abuffer_oit.js +2 -2
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/cluster_light.js +12 -6
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable_mixin.js +8 -5
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/dualdepthpeeling_oit.js +10 -5
- package/dist/render/dualdepthpeeling_oit.js.map +1 -1
- package/dist/render/envlight.js +298 -5
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/gpu_picking.js +7 -5
- package/dist/render/gpu_picking.js.map +1 -1
- package/dist/render/hzb.js +28 -19
- package/dist/render/hzb.js.map +1 -1
- package/dist/render/lightpass.js +18 -4
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +37 -4
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +8 -3
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/blackboard.js +20 -48
- package/dist/render/rendergraph/blackboard.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +18 -58
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/executor.js +89 -115
- package/dist/render/rendergraph/executor.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +1003 -715
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/frame_graph_context.js +1 -1
- package/dist/render/rendergraph/frame_graph_context.js.map +1 -1
- package/dist/render/rendergraph/frame_resource_requirements.js +14 -0
- package/dist/render/rendergraph/frame_resource_requirements.js.map +1 -0
- package/dist/render/rendergraph/history_resource_manager.js +74 -140
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +7 -5
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/rendergraph/render_context.js +19 -0
- package/dist/render/rendergraph/render_context.js.map +1 -0
- package/dist/render/rendergraph/render_pipeline.js +315 -0
- package/dist/render/rendergraph/render_pipeline.js.map +1 -0
- package/dist/render/rendergraph/rendergraph.js +158 -141
- package/dist/render/rendergraph/rendergraph.js.map +1 -1
- package/dist/render/rendergraph/scene_render_context.js +267 -0
- package/dist/render/rendergraph/scene_render_context.js.map +1 -0
- package/dist/render/rendergraph/texture_affinity_cache.js +19 -0
- package/dist/render/rendergraph/texture_affinity_cache.js.map +1 -0
- package/dist/render/rendergraph/types.js +19 -31
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +3 -3
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadow_mask_pass.js +7 -6
- package/dist/render/shadow_mask_pass.js.map +1 -1
- package/dist/render/sky.js +197 -35
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +4 -3
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +2 -0
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +10 -0
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +61 -2
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +178 -10
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/meshdrawable.js +89 -2
- package/dist/scene/meshdrawable.js.map +1 -1
- package/dist/scene/msdftext.js +2 -0
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +2 -0
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +2 -0
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +34 -1
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +2 -1
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +2 -0
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +2 -0
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/atmosphere.js +5 -4
- package/dist/shaders/atmosphere.js.map +1 -1
- package/dist/shaders/fog.js +10 -3
- package/dist/shaders/fog.js.map +1 -1
- package/dist/shaders/shadow.js +96 -29
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/ssgi_reprojection.js +118 -0
- package/dist/shaders/ssgi_reprojection.js.map +1 -0
- package/dist/shaders/ssr.js +322 -154
- package/dist/shaders/ssr.js.map +1 -1
- package/dist/shadow/esm.js +10 -7
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +12 -12
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +12 -12
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/pcss.js +15 -11
- package/dist/shadow/pcss.js.map +1 -1
- package/dist/shadow/shadow_impl.js +20 -2
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadowmapper.js +5 -2
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +13 -13
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +7 -7
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/physical.js +74 -0
- package/dist/utility/physical.js.map +1 -0
- package/dist/utility/rendermipmap.js +2 -2
- package/dist/utility/rendermipmap.js.map +1 -1
- package/dist/utility/serialization/manager.js +3 -1
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +3 -1
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +3 -1
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +598 -2
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +180 -9
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +43 -3
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +3 -1
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +3 -1
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +3 -1
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +2 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +70 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +3 -1
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +3 -1
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +3 -0
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +3 -1
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/values.js +2 -3
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
package/dist/shaders/fog.js
CHANGED
|
@@ -10,7 +10,8 @@ import { Fog } from '../values.js';
|
|
|
10
10
|
parameter3: new Vector4(0.8, 1, 0, 4),
|
|
11
11
|
parameter4: new Vector4(0, 0, 0, 0),
|
|
12
12
|
lightDir: new Vector3(0, 1, 0),
|
|
13
|
-
lightColor: new Vector3(0, 0, 0)
|
|
13
|
+
lightColor: new Vector3(0, 0, 0),
|
|
14
|
+
preExposure: 1
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
/** @internal */ function getHeightFogParamsStruct(pb) {
|
|
@@ -22,7 +23,8 @@ import { Fog } from '../values.js';
|
|
|
22
23
|
pb.float('dirInscatteringStartDistance'),
|
|
23
24
|
pb.vec3('dirInscatteringColor'),
|
|
24
25
|
pb.vec3('lightDir'),
|
|
25
|
-
pb.vec3('lightColor')
|
|
26
|
+
pb.vec3('lightColor'),
|
|
27
|
+
pb.float('preExposure')
|
|
26
28
|
]);
|
|
27
29
|
}
|
|
28
30
|
function calculateFog(scope, aerialperspective, fogType, atmosphereParams, heightFogParams, uv, isSky, cameraPos, worldPos, additive, apLut, distantLightLut) {
|
|
@@ -47,6 +49,9 @@ function calculateFog(scope, aerialperspective, fogType, atmosphereParams, heigh
|
|
|
47
49
|
});
|
|
48
50
|
this.$if(pb.and(pb.notEqual(this.withAerialPerspective, 0), pb.not(this.isSky)), function() {
|
|
49
51
|
this.$l.atmosphericFogging = aerialPerspective(this, this.uv, this.atmosphereParams, this.cameraPos, this.worldPos, pb.vec3(32), apLut);
|
|
52
|
+
// rgb is inscattered radiance from the exposure-independent AP LUT, so it takes the camera
|
|
53
|
+
// pre-exposure; alpha is transmittance and must stay unscaled.
|
|
54
|
+
this.atmosphericFogging = pb.vec4(pb.mul(this.atmosphericFogging.rgb, this.heightFogParams.preExposure), this.atmosphericFogging.a);
|
|
50
55
|
this.$if(pb.notEqual(this.fogType, Fog.FOG_TYPE_NONE), function() {
|
|
51
56
|
this.fogging = combineAerialPerspectiveFog(this, this.fogging, this.atmosphericFogging);
|
|
52
57
|
}).$else(function() {
|
|
@@ -102,7 +107,9 @@ function calculateHeightFog(scope, params, cameraPos, worldPos, isSky, skyDistan
|
|
|
102
107
|
this.$l.directionalInscattering = pb.mul(this.$l.directionalInscattering, pb.max(this.fogFactor, this.fading));
|
|
103
108
|
this.$l.fogColor = this.params.parameter1.rgb;
|
|
104
109
|
this.$if(pb.greaterThan(this.params.parameter3.y, 0), function() {
|
|
105
|
-
|
|
110
|
+
// The distant-sky LUT is baked exposure-independently (it feeds the cached IBL), so the
|
|
111
|
+
// camera pre-exposure is applied here. The authored fogColor above is already pre-exposed.
|
|
112
|
+
this.$l.skyContrib = pb.mul(pb.textureSampleLevel(skyDistantColorLut, pb.vec2(0.5), 0).rgb, this.params.preExposure);
|
|
106
113
|
this.fogColor = pb.add(this.fogColor, pb.mul(this.skyContrib, this.params.parameter3.y));
|
|
107
114
|
});
|
|
108
115
|
this.$l.fogFactor = pb.max(pb.min(this.fogFactor, this.params.parameter3.x), this.fading);
|
package/dist/shaders/fog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fog.js","sources":["../../src/shaders/fog.ts"],"sourcesContent":["import { Vector3, Vector4 } from '@zephyr3d/base';\r\nimport type { PBInsideFunctionScope, PBShaderExp, ProgramBuilder } from '@zephyr3d/device';\r\nimport { aerialPerspective, getAtmosphereParamsStruct } from './atmosphere';\r\nimport { Fog } from '../values';\r\n\r\n/** @internal */\r\nexport const MAX_FOG_HEIGHT = 100;\r\n\r\n/** @internal */\r\nexport type HeightFogParams = {\r\n parameter1: Vector4; // [rgb=fogColor a=heightFalloff]\r\n parameter2: Vector4; // [r=density g=startHeight b=startDistance a=maxHeight]\r\n parameter3: Vector4; // [r=maxOpacity g=atmosphereStrength b=rayOriginTerm a=dirInscatteringExponent]\r\n parameter4: Vector4; // [rgb=directionalInscatteringColor a=UNUSED]\r\n lightDir: Vector3;\r\n lightColor: Vector3;\r\n};\r\n\r\n/** @internal */\r\nexport function getDefaultHeightFogParams() {\r\n return {\r\n parameter1: new Vector4(0, 0, 0, 0.1),\r\n parameter2: new Vector4(0.01, 0, 0, 10000),\r\n parameter3: new Vector4(0.8, 1, 0, 4),\r\n parameter4: new Vector4(0, 0, 0, 0),\r\n lightDir: new Vector3(0, 1, 0),\r\n lightColor: new Vector3(0, 0, 0)\r\n } as HeightFogParams;\r\n}\r\n\r\n/** @internal */\r\nexport function getHeightFogParamsStruct(pb: ProgramBuilder) {\r\n return pb.defineStruct([\r\n pb.vec4('parameter1'),\r\n pb.vec4('parameter2'),\r\n pb.vec4('parameter3'),\r\n pb.vec4('parameter4'),\r\n pb.float('dirInscatteringStartDistance'),\r\n pb.vec3('dirInscatteringColor'),\r\n pb.vec3('lightDir'),\r\n pb.vec3('lightColor')\r\n ]);\r\n}\r\n\r\nexport function calculateFog(\r\n scope: PBInsideFunctionScope,\r\n aerialperspective: PBShaderExp,\r\n fogType: PBShaderExp,\r\n atmosphereParams: PBShaderExp,\r\n heightFogParams: PBShaderExp,\r\n uv: PBShaderExp,\r\n isSky: PBShaderExp | boolean,\r\n cameraPos: PBShaderExp,\r\n worldPos: PBShaderExp,\r\n additive: PBShaderExp | number,\r\n apLut: PBShaderExp,\r\n distantLightLut: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_calculateFog';\r\n const AtmosphereParams = getAtmosphereParamsStruct(pb);\r\n const HeightFogParams = getHeightFogParamsStruct(pb);\r\n pb.func(\r\n funcName,\r\n [\r\n pb.int('withAerialPerspective'),\r\n pb.int('fogType'),\r\n AtmosphereParams('atmosphereParams'),\r\n HeightFogParams('heightFogParams'),\r\n pb.bool('isSky'),\r\n pb.vec2('uv'),\r\n pb.vec3('cameraPos'),\r\n pb.vec3('worldPos'),\r\n pb.int('additive')\r\n ],\r\n function () {\r\n this.$l.fogging = pb.vec4(0, 0, 0, 1);\r\n this.$if(pb.equal(this.fogType, Fog.FOG_TYPE_HEIGHT), function () {\r\n this.fogging = calculateHeightFog(\r\n this,\r\n this.heightFogParams,\r\n this.cameraPos,\r\n this.worldPos,\r\n this.isSky,\r\n distantLightLut\r\n );\r\n });\r\n this.$if(pb.and(pb.notEqual(this.withAerialPerspective, 0), pb.not(this.isSky)), function () {\r\n this.$l.atmosphericFogging = aerialPerspective(\r\n this,\r\n this.uv,\r\n this.atmosphereParams,\r\n this.cameraPos,\r\n this.worldPos,\r\n pb.vec3(32),\r\n apLut\r\n );\r\n this.$if(pb.notEqual(this.fogType, Fog.FOG_TYPE_NONE), function () {\r\n this.fogging = combineAerialPerspectiveFog(this, this.fogging, this.atmosphericFogging);\r\n }).$else(function () {\r\n this.fogging = this.atmosphericFogging;\r\n });\r\n });\r\n this.$if(pb.notEqual(this.additive, 0), function () {\r\n this.fogging = pb.vec4(pb.vec3(0), this.fogging.a);\r\n });\r\n this.$return(this.fogging);\r\n }\r\n );\r\n return scope[funcName](\r\n aerialperspective,\r\n fogType,\r\n atmosphereParams,\r\n heightFogParams,\r\n isSky,\r\n uv,\r\n cameraPos,\r\n worldPos,\r\n additive\r\n );\r\n}\r\n\r\nexport function combineAerialPerspectiveFog(\r\n scope: PBInsideFunctionScope,\r\n fogging: PBShaderExp,\r\n aerialPerspectiveFog: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_combineAerialPerspectiveFog';\r\n pb.func(funcName, [pb.vec4('fogging'), pb.vec4('aerialPerspectiveFog')], function () {\r\n this.$l.rgb = pb.add(this.fogging.rgb, pb.mul(this.aerialPerspectiveFog.rgb, this.fogging.a));\r\n this.$l.a = pb.mul(this.fogging.a, this.aerialPerspectiveFog.a);\r\n this.$return(pb.vec4(this.rgb, this.a));\r\n });\r\n return scope[funcName](fogging, aerialPerspectiveFog);\r\n}\r\n\r\nexport function calculateHeightFog(\r\n scope: PBInsideFunctionScope,\r\n params: PBShaderExp,\r\n cameraPos: PBShaderExp,\r\n worldPos: PBShaderExp,\r\n isSky: PBShaderExp | boolean,\r\n skyDistantColorLut: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_calcHeightFog';\r\n const Params = getHeightFogParamsStruct(pb);\r\n pb.func(\r\n funcName,\r\n [Params('params'), pb.vec3('cameraPosition'), pb.vec3('worldPosition'), pb.bool('isSky')],\r\n function () {\r\n this.$l.cameraPos = this.$choice(\r\n this.isSky,\r\n this.cameraPosition,\r\n pb.vec3(\r\n this.cameraPosition.x,\r\n pb.min(this.cameraPosition.y, pb.add(this.params.parameter2.y, MAX_FOG_HEIGHT)),\r\n this.cameraPosition.z\r\n )\r\n );\r\n this.$l.ray = pb.sub(this.worldPosition, this.cameraPos);\r\n this.$l.d = pb.length(this.ray);\r\n this.$l.rayNorm = pb.div(this.ray, this.d);\r\n this.$l.origin = pb.add(this.cameraPos, pb.mul(this.rayNorm, this.params.parameter2.z));\r\n this.$l.term = this.params.parameter3.z;\r\n this.$l.worldPos = this.$choice(\r\n this.isSky,\r\n pb.add(this.cameraPosition, pb.mul(this.rayNorm, 1e8)),\r\n this.worldPosition\r\n );\r\n this.$l.falloff = pb.clamp(\r\n pb.mul(this.params.parameter1.w, pb.sub(this.worldPos.y, this.origin.y)),\r\n -125,\r\n 126\r\n );\r\n this.$l.fading = this.$choice(this.isSky, pb.smoothStep(5e6, 0, this.worldPos.y), 0);\r\n this.$l.factor = this.$choice(\r\n pb.greaterThan(pb.abs(this.falloff), 0.01),\r\n pb.div(pb.sub(1, pb.exp2(pb.neg(this.falloff))), this.falloff),\r\n pb.sub(Math.log(2), pb.mul(0.5 * Math.log(2) * Math.log(2), this.falloff))\r\n );\r\n this.$l.worldDistance = pb.dot(pb.sub(this.worldPos, this.origin), this.rayNorm);\r\n this.$l.lineIntegral = pb.mul(\r\n this.term,\r\n this.factor,\r\n pb.max(0, this.worldDistance) /*pb.distance(this.origin, this.worldPos)*/\r\n );\r\n\r\n this.$l.directionalInscattering = pb.mul(\r\n pb.add(this.params.parameter4.rgb, pb.mul(this.params.lightColor, this.params.parameter3.y)),\r\n pb.pow(pb.clamp(pb.dot(this.rayNorm, this.params.lightDir), 0, 1), this.params.parameter3.w)\r\n );\r\n this.$l.fogFactor = pb.sub(1, pb.clamp(pb.exp2(pb.neg(this.lineIntegral)), 0, 1));\r\n this.$l.distanceFactor = pb.clamp(pb.div(this.worldDistance, this.params.parameter2.w), 0, 1);\r\n this.fogFactor = pb.mul(this.fogFactor, pb.sub(1, this.distanceFactor));\r\n this.$l.directionalInscattering = pb.mul(\r\n this.$l.directionalInscattering,\r\n pb.max(this.fogFactor, this.fading)\r\n );\r\n\r\n this.$l.fogColor = this.params.parameter1.rgb;\r\n this.$if(pb.greaterThan(this.params.parameter3.y, 0), function () {\r\n this.$l.skyContrib = pb.textureSampleLevel(skyDistantColorLut, pb.vec2(0.5), 0).rgb;\r\n this.fogColor = pb.add(this.fogColor, pb.mul(this.skyContrib, this.params.parameter3.y));\r\n });\r\n this.$l.fogFactor = pb.max(pb.min(this.fogFactor, this.params.parameter3.x), this.fading);\r\n this.$l.fogColor = pb.add(pb.mul(this.fogColor, this.fogFactor), this.directionalInscattering);\r\n this.$return(pb.vec4(this.fogColor, pb.sub(1, this.fogFactor)));\r\n }\r\n );\r\n return scope[funcName](params, cameraPos, worldPos, isSky);\r\n}\r\n"],"names":["MAX_FOG_HEIGHT","getDefaultHeightFogParams","parameter1","Vector4","parameter2","parameter3","parameter4","lightDir","Vector3","lightColor","getHeightFogParamsStruct","pb","defineStruct","vec4","float","vec3","calculateFog","scope","aerialperspective","fogType","atmosphereParams","heightFogParams","uv","isSky","cameraPos","worldPos","additive","apLut","distantLightLut","$builder","funcName","AtmosphereParams","getAtmosphereParamsStruct","HeightFogParams","func","int","bool","vec2","$l","fogging","$if","equal","Fog","FOG_TYPE_HEIGHT","calculateHeightFog","and","notEqual","withAerialPerspective","not","atmosphericFogging","aerialPerspective","FOG_TYPE_NONE","combineAerialPerspectiveFog","$else","a","$return","aerialPerspectiveFog","rgb","add","mul","params","skyDistantColorLut","Params","$choice","cameraPosition","x","min","y","z","ray","sub","worldPosition","d","length","rayNorm","div","origin","term","falloff","clamp","w","fading","smoothStep","factor","greaterThan","abs","exp2","neg","Math","log","worldDistance","dot","lineIntegral","max","directionalInscattering","pow","fogFactor","distanceFactor","fogColor","skyContrib","textureSampleLevel"],"mappings":";;;;AAKA,iBACaA,MAAAA,cAAAA,GAAiB;AAY9B,iBACO,SAASC,yBAAAA,GAAAA;IACd,OAAO;AACLC,QAAAA,UAAAA,EAAY,IAAIC,OAAAA,CAAQ,CAAG,EAAA,CAAA,EAAG,CAAG,EAAA,GAAA,CAA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,IAAI,CAACwC,UAAU,EAAE,IAAI,CAACvC,MAAM,CAACvD,UAAU,CAAC8D,CAAC,CAAA,CAAA;AACxF,SAAA,CAAA;QACA,IAAI,CAAC7B,EAAE,CAAC0D,SAAS,GAAGrF,GAAGkF,GAAG,CAAClF,EAAGuD,CAAAA,GAAG,CAAC,IAAI,CAAC8B,SAAS,EAAE,IAAI,CAACpC,MAAM,CAACvD,UAAU,CAAC4D,CAAC,CAAA,EAAG,IAAI,CAACgB,MAAM,CAAA;QACxF,IAAI,CAAC3C,EAAE,CAAC4D,QAAQ,GAAGvF,EAAG+C,CAAAA,GAAG,CAAC/C,EAAGgD,CAAAA,GAAG,CAAC,IAAI,CAACuC,QAAQ,EAAE,IAAI,CAACF,SAAS,CAAA,EAAG,IAAI,CAACF,uBAAuB,CAAA;AAC7F,QAAA,IAAI,CAACvC,OAAO,CAAC5C,EAAGE,CAAAA,IAAI,CAAC,IAAI,CAACqF,QAAQ,EAAEvF,GAAG2D,GAAG,CAAC,CAAG,EAAA,IAAI,CAAC0B,SAAS,CAAA,CAAA,CAAA;AAC9D,KAAA,CAAA;AAEF,IAAA,OAAO/E,KAAK,CAACa,QAAAA,CAAS,CAAC8B,MAAAA,EAAQpC,WAAWC,QAAUF,EAAAA,KAAAA,CAAAA;AACtD;;;;"}
|
|
1
|
+
{"version":3,"file":"fog.js","sources":["../../src/shaders/fog.ts"],"sourcesContent":["import { Vector3, Vector4 } from '@zephyr3d/base';\r\nimport type { PBInsideFunctionScope, PBShaderExp, ProgramBuilder } from '@zephyr3d/device';\r\nimport { aerialPerspective, getAtmosphereParamsStruct } from './atmosphere';\r\nimport { Fog } from '../values';\r\n\r\n/** @internal */\r\nexport const MAX_FOG_HEIGHT = 100;\r\n\r\n/** @internal */\r\nexport type HeightFogParams = {\r\n parameter1: Vector4; // [rgb=fogColor a=heightFalloff]\r\n parameter2: Vector4; // [r=density g=startHeight b=startDistance a=maxHeight]\r\n parameter3: Vector4; // [r=maxOpacity g=atmosphereStrength b=rayOriginTerm a=dirInscatteringExponent]\r\n parameter4: Vector4; // [rgb=directionalInscatteringColor a=UNUSED]\r\n lightDir: Vector3;\r\n lightColor: Vector3;\r\n /**\r\n * Camera pre-exposure applied to the atmosphere-derived LUT samples (distant sky, aerial\r\n * perspective). Those LUTs are baked exposure-independently, unlike the authored fog colors which\r\n * are already pre-exposed on upload. 1 in legacy.\r\n */\r\n preExposure: number;\r\n};\r\n\r\n/** @internal */\r\nexport function getDefaultHeightFogParams() {\r\n return {\r\n parameter1: new Vector4(0, 0, 0, 0.1),\r\n parameter2: new Vector4(0.01, 0, 0, 10000),\r\n parameter3: new Vector4(0.8, 1, 0, 4),\r\n parameter4: new Vector4(0, 0, 0, 0),\r\n lightDir: new Vector3(0, 1, 0),\r\n lightColor: new Vector3(0, 0, 0),\r\n preExposure: 1\r\n } as HeightFogParams;\r\n}\r\n\r\n/** @internal */\r\nexport function getHeightFogParamsStruct(pb: ProgramBuilder) {\r\n return pb.defineStruct([\r\n pb.vec4('parameter1'),\r\n pb.vec4('parameter2'),\r\n pb.vec4('parameter3'),\r\n pb.vec4('parameter4'),\r\n pb.float('dirInscatteringStartDistance'),\r\n pb.vec3('dirInscatteringColor'),\r\n pb.vec3('lightDir'),\r\n pb.vec3('lightColor'),\r\n pb.float('preExposure')\r\n ]);\r\n}\r\n\r\nexport function calculateFog(\r\n scope: PBInsideFunctionScope,\r\n aerialperspective: PBShaderExp,\r\n fogType: PBShaderExp,\r\n atmosphereParams: PBShaderExp,\r\n heightFogParams: PBShaderExp,\r\n uv: PBShaderExp,\r\n isSky: PBShaderExp | boolean,\r\n cameraPos: PBShaderExp,\r\n worldPos: PBShaderExp,\r\n additive: PBShaderExp | number,\r\n apLut: PBShaderExp,\r\n distantLightLut: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_calculateFog';\r\n const AtmosphereParams = getAtmosphereParamsStruct(pb);\r\n const HeightFogParams = getHeightFogParamsStruct(pb);\r\n pb.func(\r\n funcName,\r\n [\r\n pb.int('withAerialPerspective'),\r\n pb.int('fogType'),\r\n AtmosphereParams('atmosphereParams'),\r\n HeightFogParams('heightFogParams'),\r\n pb.bool('isSky'),\r\n pb.vec2('uv'),\r\n pb.vec3('cameraPos'),\r\n pb.vec3('worldPos'),\r\n pb.int('additive')\r\n ],\r\n function () {\r\n this.$l.fogging = pb.vec4(0, 0, 0, 1);\r\n this.$if(pb.equal(this.fogType, Fog.FOG_TYPE_HEIGHT), function () {\r\n this.fogging = calculateHeightFog(\r\n this,\r\n this.heightFogParams,\r\n this.cameraPos,\r\n this.worldPos,\r\n this.isSky,\r\n distantLightLut\r\n );\r\n });\r\n this.$if(pb.and(pb.notEqual(this.withAerialPerspective, 0), pb.not(this.isSky)), function () {\r\n this.$l.atmosphericFogging = aerialPerspective(\r\n this,\r\n this.uv,\r\n this.atmosphereParams,\r\n this.cameraPos,\r\n this.worldPos,\r\n pb.vec3(32),\r\n apLut\r\n );\r\n // rgb is inscattered radiance from the exposure-independent AP LUT, so it takes the camera\r\n // pre-exposure; alpha is transmittance and must stay unscaled.\r\n this.atmosphericFogging = pb.vec4(\r\n pb.mul(this.atmosphericFogging.rgb, this.heightFogParams.preExposure),\r\n this.atmosphericFogging.a\r\n );\r\n this.$if(pb.notEqual(this.fogType, Fog.FOG_TYPE_NONE), function () {\r\n this.fogging = combineAerialPerspectiveFog(this, this.fogging, this.atmosphericFogging);\r\n }).$else(function () {\r\n this.fogging = this.atmosphericFogging;\r\n });\r\n });\r\n this.$if(pb.notEqual(this.additive, 0), function () {\r\n this.fogging = pb.vec4(pb.vec3(0), this.fogging.a);\r\n });\r\n this.$return(this.fogging);\r\n }\r\n );\r\n return scope[funcName](\r\n aerialperspective,\r\n fogType,\r\n atmosphereParams,\r\n heightFogParams,\r\n isSky,\r\n uv,\r\n cameraPos,\r\n worldPos,\r\n additive\r\n );\r\n}\r\n\r\nexport function combineAerialPerspectiveFog(\r\n scope: PBInsideFunctionScope,\r\n fogging: PBShaderExp,\r\n aerialPerspectiveFog: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_combineAerialPerspectiveFog';\r\n pb.func(funcName, [pb.vec4('fogging'), pb.vec4('aerialPerspectiveFog')], function () {\r\n this.$l.rgb = pb.add(this.fogging.rgb, pb.mul(this.aerialPerspectiveFog.rgb, this.fogging.a));\r\n this.$l.a = pb.mul(this.fogging.a, this.aerialPerspectiveFog.a);\r\n this.$return(pb.vec4(this.rgb, this.a));\r\n });\r\n return scope[funcName](fogging, aerialPerspectiveFog);\r\n}\r\n\r\nexport function calculateHeightFog(\r\n scope: PBInsideFunctionScope,\r\n params: PBShaderExp,\r\n cameraPos: PBShaderExp,\r\n worldPos: PBShaderExp,\r\n isSky: PBShaderExp | boolean,\r\n skyDistantColorLut: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_calcHeightFog';\r\n const Params = getHeightFogParamsStruct(pb);\r\n pb.func(\r\n funcName,\r\n [Params('params'), pb.vec3('cameraPosition'), pb.vec3('worldPosition'), pb.bool('isSky')],\r\n function () {\r\n this.$l.cameraPos = this.$choice(\r\n this.isSky,\r\n this.cameraPosition,\r\n pb.vec3(\r\n this.cameraPosition.x,\r\n pb.min(this.cameraPosition.y, pb.add(this.params.parameter2.y, MAX_FOG_HEIGHT)),\r\n this.cameraPosition.z\r\n )\r\n );\r\n this.$l.ray = pb.sub(this.worldPosition, this.cameraPos);\r\n this.$l.d = pb.length(this.ray);\r\n this.$l.rayNorm = pb.div(this.ray, this.d);\r\n this.$l.origin = pb.add(this.cameraPos, pb.mul(this.rayNorm, this.params.parameter2.z));\r\n this.$l.term = this.params.parameter3.z;\r\n this.$l.worldPos = this.$choice(\r\n this.isSky,\r\n pb.add(this.cameraPosition, pb.mul(this.rayNorm, 1e8)),\r\n this.worldPosition\r\n );\r\n this.$l.falloff = pb.clamp(\r\n pb.mul(this.params.parameter1.w, pb.sub(this.worldPos.y, this.origin.y)),\r\n -125,\r\n 126\r\n );\r\n this.$l.fading = this.$choice(this.isSky, pb.smoothStep(5e6, 0, this.worldPos.y), 0);\r\n this.$l.factor = this.$choice(\r\n pb.greaterThan(pb.abs(this.falloff), 0.01),\r\n pb.div(pb.sub(1, pb.exp2(pb.neg(this.falloff))), this.falloff),\r\n pb.sub(Math.log(2), pb.mul(0.5 * Math.log(2) * Math.log(2), this.falloff))\r\n );\r\n this.$l.worldDistance = pb.dot(pb.sub(this.worldPos, this.origin), this.rayNorm);\r\n this.$l.lineIntegral = pb.mul(\r\n this.term,\r\n this.factor,\r\n pb.max(0, this.worldDistance) /*pb.distance(this.origin, this.worldPos)*/\r\n );\r\n\r\n this.$l.directionalInscattering = pb.mul(\r\n pb.add(this.params.parameter4.rgb, pb.mul(this.params.lightColor, this.params.parameter3.y)),\r\n pb.pow(pb.clamp(pb.dot(this.rayNorm, this.params.lightDir), 0, 1), this.params.parameter3.w)\r\n );\r\n this.$l.fogFactor = pb.sub(1, pb.clamp(pb.exp2(pb.neg(this.lineIntegral)), 0, 1));\r\n this.$l.distanceFactor = pb.clamp(pb.div(this.worldDistance, this.params.parameter2.w), 0, 1);\r\n this.fogFactor = pb.mul(this.fogFactor, pb.sub(1, this.distanceFactor));\r\n this.$l.directionalInscattering = pb.mul(\r\n this.$l.directionalInscattering,\r\n pb.max(this.fogFactor, this.fading)\r\n );\r\n\r\n this.$l.fogColor = this.params.parameter1.rgb;\r\n this.$if(pb.greaterThan(this.params.parameter3.y, 0), function () {\r\n // The distant-sky LUT is baked exposure-independently (it feeds the cached IBL), so the\r\n // camera pre-exposure is applied here. The authored fogColor above is already pre-exposed.\r\n this.$l.skyContrib = pb.mul(\r\n pb.textureSampleLevel(skyDistantColorLut, pb.vec2(0.5), 0).rgb,\r\n this.params.preExposure\r\n );\r\n this.fogColor = pb.add(this.fogColor, pb.mul(this.skyContrib, this.params.parameter3.y));\r\n });\r\n this.$l.fogFactor = pb.max(pb.min(this.fogFactor, this.params.parameter3.x), this.fading);\r\n this.$l.fogColor = pb.add(pb.mul(this.fogColor, this.fogFactor), this.directionalInscattering);\r\n this.$return(pb.vec4(this.fogColor, pb.sub(1, this.fogFactor)));\r\n }\r\n );\r\n return scope[funcName](params, cameraPos, worldPos, isSky);\r\n}\r\n"],"names":["MAX_FOG_HEIGHT","getDefaultHeightFogParams","parameter1","Vector4","parameter2","parameter3","parameter4","lightDir","Vector3","lightColor","preExposure","getHeightFogParamsStruct","pb","defineStruct","vec4","float","vec3","calculateFog","scope","aerialperspective","fogType","atmosphereParams","heightFogParams","uv","isSky","cameraPos","worldPos","additive","apLut","distantLightLut","$builder","funcName","AtmosphereParams","getAtmosphereParamsStruct","HeightFogParams","func","int","bool","vec2","$l","fogging","$if","equal","Fog","FOG_TYPE_HEIGHT","calculateHeightFog","and","notEqual","withAerialPerspective","not","atmosphericFogging","aerialPerspective","mul","rgb","a","FOG_TYPE_NONE","combineAerialPerspectiveFog","$else","$return","aerialPerspectiveFog","add","params","skyDistantColorLut","Params","$choice","cameraPosition","x","min","y","z","ray","sub","worldPosition","d","length","rayNorm","div","origin","term","falloff","clamp","w","fading","smoothStep","factor","greaterThan","abs","exp2","neg","Math","log","worldDistance","dot","lineIntegral","max","directionalInscattering","pow","fogFactor","distanceFactor","fogColor","skyContrib","textureSampleLevel"],"mappings":";;;;AAKA,iBACaA,MAAAA,cAAAA,GAAiB;AAkB9B,iBACO,SAASC,yBAAAA,GAAAA;IACd,OAAO;AACLC,QAAAA,UAAAA,EAAY,IAAIC,OAAAA,CAAQ,CAAG,EAAA,CAAA,EAAG,CAAG,EAAA,GAAA,CAAA;AACjCC,QAAAA,UAAAA,EAAY,IAAID,OAAAA,CAAQ,IAAM,EAAA,CAAA,EAAG,CAAG,EAAA,KAAA,CAAA;AACpCE,QAAAA,UAAAA,EAAY,IAAIF,OAAAA,CAAQ,GAAK,EAAA,CAAA,EAAG,CAAG,EAAA,CAAA,CAAA;AACnCG,QAAAA,UAAAA,EAAY,IAAIH,OAAAA,CAAQ,CAA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W,CAAA;YAEzB,IAAI,CAACyF,QAAQ,GAAGvF,EAAAA,CAAGgD,GAAG,CAAC,IAAI,CAACuC,QAAQ,EAAEvF,EAAAA,CAAGwC,GAAG,CAAC,IAAI,CAACgD,UAAU,EAAE,IAAI,CAACvC,MAAM,CAACxD,UAAU,CAAC+D,CAAC,CAAA,CAAA;AACxF,SAAA,CAAA;QACA,IAAI,CAAC7B,EAAE,CAAC0D,SAAS,GAAGrF,GAAGkF,GAAG,CAAClF,EAAGuD,CAAAA,GAAG,CAAC,IAAI,CAAC8B,SAAS,EAAE,IAAI,CAACpC,MAAM,CAACxD,UAAU,CAAC6D,CAAC,CAAA,EAAG,IAAI,CAACgB,MAAM,CAAA;QACxF,IAAI,CAAC3C,EAAE,CAAC4D,QAAQ,GAAGvF,EAAGgD,CAAAA,GAAG,CAAChD,EAAGwC,CAAAA,GAAG,CAAC,IAAI,CAAC+C,QAAQ,EAAE,IAAI,CAACF,SAAS,CAAA,EAAG,IAAI,CAACF,uBAAuB,CAAA;AAC7F,QAAA,IAAI,CAACrC,OAAO,CAAC9C,EAAGE,CAAAA,IAAI,CAAC,IAAI,CAACqF,QAAQ,EAAEvF,GAAG2D,GAAG,CAAC,CAAG,EAAA,IAAI,CAAC0B,SAAS,CAAA,CAAA,CAAA;AAC9D,KAAA,CAAA;AAEF,IAAA,OAAO/E,KAAK,CAACa,QAAAA,CAAS,CAAC8B,MAAAA,EAAQpC,WAAWC,QAAUF,EAAAA,KAAAA,CAAAA;AACtD;;;;"}
|
package/dist/shaders/shadow.js
CHANGED
|
@@ -1,10 +1,54 @@
|
|
|
1
1
|
import { hasDepthChannel } from '@zephyr3d/device';
|
|
2
|
+
import { REVERSE_Z, DEPTH_FARTHEST } from '@zephyr3d/base';
|
|
2
3
|
import { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_RECT, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values.js';
|
|
3
4
|
import { encodeNormalizedFloatToRGBA, decode2HalfFromRGBA, decodeNormalizedFloatFromRGBA } from './misc.js';
|
|
4
5
|
import { ShaderHelper } from '../material/shader/helper.js';
|
|
5
6
|
import { smoothNoise3D } from './noise.js';
|
|
6
7
|
import { getDevice } from '../app/api.js';
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Whether the shadow-space depth compared by a filter is the device depth
|
|
11
|
+
* (direction flips under reverse-Z) or a linear distance encoding
|
|
12
|
+
* (direction independent). Directional/rect receivers use the light
|
|
13
|
+
* projection device depth; point uses distance/range and spot a linear
|
|
14
|
+
* view-depth encoding.
|
|
15
|
+
* @internal
|
|
16
|
+
*/ function isDeviceDepthShadow(lightType) {
|
|
17
|
+
return lightType !== LIGHT_TYPE_POINT && lightType !== LIGHT_TYPE_SPOT;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Maps the shadow-space NDC position to shadow map coordinates: xy to
|
|
21
|
+
* [0, 1] texture space, depth to the device depth range. Under standard-Z
|
|
22
|
+
* all components map from GL [-1, 1]; under reverse-Z the depth is already
|
|
23
|
+
* zero-to-one and passes through.
|
|
24
|
+
* @internal
|
|
25
|
+
*/ function ndcToShadowCoord(scope, ndc) {
|
|
26
|
+
const pb = scope.$builder;
|
|
27
|
+
return REVERSE_Z ? pb.vec4(pb.add(pb.mul(ndc.xy, 0.5), pb.vec2(0.5)), ndc.z, ndc.w) : pb.add(pb.mul(ndc, 0.5), 0.5);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* vec3 variant of {@link ndcToShadowCoord}.
|
|
31
|
+
* @internal
|
|
32
|
+
*/ function ndcToShadowCoord3(scope, ndc) {
|
|
33
|
+
const pb = scope.$builder;
|
|
34
|
+
return REVERSE_Z ? pb.vec3(pb.add(pb.mul(ndc.xy, 0.5), pb.vec2(0.5)), ndc.z) : pb.add(pb.mul(ndc, 0.5), 0.5);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether a shadow map device depth lies within the far bound of the
|
|
38
|
+
* shadow projection ("not beyond the shadow far plane").
|
|
39
|
+
* @internal
|
|
40
|
+
*/ function shadowCoordDepthInRange(scope, z) {
|
|
41
|
+
const pb = scope.$builder;
|
|
42
|
+
return REVERSE_Z ? pb.greaterThanEqual(z, 0) : pb.lessThanEqual(z, 1);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Applies a depth bias that moves the receiver towards the light in the
|
|
46
|
+
* encoding of the compared shadow depth.
|
|
47
|
+
* @internal
|
|
48
|
+
*/ function applyShadowDepthBias(scope, z, bias, deviceEncoded) {
|
|
49
|
+
const pb = scope.$builder;
|
|
50
|
+
return REVERSE_Z && deviceEncoded ? pb.add(z, bias) : pb.sub(z, bias);
|
|
51
|
+
}
|
|
8
52
|
/*
|
|
9
53
|
const PCF_KERNEL_3x3 = [
|
|
10
54
|
[0.5, 1.0, 0.5],
|
|
@@ -393,15 +437,17 @@ function sampleShadowMapPCF(scope, shadowMapFormat, pos, offset, depth, cascade)
|
|
|
393
437
|
if (shadowMapFormat === 'rgba8unorm') {
|
|
394
438
|
this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
|
|
395
439
|
}
|
|
396
|
-
|
|
440
|
+
// Receiver and stored depth are device-encoded here; under reverse-Z
|
|
441
|
+
// "lit" means receiver depth >= stored depth.
|
|
442
|
+
this.$return(REVERSE_Z ? pb.step(this.shadowTex.x, sampleDepth) : pb.step(sampleDepth, this.shadowTex.x));
|
|
397
443
|
}
|
|
398
444
|
});
|
|
399
445
|
return pb.getGlobalScope()[funcName](pos, depth, offset, ...cascade ? [
|
|
400
446
|
cascade
|
|
401
447
|
] : []);
|
|
402
448
|
}
|
|
403
|
-
function sampleShadowDepthPCSS(scope, shadowMapFormat, pos, bounds, cascade) {
|
|
404
|
-
const funcName = `lib_sampleShadowDepthPCSS_${shadowMapFormat}_${cascade ? 1 : 0}`;
|
|
449
|
+
function sampleShadowDepthPCSS(scope, shadowMapFormat, deviceEncoded, pos, bounds, cascade) {
|
|
450
|
+
const funcName = `lib_sampleShadowDepthPCSS_${shadowMapFormat}_${cascade ? 1 : 0}${REVERSE_Z && deviceEncoded ? '_rev' : ''}`;
|
|
405
451
|
const pb = scope.$builder;
|
|
406
452
|
pb.func(funcName, [
|
|
407
453
|
pb.vec2('coords'),
|
|
@@ -410,7 +456,9 @@ function sampleShadowDepthPCSS(scope, shadowMapFormat, pos, bounds, cascade) {
|
|
|
410
456
|
pb.int('cascade')
|
|
411
457
|
] : []
|
|
412
458
|
], function() {
|
|
413
|
-
|
|
459
|
+
// out-of-bounds samples read as "farthest" (no blocker); farthest is
|
|
460
|
+
// DEPTH_FARTHEST for device-encoded depth, 1 for linear encodings
|
|
461
|
+
this.$l.depth = pb.float(deviceEncoded ? DEPTH_FARTHEST : 1);
|
|
414
462
|
this.$l.sampleInside = pb.all(pb.bvec4(pb.greaterThanEqual(this.coords.x, this.bounds.x), pb.lessThanEqual(this.coords.x, this.bounds.z), pb.greaterThanEqual(this.coords.y, this.bounds.y), pb.lessThanEqual(this.coords.y, this.bounds.w)));
|
|
415
463
|
this.$if(this.sampleInside, function() {
|
|
416
464
|
this.$l.boundsPadding = pb.mul(pb.sub(this.bounds.zw, this.bounds.xy), getShadowMapTexelSize(this), 0.5);
|
|
@@ -435,21 +483,24 @@ function samplePointShadowDepthPCSS(scope, shadowMapFormat, dir) {
|
|
|
435
483
|
});
|
|
436
484
|
return pb.getGlobalScope()[funcName](dir);
|
|
437
485
|
}
|
|
438
|
-
function compareShadowDepthPCSS(scope, sampleDepth, compareDepth, transitionWidth) {
|
|
439
|
-
|
|
486
|
+
function compareShadowDepthPCSS(scope, sampleDepth, compareDepth, transitionWidth, deviceEncoded) {
|
|
487
|
+
// Lit when the stored depth is farther than the receiver; farther means a
|
|
488
|
+
// smaller value for device-encoded depth under reverse-Z.
|
|
489
|
+
const flip = REVERSE_Z && deviceEncoded;
|
|
490
|
+
const funcName = flip ? 'lib_compareShadowDepthPCSSRev' : 'lib_compareShadowDepthPCSS';
|
|
440
491
|
const pb = scope.$builder;
|
|
441
492
|
pb.func(funcName, [
|
|
442
493
|
pb.float('sampleDepth'),
|
|
443
494
|
pb.float('compareDepth'),
|
|
444
495
|
pb.float('transitionWidth')
|
|
445
496
|
], function() {
|
|
446
|
-
this.$l.depthDelta = pb.sub(this.sampleDepth, this.compareDepth);
|
|
497
|
+
this.$l.depthDelta = flip ? pb.sub(this.compareDepth, this.sampleDepth) : pb.sub(this.sampleDepth, this.compareDepth);
|
|
447
498
|
this.$return(pb.smoothStep(pb.neg(this.transitionWidth), this.transitionWidth, this.depthDelta));
|
|
448
499
|
});
|
|
449
500
|
return pb.getGlobalScope()[funcName](sampleDepth, compareDepth, transitionWidth);
|
|
450
501
|
}
|
|
451
|
-
function sampleShadowPCFPCSS(scope, shadowMapFormat, pos, bounds, compareDepth, texelSize, receiverPlaneDepthBias, cascade) {
|
|
452
|
-
const funcName = `lib_sampleShadowPCFPCSS_${shadowMapFormat}_${receiverPlaneDepthBias ? 1 : 0}_${cascade ? 1 : 0}`;
|
|
502
|
+
function sampleShadowPCFPCSS(scope, shadowMapFormat, deviceEncoded, pos, bounds, compareDepth, texelSize, receiverPlaneDepthBias, cascade) {
|
|
503
|
+
const funcName = `lib_sampleShadowPCFPCSS_${shadowMapFormat}_${receiverPlaneDepthBias ? 1 : 0}_${cascade ? 1 : 0}${REVERSE_Z && deviceEncoded ? '_rev' : ''}`;
|
|
453
504
|
const pb = scope.$builder;
|
|
454
505
|
pb.func(funcName, [
|
|
455
506
|
pb.vec2('coords'),
|
|
@@ -490,9 +541,9 @@ function sampleShadowPCFPCSS(scope, shadowMapFormat, pos, bounds, compareDepth,
|
|
|
490
541
|
for (const [ox, oy] of offsets){
|
|
491
542
|
this.offset = pb.mul(pb.vec2(ox, oy), this.texelSize);
|
|
492
543
|
this.tapCoord = pb.add(this.coords, this.offset);
|
|
493
|
-
this.sampleDepth = sampleShadowDepthPCSS(this, shadowMapFormat, this.tapCoord, this.bounds, this.cascade);
|
|
544
|
+
this.sampleDepth = sampleShadowDepthPCSS(this, shadowMapFormat, deviceEncoded, this.tapCoord, this.bounds, this.cascade);
|
|
494
545
|
this.tapCompareDepth = receiverPlaneDepthBias ? pb.add(this.compareDepth, pb.dot(this.offset, this.receiverPlaneDepthBias.xy)) : this.compareDepth;
|
|
495
|
-
this.shadow = pb.add(this.shadow, compareShadowDepthPCSS(this, this.sampleDepth, this.tapCompareDepth, this.transitionWidth));
|
|
546
|
+
this.shadow = pb.add(this.shadow, compareShadowDepthPCSS(this, this.sampleDepth, this.tapCompareDepth, this.transitionWidth, deviceEncoded));
|
|
496
547
|
}
|
|
497
548
|
this.$return(pb.mul(this.shadow, 0.25));
|
|
498
549
|
});
|
|
@@ -539,14 +590,14 @@ function samplePointShadowPCFPCSS(scope, shadowMapFormat, dir, compareDepth, tex
|
|
|
539
590
|
this.offset = pb.mul(pb.vec2(ox, oy), this.texelSize);
|
|
540
591
|
this.sampleDir = pb.normalize(pb.add(this.dir, pb.add(pb.mul(this.tangent, this.offset.x), pb.mul(this.bitangent, this.offset.y))));
|
|
541
592
|
this.sampleDepth = samplePointShadowDepthPCSS(this, shadowMapFormat, this.sampleDir);
|
|
542
|
-
this.shadow = pb.add(this.shadow, compareShadowDepthPCSS(this, this.sampleDepth, this.compareDepth, this.transitionWidth));
|
|
593
|
+
this.shadow = pb.add(this.shadow, compareShadowDepthPCSS(this, this.sampleDepth, this.compareDepth, this.transitionWidth, false));
|
|
543
594
|
}
|
|
544
595
|
this.$return(pb.mul(this.shadow, 0.25));
|
|
545
596
|
});
|
|
546
597
|
return pb.getGlobalScope()[funcName](dir, compareDepth, texelSize, tangent, bitangent);
|
|
547
598
|
}
|
|
548
|
-
function findBlockerPCSS(scope, shadowMapFormat, tapCount, texCoord, bounds, searchRadius, transitionWidth, matrix, cascade) {
|
|
549
|
-
const funcName = `lib_findBlockerPCSS_${shadowMapFormat}_${cascade ? 1 : 0}`;
|
|
599
|
+
function findBlockerPCSS(scope, shadowMapFormat, deviceEncoded, tapCount, texCoord, bounds, searchRadius, transitionWidth, matrix, cascade) {
|
|
600
|
+
const funcName = `lib_findBlockerPCSS_${shadowMapFormat}_${cascade ? 1 : 0}${REVERSE_Z && deviceEncoded ? '_rev' : ''}`;
|
|
550
601
|
const pb = scope.$builder;
|
|
551
602
|
pb.func(funcName, [
|
|
552
603
|
pb.vec4('texCoord'),
|
|
@@ -568,8 +619,10 @@ function findBlockerPCSS(scope, shadowMapFormat, tapCount, texCoord, bounds, sea
|
|
|
568
619
|
this.$for(pb.float('i'), 0, this.tapCount, function() {
|
|
569
620
|
this.duv = pb.mul(pb.mul(this.matrix, this.PCSSpdSamples.at(pb.mod(pb.mul(pb.int(this.i), 19), PCF_POISSON_DISC.length))), this.searchRadius);
|
|
570
621
|
this.sampleCoord = pb.add(this.texCoord.xy, this.duv);
|
|
571
|
-
this.sampleDepth = sampleShadowDepthPCSS(this, shadowMapFormat, this.sampleCoord, this.bounds, this.cascade);
|
|
572
|
-
|
|
622
|
+
this.sampleDepth = sampleShadowDepthPCSS(this, shadowMapFormat, deviceEncoded, this.sampleCoord, this.bounds, this.cascade);
|
|
623
|
+
// Blocker when the sample is closer to the light than the receiver;
|
|
624
|
+
// device-encoded depth mirrors the difference under reverse-Z.
|
|
625
|
+
this.blockerWeight = pb.sub(1, pb.smoothStep(pb.neg(this.transitionWidth), this.transitionWidth, REVERSE_Z && deviceEncoded ? pb.sub(this.texCoord.z, this.sampleDepth) : pb.sub(this.sampleDepth, this.texCoord.z)));
|
|
573
626
|
this.blockerDepthSum = pb.add(this.blockerDepthSum, pb.mul(this.sampleDepth, this.blockerWeight));
|
|
574
627
|
this.blockerCount = pb.add(this.blockerCount, this.blockerWeight);
|
|
575
628
|
});
|
|
@@ -610,8 +663,9 @@ function findPointBlockerPCSS(scope, shadowMapFormat, tapCount, dir, compareDept
|
|
|
610
663
|
});
|
|
611
664
|
return pb.getGlobalScope()[funcName](dir, compareDepth, searchRadius, tapCount, transitionWidth, matrix, tangent, bitangent);
|
|
612
665
|
}
|
|
613
|
-
function chebyshevUpperBound(scope, distance, occluder) {
|
|
614
|
-
const
|
|
666
|
+
function chebyshevUpperBound(scope, distance, occluder, deviceEncoded) {
|
|
667
|
+
const flip = REVERSE_Z && deviceEncoded;
|
|
668
|
+
const funcNameChebyshevUpperBound = flip ? 'lib_chebyshevUpperBoundRev' : 'lib_chebyshevUpperBound';
|
|
615
669
|
const pb = scope.$builder;
|
|
616
670
|
pb.func(funcNameChebyshevUpperBound, [
|
|
617
671
|
pb.float('distance'),
|
|
@@ -621,7 +675,11 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
621
675
|
this.$l.coverage = this.occluder.z;
|
|
622
676
|
this.$l.invCoverage = pb.div(1, pb.max(this.coverage, 0.00001));
|
|
623
677
|
this.$l.moments = pb.mul(this.occluder.xy, this.invCoverage);
|
|
624
|
-
|
|
678
|
+
// The one-sided Chebyshev bound applies when the receiver is farther
|
|
679
|
+
// than the mean occluder depth; variance and squared difference are
|
|
680
|
+
// invariant under the reverse-Z d -> 1-d mirror, only the side test
|
|
681
|
+
// flips.
|
|
682
|
+
this.$l.test = flip ? pb.step(this.moments.x, this.distance) : pb.step(this.distance, this.moments.x);
|
|
625
683
|
this.$if(pb.notEqual(this.test, 1), function() {
|
|
626
684
|
this.$l.d = pb.sub(this.distance, this.moments.x);
|
|
627
685
|
this.$l.variance = pb.max(pb.sub(this.moments.y, pb.mul(this.moments.x, this.moments.x)), 0.000002);
|
|
@@ -645,14 +703,14 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
645
703
|
], function() {
|
|
646
704
|
if (lightType === LIGHT_TYPE_POINT) {
|
|
647
705
|
this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.texCoord.xyz, 0);
|
|
648
|
-
this.$return(chebyshevUpperBound(this, this.texCoord.w, shadowMapFormat === 'rgba8unorm' ? pb.vec3(decode2HalfFromRGBA(this, this.shadowTex), 1) : this.shadowTex.rgb));
|
|
706
|
+
this.$return(chebyshevUpperBound(this, this.texCoord.w, shadowMapFormat === 'rgba8unorm' ? pb.vec3(decode2HalfFromRGBA(this, this.shadowTex), 1) : this.shadowTex.rgb, false));
|
|
649
707
|
} else {
|
|
650
708
|
if (getDevice().type !== 'webgl' && cascade) {
|
|
651
709
|
this.$l.shadowTex = pb.textureArraySampleLevel(ShaderHelper.getShadowMap(this), this.texCoord.xy, this.cascade, 0);
|
|
652
710
|
} else {
|
|
653
711
|
this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.texCoord.xy, 0);
|
|
654
712
|
}
|
|
655
|
-
this.$return(chebyshevUpperBound(this, this.texCoord.z, shadowMapFormat === 'rgba8unorm' ? pb.vec3(decode2HalfFromRGBA(this, this.shadowTex), 1) : this.shadowTex.rgb));
|
|
713
|
+
this.$return(chebyshevUpperBound(this, this.texCoord.z, shadowMapFormat === 'rgba8unorm' ? pb.vec3(decode2HalfFromRGBA(this, this.shadowTex), 1) : this.shadowTex.rgb, isDeviceDepthShadow(lightType)));
|
|
656
714
|
}
|
|
657
715
|
});
|
|
658
716
|
return pb.getGlobalScope()[funcNameFilterShadowVSM](texCoord, ...cascade ? [
|
|
@@ -693,11 +751,15 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
693
751
|
this.$l.depth = this.shadowVertex.z;
|
|
694
752
|
}
|
|
695
753
|
}
|
|
754
|
+
const deviceEncoded = isDeviceDepthShadow(lightType);
|
|
696
755
|
if (depthBias) {
|
|
697
|
-
this.depth = pb.max(0, pb.sub(this.depth, this.depthBias));
|
|
756
|
+
this.depth = REVERSE_Z && deviceEncoded ? pb.min(1, pb.add(this.depth, this.depthBias)) : pb.max(0, pb.sub(this.depth, this.depthBias));
|
|
698
757
|
}
|
|
699
758
|
const depthScale = ShaderHelper.getDepthBiasValues(this).z;
|
|
700
|
-
|
|
759
|
+
// ESM expects exp(k * (occluder - receiver)) with depth growing away
|
|
760
|
+
// from the light; device-encoded depth grows towards the light under
|
|
761
|
+
// reverse-Z, so the difference is mirrored.
|
|
762
|
+
this.$l.shadow = REVERSE_Z && deviceEncoded ? logSpace ? pb.clamp(pb.exp(pb.min(87, pb.sub(pb.mul(depthScale, this.depth), this.shadowTex.x))), 0, 1) : pb.clamp(pb.exp(pb.min(87, pb.mul(depthScale, pb.sub(this.depth, this.shadowTex.x)))), 0, 1) : logSpace ? pb.clamp(pb.exp(pb.min(87, pb.sub(this.shadowTex.x, pb.mul(depthScale, this.depth)))), 0, 1) : pb.clamp(pb.exp(pb.min(87, pb.mul(depthScale, pb.sub(this.shadowTex.x, this.depth)))), 0, 1);
|
|
701
763
|
if (shadowMapFormat !== 'rgba8unorm') {
|
|
702
764
|
this.shadow = pb.mix(1, this.shadow, pb.clamp(this.shadowTex.y, 0, 1));
|
|
703
765
|
}
|
|
@@ -723,7 +785,7 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
723
785
|
], function() {
|
|
724
786
|
this.$l.lightDepth = this.texCoord.z;
|
|
725
787
|
if (receiverPlaneDepthBias) {
|
|
726
|
-
this.lightDepth = pb.sub(this.lightDepth, this.receiverPlaneDepthBias.z);
|
|
788
|
+
this.lightDepth = REVERSE_Z ? pb.add(this.lightDepth, this.receiverPlaneDepthBias.z) : pb.sub(this.lightDepth, this.receiverPlaneDepthBias.z);
|
|
727
789
|
}
|
|
728
790
|
const shadowMapTexelSize = getShadowMapTexelSize(this);
|
|
729
791
|
this.$l.uv = pb.add(pb.mul(this.texCoord.xy, pb.vec2(getShadowMapSize(this))), pb.vec2(0));
|
|
@@ -838,9 +900,12 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
838
900
|
this.$return(this.shadow);
|
|
839
901
|
return;
|
|
840
902
|
}
|
|
903
|
+
// Directional/rect compare device depth (flips under reverse-Z);
|
|
904
|
+
// spot receivers and their stored depth use a linear encoding.
|
|
905
|
+
const deviceEncoded = isDeviceDepthShadow(lightType);
|
|
841
906
|
this.$l.lightDepth = this.texCoord.z;
|
|
842
907
|
if (receiverPlaneDepthBias) {
|
|
843
|
-
this.lightDepth = pb.sub(this.lightDepth, this.receiverPlaneDepthBias.z);
|
|
908
|
+
this.lightDepth = REVERSE_Z && deviceEncoded ? pb.add(this.lightDepth, this.receiverPlaneDepthBias.z) : pb.sub(this.lightDepth, this.receiverPlaneDepthBias.z);
|
|
844
909
|
}
|
|
845
910
|
this.$l.sampleBounds = pb.vec4(0, 0, 1, 1);
|
|
846
911
|
if (cascade && getDevice().type === 'webgl' && numCascades > 1) {
|
|
@@ -855,11 +920,13 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
855
920
|
this.$l.matrix = getPCSSRotationMatrix(this, pb.mul(this.texCoord.xy, pb.vec2(getShadowMapSize(this))), temporalJitter);
|
|
856
921
|
this.$l.searchRadius = pb.mul(pb.clamp(this.PCSSsearchRadius, 0, pb.max(0, this.PCSSmaxFilterRadius)), this.shadowMapTexelSize);
|
|
857
922
|
this.$l.blockerTransitionWidth = receiverPlaneDepthBias ? pb.max(pb.dot(pb.abs(this.receiverPlaneDepthBias.xy), this.searchRadius), 1 / 65535) : pb.float(1 / 65535);
|
|
858
|
-
this.$l.blocker = findBlockerPCSS(this, shadowMapFormat, this.PCSSblockerSampleCount, pb.vec4(this.texCoord.xy, this.lightDepth, this.texCoord.w), this.sampleBounds, this.searchRadius, this.blockerTransitionWidth, this.matrix, this.cascade);
|
|
923
|
+
this.$l.blocker = findBlockerPCSS(this, shadowMapFormat, deviceEncoded, this.PCSSblockerSampleCount, pb.vec4(this.texCoord.xy, this.lightDepth, this.texCoord.w), this.sampleBounds, this.searchRadius, this.blockerTransitionWidth, this.matrix, this.cascade);
|
|
859
924
|
this.$if(pb.lessThanEqual(this.blocker.y, 0), function() {
|
|
860
925
|
this.$return(pb.float(1));
|
|
861
926
|
});
|
|
862
|
-
|
|
927
|
+
// Penumbra estimation (receiver - blocker) / blocker; for device
|
|
928
|
+
// depth under reverse-Z apply the d -> 1-d mirror of the expression.
|
|
929
|
+
this.$l.penumbra = REVERSE_Z && deviceEncoded ? pb.div(pb.max(pb.sub(this.blocker.x, this.lightDepth), 0), pb.max(pb.sub(1, this.blocker.x), 0.0001)) : pb.div(pb.max(pb.sub(this.lightDepth, this.blocker.x), 0), pb.max(this.blocker.x, 0.0001));
|
|
863
930
|
this.$l.filterRadius = pb.mul(pb.clamp(pb.mul(this.penumbra, this.PCSSlightRadius), 0, pb.max(0, this.PCSSmaxFilterRadius)), this.shadowMapTexelSize);
|
|
864
931
|
this.$l.shadow = pb.float(0);
|
|
865
932
|
this.$l.duv = pb.vec2();
|
|
@@ -869,7 +936,7 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
869
936
|
this.duv = pb.mul(pb.mul(this.matrix, this.PCSSpdSamples.at(pb.mod(pb.mul(pb.int(this.i), 19), PCF_POISSON_DISC.length))), this.filterRadius);
|
|
870
937
|
this.sampleCoord = pb.add(this.texCoord.xy, this.duv);
|
|
871
938
|
this.compareDepth = receiverPlaneDepthBias ? pb.add(this.lightDepth, pb.dot(this.duv, this.receiverPlaneDepthBias.xy)) : this.lightDepth;
|
|
872
|
-
this.shadow = pb.add(this.shadow, sampleShadowPCFPCSS(this, shadowMapFormat, this.sampleCoord, this.sampleBounds, this.compareDepth, this.shadowMapTexelSize, this.receiverPlaneDepthBias, this.cascade));
|
|
939
|
+
this.shadow = pb.add(this.shadow, sampleShadowPCFPCSS(this, shadowMapFormat, deviceEncoded, this.sampleCoord, this.sampleBounds, this.compareDepth, this.shadowMapTexelSize, this.receiverPlaneDepthBias, this.cascade));
|
|
873
940
|
});
|
|
874
941
|
this.shadow = pb.div(this.shadow, this.PCSSfilterSampleCount);
|
|
875
942
|
this.$return(this.shadow);
|
|
@@ -881,5 +948,5 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
881
948
|
] : []);
|
|
882
949
|
}
|
|
883
950
|
|
|
884
|
-
export { computeReceiverPlaneDepthBias, computeShadowMapDepth, filterShadowESM, filterShadowPCF, filterShadowPCSS, filterShadowVSM };
|
|
951
|
+
export { applyShadowDepthBias, computeReceiverPlaneDepthBias, computeShadowMapDepth, filterShadowESM, filterShadowPCF, filterShadowPCSS, filterShadowVSM, isDeviceDepthShadow, ndcToShadowCoord, ndcToShadowCoord3, shadowCoordDepthInRange };
|
|
885
952
|
//# sourceMappingURL=shadow.js.map
|