@zephyr3d/scene 0.1.2 → 0.3.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/asset/assetmanager.js +83 -34
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/builtin.js +2 -2
- package/dist/asset/loaders/gltf/gltf_loader.js +105 -59
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/hdr/hdr.js +1 -1
- package/dist/blitter/blitter.js +0 -1
- package/dist/blitter/blitter.js.map +1 -1
- package/dist/blitter/depthlimitedgaussion.js +0 -1
- package/dist/blitter/depthlimitedgaussion.js.map +1 -1
- package/dist/blitter/gaussianblur.js +0 -1
- package/dist/blitter/gaussianblur.js.map +1 -1
- package/dist/camera/camera.js +11 -8
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/orbit.js +24 -7
- package/dist/camera/orbit.js.map +1 -1
- package/dist/index.d.ts +3220 -3680
- package/dist/index.js +23 -11
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +47 -57
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/grassmat.js +127 -0
- package/dist/material/grassmat.js.map +1 -0
- package/dist/material/grassmaterial.js +58 -186
- package/dist/material/grassmaterial.js.map +1 -1
- package/dist/material/lambert.js +48 -22
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/lightmodel.js +4 -4
- package/dist/material/material.js +124 -105
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +321 -145
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +32 -99
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/foliage.js +47 -0
- package/dist/material/mixins/foliage.js.map +1 -0
- package/dist/material/mixins/ggxlut.js +213 -0
- package/dist/material/mixins/ggxlut.js.map +1 -0
- package/dist/material/mixins/lightmodel/blinnphong.js +89 -0
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -0
- package/dist/material/mixins/lightmodel/lambert.js +58 -0
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -0
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +132 -0
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +105 -0
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
- package/dist/material/mixins/lit.js +464 -0
- package/dist/material/mixins/lit.js.map +1 -0
- package/dist/material/mixins/pbr/common.js +451 -0
- package/dist/material/mixins/pbr/common.js.map +1 -0
- package/dist/material/mixins/pbr/metallicroughness.js +126 -0
- package/dist/material/mixins/pbr/metallicroughness.js.map +1 -0
- package/dist/material/mixins/pbr/specularglossness.js +104 -0
- package/dist/material/mixins/pbr/specularglossness.js.map +1 -0
- package/dist/material/mixins/texture.js +157 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +16 -11
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/pbrmr.js +65 -0
- package/dist/material/pbrmr.js.map +1 -0
- package/dist/material/pbrsg.js +64 -0
- package/dist/material/pbrsg.js.map +1 -0
- package/dist/material/shader/helper.js +905 -0
- package/dist/material/shader/helper.js.map +1 -0
- package/dist/material/terrainmat.js +357 -0
- package/dist/material/terrainmat.js.map +1 -0
- package/dist/material/terrainmaterial.js +302 -94
- package/dist/material/terrainmaterial.js.map +1 -1
- package/dist/material/unlit.js +12 -9
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/bloom.js +9 -6
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +15 -6
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/posteffect.js +1 -1
- package/dist/posteffect/sao.js +8 -5
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/tonemap.js +2 -2
- package/dist/posteffect/water.js +11 -8
- package/dist/posteffect/water.js.map +1 -1
- package/dist/render/cluster_light.js +6 -5
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/cull_visitor.js +24 -3
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/depthpass.js +46 -0
- package/dist/render/depthpass.js.map +1 -0
- package/dist/render/envlight.js +26 -24
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/fullscreenquad.js +38 -0
- package/dist/render/fullscreenquad.js.map +1 -0
- package/dist/render/lightpass.js +98 -0
- package/dist/render/lightpass.js.map +1 -0
- package/dist/render/primitive.js +31 -0
- package/dist/render/primitive.js.map +1 -1
- package/dist/render/render_queue.js +113 -39
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +200 -0
- package/dist/render/renderer.js.map +1 -0
- package/dist/render/renderpass.js +10 -8
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +3 -4
- package/dist/render/shadowmap_pass.js.map +1 -1
- package/dist/render/sky.js +33 -19
- package/dist/render/sky.js.map +1 -1
- package/dist/scene/batchgroup.js +126 -0
- package/dist/scene/batchgroup.js.map +1 -0
- package/dist/scene/environment.js +9 -6
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +11 -0
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +48 -14
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/octree.js +37 -72
- package/dist/scene/octree.js.map +1 -1
- package/dist/scene/octree_update_visitor.js +5 -1
- package/dist/scene/octree_update_visitor.js.map +1 -1
- package/dist/scene/scene.js +17 -31
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +59 -52
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +4 -14
- package/dist/scene/terrain/grass.js.map +1 -1
- package/dist/scene/terrain/patch.js +3 -3
- package/dist/scene/terrain/terrain.js +4 -9
- package/dist/scene/terrain/terrain.js.map +1 -1
- package/dist/scene/xform.js +61 -36
- package/dist/scene/xform.js.map +1 -1
- package/dist/shaders/framework.js +17 -3
- package/dist/shaders/framework.js.map +1 -1
- package/dist/shaders/misc.js +13 -161
- package/dist/shaders/misc.js.map +1 -1
- package/dist/shaders/noise.js +7 -7
- package/dist/shaders/pbr.js +1 -82
- package/dist/shaders/pbr.js.map +1 -1
- package/dist/shaders/shadow.js +33 -31
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/water.js +3 -9
- package/dist/shaders/water.js.map +1 -1
- package/dist/shadow/esm.js +12 -9
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +15 -15
- package/dist/shadow/pcf_pd.js +15 -15
- package/dist/shadow/shadowmapper.js +35 -21
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +21 -55
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +16 -13
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/shapes/box.js +15 -6
- package/dist/shapes/box.js.map +1 -1
- package/dist/shapes/cylinder.js +1 -4
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/shapes/shape.js +5 -0
- package/dist/shapes/shape.js.map +1 -1
- package/dist/shapes/sphere.js +3 -0
- package/dist/shapes/sphere.js.map +1 -1
- package/dist/shapes/torus.js +2 -2
- package/dist/utility/bounding_volume.js +27 -27
- package/dist/utility/pmrem.js +4 -4
- package/dist/utility/sheenlut.js +196 -0
- package/dist/utility/sheenlut.js.map +1 -0
- package/dist/utility/shprojection.js +0 -1
- package/dist/utility/shprojection.js.map +1 -1
- package/dist/values.js +11 -8
- package/dist/values.js.map +1 -1
- package/package.json +6 -6
package/dist/shaders/misc.js
CHANGED
|
@@ -1,130 +1,5 @@
|
|
|
1
1
|
import { PBPrimitiveType, PBInsideFunctionScope } from '@zephyr3d/device';
|
|
2
|
-
import { ShaderFramework } from './framework.js';
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
* Calculates the TBN matrix
|
|
6
|
-
*
|
|
7
|
-
* @remarks
|
|
8
|
-
* This function computes the tangent frame for normal mapping without world normal
|
|
9
|
-
*
|
|
10
|
-
* @param scope - Current shader scope
|
|
11
|
-
* @param worldPosition - World position of current fragment
|
|
12
|
-
* @param uv - Texture coordinate for normal map
|
|
13
|
-
* @returns The calculated TBN matrix
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
*/ function calculateTBN(scope, worldPosition, uv, doubleSideLighting) {
|
|
17
|
-
const funcName = 'lib_calculateTBN';
|
|
18
|
-
const pb = scope.$builder;
|
|
19
|
-
pb.func(funcName, [
|
|
20
|
-
pb.vec3('posW'),
|
|
21
|
-
pb.vec2('uv')
|
|
22
|
-
], function() {
|
|
23
|
-
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
24
|
-
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
25
|
-
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
26
|
-
this.uv_dx = pb.vec3(1, 0, 0);
|
|
27
|
-
this.uv_dy = pb.vec3(0, 1, 0);
|
|
28
|
-
});
|
|
29
|
-
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(this.posW), this.uv_dy.y), pb.mul(pb.dpdy(this.posW), this.uv_dx.y)), pb.sub(pb.mul(this.uv_dx.x, this.uv_dy.y), pb.mul(this.uv_dx.y, this.uv_dy.x)));
|
|
30
|
-
this.$l.ng = pb.normalize(pb.cross(pb.dpdx(this.posW), pb.dpdy(this.posW)));
|
|
31
|
-
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
32
|
-
this.$l.b = pb.cross(this.ng, this.t);
|
|
33
|
-
if (doubleSideLighting) {
|
|
34
|
-
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
35
|
-
this.t = pb.mul(this.t, -1);
|
|
36
|
-
this.b = pb.mul(this.b, -1);
|
|
37
|
-
this.ng = pb.mul(this.ng, -1);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
this.$return(pb.mat3(this.t, this.b, this.ng));
|
|
41
|
-
});
|
|
42
|
-
return pb.getGlobalScope()[funcName](worldPosition.xyz, uv);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Calculates the TBN matrix
|
|
46
|
-
*
|
|
47
|
-
* @remarks
|
|
48
|
-
* This function computes the tangent frame for normal mapping with world normal
|
|
49
|
-
*
|
|
50
|
-
* @param scope - Current shader scope
|
|
51
|
-
* @param worldPosition - World position of current fragment
|
|
52
|
-
* @param worldNormal - World normal of current fragment
|
|
53
|
-
* @param uv - Texture coordinate for normal map
|
|
54
|
-
* @returns The calculated TBN matrix
|
|
55
|
-
*
|
|
56
|
-
* @public
|
|
57
|
-
*/ function calculateTBNWithNormal(scope, worldPosition, worldNormal, uv, doubleSideLighting) {
|
|
58
|
-
const funcName = 'lib_calculateTBNWithNormal';
|
|
59
|
-
const pb = scope.$builder;
|
|
60
|
-
pb.func(funcName, [
|
|
61
|
-
pb.vec3('posW'),
|
|
62
|
-
pb.vec3('normalW'),
|
|
63
|
-
pb.vec2('uv')
|
|
64
|
-
], function() {
|
|
65
|
-
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
66
|
-
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
67
|
-
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
68
|
-
this.uv_dx = pb.vec3(1, 0, 0);
|
|
69
|
-
this.uv_dy = pb.vec3(0, 1, 0);
|
|
70
|
-
});
|
|
71
|
-
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(this.posW), this.uv_dy.y), pb.mul(pb.dpdy(this.posW), this.uv_dx.y)), pb.sub(pb.mul(this.uv_dx.x, this.uv_dy.y), pb.mul(this.uv_dx.y, this.uv_dy.x)));
|
|
72
|
-
this.$l.ng = pb.normalize(this.normalW);
|
|
73
|
-
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
74
|
-
this.$l.b = pb.cross(this.ng, this.t);
|
|
75
|
-
if (doubleSideLighting) {
|
|
76
|
-
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
77
|
-
this.t = pb.mul(this.t, -1);
|
|
78
|
-
this.b = pb.mul(this.b, -1);
|
|
79
|
-
this.ng = pb.mul(this.ng, -1);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
this.$return(pb.mat3(this.t, this.b, this.ng));
|
|
83
|
-
});
|
|
84
|
-
return pb.getGlobalScope()[funcName](worldPosition, worldNormal, uv);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Calculates the non-linear depth from linear depth
|
|
88
|
-
*
|
|
89
|
-
* @param scope - Current shader scope
|
|
90
|
-
* @param depth - The linear depth
|
|
91
|
-
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
92
|
-
* @returns The calculated non-linear depth
|
|
93
|
-
*
|
|
94
|
-
* @public
|
|
95
|
-
*/ function linearDepthToNonLinear(scope, depth, nearFar) {
|
|
96
|
-
const pb = scope.$builder;
|
|
97
|
-
nearFar = nearFar || ShaderFramework.getCameraParams(scope);
|
|
98
|
-
return pb.div(pb.sub(nearFar.y, pb.div(pb.mul(nearFar.x, nearFar.y), depth)), pb.sub(nearFar.y, nearFar.x));
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Calculates the linear depth from non-linear depth
|
|
102
|
-
*
|
|
103
|
-
* @param scope - Current shader scope
|
|
104
|
-
* @param depth - The non-linear depth
|
|
105
|
-
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
106
|
-
* @returns The calculated linear depth
|
|
107
|
-
*
|
|
108
|
-
* @public
|
|
109
|
-
*/ function nonLinearDepthToLinear(scope, depth, nearFar) {
|
|
110
|
-
const pb = scope.$builder;
|
|
111
|
-
nearFar = nearFar || ShaderFramework.getCameraParams(scope);
|
|
112
|
-
return pb.div(pb.mul(nearFar.x, nearFar.y), pb.mix(nearFar.y, nearFar.x, depth));
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Calculates the normalized linear depth from non-linear depth
|
|
116
|
-
*
|
|
117
|
-
* @param scope - Current shader scope
|
|
118
|
-
* @param depth - The non-linear depth
|
|
119
|
-
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
120
|
-
* @returns The calculated normalized linear depth
|
|
121
|
-
*
|
|
122
|
-
* @public
|
|
123
|
-
*/ function nonLinearDepthToLinearNormalized(scope, depth, nearFar) {
|
|
124
|
-
const pb = scope.$builder;
|
|
125
|
-
nearFar = nearFar || ShaderFramework.getCameraParams(scope);
|
|
126
|
-
return pb.div(nearFar.x, pb.mix(nearFar.y, nearFar.x, depth));
|
|
127
|
-
}
|
|
128
3
|
/**
|
|
129
4
|
* Decodes a float that was encoded into a rgba8unorm
|
|
130
5
|
*
|
|
@@ -141,7 +16,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
141
16
|
if (!scope || !(scope instanceof PBInsideFunctionScope)) {
|
|
142
17
|
throw new Error('decodeFloatFromRGBA() failed: decodeNormalizedFloatFromRGBA() must be called inside a function');
|
|
143
18
|
}
|
|
144
|
-
const funcName = '
|
|
19
|
+
const funcName = 'Z_DecodeFloatFromRGBA';
|
|
145
20
|
pb.func(funcName, [
|
|
146
21
|
pb.vec4('value')
|
|
147
22
|
], function() {
|
|
@@ -173,7 +48,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
173
48
|
* @public
|
|
174
49
|
*/ function encodeFloatToRGBA(scope, value) {
|
|
175
50
|
const pb = scope.$builder;
|
|
176
|
-
const funcName = '
|
|
51
|
+
const funcName = 'Z_EncodeFloatToRGBA';
|
|
177
52
|
pb.func(funcName, [
|
|
178
53
|
pb.float('value')
|
|
179
54
|
], function() {
|
|
@@ -204,8 +79,8 @@ import { ShaderFramework } from './framework.js';
|
|
|
204
79
|
this.pack.x = pb.add(this.pack.x, pb.floor(pb.div(this.expbias, 2.0)));
|
|
205
80
|
this.expbias = pb.sub(this.expbias, pb.mul(this.pack.x, 2.0));
|
|
206
81
|
this.pack.y = pb.add(this.pack.y, pb.mul(pb.floor(this.expbias), 128.0));
|
|
207
|
-
this.pack.x = pb.add(this.pack.x, pb.mul(128.0, pb.float(pb.lessThan(this.value, 0
|
|
208
|
-
this.$return(pb.div(pb.floor(pb.add(this.pack, pb.vec4(.5))), 255.0));
|
|
82
|
+
this.pack.x = pb.add(this.pack.x, pb.mul(128.0, pb.float(pb.lessThan(this.value, 0)))); // Sign
|
|
83
|
+
this.$return(pb.div(pb.floor(pb.add(this.pack, pb.vec4(0.5))), 255.0));
|
|
209
84
|
});
|
|
210
85
|
return pb.getGlobalScope()[funcName](value);
|
|
211
86
|
}
|
|
@@ -225,7 +100,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
225
100
|
if (!scope || !(scope instanceof PBInsideFunctionScope)) {
|
|
226
101
|
throw new Error('decodeNormalizedFloatFromRGBA() failed: decodeNormalizedFloatFromRGBA() must be called inside a function');
|
|
227
102
|
}
|
|
228
|
-
const funcName = '
|
|
103
|
+
const funcName = 'Z_decodeNormalizedFloatFromRGBA';
|
|
229
104
|
pb.func(funcName, [
|
|
230
105
|
pb.vec4('value')
|
|
231
106
|
], function() {
|
|
@@ -244,7 +119,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
244
119
|
* @public
|
|
245
120
|
*/ function encodeNormalizedFloatToRGBA(scope, value) {
|
|
246
121
|
const pb = scope.$builder;
|
|
247
|
-
const funcName = '
|
|
122
|
+
const funcName = 'Z_encodeNormalizedFloatToRGBA';
|
|
248
123
|
pb.func(funcName, [
|
|
249
124
|
pb.float('value')
|
|
250
125
|
], function() {
|
|
@@ -266,7 +141,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
266
141
|
* @public
|
|
267
142
|
*/ function encode2HalfToRGBA(scope, a, b) {
|
|
268
143
|
const pb = scope.$builder;
|
|
269
|
-
const funcName = '
|
|
144
|
+
const funcName = 'Z_encode2HalfToRGBA';
|
|
270
145
|
pb.func(funcName, [
|
|
271
146
|
pb.float('a'),
|
|
272
147
|
pb.float('b')
|
|
@@ -286,7 +161,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
286
161
|
* @public
|
|
287
162
|
*/ function decode2HalfFromRGBA(scope, value) {
|
|
288
163
|
const pb = scope.$builder;
|
|
289
|
-
const funcName = '
|
|
164
|
+
const funcName = 'Z_decode2HalfFromRGBA';
|
|
290
165
|
pb.func(funcName, [
|
|
291
166
|
pb.vec4('value')
|
|
292
167
|
], function() {
|
|
@@ -294,29 +169,6 @@ import { ShaderFramework } from './framework.js';
|
|
|
294
169
|
});
|
|
295
170
|
return pb.getGlobalScope()[funcName](value);
|
|
296
171
|
}
|
|
297
|
-
/**
|
|
298
|
-
* Transform color to sRGB color space if nessesary
|
|
299
|
-
*
|
|
300
|
-
* @param scope - Current shader scope
|
|
301
|
-
* @param outputColor - The color to be transformed
|
|
302
|
-
* @returns The transformed color
|
|
303
|
-
*
|
|
304
|
-
* @public
|
|
305
|
-
*/ function encodeColorOutput(scope, outputColor) {
|
|
306
|
-
const pb = scope.$builder;
|
|
307
|
-
const funcName = 'lib_EncodeColorOutput';
|
|
308
|
-
pb.func(funcName, [
|
|
309
|
-
pb.vec4('outputColor')
|
|
310
|
-
], function() {
|
|
311
|
-
const params = ShaderFramework.getCameraParams(this);
|
|
312
|
-
this.$if(pb.notEqual(params.w, 0), function() {
|
|
313
|
-
this.$return(pb.vec4(linearToGamma(this, this.outputColor.rgb), this.outputColor.w));
|
|
314
|
-
}).$else(function() {
|
|
315
|
-
this.$return(this.outputColor);
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
return pb.getGlobalScope()[funcName](outputColor);
|
|
319
|
-
}
|
|
320
172
|
/**
|
|
321
173
|
* Encodes a color value into RGBM format
|
|
322
174
|
*
|
|
@@ -328,7 +180,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
328
180
|
* @public
|
|
329
181
|
*/ function encodeRGBM(scope, rgb, maxRange) {
|
|
330
182
|
const pb = scope.$builder;
|
|
331
|
-
const funcName = '
|
|
183
|
+
const funcName = 'Z_encodeRGBM';
|
|
332
184
|
pb.func(funcName, [
|
|
333
185
|
pb.vec3('rgb'),
|
|
334
186
|
pb.float('range')
|
|
@@ -351,7 +203,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
351
203
|
* @public
|
|
352
204
|
*/ function decodeRGBM(scope, rgbm, maxRange) {
|
|
353
205
|
const pb = scope.$builder;
|
|
354
|
-
const funcName = '
|
|
206
|
+
const funcName = 'Z_decodeRGBM';
|
|
355
207
|
pb.func(funcName, [
|
|
356
208
|
pb.vec4('rgbm'),
|
|
357
209
|
pb.float('range')
|
|
@@ -370,7 +222,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
370
222
|
* @public
|
|
371
223
|
*/ function gammaToLinear(scope, color) {
|
|
372
224
|
const pb = scope.$builder;
|
|
373
|
-
const funcName = '
|
|
225
|
+
const funcName = 'Z_gammaToLinear';
|
|
374
226
|
pb.func(funcName, [
|
|
375
227
|
pb.vec3('color')
|
|
376
228
|
], function() {
|
|
@@ -390,7 +242,7 @@ import { ShaderFramework } from './framework.js';
|
|
|
390
242
|
* @public
|
|
391
243
|
*/ function linearToGamma(scope, color) {
|
|
392
244
|
const pb = scope.$builder;
|
|
393
|
-
const funcName = '
|
|
245
|
+
const funcName = 'Z_linearToGamma';
|
|
394
246
|
pb.func(funcName, [
|
|
395
247
|
pb.vec3('color')
|
|
396
248
|
], function() {
|
|
@@ -401,5 +253,5 @@ import { ShaderFramework } from './framework.js';
|
|
|
401
253
|
return pb.getGlobalScope()[funcName](color);
|
|
402
254
|
}
|
|
403
255
|
|
|
404
|
-
export {
|
|
256
|
+
export { decode2HalfFromRGBA, decodeFloatFromRGBA, decodeNormalizedFloatFromRGBA, decodeRGBM, encode2HalfToRGBA, encodeFloatToRGBA, encodeNormalizedFloatToRGBA, encodeRGBM, gammaToLinear, linearToGamma };
|
|
405
257
|
//# sourceMappingURL=misc.js.map
|
package/dist/shaders/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"misc.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/shaders/noise.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* @public
|
|
9
9
|
*/ function noisef(scope, p) {
|
|
10
10
|
const pb = scope.$builder;
|
|
11
|
-
const funcNameHash = '
|
|
12
|
-
const funcNameNoise = '
|
|
11
|
+
const funcNameHash = 'Z_hashf';
|
|
12
|
+
const funcNameNoise = 'Z_noisef';
|
|
13
13
|
pb.func(funcNameHash, [
|
|
14
14
|
pb.vec2('p')
|
|
15
15
|
], function() {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
* @public
|
|
43
43
|
*/ function worleyNoise(scope, uv, freq) {
|
|
44
44
|
const pb = scope.$builder;
|
|
45
|
-
const funcNameHash = '
|
|
45
|
+
const funcNameHash = 'Z_worleyHash';
|
|
46
46
|
// https://www.shadertoy.com/view/4sc3z2
|
|
47
47
|
pb.func(funcNameHash, [
|
|
48
48
|
pb.vec3('p')
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
this.$return(pb.sub(pb.mul(pb.fract(pb.vec3(pb.mul(pb.add(this.p3.x, this.p3.y), this.p3.z), pb.mul(pb.add(this.p3.x, this.p3.z), this.p3.y), pb.mul(pb.add(this.p3.y, this.p3.z), this.p3.x))), 2), 1));
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
|
-
const funcNameNoise = '
|
|
57
|
+
const funcNameNoise = 'Z_worleyNoise';
|
|
58
58
|
pb.func(funcNameNoise, [
|
|
59
59
|
pb.vec3('uv'),
|
|
60
60
|
pb.float('freq')
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
* @public
|
|
91
91
|
*/ function worleyFBM(scope, p, freq) {
|
|
92
92
|
const pb = scope.$builder;
|
|
93
|
-
const funcName = '
|
|
93
|
+
const funcName = 'Z_worleyFBM';
|
|
94
94
|
pb.func(funcName, [
|
|
95
95
|
pb.vec3('p'),
|
|
96
96
|
pb.float('freq')
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
* @public
|
|
114
114
|
*/ function noise3D(scope, p) {
|
|
115
115
|
const pb = scope.$builder;
|
|
116
|
-
const funcName = '
|
|
116
|
+
const funcName = 'Z_noise3d';
|
|
117
117
|
pb.func(funcName, [
|
|
118
118
|
pb.vec3('p')
|
|
119
119
|
], function() {
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
* @public
|
|
134
134
|
*/ function smoothNoise3D(scope, p) {
|
|
135
135
|
const pb = scope.$builder;
|
|
136
|
-
const funcName = '
|
|
136
|
+
const funcName = 'Z_smoothNoise3D';
|
|
137
137
|
pb.func(funcName, [
|
|
138
138
|
pb.vec3('p')
|
|
139
139
|
], function() {
|
package/dist/shaders/pbr.js
CHANGED
|
@@ -46,87 +46,6 @@
|
|
|
46
46
|
});
|
|
47
47
|
return pb.getGlobalScope()[funcName](NdotV, NdotL, alphaRoughness);
|
|
48
48
|
}
|
|
49
|
-
/** @internal */ function D_Charlie(scope, NdotH, sheenRoughness) {
|
|
50
|
-
const funcNameDCharlie = 'lib_DCharlie';
|
|
51
|
-
const pb = scope.$builder;
|
|
52
|
-
pb.func(funcNameDCharlie, [
|
|
53
|
-
pb.float('NdotH'),
|
|
54
|
-
pb.float('sheenRoughness')
|
|
55
|
-
], function() {
|
|
56
|
-
this.$l.alphaG = pb.mul(this.sheenRoughness, this.sheenRoughness);
|
|
57
|
-
this.$l.invR = pb.div(1, this.alphaG);
|
|
58
|
-
this.$l.cos2h = pb.mul(this.NdotH, this.NdotH);
|
|
59
|
-
this.$l.sin2h = pb.max(pb.sub(1, this.cos2h), 0.0078125);
|
|
60
|
-
this.$return(pb.div(pb.mul(pb.add(this.invR, 2), pb.pow(this.sin2h, pb.mul(this.invR, 0.5))), 2 * Math.PI));
|
|
61
|
-
});
|
|
62
|
-
return pb.getGlobalScope()[funcNameDCharlie](NdotH, sheenRoughness);
|
|
63
|
-
}
|
|
64
|
-
/** @internal */ function V_Ashikhmin(scope, NdotL, NdotV) {
|
|
65
|
-
const funcNameVAshikhmin = 'lib_VAshikhmin';
|
|
66
|
-
const pb = scope.$builder;
|
|
67
|
-
pb.func(funcNameVAshikhmin, [
|
|
68
|
-
pb.float('NdotL'),
|
|
69
|
-
pb.float('NdotV')
|
|
70
|
-
], function() {
|
|
71
|
-
this.$return(pb.clamp(pb.div(1, pb.mul(pb.sub(pb.add(this.NdotL, this.NdotV), pb.mul(this.NdotL, this.NdotV)), 4)), 0, 1));
|
|
72
|
-
});
|
|
73
|
-
return pb.getGlobalScope()[funcNameVAshikhmin](NdotL, NdotV);
|
|
74
|
-
}
|
|
75
|
-
/** @internal */ function directClearcoatLighting(scope, NdotV, NdotH, NdotL, F, clearcoatRoughness) {
|
|
76
|
-
const pb = scope.$builder;
|
|
77
|
-
const funcName = 'pbrDirectClearcoatLighting';
|
|
78
|
-
pb.func(funcName, [
|
|
79
|
-
pb.float('NdotV'),
|
|
80
|
-
pb.float('NdotH'),
|
|
81
|
-
pb.float('NdotL'),
|
|
82
|
-
pb.vec3('F'),
|
|
83
|
-
pb.float('clearcoatRoughness')
|
|
84
|
-
], function() {
|
|
85
|
-
this.$l.ccRoughness = pb.mul(this.clearcoatRoughness, this.clearcoatRoughness);
|
|
86
|
-
this.$l.ccD = distributionGGX(this, this.NdotH, this.ccRoughness);
|
|
87
|
-
this.$l.ccV = visGGX(this, this.NdotV, this.NdotL, this.ccRoughness);
|
|
88
|
-
this.$return(pb.mul(this.ccD, this.ccV, this.F));
|
|
89
|
-
});
|
|
90
|
-
return pb.getGlobalScope()[funcName](NdotV, NdotH, NdotL, F, clearcoatRoughness);
|
|
91
|
-
}
|
|
92
|
-
/** @internal */ function directSheenLighting(scope, NdotV, NdotL, NdotH, sheenColor, sheenRoughness) {
|
|
93
|
-
const pb = scope.$builder;
|
|
94
|
-
const funcName = 'pbrDirectSheenLighting';
|
|
95
|
-
pb.func(funcName, [
|
|
96
|
-
pb.float('NdotV'),
|
|
97
|
-
pb.float('NdotL'),
|
|
98
|
-
pb.float('NdotH'),
|
|
99
|
-
pb.vec3('sheenColor'),
|
|
100
|
-
pb.float('sheenRoughness')
|
|
101
|
-
], function() {
|
|
102
|
-
this.$l.D = D_Charlie(this, this.NdotH, this.sheenRoughness);
|
|
103
|
-
this.$l.V = V_Ashikhmin(this, this.NdotL, this.NdotV);
|
|
104
|
-
this.$return(pb.mul(this.sheenColor, this.D, this.V));
|
|
105
|
-
});
|
|
106
|
-
return pb.getGlobalScope()[funcName](NdotV, NdotL, NdotH, sheenColor, sheenRoughness);
|
|
107
|
-
}
|
|
108
|
-
/** @internal */ function directLighting(scope, diffuse, NdotV, NdotH, NdotL, F, roughness, specularWeight, outSpecular, outDiffuse) {
|
|
109
|
-
const pb = scope.$builder;
|
|
110
|
-
const funcName = 'pbrDirectLighting';
|
|
111
|
-
pb.func(funcName, [
|
|
112
|
-
pb.vec3('diffuse'),
|
|
113
|
-
pb.float('NdotV'),
|
|
114
|
-
pb.float('NdotH'),
|
|
115
|
-
pb.float('NdotL'),
|
|
116
|
-
pb.vec3('F'),
|
|
117
|
-
pb.float('roughness'),
|
|
118
|
-
pb.float('specularWeight'),
|
|
119
|
-
pb.vec3('outSpecular').out(),
|
|
120
|
-
pb.vec3('outDiffuse').out()
|
|
121
|
-
], function() {
|
|
122
|
-
this.$l.alphaRoughness = pb.mul(this.roughness, this.roughness);
|
|
123
|
-
this.$l.D = distributionGGX(this, this.NdotH, this.alphaRoughness);
|
|
124
|
-
this.$l.V = visGGX(this, this.NdotV, this.NdotL, this.alphaRoughness);
|
|
125
|
-
this.outSpecular = pb.mul(this.D, this.V, this.F, this.specularWeight);
|
|
126
|
-
this.outDiffuse = pb.mul(pb.sub(pb.vec3(1), pb.mul(this.F, this.specularWeight)), pb.div(this.diffuse, Math.PI));
|
|
127
|
-
});
|
|
128
|
-
pb.getGlobalScope()[funcName](diffuse, NdotV, NdotH, NdotL, F, roughness, specularWeight, outSpecular, outDiffuse);
|
|
129
|
-
}
|
|
130
49
|
|
|
131
|
-
export {
|
|
50
|
+
export { distributionGGX, fresnelSchlick, visGGX };
|
|
132
51
|
//# sourceMappingURL=pbr.js.map
|
package/dist/shaders/pbr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pbr.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/shaders/shadow.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { hasDepthChannel } from '@zephyr3d/device';
|
|
2
2
|
import { Application } from '../app.js';
|
|
3
3
|
import { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { encodeNormalizedFloatToRGBA, decode2HalfFromRGBA, decodeNormalizedFloatFromRGBA } from './misc.js';
|
|
5
|
+
import { ShaderHelper } from '../material/shader/helper.js';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
8
|
const PCF_KERNEL_3x3 = [
|
|
@@ -303,34 +303,36 @@ import { encodeNormalizedFloatToRGBA, decode2HalfFromRGBA, decodeNormalizedFloat
|
|
|
303
303
|
]
|
|
304
304
|
];
|
|
305
305
|
function getShadowMapTexelSize(scope) {
|
|
306
|
-
return scope.$builder.div(1,
|
|
306
|
+
return scope.$builder.div(1, ShaderHelper.getShadowCameraParams(scope).z);
|
|
307
307
|
}
|
|
308
308
|
function getShadowMapSize(scope) {
|
|
309
|
-
return
|
|
309
|
+
return ShaderHelper.getShadowCameraParams(scope).z;
|
|
310
310
|
}
|
|
311
|
-
/** @internal */ function computeShadowMapDepth(scope, targetFormat) {
|
|
312
|
-
const funcNameComputeShadowMapDepth = '
|
|
311
|
+
/** @internal */ function computeShadowMapDepth(scope, worldPos, targetFormat) {
|
|
312
|
+
const funcNameComputeShadowMapDepth = 'Z_computeShadowMapDepth';
|
|
313
313
|
const pb = scope.$builder;
|
|
314
|
-
pb.func(funcNameComputeShadowMapDepth, [
|
|
314
|
+
pb.func(funcNameComputeShadowMapDepth, [
|
|
315
|
+
pb.vec3('worldPos')
|
|
316
|
+
], function() {
|
|
315
317
|
if (hasDepthChannel(targetFormat)) {
|
|
316
318
|
// use native shadowmap
|
|
317
319
|
this.$return(pb.vec4(pb.emulateDepthClamp ? pb.clamp(scope.$inputs.clamppedDepth, 0, 1) : scope.$builtins.fragCoord.z, 0, 0, 1));
|
|
318
320
|
} else {
|
|
319
321
|
this.$l.depth = pb.float();
|
|
320
|
-
this.$l.lightType =
|
|
322
|
+
this.$l.lightType = ShaderHelper.getLightTypeForShadow(this);
|
|
321
323
|
this.$if(pb.equal(this.lightType, LIGHT_TYPE_DIRECTIONAL), function() {
|
|
322
324
|
this.depth = pb.emulateDepthClamp ? pb.clamp(this.$inputs.clamppedDepth, 0, 1) : this.$builtins.fragCoord.z;
|
|
323
325
|
}).$elseif(pb.equal(this.lightType, LIGHT_TYPE_POINT), function() {
|
|
324
|
-
this.$l.lightSpacePos = pb.mul(
|
|
325
|
-
this.depth = pb.clamp(pb.div(pb.length(this.lightSpacePos.xyz),
|
|
326
|
+
this.$l.lightSpacePos = pb.mul(ShaderHelper.getLightViewMatrixForShadow(this), pb.vec4(this.worldPos, 1));
|
|
327
|
+
this.depth = pb.clamp(pb.div(pb.length(this.lightSpacePos.xyz), ShaderHelper.getLightPositionAndRangeForShadow(this).w), 0, 1);
|
|
326
328
|
}).$else(function() {
|
|
327
|
-
this.$l.lightSpacePos = pb.mul(
|
|
328
|
-
this.depth = pb.clamp(pb.div(pb.neg(this.lightSpacePos.z),
|
|
329
|
+
this.$l.lightSpacePos = pb.mul(ShaderHelper.getLightViewMatrixForShadow(this), pb.vec4(this.worldPos, 1));
|
|
330
|
+
this.depth = pb.clamp(pb.div(pb.neg(this.lightSpacePos.z), ShaderHelper.getLightPositionAndRangeForShadow(this).w), 0, 1);
|
|
329
331
|
});
|
|
330
332
|
this.$return(targetFormat === 'rgba8unorm' ? encodeNormalizedFloatToRGBA(this, this.depth) : pb.vec4(this.depth, 0, 0, 1));
|
|
331
333
|
}
|
|
332
334
|
});
|
|
333
|
-
return pb.getGlobalScope()[funcNameComputeShadowMapDepth]();
|
|
335
|
+
return pb.getGlobalScope()[funcNameComputeShadowMapDepth](worldPos);
|
|
334
336
|
}
|
|
335
337
|
/** @internal */ function computeReceiverPlaneDepthBias(scope, texCoord) {
|
|
336
338
|
const funcNameComputeReceiverPlaneDepthBias = 'lib_computeReceiverPlaneDepthBias';
|
|
@@ -374,7 +376,7 @@ function getRandomRotationMatrix(scope, fragCoord) {
|
|
|
374
376
|
return pb.getGlobalScope()[funcNameGetRandomRotationMatrix](fragCoord);
|
|
375
377
|
}
|
|
376
378
|
function getPoissonDiscSampleRadius(scope) {
|
|
377
|
-
return
|
|
379
|
+
return ShaderHelper.getDepthBiasValues(scope).z;
|
|
378
380
|
}
|
|
379
381
|
function sampleShadowMapPCF(scope, shadowMapFormat, pos, offset, depth, cascade) {
|
|
380
382
|
const funcName = cascade ? 'lib_sampleShadowMapCascadePCF' : 'lib_sampleShadowMapPCF';
|
|
@@ -391,9 +393,9 @@ function sampleShadowMapPCF(scope, shadowMapFormat, pos, offset, depth, cascade)
|
|
|
391
393
|
const sampleDepth = this.z;
|
|
392
394
|
const uv = pb.add(this.coords, this.offset);
|
|
393
395
|
if (nativeShadowMap) {
|
|
394
|
-
this.$return(cascade && Application.instance.device.type !== 'webgl' ? pb.textureArraySampleCompareLevel(this
|
|
396
|
+
this.$return(cascade && Application.instance.device.type !== 'webgl' ? pb.textureArraySampleCompareLevel(ShaderHelper.getShadowMap(this), uv, this.cascade, sampleDepth) : pb.textureSampleCompareLevel(ShaderHelper.getShadowMap(this), uv, sampleDepth));
|
|
395
397
|
} else {
|
|
396
|
-
this.$l.shadowTex = cascade && Application.instance.device.type !== 'webgl' ? pb.textureArraySampleLevel(this
|
|
398
|
+
this.$l.shadowTex = cascade && Application.instance.device.type !== 'webgl' ? pb.textureArraySampleLevel(ShaderHelper.getShadowMap(this), uv, this.cascade, 0) : pb.textureSampleLevel(ShaderHelper.getShadowMap(this), uv, 0);
|
|
397
399
|
if (shadowMapFormat === 'rgba8unorm') {
|
|
398
400
|
this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
|
|
399
401
|
}
|
|
@@ -417,9 +419,9 @@ function sampleShadowMap(scope, lightType, shadowMapFormat, pos, depth, cascade)
|
|
|
417
419
|
], function() {
|
|
418
420
|
if (lightType === LIGHT_TYPE_POINT) {
|
|
419
421
|
if (nativeShadowMap) {
|
|
420
|
-
this.$return(pb.clamp(pb.textureSampleCompareLevel(this
|
|
422
|
+
this.$return(pb.clamp(pb.textureSampleCompareLevel(ShaderHelper.getShadowMap(this), this.coords, this.z), 0, 1));
|
|
421
423
|
} else {
|
|
422
|
-
this.$l.shadowTex = pb.textureSampleLevel(this
|
|
424
|
+
this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.coords, 0);
|
|
423
425
|
if (shadowMapFormat === 'rgba8unorm') {
|
|
424
426
|
this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
|
|
425
427
|
}
|
|
@@ -427,9 +429,9 @@ function sampleShadowMap(scope, lightType, shadowMapFormat, pos, depth, cascade)
|
|
|
427
429
|
}
|
|
428
430
|
} else {
|
|
429
431
|
if (nativeShadowMap) {
|
|
430
|
-
this.$return(cascade && Application.instance.device.type !== 'webgl' ? pb.textureArraySampleCompareLevel(this
|
|
432
|
+
this.$return(cascade && Application.instance.device.type !== 'webgl' ? pb.textureArraySampleCompareLevel(ShaderHelper.getShadowMap(this), this.coords, this.cascade, this.z) : pb.textureSampleCompareLevel(ShaderHelper.getShadowMap(this), this.coords, this.z));
|
|
431
433
|
} else {
|
|
432
|
-
this.$l.shadowTex = cascade && Application.instance.device.type !== 'webgl' ? pb.textureArraySampleLevel(this
|
|
434
|
+
this.$l.shadowTex = cascade && Application.instance.device.type !== 'webgl' ? pb.textureArraySampleLevel(ShaderHelper.getShadowMap(this), this.coords, this.cascade, 0) : pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.coords, 0);
|
|
433
435
|
if (shadowMapFormat === 'rgba8unorm') {
|
|
434
436
|
this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
|
|
435
437
|
}
|
|
@@ -451,7 +453,7 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
451
453
|
this.$if(pb.notEqual(this.test, 1), function() {
|
|
452
454
|
this.$l.d = pb.sub(this.distance, this.occluder.x);
|
|
453
455
|
this.$l.variance = pb.max(pb.mul(this.occluder.y, this.occluder.y), 0);
|
|
454
|
-
const darkness =
|
|
456
|
+
const darkness = ShaderHelper.getDepthBiasValues(this).z;
|
|
455
457
|
this.shadow = pb.div(this.variance, pb.add(this.variance, pb.mul(this.d, this.d)));
|
|
456
458
|
this.shadow = pb.clamp(pb.div(pb.sub(this.shadow, darkness), pb.sub(1, darkness)), 0, 1);
|
|
457
459
|
});
|
|
@@ -469,13 +471,13 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
469
471
|
] : []
|
|
470
472
|
], function() {
|
|
471
473
|
if (lightType === LIGHT_TYPE_POINT) {
|
|
472
|
-
this.$l.shadowTex = pb.textureSampleLevel(this
|
|
474
|
+
this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.texCoord.xyz, 0);
|
|
473
475
|
this.$return(chebyshevUpperBound(this, this.texCoord.w, shadowMapFormat === 'rgba8unorm' ? decode2HalfFromRGBA(this, this.shadowTex) : this.shadowTex.rg));
|
|
474
476
|
} else {
|
|
475
477
|
if (Application.instance.device.type !== 'webgl' && cascade) {
|
|
476
|
-
this.$l.shadowTex = pb.textureArraySampleLevel(this
|
|
478
|
+
this.$l.shadowTex = pb.textureArraySampleLevel(ShaderHelper.getShadowMap(this), this.texCoord.xy, this.cascade, 0);
|
|
477
479
|
} else {
|
|
478
|
-
this.$l.shadowTex = pb.textureSampleLevel(this
|
|
480
|
+
this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.texCoord.xy, 0);
|
|
479
481
|
}
|
|
480
482
|
this.$return(chebyshevUpperBound(this, this.texCoord.z, shadowMapFormat === 'rgba8unorm' ? decode2HalfFromRGBA(this, this.shadowTex) : this.shadowTex.rg));
|
|
481
483
|
}
|
|
@@ -494,28 +496,28 @@ function chebyshevUpperBound(scope, distance, occluder) {
|
|
|
494
496
|
] : []
|
|
495
497
|
], function() {
|
|
496
498
|
if (lightType === LIGHT_TYPE_POINT) {
|
|
497
|
-
this.$l.depth = pb.div(pb.length(this.shadowVertex.xyz),
|
|
498
|
-
this.$l.shadowTex = pb.textureSampleLevel(this
|
|
499
|
+
this.$l.depth = pb.div(pb.length(this.shadowVertex.xyz), ShaderHelper.getLightPositionAndRangeForShadow(this).w);
|
|
500
|
+
this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.shadowVertex.xyz, 0);
|
|
499
501
|
if (shadowMapFormat === 'rgba8unorm') {
|
|
500
502
|
this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
|
|
501
503
|
}
|
|
502
504
|
} else {
|
|
503
505
|
if (cascade && Application.instance.device.type !== 'webgl') {
|
|
504
|
-
this.$l.shadowTex = pb.textureArraySampleLevel(this
|
|
506
|
+
this.$l.shadowTex = pb.textureArraySampleLevel(ShaderHelper.getShadowMap(this), this.shadowVertex.xy, this.cascade, 0);
|
|
505
507
|
} else {
|
|
506
|
-
this.$l.shadowTex = pb.textureSampleLevel(this
|
|
508
|
+
this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.shadowVertex.xy, 0);
|
|
507
509
|
}
|
|
508
510
|
if (shadowMapFormat === 'rgba8unorm') {
|
|
509
511
|
this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
|
|
510
512
|
}
|
|
511
513
|
if (lightType === LIGHT_TYPE_SPOT) {
|
|
512
|
-
this.$l.nearFar =
|
|
513
|
-
this.$l.depth = nonLinearDepthToLinearNormalized(this, this.shadowVertex.z, this.nearFar);
|
|
514
|
+
this.$l.nearFar = ShaderHelper.getShadowCameraParams(this).xy;
|
|
515
|
+
this.$l.depth = ShaderHelper.nonLinearDepthToLinearNormalized(this, this.shadowVertex.z, this.nearFar);
|
|
514
516
|
} else {
|
|
515
517
|
this.$l.depth = this.shadowVertex.z;
|
|
516
518
|
}
|
|
517
519
|
}
|
|
518
|
-
const depthScale =
|
|
520
|
+
const depthScale = ShaderHelper.getDepthBiasValues(this).z;
|
|
519
521
|
this.$return(pb.clamp(pb.exp(pb.min(87, pb.mul(depthScale, pb.sub(this.shadowTex.x, this.depth)))), 0, 1));
|
|
520
522
|
});
|
|
521
523
|
return pb.getGlobalScope()[funcNameFilterShadowESM](shadowVertex, ...cascade ? [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadow.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shadow.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/shaders/water.js
CHANGED
|
@@ -31,15 +31,9 @@ import { Application } from '../app.js';
|
|
|
31
31
|
this.$outputs.uv0 = pb.div(this.xz, this.sizes.x);
|
|
32
32
|
this.$outputs.uv1 = pb.div(this.xz, this.sizes.y);
|
|
33
33
|
this.$outputs.uv2 = pb.div(this.xz, this.sizes.z);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.$l.c = pb.mul(pb.textureSample(this.dx_hy_dz_dxdz2, this.$outputs.uv2).rgb, pb.vec3(this.croppinesses.z, 1, this.croppinesses.z));
|
|
38
|
-
} else {
|
|
39
|
-
this.$l.a = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz0, this.$outputs.uv0, 0).rgb, pb.vec3(this.croppinesses.x, 1, this.croppinesses.x));
|
|
40
|
-
this.$l.b = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz1, this.$outputs.uv1, 0).rgb, pb.vec3(this.croppinesses.y, 1, this.croppinesses.y));
|
|
41
|
-
this.$l.c = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz2, this.$outputs.uv2, 0).rgb, pb.vec3(this.croppinesses.z, 1, this.croppinesses.z));
|
|
42
|
-
}
|
|
34
|
+
this.$l.a = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz0, this.$outputs.uv0, 0).rgb, pb.vec3(this.croppinesses.x, 1, this.croppinesses.x));
|
|
35
|
+
this.$l.b = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz1, this.$outputs.uv1, 0).rgb, pb.vec3(this.croppinesses.y, 1, this.croppinesses.y));
|
|
36
|
+
this.$l.c = pb.mul(pb.textureSampleLevel(this.dx_hy_dz_dxdz2, this.$outputs.uv2, 0).rgb, pb.vec3(this.croppinesses.z, 1, this.croppinesses.z));
|
|
43
37
|
this.$l.displacement = pb.add(this.a, this.b, this.c);
|
|
44
38
|
this.$outputs.outPos = pb.add(pb.vec3(this.xz.x, this.level, this.xz.y), this.displacement);
|
|
45
39
|
this.$outputs.outXZ = this.xz;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"water.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"water.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|