@zephyr3d/scene 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/animation.js +173 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/animationset.js +95 -0
- package/dist/animation/animationset.js.map +1 -0
- package/dist/animation/animationtrack.js +38 -0
- package/dist/animation/animationtrack.js.map +1 -0
- package/dist/animation/eulerrotationtrack.js +33 -0
- package/dist/animation/eulerrotationtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +37 -0
- package/dist/animation/rotationtrack.js.map +1 -0
- package/dist/animation/scaletrack.js +36 -0
- package/dist/animation/scaletrack.js.map +1 -0
- package/dist/animation/skeleton.js +97 -0
- package/dist/animation/skeleton.js.map +1 -0
- package/dist/animation/translationtrack.js +36 -0
- package/dist/animation/translationtrack.js.map +1 -0
- package/dist/animation/usertrack.js +47 -0
- package/dist/animation/usertrack.js.map +1 -0
- package/dist/app.js +173 -0
- package/dist/app.js.map +1 -0
- package/dist/asset/assetmanager.js +476 -0
- package/dist/asset/assetmanager.js.map +1 -0
- package/dist/asset/builtin.js +373 -0
- package/dist/asset/builtin.js.map +1 -0
- package/dist/asset/loaders/dds/dds.js +472 -0
- package/dist/asset/loaders/dds/dds.js.map +1 -0
- package/dist/asset/loaders/dds/dds_loader.js +38 -0
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/helpers.js +314 -0
- package/dist/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/asset/loaders/hdr/hdr.js +175 -0
- package/dist/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/asset/loaders/image/tga_Loader.js +117 -0
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/asset/loaders/image/webimage_loader.js +50 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/asset/loaders/loader.js +45 -0
- package/dist/asset/loaders/loader.js.map +1 -0
- package/dist/asset/model.js +264 -0
- package/dist/asset/model.js.map +1 -0
- package/dist/blitter/blitter.js +389 -0
- package/dist/blitter/blitter.js.map +1 -0
- package/dist/blitter/box.js +118 -0
- package/dist/blitter/box.js.map +1 -0
- package/dist/blitter/copy.js +22 -0
- package/dist/blitter/copy.js.map +1 -0
- package/dist/blitter/depthlimitedgaussion.js +166 -0
- package/dist/blitter/depthlimitedgaussion.js.map +1 -0
- package/dist/blitter/gaussianblur.js +229 -0
- package/dist/blitter/gaussianblur.js.map +1 -0
- package/dist/camera/base.js +90 -0
- package/dist/camera/base.js.map +1 -0
- package/dist/camera/camera.js +358 -0
- package/dist/camera/camera.js.map +1 -0
- package/dist/camera/fps.js +246 -0
- package/dist/camera/fps.js.map +1 -0
- package/dist/camera/orbit.js +157 -0
- package/dist/camera/orbit.js.map +1 -0
- package/dist/camera/orthocamera.js +126 -0
- package/dist/camera/orthocamera.js.map +1 -0
- package/dist/camera/perspectivecamera.js +133 -0
- package/dist/camera/perspectivecamera.js.map +1 -0
- package/dist/index.d.ts +8402 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/input/inputmgr.js +242 -0
- package/dist/input/inputmgr.js.map +1 -0
- package/dist/material/blinn.js +75 -0
- package/dist/material/blinn.js.map +1 -0
- package/dist/material/grassmaterial.js +221 -0
- package/dist/material/grassmaterial.js.map +1 -0
- package/dist/material/lambert.js +52 -0
- package/dist/material/lambert.js.map +1 -0
- package/dist/material/lightmodel.js +2074 -0
- package/dist/material/lightmodel.js.map +1 -0
- package/dist/material/lit.js +578 -0
- package/dist/material/lit.js.map +1 -0
- package/dist/material/material.js +458 -0
- package/dist/material/material.js.map +1 -0
- package/dist/material/meshmaterial.js +311 -0
- package/dist/material/meshmaterial.js.map +1 -0
- package/dist/material/mixins/albedocolor.js +130 -0
- package/dist/material/mixins/albedocolor.js.map +1 -0
- package/dist/material/mixins/texture.js +110 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +45 -0
- package/dist/material/mixins/vertexcolor.js.map +1 -0
- package/dist/material/pbr.js +27 -0
- package/dist/material/pbr.js.map +1 -0
- package/dist/material/standard.js +282 -0
- package/dist/material/standard.js.map +1 -0
- package/dist/material/terrainlightmodel.js +259 -0
- package/dist/material/terrainlightmodel.js.map +1 -0
- package/dist/material/terrainmaterial.js +139 -0
- package/dist/material/terrainmaterial.js.map +1 -0
- package/dist/material/unlit.js +29 -0
- package/dist/material/unlit.js.map +1 -0
- package/dist/posteffect/bloom.js +398 -0
- package/dist/posteffect/bloom.js.map +1 -0
- package/dist/posteffect/compositor.js +264 -0
- package/dist/posteffect/compositor.js.map +1 -0
- package/dist/posteffect/fxaa.js +291 -0
- package/dist/posteffect/fxaa.js.map +1 -0
- package/dist/posteffect/grayscale.js +87 -0
- package/dist/posteffect/grayscale.js.map +1 -0
- package/dist/posteffect/posteffect.js +165 -0
- package/dist/posteffect/posteffect.js.map +1 -0
- package/dist/posteffect/sao.js +327 -0
- package/dist/posteffect/sao.js.map +1 -0
- package/dist/posteffect/tonemap.js +112 -0
- package/dist/posteffect/tonemap.js.map +1 -0
- package/dist/posteffect/water.js +535 -0
- package/dist/posteffect/water.js.map +1 -0
- package/dist/render/clipmap.js +462 -0
- package/dist/render/clipmap.js.map +1 -0
- package/dist/render/cluster_light.js +329 -0
- package/dist/render/cluster_light.js.map +1 -0
- package/dist/render/cull_visitor.js +124 -0
- package/dist/render/cull_visitor.js.map +1 -0
- package/dist/render/depth_pass.js +47 -0
- package/dist/render/depth_pass.js.map +1 -0
- package/dist/render/envlight.js +282 -0
- package/dist/render/envlight.js.map +1 -0
- package/dist/render/forward.js +186 -0
- package/dist/render/forward.js.map +1 -0
- package/dist/render/forward_pass.js +137 -0
- package/dist/render/forward_pass.js.map +1 -0
- package/dist/render/helper.js +38 -0
- package/dist/render/helper.js.map +1 -0
- package/dist/render/primitive.js +246 -0
- package/dist/render/primitive.js.map +1 -0
- package/dist/render/render_queue.js +163 -0
- package/dist/render/render_queue.js.map +1 -0
- package/dist/render/renderpass.js +151 -0
- package/dist/render/renderpass.js.map +1 -0
- package/dist/render/renderscheme.js +61 -0
- package/dist/render/renderscheme.js.map +1 -0
- package/dist/render/scatteringlut.js +634 -0
- package/dist/render/scatteringlut.js.map +1 -0
- package/dist/render/shadowmap_pass.js +70 -0
- package/dist/render/shadowmap_pass.js.map +1 -0
- package/dist/render/sky.js +881 -0
- package/dist/render/sky.js.map +1 -0
- package/dist/render/temporalcache.js +222 -0
- package/dist/render/temporalcache.js.map +1 -0
- package/dist/render/watermesh.js +835 -0
- package/dist/render/watermesh.js.map +1 -0
- package/dist/scene/environment.js +146 -0
- package/dist/scene/environment.js.map +1 -0
- package/dist/scene/graph_node.js +69 -0
- package/dist/scene/graph_node.js.map +1 -0
- package/dist/scene/light.js +436 -0
- package/dist/scene/light.js.map +1 -0
- package/dist/scene/mesh.js +215 -0
- package/dist/scene/mesh.js.map +1 -0
- package/dist/scene/model.js +111 -0
- package/dist/scene/model.js.map +1 -0
- package/dist/scene/octree.js +651 -0
- package/dist/scene/octree.js.map +1 -0
- package/dist/scene/octree_update_visitor.js +16 -0
- package/dist/scene/octree_update_visitor.js.map +1 -0
- package/dist/scene/raycast_visitor.js +72 -0
- package/dist/scene/raycast_visitor.js.map +1 -0
- package/dist/scene/scene.js +225 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/scene/scene_node.js +299 -0
- package/dist/scene/scene_node.js.map +1 -0
- package/dist/scene/terrain/grass.js +277 -0
- package/dist/scene/terrain/grass.js.map +1 -0
- package/dist/scene/terrain/heightfield.js +391 -0
- package/dist/scene/terrain/heightfield.js.map +1 -0
- package/dist/scene/terrain/patch.js +530 -0
- package/dist/scene/terrain/patch.js.map +1 -0
- package/dist/scene/terrain/quadtree.js +430 -0
- package/dist/scene/terrain/quadtree.js.map +1 -0
- package/dist/scene/terrain/terrain.js +258 -0
- package/dist/scene/terrain/terrain.js.map +1 -0
- package/dist/scene/xform.js +224 -0
- package/dist/scene/xform.js.map +1 -0
- package/dist/shaders/builtins.js +110 -0
- package/dist/shaders/builtins.js.map +1 -0
- package/dist/shaders/framework.js +709 -0
- package/dist/shaders/framework.js.map +1 -0
- package/dist/shaders/lighting.js +335 -0
- package/dist/shaders/lighting.js.map +1 -0
- package/dist/shaders/misc.js +405 -0
- package/dist/shaders/misc.js.map +1 -0
- package/dist/shaders/noise.js +157 -0
- package/dist/shaders/noise.js.map +1 -0
- package/dist/shaders/pbr.js +132 -0
- package/dist/shaders/pbr.js.map +1 -0
- package/dist/shaders/shadow.js +642 -0
- package/dist/shaders/shadow.js.map +1 -0
- package/dist/shaders/water.js +630 -0
- package/dist/shaders/water.js.map +1 -0
- package/dist/shadow/esm.js +235 -0
- package/dist/shadow/esm.js.map +1 -0
- package/dist/shadow/pcf_opt.js +182 -0
- package/dist/shadow/pcf_opt.js.map +1 -0
- package/dist/shadow/pcf_pd.js +190 -0
- package/dist/shadow/pcf_pd.js.map +1 -0
- package/dist/shadow/shadow_impl.js +15 -0
- package/dist/shadow/shadow_impl.js.map +1 -0
- package/dist/shadow/shadowmapper.js +709 -0
- package/dist/shadow/shadowmapper.js.map +1 -0
- package/dist/shadow/ssm.js +194 -0
- package/dist/shadow/ssm.js.map +1 -0
- package/dist/shadow/vsm.js +298 -0
- package/dist/shadow/vsm.js.map +1 -0
- package/dist/shapes/box.js +313 -0
- package/dist/shapes/box.js.map +1 -0
- package/dist/shapes/cylinder.js +74 -0
- package/dist/shapes/cylinder.js.map +1 -0
- package/dist/shapes/plane.js +48 -0
- package/dist/shapes/plane.js.map +1 -0
- package/dist/shapes/shape.js +33 -0
- package/dist/shapes/shape.js.map +1 -0
- package/dist/shapes/sphere.js +91 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/torus.js +100 -0
- package/dist/shapes/torus.js.map +1 -0
- package/dist/utility/aabbtree.js +390 -0
- package/dist/utility/aabbtree.js.map +1 -0
- package/dist/utility/bounding_volume.js +78 -0
- package/dist/utility/bounding_volume.js.map +1 -0
- package/dist/utility/panorama.js +163 -0
- package/dist/utility/panorama.js.map +1 -0
- package/dist/utility/pmrem.js +345 -0
- package/dist/utility/pmrem.js.map +1 -0
- package/dist/utility/shprojection.js +448 -0
- package/dist/utility/shprojection.js.map +1 -0
- package/dist/values.js +48 -0
- package/dist/values.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { PBInsideFunctionScope } from '@zephyr3d/device';
|
|
2
|
+
import { RENDER_PASS_TYPE_FORWARD, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values.js';
|
|
3
|
+
import { ShaderFramework } from './framework.js';
|
|
4
|
+
import { nonLinearDepthToLinear } from './misc.js';
|
|
5
|
+
import { Application } from '../app.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Calculate lighting for forward renderer
|
|
9
|
+
*
|
|
10
|
+
* @param scope - Current shader scope
|
|
11
|
+
* @param lm - The light model
|
|
12
|
+
* @param ctx - The drawing context
|
|
13
|
+
* @returns The final color
|
|
14
|
+
*/ function forwardComputeLighting(scope, lm, ctx) {
|
|
15
|
+
const env = ctx.drawEnvLight ? ctx.env.light.envLight : null;
|
|
16
|
+
const funcNameIllumPointLight = 'stdmat_illumPointLight';
|
|
17
|
+
const funcNameIllumDirectionalLight = 'stdmat_illumDirectionalLight';
|
|
18
|
+
const funcNameIllumSpotLight = 'stdmat_illumSpotLight';
|
|
19
|
+
const funcNameIllumDirectionalShadowLight = 'stdmat_illumDirectionalShadowLight';
|
|
20
|
+
const funcNameIllumPointShadowLight = 'stdmat_illumPointShadowLight';
|
|
21
|
+
const funcNameIllumCascadedShadowLight = 'stdmat_illumCascadedShadowLight';
|
|
22
|
+
const funcNameIllumUnshadowedLights = 'stdmat_illumUnshadowedLights';
|
|
23
|
+
const funcNameGetClusterIndex = 'stdmat_getClusterIndex';
|
|
24
|
+
const funcNameIllumOneLight = 'stdmat_illumOneLight';
|
|
25
|
+
const funcNameComputeLighting = 'stdmat_computeLighting';
|
|
26
|
+
const pb = scope.$builder;
|
|
27
|
+
if (!scope || !(scope instanceof PBInsideFunctionScope)) {
|
|
28
|
+
throw new Error('forwardComputeLighting() failed: forwardComputeLighting() must be called inside a function');
|
|
29
|
+
}
|
|
30
|
+
if (ctx.renderPass.type !== RENDER_PASS_TYPE_FORWARD) {
|
|
31
|
+
throw new Error(`forwardComputeLighting() failed: invalid render pass type: ${ctx.renderPass.type}`);
|
|
32
|
+
}
|
|
33
|
+
function illumPointLight(lm, ...args) {
|
|
34
|
+
pb.func(funcNameIllumPointLight, [
|
|
35
|
+
pb.vec4('lightPositionRange'),
|
|
36
|
+
pb.vec4('lightDirectionCutoff'),
|
|
37
|
+
pb.vec3('lightDir'),
|
|
38
|
+
pb.vec3('attenuation')
|
|
39
|
+
], function() {
|
|
40
|
+
this.$l.dist = pb.distance(this.lightPositionRange.xyz, ShaderFramework.getWorldPosition(this).xyz);
|
|
41
|
+
this.$l.a = pb.div(1, pb.add(1, pb.mul(this.dist, this.dist)));
|
|
42
|
+
this.$l.falloff = pb.mul(this.a, pb.clamp(pb.sub(1, pb.div(this.dist, this.lightPositionRange.w)), 0, 1));
|
|
43
|
+
//this.$l.t = pb.div(pb.mul(this.dist, 16), this.lightPositionRange.w);
|
|
44
|
+
//this.$l.falloff = pb.div(1, pb.add(1, pb.mul(this.t, this.t)));
|
|
45
|
+
//this.$l.falloff = pb.div(1, ) pb.max(0, pb.sub(1, pb.div(this.dist, this.lightPositionRange.w)));
|
|
46
|
+
//this.falloff = pb.mul(this.falloff, this.falloff);
|
|
47
|
+
this.$if(pb.greaterThan(this.falloff, 0), function() {
|
|
48
|
+
lm.directBRDF(this, this.lightDir, pb.mul(this.attenuation, this.falloff));
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
pb.getGlobalScope()[funcNameIllumPointLight](...args);
|
|
52
|
+
}
|
|
53
|
+
function illumDirectionalLight(lm, ...args) {
|
|
54
|
+
pb.func(funcNameIllumDirectionalLight, [
|
|
55
|
+
pb.vec4('lightPositionRange'),
|
|
56
|
+
pb.vec4('lightDirectionCutoff'),
|
|
57
|
+
pb.vec3('lightDir'),
|
|
58
|
+
pb.vec3('attenuation')
|
|
59
|
+
], function() {
|
|
60
|
+
lm.directBRDF(this, this.lightDir, this.attenuation);
|
|
61
|
+
});
|
|
62
|
+
pb.getGlobalScope()[funcNameIllumDirectionalLight](...args);
|
|
63
|
+
}
|
|
64
|
+
function illumSpotLight(lm, ...args) {
|
|
65
|
+
pb.func(funcNameIllumSpotLight, [
|
|
66
|
+
pb.vec4('lightPositionRange'),
|
|
67
|
+
pb.vec4('lightDirectionCutoff'),
|
|
68
|
+
pb.vec3('lightDir'),
|
|
69
|
+
pb.vec3('attenuation')
|
|
70
|
+
], function() {
|
|
71
|
+
this.$l.spotFactor = pb.dot(this.lightDir, this.lightDirectionCutoff.xyz);
|
|
72
|
+
this.spotFactor = pb.smoothStep(this.lightDirectionCutoff.w, pb.mix(this.lightDirectionCutoff.w, 1, 0.5), this.spotFactor);
|
|
73
|
+
this.$if(pb.greaterThan(this.spotFactor, 0), function() {
|
|
74
|
+
illumPointLight(lm, this.lightPositionRange, this.lightDirectionCutoff, this.lightDir, pb.mul(this.attenuation, this.spotFactor));
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
pb.getGlobalScope()[funcNameIllumSpotLight](...args);
|
|
78
|
+
}
|
|
79
|
+
function illumLight(scope, lightType, lm, ...args) {
|
|
80
|
+
if (typeof lightType === 'number') {
|
|
81
|
+
if (lightType === LIGHT_TYPE_DIRECTIONAL) {
|
|
82
|
+
illumDirectionalLight(lm, ...args);
|
|
83
|
+
} else if (lightType === LIGHT_TYPE_POINT) {
|
|
84
|
+
illumPointLight(lm, ...args);
|
|
85
|
+
} else if (lightType === LIGHT_TYPE_SPOT) {
|
|
86
|
+
illumSpotLight(lm, ...args);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
scope.$if(pb.equal(lightType, LIGHT_TYPE_DIRECTIONAL), function() {
|
|
90
|
+
illumDirectionalLight(lm, ...args);
|
|
91
|
+
}).$elseif(pb.equal(lightType, LIGHT_TYPE_POINT), function() {
|
|
92
|
+
illumPointLight(lm, ...args);
|
|
93
|
+
}).$elseif(pb.equal(lightType, LIGHT_TYPE_SPOT), function() {
|
|
94
|
+
illumSpotLight(lm, ...args);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function illumDirectionalShadowLight(lightType, lm) {
|
|
99
|
+
pb.func(funcNameIllumDirectionalShadowLight, [], function() {
|
|
100
|
+
this.$l.positionRange = scope.global.light.positionAndRange; //ShaderFramework.getLightPositionAndRange(this, 0);
|
|
101
|
+
this.$l.directionCutoff = scope.global.light.directionAndCutoff; //ShaderFramework.getLightDirectionAndCutoff(this, 0);
|
|
102
|
+
this.$l.diffuseIntensity = scope.global.light.diffuseAndIntensity; //ShaderFramework.getLightColorAndIntensity(this, 0);
|
|
103
|
+
this.$l.lightcolor = pb.mul(this.diffuseIntensity.xyz, this.diffuseIntensity.w);
|
|
104
|
+
this.$l.lightDir = pb.vec3();
|
|
105
|
+
this.$l.nl = pb.float();
|
|
106
|
+
this.$l.NdotL = pb.float();
|
|
107
|
+
if (lightType === LIGHT_TYPE_DIRECTIONAL) {
|
|
108
|
+
this.lightDir = this.directionCutoff.xyz;
|
|
109
|
+
this.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
110
|
+
this.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
111
|
+
} else {
|
|
112
|
+
this.lightDir = pb.sub(ShaderFramework.getWorldPosition(this).xyz, this.positionRange.xyz);
|
|
113
|
+
this.lightDir = pb.normalize(this.lightDir);
|
|
114
|
+
this.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
115
|
+
this.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
116
|
+
}
|
|
117
|
+
this.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this);
|
|
118
|
+
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
119
|
+
this.$l.shadow = shadowMapParams.impl.computeShadow(shadowMapParams, this, this.shadowVertex, this.NdotL);
|
|
120
|
+
this.$l.shadowDistance = ShaderFramework.getShadowCameraParams(scope).w;
|
|
121
|
+
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(ShaderFramework.getCameraPosition(this), ShaderFramework.getWorldPosition(this).xyz)));
|
|
122
|
+
// TODO: cannot early exit, shoud make computeShadow() running in non-uniform control flow
|
|
123
|
+
if (lightType !== LIGHT_TYPE_DIRECTIONAL) {
|
|
124
|
+
this.$if(pb.greaterThan(pb.length(this.lightDir), this.positionRange.w), function() {
|
|
125
|
+
this.$return();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
this.$if(pb.greaterThan(this.NdotL, 0), function() {
|
|
129
|
+
this.$l.attenuation = pb.mul(pb.mul(this.lightcolor, this.NdotL), pb.vec3(this.shadow));
|
|
130
|
+
illumLight(this, lightType, lm, this.positionRange, this.directionCutoff, this.lightDir, this.attenuation);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
pb.getGlobalScope()[funcNameIllumDirectionalShadowLight]();
|
|
134
|
+
}
|
|
135
|
+
function illumPointShadowLight(lm) {
|
|
136
|
+
pb.func(funcNameIllumPointShadowLight, [], function() {
|
|
137
|
+
const worldPos = ShaderFramework.getWorldPosition(this);
|
|
138
|
+
this.$l.positionRange = scope.global.light.positionAndRange; //ShaderFramework.getLightPositionAndRange(this, 0);
|
|
139
|
+
this.$l.directionCutoff = scope.global.light.directionAndCutoff; //ShaderFramework.getLightDirectionAndCutoff(this, 0);
|
|
140
|
+
this.$l.diffuseIntensity = scope.global.light.diffuseAndIntensity; //ShaderFramework.getLightColorAndIntensity(this, 0);
|
|
141
|
+
this.$l.lightcolor = pb.mul(this.diffuseIntensity.xyz, this.diffuseIntensity.w);
|
|
142
|
+
this.$l.lightDir = pb.sub(worldPos.xyz, this.positionRange.xyz);
|
|
143
|
+
this.$if(pb.greaterThan(pb.length(this.lightDir), this.positionRange.w), function() {
|
|
144
|
+
this.$return();
|
|
145
|
+
});
|
|
146
|
+
this.lightDir = pb.normalize(this.lightDir);
|
|
147
|
+
this.$l.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
148
|
+
this.$l.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
149
|
+
this.shadowBound = pb.vec4(0, 0, 1, 1);
|
|
150
|
+
this.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this);
|
|
151
|
+
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
152
|
+
this.$l.shadow = shadowMapParams.impl.computeShadow(shadowMapParams, this, this.shadowVertex, this.NdotL);
|
|
153
|
+
this.$l.shadowDistance = ShaderFramework.getShadowCameraParams(scope).w;
|
|
154
|
+
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(ShaderFramework.getCameraPosition(this), ShaderFramework.getWorldPosition(this).xyz)));
|
|
155
|
+
this.$if(pb.greaterThan(this.NdotL, 0), function() {
|
|
156
|
+
this.$l.attenuation = pb.mul(pb.mul(this.lightcolor, this.NdotL), pb.vec3(this.shadow));
|
|
157
|
+
illumLight(this, LIGHT_TYPE_POINT, lm, this.positionRange, this.directionCutoff, this.lightDir, this.attenuation);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
pb.getGlobalScope()[funcNameIllumPointShadowLight]();
|
|
161
|
+
}
|
|
162
|
+
function illumCascadedShadowLight(lm) {
|
|
163
|
+
pb.func(funcNameIllumCascadedShadowLight, [], function() {
|
|
164
|
+
this.$l.shadowCascades = this.global.light.shadowCascades; //ShaderFramework.getLightInfo(this, 0).y;
|
|
165
|
+
this.$l.positionRange = this.global.light.positionAndRange; //ShaderFramework.getLightPositionAndRange(this, 0);
|
|
166
|
+
this.$l.directionCutoff = this.global.light.directionAndCutoff; //ShaderFramework.getLightDirectionAndCutoff(this, 0);
|
|
167
|
+
this.$l.diffuseIntensity = this.global.light.diffuseAndIntensity; //ShaderFramework.getLightColorAndIntensity(this, 0);
|
|
168
|
+
this.$l.lightcolor = pb.mul(this.diffuseIntensity.xyz, this.diffuseIntensity.w);
|
|
169
|
+
this.$l.lightDir = pb.vec3();
|
|
170
|
+
this.lightDir = this.directionCutoff.xyz;
|
|
171
|
+
this.$l.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
172
|
+
this.$l.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
173
|
+
this.$l.shadowBound = pb.vec4(0, 0, 1, 1);
|
|
174
|
+
this.$l.linearDepth = nonLinearDepthToLinear(this, this.$builtins.fragCoord.z);
|
|
175
|
+
this.$l.splitDistances = ShaderFramework.getCascadeDistances(this);
|
|
176
|
+
this.$l.comparison = pb.vec4(pb.greaterThan(pb.vec4(this.linearDepth), this.splitDistances));
|
|
177
|
+
this.$l.cascadeFlags = pb.vec4(pb.float(pb.greaterThan(this.shadowCascades, 0)), pb.float(pb.greaterThan(this.shadowCascades, 1)), pb.float(pb.greaterThan(this.shadowCascades, 2)), pb.float(pb.greaterThan(this.shadowCascades, 3)));
|
|
178
|
+
this.$l.split = pb.int(pb.dot(this.comparison, this.cascadeFlags));
|
|
179
|
+
this.$l.shadowVertex = pb.vec4();
|
|
180
|
+
if (Application.instance.device.type === 'webgl') {
|
|
181
|
+
this.$for(pb.int('cascade'), 0, 4, function() {
|
|
182
|
+
this.$if(pb.equal(this.cascade, this.split), function() {
|
|
183
|
+
this.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this, this.cascade);
|
|
184
|
+
this.$break();
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
} else {
|
|
188
|
+
this.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this, this.split);
|
|
189
|
+
}
|
|
190
|
+
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
191
|
+
this.$l.shadow = shadowMapParams.impl.computeShadowCSM(shadowMapParams, this, this.shadowVertex, this.NdotL, this.split);
|
|
192
|
+
this.$l.shadowDistance = ShaderFramework.getShadowCameraParams(scope).w;
|
|
193
|
+
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(ShaderFramework.getCameraPosition(this), ShaderFramework.getWorldPosition(this).xyz)));
|
|
194
|
+
this.$if(pb.greaterThan(this.NdotL, 0), function() {
|
|
195
|
+
this.$l.attenuation = pb.mul(pb.mul(this.lightcolor, this.NdotL), pb.vec3(this.shadow));
|
|
196
|
+
illumLight(this, LIGHT_TYPE_DIRECTIONAL, lm, this.positionRange, this.directionCutoff, this.lightDir, this.attenuation);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
pb.getGlobalScope()[funcNameIllumCascadedShadowLight]();
|
|
200
|
+
}
|
|
201
|
+
function illumOneLight(lm, positionRange, directionCutoff, diffuseIntensity) {
|
|
202
|
+
pb.func(funcNameIllumOneLight, [
|
|
203
|
+
pb.vec4('positionRange'),
|
|
204
|
+
pb.vec4('directionCutoff'),
|
|
205
|
+
pb.vec4('diffuseIntensity')
|
|
206
|
+
], function() {
|
|
207
|
+
this.$l.lightcolor = pb.mul(this.diffuseIntensity.xyz, this.diffuseIntensity.w);
|
|
208
|
+
this.$l.lightDir = pb.vec3();
|
|
209
|
+
this.$l.nl = pb.float();
|
|
210
|
+
this.$l.NdotL = pb.float();
|
|
211
|
+
this.$l.lightType = pb.int();
|
|
212
|
+
this.$if(pb.lessThan(this.positionRange.w, 0), function() {
|
|
213
|
+
this.lightDir = this.directionCutoff.xyz;
|
|
214
|
+
this.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
215
|
+
this.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
216
|
+
this.lightType = LIGHT_TYPE_DIRECTIONAL;
|
|
217
|
+
}).$else(function() {
|
|
218
|
+
this.lightDir = pb.sub(ShaderFramework.getWorldPosition(this).xyz, this.positionRange.xyz);
|
|
219
|
+
this.$if(pb.greaterThan(pb.length(this.lightDir), this.positionRange.w), function() {
|
|
220
|
+
this.$return();
|
|
221
|
+
});
|
|
222
|
+
this.lightDir = pb.normalize(this.lightDir);
|
|
223
|
+
this.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
224
|
+
this.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
225
|
+
this.$if(pb.lessThan(this.directionCutoff.w, 0), function() {
|
|
226
|
+
this.lightType = LIGHT_TYPE_POINT;
|
|
227
|
+
}).$else(function() {
|
|
228
|
+
this.lightType = LIGHT_TYPE_SPOT;
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
this.$if(pb.greaterThan(this.NdotL, 0), function() {
|
|
232
|
+
illumLight(this, this.lightType, lm, this.positionRange, this.directionCutoff, this.lightDir, pb.mul(this.lightcolor, this.NdotL));
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
pb.getGlobalScope()[funcNameIllumOneLight](positionRange, directionCutoff, diffuseIntensity);
|
|
236
|
+
}
|
|
237
|
+
function getClusterIndex(fragCoord) {
|
|
238
|
+
pb.func(funcNameGetClusterIndex, [
|
|
239
|
+
pb.vec3('fragCoord')
|
|
240
|
+
], function() {
|
|
241
|
+
const clusterParams = ShaderFramework.getClusterParams(this);
|
|
242
|
+
const countParams = ShaderFramework.getCountParams(this);
|
|
243
|
+
this.$l.zTile = pb.int(pb.max(pb.add(pb.mul(pb.log2(nonLinearDepthToLinear(this, this.fragCoord.z)), clusterParams.z), clusterParams.w), 0));
|
|
244
|
+
this.$l.f = pb.vec2(this.fragCoord.x, pb.sub(clusterParams.y, pb.add(this.fragCoord.y, 1)));
|
|
245
|
+
this.$l.xyTile = pb.ivec2(pb.div(this.f, pb.div(clusterParams.xy, pb.vec2(countParams.xy))));
|
|
246
|
+
this.$return(pb.ivec3(this.xyTile, this.zTile));
|
|
247
|
+
});
|
|
248
|
+
return pb.getGlobalScope()[funcNameGetClusterIndex](fragCoord);
|
|
249
|
+
}
|
|
250
|
+
function illumUnshadowedLights(lm) {
|
|
251
|
+
pb.func(funcNameIllumUnshadowedLights, [], function() {
|
|
252
|
+
const countParams = ShaderFramework.getCountParams(this);
|
|
253
|
+
this.$l.cluster = getClusterIndex(this.$builtins.fragCoord.xyz);
|
|
254
|
+
this.$l.clusterIndex = pb.add(this.cluster.x, pb.mul(this.cluster.y, countParams.x), pb.mul(this.cluster.z, countParams.x, countParams.y));
|
|
255
|
+
this.$l.texSize = this.global.light.lightIndexTexSize;
|
|
256
|
+
if (pb.getDevice().type === 'webgl') {
|
|
257
|
+
this.$l.texCoordX = pb.div(pb.add(pb.mod(pb.float(this.clusterIndex), pb.float(this.texSize.x)), 0.5), pb.float(this.texSize.x));
|
|
258
|
+
this.$l.texCoordY = pb.div(pb.add(pb.float(pb.div(this.clusterIndex, this.texSize.x)), 0.5), pb.float(this.texSize.y));
|
|
259
|
+
this.$l.samp = pb.textureSample(ShaderFramework.getClusteredLightIndexTexture(this), pb.vec2(this.texCoordX, this.texCoordY));
|
|
260
|
+
} else {
|
|
261
|
+
// this.$l.texSize = pb.ivec2(pb.textureDimensions(ShaderFramework.getClusteredLightIndexTexture(this), 0));
|
|
262
|
+
this.$l.texCoordX = pb.mod(this.clusterIndex, this.texSize.x);
|
|
263
|
+
this.$l.texCoordY = pb.div(this.clusterIndex, this.texSize.x);
|
|
264
|
+
this.$l.samp = pb.textureLoad(ShaderFramework.getClusteredLightIndexTexture(this), pb.ivec2(this.texCoordX, this.texCoordY), 0);
|
|
265
|
+
}
|
|
266
|
+
if (pb.getDevice().type === 'webgl') {
|
|
267
|
+
this.$for(pb.int('i'), 0, 4, function() {
|
|
268
|
+
this.$l.k = this.samp.at(this.i);
|
|
269
|
+
this.$l.lights = pb.int[2]();
|
|
270
|
+
this.$l.lights[0] = pb.int(pb.mod(this.k, 256));
|
|
271
|
+
this.$l.lights[1] = pb.int(pb.div(this.k, 256));
|
|
272
|
+
this.$for(pb.int('k'), 0, 2, function() {
|
|
273
|
+
this.$l.li = this.lights.at(this.k);
|
|
274
|
+
this.$if(pb.greaterThan(this.li, 0), function() {
|
|
275
|
+
this.$for(pb.int('j'), 1, 256, function() {
|
|
276
|
+
this.$if(pb.equal(this.j, this.li), function() {
|
|
277
|
+
this.$l.positionRange = ShaderFramework.getLightPositionAndRange(this, this.j);
|
|
278
|
+
this.$l.directionCutoff = ShaderFramework.getLightDirectionAndCutoff(this, this.j);
|
|
279
|
+
this.$l.diffuseIntensity = ShaderFramework.getLightColorAndIntensity(this, this.j);
|
|
280
|
+
illumOneLight(lm, this.positionRange, this.directionCutoff, this.diffuseIntensity);
|
|
281
|
+
this.$break();
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
} else {
|
|
288
|
+
this.$for(pb.uint('i'), 0, 4, function() {
|
|
289
|
+
this.$for(pb.uint('k'), 0, 4, function() {
|
|
290
|
+
this.$l.c = pb.compAnd(pb.sar(this.samp.at(this.i), pb.mul(this.k, 8)), 0xff);
|
|
291
|
+
this.$if(pb.greaterThan(this.c, 0), function() {
|
|
292
|
+
this.$l.positionRange = ShaderFramework.getLightPositionAndRange(this, this.c);
|
|
293
|
+
this.$l.directionCutoff = ShaderFramework.getLightDirectionAndCutoff(this, this.c);
|
|
294
|
+
this.$l.diffuseIntensity = ShaderFramework.getLightColorAndIntensity(this, this.c);
|
|
295
|
+
illumOneLight(lm, this.positionRange, this.directionCutoff, this.diffuseIntensity);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
pb.getGlobalScope()[funcNameIllumUnshadowedLights]();
|
|
302
|
+
}
|
|
303
|
+
pb.func(funcNameComputeLighting, [], function() {
|
|
304
|
+
const worldPosition = ShaderFramework.getWorldPosition(this);
|
|
305
|
+
const worldNormal = ShaderFramework.getWorldNormal(this);
|
|
306
|
+
const worldTangent = ShaderFramework.getWorldTangent(this);
|
|
307
|
+
const worldBinormal = ShaderFramework.getWorldBinormal(this);
|
|
308
|
+
lm.getSurfaceData(this, env, worldPosition, worldNormal, worldTangent, worldBinormal);
|
|
309
|
+
ShaderFramework.discardIfClipped(this);
|
|
310
|
+
if (lm.supportLighting()) {
|
|
311
|
+
if (env) {
|
|
312
|
+
lm.envBRDF(env, this);
|
|
313
|
+
}
|
|
314
|
+
if (ctx.currentShadowLight) {
|
|
315
|
+
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
316
|
+
if (shadowMapParams.numShadowCascades > 1) {
|
|
317
|
+
illumCascadedShadowLight(lm);
|
|
318
|
+
} else if (shadowMapParams.shadowMap.isTextureCube()) {
|
|
319
|
+
illumPointShadowLight(lm);
|
|
320
|
+
} else {
|
|
321
|
+
illumDirectionalShadowLight(shadowMapParams.lightType, lm);
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
illumUnshadowedLights(lm);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
this.$return(lm.finalComposite(this));
|
|
328
|
+
// this.$l.result = pb.add(this.lightDiffuse, this.lightSpecular);
|
|
329
|
+
// this.$return(pb.vec4(this.result, this.surfaceData.diffuse.a));
|
|
330
|
+
});
|
|
331
|
+
return pb.getGlobalScope()[funcNameComputeLighting]();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export { forwardComputeLighting };
|
|
335
|
+
//# sourceMappingURL=lighting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lighting.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|