@zephyr3d/scene 0.3.1 → 0.5.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 +25 -117
- package/dist/animation/animation.js.map +1 -1
- package/dist/animation/animationset.js +164 -24
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/animationtrack.js +6 -18
- package/dist/animation/animationtrack.js.map +1 -1
- package/dist/animation/eulerrotationtrack.js +16 -6
- package/dist/animation/eulerrotationtrack.js.map +1 -1
- package/dist/animation/morphtarget.js +104 -0
- package/dist/animation/morphtarget.js.map +1 -0
- package/dist/animation/morphtrack.js +68 -0
- package/dist/animation/morphtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +15 -7
- package/dist/animation/rotationtrack.js.map +1 -1
- package/dist/animation/scaletrack.js +15 -7
- package/dist/animation/scaletrack.js.map +1 -1
- package/dist/animation/skeleton.js +101 -1
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/translationtrack.js +15 -7
- package/dist/animation/translationtrack.js.map +1 -1
- package/dist/animation/usertrack.js +2 -2
- package/dist/app.js +4 -26
- package/dist/app.js.map +1 -1
- package/dist/asset/assetmanager.js +58 -107
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/loaders/dds/dds.js +77 -3
- package/dist/asset/loaders/dds/dds.js.map +1 -1
- package/dist/asset/loaders/dds/dds_loader.js +1 -1
- package/dist/asset/loaders/gltf/gltf_loader.js +284 -45
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/image/tga_Loader.js +1 -1
- package/dist/asset/model.js +13 -0
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/blitter.js +2 -2
- package/dist/camera/camera.js +83 -5
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +5212 -4785
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +9 -4
- 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 +15 -0
- package/dist/material/grassmaterial.js.map +1 -1
- package/dist/material/lambert.js +22 -17
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/lightmodel.js +7 -6
- package/dist/material/lightmodel.js.map +1 -1
- package/dist/material/lit.js +99 -5
- package/dist/material/lit.js.map +1 -1
- package/dist/material/material.js +88 -347
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +122 -102
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +11 -3
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +3 -3
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +3 -3
- package/dist/material/mixins/lit.js +2 -2
- package/dist/material/mixins/pbr/common.js +433 -10
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/pbrmr.js +17 -6
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +16 -9
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +186 -117
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/terrainlightmodel.js +3 -1
- package/dist/material/terrainlightmodel.js.map +1 -1
- package/dist/material/terrainmat.js +357 -0
- package/dist/material/terrainmat.js.map +1 -0
- package/dist/material/terrainmaterial.js +16 -0
- package/dist/material/terrainmaterial.js.map +1 -1
- package/dist/material/unlit.js +8 -4
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/bloom.js +34 -45
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +11 -41
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/fxaa.js +1 -2
- package/dist/posteffect/fxaa.js.map +1 -1
- package/dist/posteffect/grayscale.js +1 -2
- package/dist/posteffect/grayscale.js.map +1 -1
- package/dist/posteffect/posteffect.js +0 -74
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +13 -29
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/tonemap.js +1 -2
- package/dist/posteffect/tonemap.js.map +1 -1
- package/dist/posteffect/water.js +20 -18
- package/dist/posteffect/water.js.map +1 -1
- package/dist/render/abuffer_oit.js +352 -0
- package/dist/render/abuffer_oit.js.map +1 -0
- package/dist/render/cull_visitor.js +3 -3
- package/dist/render/depth_pass.js +3 -2
- package/dist/render/depth_pass.js.map +1 -1
- package/dist/render/depthpass.js +16 -19
- package/dist/render/depthpass.js.map +1 -1
- package/dist/render/drawable_mixin.js +152 -0
- package/dist/render/drawable_mixin.js.map +1 -0
- package/dist/render/envlight.js +165 -31
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/forward.js +3 -6
- package/dist/render/forward.js.map +1 -1
- package/dist/render/forward_pass.js +6 -5
- package/dist/render/forward_pass.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +58 -0
- package/dist/render/globalbindgroup_allocator.js.map +1 -0
- package/dist/render/lightpass.js +83 -49
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/objectcolorpass.js +50 -0
- package/dist/render/objectcolorpass.js.map +1 -0
- package/dist/render/objectpool.js +295 -0
- package/dist/render/objectpool.js.map +1 -0
- package/dist/render/oit.js +16 -0
- package/dist/render/oit.js.map +1 -0
- package/dist/render/render_queue.js +294 -107
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderbundle_wrapper.js +20 -0
- package/dist/render/renderbundle_wrapper.js.map +1 -0
- package/dist/render/renderer.js +108 -28
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/renderpass.js +96 -34
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +18 -37
- package/dist/render/shadowmap_pass.js.map +1 -1
- package/dist/render/sky.js +2 -2
- package/dist/render/watermesh.js +140 -48
- package/dist/render/watermesh.js.map +1 -1
- package/dist/render/weightedblended_oit.js +171 -0
- package/dist/render/weightedblended_oit.js.map +1 -0
- package/dist/scene/batchgroup.js +8 -35
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +24 -4
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +1 -10
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +42 -32
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/scene.js +7 -37
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +6 -2
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +26 -11
- package/dist/scene/terrain/grass.js.map +1 -1
- package/dist/scene/terrain/patch.js +27 -15
- package/dist/scene/terrain/patch.js.map +1 -1
- package/dist/scene/terrain/quadtree.js +3 -3
- package/dist/scene/terrain/terrain.js +0 -8
- package/dist/scene/terrain/terrain.js.map +1 -1
- package/dist/shaders/lighting.js +14 -10
- package/dist/shaders/lighting.js.map +1 -1
- package/dist/shaders/water.js +4 -4
- package/dist/shadow/esm.js +4 -23
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/shadowmapper.js +45 -21
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +4 -25
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/draco/decoder.js +116 -0
- package/dist/utility/draco/decoder.js.map +1 -0
- package/dist/utility/sheenlut.js +196 -0
- package/dist/utility/sheenlut.js.map +1 -0
- package/dist/values.js +18 -1
- package/dist/values.js.map +1 -1
- package/package.json +7 -6
- package/dist/utility/noisetexture.js +0 -66
- package/dist/utility/noisetexture.js.map +0 -1
- package/dist/utility/textures/gradientnoise.js +0 -66
- package/dist/utility/textures/gradientnoise.js.map +0 -1
- package/dist/utility/textures/randomnoise.js +0 -41
- package/dist/utility/textures/randomnoise.js.map +0 -1
package/dist/shaders/lighting.js
CHANGED
|
@@ -38,10 +38,14 @@ import { Application } from '../app.js';
|
|
|
38
38
|
pb.vec3('attenuation')
|
|
39
39
|
], function() {
|
|
40
40
|
this.$l.dist = pb.distance(this.lightPositionRange.xyz, ShaderFramework.getWorldPosition(this).xyz);
|
|
41
|
-
this.$l.
|
|
42
|
-
this.$l.
|
|
43
|
-
this.$
|
|
44
|
-
|
|
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));
|
|
45
49
|
});
|
|
46
50
|
});
|
|
47
51
|
pb.getGlobalScope()[funcNameIllumPointLight](...args);
|
|
@@ -166,12 +170,12 @@ import { Application } from '../app.js';
|
|
|
166
170
|
this.lightDir = this.directionCutoff.xyz;
|
|
167
171
|
this.$l.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
168
172
|
this.$l.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
169
|
-
this.shadowBound = pb.vec4(0, 0, 1, 1);
|
|
170
|
-
this.linearDepth = nonLinearDepthToLinear(this, this.$builtins.fragCoord.z);
|
|
171
|
-
this.splitDistances = ShaderFramework.getCascadeDistances(this);
|
|
172
|
-
this.comparison = pb.vec4(pb.greaterThan(pb.vec4(this.linearDepth), this.splitDistances));
|
|
173
|
-
this.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)));
|
|
174
|
-
this.split = pb.int(pb.dot(this.comparison, this.cascadeFlags));
|
|
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));
|
|
175
179
|
this.$l.shadowVertex = pb.vec4();
|
|
176
180
|
if (Application.instance.device.type === 'webgl') {
|
|
177
181
|
this.$for(pb.int('cascade'), 0, 4, function() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lighting.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/shaders/water.js
CHANGED
|
@@ -12,13 +12,13 @@ import { Application } from '../app.js';
|
|
|
12
12
|
this.$outputs.uv2 = pb.vec2();
|
|
13
13
|
this.flip = pb.int().uniform(0);
|
|
14
14
|
this.viewProjMatrix = pb.mat4().uniform(0);
|
|
15
|
-
this.modelMatrix = pb.mat4().uniform(
|
|
16
|
-
this.gridScale = pb.float().uniform(
|
|
15
|
+
this.modelMatrix = pb.mat4().uniform(1);
|
|
16
|
+
this.gridScale = pb.float().uniform(1);
|
|
17
17
|
this.level = pb.float().uniform(0);
|
|
18
18
|
this.sizes = pb.vec4().uniform(0);
|
|
19
19
|
this.croppinesses = pb.vec4().uniform(0);
|
|
20
|
-
this.offset = pb.vec2().uniform(
|
|
21
|
-
this.scale = pb.float().uniform(
|
|
20
|
+
this.offset = pb.vec2().uniform(1);
|
|
21
|
+
this.scale = pb.float().uniform(1);
|
|
22
22
|
this.dx_hy_dz_dxdz0 = pb.tex2D().uniform(0);
|
|
23
23
|
this.sx_sz_dxdx_dzdz0 = pb.tex2D().uniform(0);
|
|
24
24
|
this.dx_hy_dz_dxdz1 = pb.tex2D().uniform(0);
|
package/dist/shadow/esm.js
CHANGED
|
@@ -5,23 +5,9 @@ import '@zephyr3d/device';
|
|
|
5
5
|
import { decodeNormalizedFloatFromRGBA, encodeNormalizedFloatToRGBA } from '../shaders/misc.js';
|
|
6
6
|
import { GaussianBlurBlitter } from '../blitter/gaussianblur.js';
|
|
7
7
|
import { computeShadowMapDepth, filterShadowESM } from '../shaders/shadow.js';
|
|
8
|
-
import '../scene/octree.js';
|
|
9
8
|
import { LIGHT_TYPE_POINT } from '../values.js';
|
|
9
|
+
import { ShadowMapper } from './shadowmapper.js';
|
|
10
10
|
import { ShaderHelper } from '../material/shader/helper.js';
|
|
11
|
-
import '../material/lambert.js';
|
|
12
|
-
import '../material/blinn.js';
|
|
13
|
-
import '../material/unlit.js';
|
|
14
|
-
import '../material/material.js';
|
|
15
|
-
import '../material/meshmaterial.js';
|
|
16
|
-
import '../material/grassmaterial.js';
|
|
17
|
-
import '../material/terrainmaterial.js';
|
|
18
|
-
import '../material/pbrmr.js';
|
|
19
|
-
import '../material/pbrsg.js';
|
|
20
|
-
import '../render/renderer.js';
|
|
21
|
-
import '../render/sky.js';
|
|
22
|
-
import '../render/clipmap.js';
|
|
23
|
-
import { TemporalCache } from '../render/temporalcache.js';
|
|
24
|
-
import '../render/watermesh.js';
|
|
25
11
|
|
|
26
12
|
class BlurBlitter extends GaussianBlurBlitter {
|
|
27
13
|
_packFloat;
|
|
@@ -133,13 +119,12 @@ class BlurBlitter extends GaussianBlurBlitter {
|
|
|
133
119
|
};
|
|
134
120
|
shadowMapParams.implData = implData;
|
|
135
121
|
const colorFormat = this.getShadowMapColorFormat(shadowMapParams);
|
|
136
|
-
const target = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].target;
|
|
137
122
|
const shadowMapWidth = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].width;
|
|
138
123
|
const shadowMapHeight = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].height;
|
|
139
124
|
if (this._blur) {
|
|
140
125
|
shadowMapParams.implData = {
|
|
141
|
-
blurFramebuffer:
|
|
142
|
-
blurFramebuffer2:
|
|
126
|
+
blurFramebuffer: ShadowMapper.fetchTemporalFramebuffer(true, shadowMapParams.lightType, shadowMapParams.numShadowCascades, shadowMapWidth, shadowMapHeight, colorFormat, null, false),
|
|
127
|
+
blurFramebuffer2: ShadowMapper.fetchTemporalFramebuffer(true, shadowMapParams.lightType, shadowMapParams.numShadowCascades, shadowMapWidth, shadowMapHeight, colorFormat, null, true)
|
|
143
128
|
};
|
|
144
129
|
}
|
|
145
130
|
shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);
|
|
@@ -162,11 +147,7 @@ class BlurBlitter extends GaussianBlurBlitter {
|
|
|
162
147
|
}
|
|
163
148
|
}
|
|
164
149
|
releaseTemporalResources(shadowMapParams) {
|
|
165
|
-
|
|
166
|
-
if (implData) {
|
|
167
|
-
TemporalCache.releaseFramebuffer(implData.blurFramebuffer);
|
|
168
|
-
TemporalCache.releaseFramebuffer(implData.blurFramebuffer2);
|
|
169
|
-
}
|
|
150
|
+
return;
|
|
170
151
|
}
|
|
171
152
|
getDepthScale() {
|
|
172
153
|
return this._depthScale;
|
package/dist/shadow/esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -6,24 +6,8 @@ import { VSM } from './vsm.js';
|
|
|
6
6
|
import { PCFPD } from './pcf_pd.js';
|
|
7
7
|
import { PCFOPT } from './pcf_opt.js';
|
|
8
8
|
import { Application } from '../app.js';
|
|
9
|
-
import '../
|
|
10
|
-
import { LIGHT_TYPE_NONE, LIGHT_TYPE_DIRECTIONAL } from '../values.js';
|
|
9
|
+
import { LIGHT_TYPE_NONE, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT } from '../values.js';
|
|
11
10
|
import { ShaderHelper } from '../material/shader/helper.js';
|
|
12
|
-
import '../material/lambert.js';
|
|
13
|
-
import '../material/blinn.js';
|
|
14
|
-
import '../material/unlit.js';
|
|
15
|
-
import '../material/material.js';
|
|
16
|
-
import '../material/meshmaterial.js';
|
|
17
|
-
import '../material/grassmaterial.js';
|
|
18
|
-
import '../material/terrainmaterial.js';
|
|
19
|
-
import '../material/pbrmr.js';
|
|
20
|
-
import '../material/pbrsg.js';
|
|
21
|
-
import '@zephyr3d/device';
|
|
22
|
-
import '../render/renderer.js';
|
|
23
|
-
import '../render/sky.js';
|
|
24
|
-
import '../render/clipmap.js';
|
|
25
|
-
import { TemporalCache } from '../render/temporalcache.js';
|
|
26
|
-
import '../render/watermesh.js';
|
|
27
11
|
|
|
28
12
|
const tmpMatrix = new Matrix4x4();
|
|
29
13
|
const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
@@ -289,7 +273,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
289
273
|
if (ctx.shadowMapInfo) {
|
|
290
274
|
for (const k of ctx.shadowMapInfo.keys()){
|
|
291
275
|
const shadowMapParams = ctx.shadowMapInfo.get(k);
|
|
292
|
-
|
|
276
|
+
ctx.device.pool.releaseFrameBuffer(shadowMapParams.shadowMapFramebuffer);
|
|
293
277
|
shadowMapParams.impl.releaseTemporalResources(shadowMapParams);
|
|
294
278
|
shadowMapParams.lightType = LIGHT_TYPE_NONE;
|
|
295
279
|
shadowMapParams.depthClampEnabled = false;
|
|
@@ -345,6 +329,26 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
345
329
|
return null;
|
|
346
330
|
}
|
|
347
331
|
}
|
|
332
|
+
/** @internal */ static fetchTemporalFramebuffer(autoRelease, lightType, numCascades, width, height, colorFormat, depthFormat, mipmapping) {
|
|
333
|
+
const device = Application.instance.device;
|
|
334
|
+
const useTextureArray = numCascades > 1 && device.type !== 'webgl';
|
|
335
|
+
const colorAttachments = colorFormat ? useTextureArray ? [
|
|
336
|
+
device.pool.fetchTemporalTexture2DArray(false, colorFormat, width, height, numCascades, mipmapping)
|
|
337
|
+
] : lightType === LIGHT_TYPE_POINT ? [
|
|
338
|
+
device.pool.fetchTemporalTextureCube(false, colorFormat, width, mipmapping)
|
|
339
|
+
] : [
|
|
340
|
+
device.pool.fetchTemporalTexture2D(false, colorFormat, width, height, mipmapping)
|
|
341
|
+
] : null;
|
|
342
|
+
const depthAttachment = depthFormat ? useTextureArray ? device.pool.fetchTemporalTexture2DArray(false, depthFormat, width, height, numCascades, false) : device.type !== 'webgl' && lightType === LIGHT_TYPE_POINT ? device.pool.fetchTemporalTextureCube(false, depthFormat, width, false) : device.pool.fetchTemporalTexture2D(false, depthFormat, width, height, false) : null;
|
|
343
|
+
const fb = device.pool.createTemporalFramebuffer(autoRelease, colorAttachments, depthAttachment);
|
|
344
|
+
if (colorAttachments) {
|
|
345
|
+
device.pool.releaseTexture(colorAttachments[0]);
|
|
346
|
+
}
|
|
347
|
+
if (depthAttachment) {
|
|
348
|
+
device.pool.releaseTexture(depthAttachment);
|
|
349
|
+
}
|
|
350
|
+
return fb;
|
|
351
|
+
}
|
|
348
352
|
/** @internal */ updateResources(shadowMapParams) {
|
|
349
353
|
const device = Application.instance.device;
|
|
350
354
|
const colorFormat = shadowMapParams.impl.getShadowMapColorFormat(shadowMapParams);
|
|
@@ -353,9 +357,29 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
353
357
|
const useTextureArray = numCascades > 1 && device.type !== 'webgl';
|
|
354
358
|
const shadowMapWidth = numCascades > 1 && !useTextureArray ? 2 * this._config.shadowMapSize : this._config.shadowMapSize;
|
|
355
359
|
const shadowMapHeight = numCascades > 2 && !useTextureArray ? 2 * this._config.shadowMapSize : this._config.shadowMapSize;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
360
|
+
/*
|
|
361
|
+
const colorAttachments = colorFormat
|
|
362
|
+
? useTextureArray
|
|
363
|
+
? [device.pool.fetchTemporalTexture2DArray(false, colorFormat, shadowMapWidth, shadowMapHeight, numCascades, false)]
|
|
364
|
+
: this._light.isPointLight()
|
|
365
|
+
? [device.pool.fetchTemporalTextureCube(false, colorFormat, shadowMapWidth, false)]
|
|
366
|
+
: [device.pool.fetchTemporalTexture2D(false, colorFormat, shadowMapWidth, shadowMapHeight, false)]
|
|
367
|
+
: null;
|
|
368
|
+
const depthAttachment = depthFormat
|
|
369
|
+
? useTextureArray
|
|
370
|
+
? device.pool.fetchTemporalTexture2DArray(false, depthFormat, shadowMapWidth, shadowMapHeight, numCascades, false)
|
|
371
|
+
: device.type !== 'webgl' && this._light.isPointLight()
|
|
372
|
+
? device.pool.fetchTemporalTextureCube(false, depthFormat, shadowMapWidth, false)
|
|
373
|
+
: device.pool.fetchTemporalTexture2D(false, depthFormat, shadowMapWidth, shadowMapHeight, false)
|
|
374
|
+
: null;
|
|
375
|
+
shadowMapParams.shadowMapFramebuffer = device.pool.createTemporalFramebuffer(false, colorAttachments, depthAttachment);
|
|
376
|
+
if (colorAttachments) {
|
|
377
|
+
device.pool.releaseTexture(colorAttachments[0]);
|
|
378
|
+
}
|
|
379
|
+
if (depthAttachment) {
|
|
380
|
+
device.pool.releaseTexture(depthAttachment);
|
|
381
|
+
}
|
|
382
|
+
*/ shadowMapParams.shadowMapFramebuffer = ShadowMapper.fetchTemporalFramebuffer(false, this._light.lightType, numCascades, shadowMapWidth, shadowMapHeight, colorFormat, depthFormat);
|
|
359
383
|
shadowMapParams.impl = this._impl;
|
|
360
384
|
this._impl.updateResources(shadowMapParams);
|
|
361
385
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadowmapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shadowmapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/shadow/vsm.js
CHANGED
|
@@ -4,25 +4,8 @@ import { decodeNormalizedFloatFromRGBA, decode2HalfFromRGBA, encode2HalfToRGBA }
|
|
|
4
4
|
import { Application } from '../app.js';
|
|
5
5
|
import { computeShadowMapDepth, filterShadowVSM } from '../shaders/shadow.js';
|
|
6
6
|
import { ShadowMapper } from './shadowmapper.js';
|
|
7
|
-
import '@zephyr3d/base';
|
|
8
|
-
import '../scene/octree.js';
|
|
9
7
|
import { LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values.js';
|
|
10
8
|
import { ShaderHelper } from '../material/shader/helper.js';
|
|
11
|
-
import '../material/lambert.js';
|
|
12
|
-
import '../material/blinn.js';
|
|
13
|
-
import '../material/unlit.js';
|
|
14
|
-
import '../material/material.js';
|
|
15
|
-
import '../material/meshmaterial.js';
|
|
16
|
-
import '../material/grassmaterial.js';
|
|
17
|
-
import '../material/terrainmaterial.js';
|
|
18
|
-
import '../material/pbrmr.js';
|
|
19
|
-
import '../material/pbrsg.js';
|
|
20
|
-
import '@zephyr3d/device';
|
|
21
|
-
import '../render/renderer.js';
|
|
22
|
-
import '../render/sky.js';
|
|
23
|
-
import '../render/clipmap.js';
|
|
24
|
-
import { TemporalCache } from '../render/temporalcache.js';
|
|
25
|
-
import '../render/watermesh.js';
|
|
26
9
|
|
|
27
10
|
class VSMBlitter extends Blitter {
|
|
28
11
|
_phase;
|
|
@@ -192,13 +175,13 @@ class VSMBlitter extends Blitter {
|
|
|
192
175
|
}
|
|
193
176
|
doUpdateResources(shadowMapParams) {
|
|
194
177
|
const colorFormat = this.getShadowMapColorFormat(shadowMapParams);
|
|
195
|
-
const target = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].target;
|
|
178
|
+
//const target = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].target;
|
|
196
179
|
const shadowMapWidth = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].width;
|
|
197
180
|
const shadowMapHeight = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].height;
|
|
198
181
|
if (this._blur) {
|
|
199
182
|
shadowMapParams.implData = {
|
|
200
|
-
blurFramebuffer:
|
|
201
|
-
blurFramebuffer2:
|
|
183
|
+
blurFramebuffer: ShadowMapper.fetchTemporalFramebuffer(true, shadowMapParams.lightType, shadowMapParams.numShadowCascades, shadowMapWidth, shadowMapHeight, colorFormat, null, false),
|
|
184
|
+
blurFramebuffer2: ShadowMapper.fetchTemporalFramebuffer(true, shadowMapParams.lightType, shadowMapParams.numShadowCascades, shadowMapWidth, shadowMapHeight, colorFormat, null, this._mipmap)
|
|
202
185
|
};
|
|
203
186
|
}
|
|
204
187
|
shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);
|
|
@@ -218,11 +201,7 @@ class VSMBlitter extends Blitter {
|
|
|
218
201
|
}
|
|
219
202
|
}
|
|
220
203
|
releaseTemporalResources(shadowMapParams) {
|
|
221
|
-
|
|
222
|
-
if (implData) {
|
|
223
|
-
TemporalCache.releaseFramebuffer(implData.blurFramebuffer);
|
|
224
|
-
TemporalCache.releaseFramebuffer(implData.blurFramebuffer2);
|
|
225
|
-
}
|
|
204
|
+
return;
|
|
226
205
|
}
|
|
227
206
|
getShaderHash() {
|
|
228
207
|
return '';
|
package/dist/shadow/vsm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vsm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vsm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
class DracoMeshDecoder {
|
|
2
|
+
_module;
|
|
3
|
+
_decoder;
|
|
4
|
+
_mesh;
|
|
5
|
+
constructor(data, decoderModule){
|
|
6
|
+
this._module = decoderModule;
|
|
7
|
+
this._decoder = new this._module.Decoder();
|
|
8
|
+
const buffer = new this._module.DecoderBuffer();
|
|
9
|
+
buffer.Init(data, data.byteLength);
|
|
10
|
+
const geometryType = this._decoder.GetEncodedGeometryType(buffer);
|
|
11
|
+
if (geometryType !== this._module.TRIANGULAR_MESH) {
|
|
12
|
+
this._module.destroy(buffer);
|
|
13
|
+
this._module.destroy(this._decoder);
|
|
14
|
+
this._decoder = null;
|
|
15
|
+
throw new Error(`Unsupported geometry type: ${geometryType}`);
|
|
16
|
+
}
|
|
17
|
+
this._mesh = new this._module.Mesh();
|
|
18
|
+
const status = this._decoder.DecodeBufferToMesh(buffer, this._mesh);
|
|
19
|
+
this._module.destroy(buffer);
|
|
20
|
+
if (!status.ok() || this._mesh.ptr === 0) {
|
|
21
|
+
this._module.destroy(this._decoder);
|
|
22
|
+
this._decoder = null;
|
|
23
|
+
this._module.destroy(this._mesh);
|
|
24
|
+
this._mesh = null;
|
|
25
|
+
throw new Error(status.error_msg());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getIndexBuffer() {
|
|
29
|
+
if (!this._decoder || !this._mesh) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const numFaces = this._mesh.num_faces();
|
|
33
|
+
const numIndices = numFaces * 3;
|
|
34
|
+
// Uint32
|
|
35
|
+
const indexBuffer = new Uint32Array(numIndices);
|
|
36
|
+
const ptr = this._module._malloc(indexBuffer.byteLength);
|
|
37
|
+
this._decoder.GetTrianglesUInt32Array(this._mesh, indexBuffer.byteLength, ptr);
|
|
38
|
+
const tmpBuffer = new Uint32Array(this._module.HEAPU32.buffer, ptr, numIndices);
|
|
39
|
+
indexBuffer.set(tmpBuffer);
|
|
40
|
+
this._module._free(ptr);
|
|
41
|
+
return indexBuffer;
|
|
42
|
+
}
|
|
43
|
+
getAttributeBuffer(id, buffer) {
|
|
44
|
+
if (!this._decoder || !this._mesh) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const attribute = this._decoder.GetAttributeByUniqueId(this._mesh, id);
|
|
48
|
+
if (!attribute) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const numComponents = attribute.num_components();
|
|
52
|
+
const numPoints = this._mesh.num_points();
|
|
53
|
+
const numValues = numPoints * numComponents;
|
|
54
|
+
if (buffer.length !== numValues) {
|
|
55
|
+
console.error(`getAttributeBuffer(): buffer length must be ${numValues}`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const ptr = this._module._malloc(buffer.byteLength);
|
|
59
|
+
this._decoder.GetAttributeDataArrayForAllPoints(this._mesh, attribute, this.getDracoDataType(buffer), buffer.byteLength, ptr);
|
|
60
|
+
const tmpBuffer = new buffer.constructor(this.getDracoHeap(buffer).buffer, ptr, numValues);
|
|
61
|
+
buffer.set(tmpBuffer);
|
|
62
|
+
this._module._free(ptr);
|
|
63
|
+
return buffer;
|
|
64
|
+
}
|
|
65
|
+
getDracoDataType(buffer) {
|
|
66
|
+
if (buffer instanceof Float32Array) {
|
|
67
|
+
return this._module.DT_FLOAT32;
|
|
68
|
+
}
|
|
69
|
+
if (buffer instanceof Int8Array) {
|
|
70
|
+
return this._module.DT_INT8;
|
|
71
|
+
}
|
|
72
|
+
if (buffer instanceof Int16Array) {
|
|
73
|
+
return this._module.DT_INT16;
|
|
74
|
+
}
|
|
75
|
+
if (buffer instanceof Int32Array) {
|
|
76
|
+
return this._module.DT_INT32;
|
|
77
|
+
}
|
|
78
|
+
if (buffer instanceof Uint8Array) {
|
|
79
|
+
return this._module.DT_UINT8;
|
|
80
|
+
}
|
|
81
|
+
if (buffer instanceof Uint16Array) {
|
|
82
|
+
return this._module.DT_UINT16;
|
|
83
|
+
}
|
|
84
|
+
if (buffer instanceof Uint32Array) {
|
|
85
|
+
return this._module.DT_UINT32;
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`getDracoDataType(): invalid buffer type`);
|
|
88
|
+
}
|
|
89
|
+
getDracoHeap(buffer) {
|
|
90
|
+
if (buffer instanceof Float32Array) {
|
|
91
|
+
return this._module.HEAPF32;
|
|
92
|
+
}
|
|
93
|
+
if (buffer instanceof Int8Array) {
|
|
94
|
+
return this._module.HEAP8;
|
|
95
|
+
}
|
|
96
|
+
if (buffer instanceof Int16Array) {
|
|
97
|
+
return this._module.HEAP16;
|
|
98
|
+
}
|
|
99
|
+
if (buffer instanceof Int32Array) {
|
|
100
|
+
return this._module.HEAP32;
|
|
101
|
+
}
|
|
102
|
+
if (buffer instanceof Uint8Array) {
|
|
103
|
+
return this._module.HEAPU8;
|
|
104
|
+
}
|
|
105
|
+
if (buffer instanceof Uint16Array) {
|
|
106
|
+
return this._module.HEAPU16;
|
|
107
|
+
}
|
|
108
|
+
if (buffer instanceof Uint32Array) {
|
|
109
|
+
return this._module.HEAPU32;
|
|
110
|
+
}
|
|
111
|
+
throw new Error(`getDracoHeap(): invalid buffer type`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { DracoMeshDecoder };
|
|
116
|
+
//# sourceMappingURL=decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoder.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Vector3, Vector2 } from '@zephyr3d/base';
|
|
2
|
+
import { Application } from '../app.js';
|
|
3
|
+
|
|
4
|
+
const bits = new Uint32Array(1);
|
|
5
|
+
//Van der Corput radical inverse
|
|
6
|
+
function radicalInverse_VdC(i) {
|
|
7
|
+
bits[0] = i;
|
|
8
|
+
bits[0] = (bits[0] << 16 | bits[0] >> 16) >>> 0;
|
|
9
|
+
bits[0] = (bits[0] & 0x55555555) << 1 | (bits[0] & 0xaaaaaaaa) >>> 1 >>> 0;
|
|
10
|
+
bits[0] = (bits[0] & 0x33333333) << 2 | (bits[0] & 0xcccccccc) >>> 2 >>> 0;
|
|
11
|
+
bits[0] = (bits[0] & 0x0f0f0f0f) << 4 | (bits[0] & 0xf0f0f0f0) >>> 4 >>> 0;
|
|
12
|
+
bits[0] = (bits[0] & 0x00ff00ff) << 8 | (bits[0] & 0xff00ff00) >>> 8 >>> 0;
|
|
13
|
+
return bits[0] * 2.3283064365386963e-10; // / 0x100000000 or / 4294967296
|
|
14
|
+
}
|
|
15
|
+
function hammersley(i, iN, out) {
|
|
16
|
+
out.setXY(i * iN, radicalInverse_VdC(i));
|
|
17
|
+
}
|
|
18
|
+
function distributionCharlie(NdotH, roughness) {
|
|
19
|
+
// roughness = Math.max(roughness, 0.000001);
|
|
20
|
+
const invAlpha = 1 / roughness;
|
|
21
|
+
const cos2h = NdotH * NdotH;
|
|
22
|
+
const sin2h = 1 - cos2h;
|
|
23
|
+
return (2 + invAlpha) * Math.pow(sin2h, invAlpha * 0.5) / (2 * Math.PI);
|
|
24
|
+
}
|
|
25
|
+
function visibilityAshikhmin(NdotV, NdotL) {
|
|
26
|
+
return Math.min(Math.max(1 / (4 * (NdotL + NdotV - NdotL * NdotV)), 0), 1);
|
|
27
|
+
}
|
|
28
|
+
function hemisphereUniformSample(u, out) {
|
|
29
|
+
const phi = 2 * Math.PI * u.x;
|
|
30
|
+
const cosTheta = 1 - u.y;
|
|
31
|
+
const sinTheta = Math.sqrt(1 - cosTheta * cosTheta);
|
|
32
|
+
out.setXYZ(sinTheta * Math.cos(phi), sinTheta * Math.sin(phi), cosTheta);
|
|
33
|
+
}
|
|
34
|
+
function dfvCharlieUniform(NdotV, roughness, numSamples) {
|
|
35
|
+
let r = 0;
|
|
36
|
+
const V = new Vector3(Math.sqrt(1 - NdotV * NdotV), 0, NdotV);
|
|
37
|
+
const u = new Vector2();
|
|
38
|
+
const H = new Vector3();
|
|
39
|
+
const L = new Vector3();
|
|
40
|
+
for(let i = 0; i < numSamples; i++){
|
|
41
|
+
hammersley(i, 1 / numSamples, u);
|
|
42
|
+
hemisphereUniformSample(u, H);
|
|
43
|
+
Vector3.scale(H, Vector3.dot(V, H) * 2, L).subBy(V);
|
|
44
|
+
const VdotH = Math.min(Math.max(Vector3.dot(V, H), 0), 1);
|
|
45
|
+
const NdotL = Math.min(Math.max(L.z, 0), 1);
|
|
46
|
+
const NdotH = Math.min(Math.max(H.z, 0), 1);
|
|
47
|
+
if (NdotL > 0) {
|
|
48
|
+
const v = visibilityAshikhmin(NdotV, NdotL);
|
|
49
|
+
// const v = visibilityCharlie(NdotV, NdotL, roughness);
|
|
50
|
+
const d = distributionCharlie(NdotH, roughness);
|
|
51
|
+
r += v * d * NdotL * VdotH;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return r * (4 * 2 * Math.PI / numSamples);
|
|
55
|
+
}
|
|
56
|
+
const _tables = function _generateTables() {
|
|
57
|
+
// float32 to float16 helpers
|
|
58
|
+
const buffer = new ArrayBuffer(4);
|
|
59
|
+
const floatView = new Float32Array(buffer);
|
|
60
|
+
const uint32View = new Uint32Array(buffer);
|
|
61
|
+
const baseTable = new Uint32Array(512);
|
|
62
|
+
const shiftTable = new Uint32Array(512);
|
|
63
|
+
for(let i = 0; i < 256; ++i){
|
|
64
|
+
const e = i - 127;
|
|
65
|
+
// very small number (0, -0)
|
|
66
|
+
if (e < -27) {
|
|
67
|
+
baseTable[i] = 0x0000;
|
|
68
|
+
baseTable[i | 0x100] = 0x8000;
|
|
69
|
+
shiftTable[i] = 24;
|
|
70
|
+
shiftTable[i | 0x100] = 24;
|
|
71
|
+
// small number (denorm)
|
|
72
|
+
} else if (e < -14) {
|
|
73
|
+
baseTable[i] = 0x0400 >> -e - 14;
|
|
74
|
+
baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
|
|
75
|
+
shiftTable[i] = -e - 1;
|
|
76
|
+
shiftTable[i | 0x100] = -e - 1;
|
|
77
|
+
// normal number
|
|
78
|
+
} else if (e <= 15) {
|
|
79
|
+
baseTable[i] = e + 15 << 10;
|
|
80
|
+
baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
|
|
81
|
+
shiftTable[i] = 13;
|
|
82
|
+
shiftTable[i | 0x100] = 13;
|
|
83
|
+
// large number (Infinity, -Infinity)
|
|
84
|
+
} else if (e < 128) {
|
|
85
|
+
baseTable[i] = 0x7c00;
|
|
86
|
+
baseTable[i | 0x100] = 0xfc00;
|
|
87
|
+
shiftTable[i] = 24;
|
|
88
|
+
shiftTable[i | 0x100] = 24;
|
|
89
|
+
// stay (NaN, Infinity, -Infinity)
|
|
90
|
+
} else {
|
|
91
|
+
baseTable[i] = 0x7c00;
|
|
92
|
+
baseTable[i | 0x100] = 0xfc00;
|
|
93
|
+
shiftTable[i] = 13;
|
|
94
|
+
shiftTable[i | 0x100] = 13;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// float16 to float32 helpers
|
|
98
|
+
const mantissaTable = new Uint32Array(2048);
|
|
99
|
+
const exponentTable = new Uint32Array(64);
|
|
100
|
+
const offsetTable = new Uint32Array(64);
|
|
101
|
+
for(let i = 1; i < 1024; ++i){
|
|
102
|
+
let m = i << 13; // zero pad mantissa bits
|
|
103
|
+
let e = 0; // zero exponent
|
|
104
|
+
// normalized
|
|
105
|
+
while((m & 0x00800000) === 0){
|
|
106
|
+
m <<= 1;
|
|
107
|
+
e -= 0x00800000; // decrement exponent
|
|
108
|
+
}
|
|
109
|
+
m &= ~0x00800000; // clear leading 1 bit
|
|
110
|
+
e += 0x38800000; // adjust bias
|
|
111
|
+
mantissaTable[i] = m | e;
|
|
112
|
+
}
|
|
113
|
+
for(let i = 1024; i < 2048; ++i){
|
|
114
|
+
mantissaTable[i] = 0x38000000 + (i - 1024 << 13);
|
|
115
|
+
}
|
|
116
|
+
for(let i = 1; i < 31; ++i){
|
|
117
|
+
exponentTable[i] = i << 23;
|
|
118
|
+
}
|
|
119
|
+
exponentTable[31] = 0x47800000;
|
|
120
|
+
exponentTable[32] = 0x80000000;
|
|
121
|
+
for(let i = 33; i < 63; ++i){
|
|
122
|
+
exponentTable[i] = 0x80000000 + (i - 32 << 23);
|
|
123
|
+
}
|
|
124
|
+
exponentTable[63] = 0xc7800000;
|
|
125
|
+
for(let i = 1; i < 64; ++i){
|
|
126
|
+
if (i !== 32) {
|
|
127
|
+
offsetTable[i] = 1024;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
floatView: floatView,
|
|
132
|
+
uint32View: uint32View,
|
|
133
|
+
baseTable: baseTable,
|
|
134
|
+
shiftTable: shiftTable,
|
|
135
|
+
mantissaTable: mantissaTable,
|
|
136
|
+
exponentTable: exponentTable,
|
|
137
|
+
offsetTable: offsetTable
|
|
138
|
+
};
|
|
139
|
+
}();
|
|
140
|
+
function encodeF16(val) {
|
|
141
|
+
val = Math.min(Math.max(val, -65504), 65504);
|
|
142
|
+
_tables.floatView[0] = val;
|
|
143
|
+
const f = _tables.uint32View[0];
|
|
144
|
+
const e = f >> 23 & 0x1ff;
|
|
145
|
+
return _tables.baseTable[e] + ((f & 0x007fffff) >> _tables.shiftTable[e]);
|
|
146
|
+
}
|
|
147
|
+
/*
|
|
148
|
+
function decodeF16(val: number) {
|
|
149
|
+
const exponent = (val & 0x7c00) >> 10;
|
|
150
|
+
const fraction = val & 0x03ff;
|
|
151
|
+
return (
|
|
152
|
+
(val >> 15 ? -1 : 1) *
|
|
153
|
+
(exponent
|
|
154
|
+
? exponent === 0x1f
|
|
155
|
+
? fraction
|
|
156
|
+
? NaN
|
|
157
|
+
: Infinity
|
|
158
|
+
: Math.pow(2, exponent - 15) * (1 + fraction / 0x400)
|
|
159
|
+
: 6.103515625e-5 * (fraction / 0x400))
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
*/ async function createSheenLUT(textureSize, texture) {
|
|
163
|
+
if (texture) {
|
|
164
|
+
if (!texture.isTexture2D()) {
|
|
165
|
+
throw new Error('can not reload sheen lut texture: invalid texture type');
|
|
166
|
+
}
|
|
167
|
+
if (texture.format !== 'rgba16f') {
|
|
168
|
+
throw new Error('can not reload sheen lut texture: invalid texture format');
|
|
169
|
+
}
|
|
170
|
+
if (texture.width !== textureSize || texture.height !== textureSize) {
|
|
171
|
+
throw new Error('can not reload sheen lut texture: invalid texture size');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const tex = texture || Application.instance.device.createTexture2D('rgba16f', textureSize, textureSize);
|
|
175
|
+
const image = new Uint16Array(textureSize * textureSize * 4);
|
|
176
|
+
let p = 0;
|
|
177
|
+
const one = encodeF16(1);
|
|
178
|
+
for(let y = textureSize - 1; y >= 0; y--){
|
|
179
|
+
const coord = Math.min(Math.max((y + 0.5) / textureSize, 0), 1);
|
|
180
|
+
const roughness = coord * coord;
|
|
181
|
+
for(let x = 0; x < textureSize; x++){
|
|
182
|
+
const NdotV = Math.min(Math.max((x + 0.5) / textureSize, 0), 1);
|
|
183
|
+
const c = dfvCharlieUniform(NdotV, roughness, 512);
|
|
184
|
+
const f16 = encodeF16(c);
|
|
185
|
+
image[p++] = 0;
|
|
186
|
+
image[p++] = 0;
|
|
187
|
+
image[p++] = f16;
|
|
188
|
+
image[p++] = one;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
tex.update(image, 0, 0, textureSize, textureSize);
|
|
192
|
+
return tex;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export { createSheenLUT };
|
|
196
|
+
//# sourceMappingURL=sheenlut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sheenlut.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/values.js
CHANGED
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
* Depth only render pass type
|
|
11
11
|
* @public
|
|
12
12
|
*/ const RENDER_PASS_TYPE_DEPTH = 2;
|
|
13
|
+
/**
|
|
14
|
+
* Object color render pass type
|
|
15
|
+
* @public
|
|
16
|
+
*/ const RENDER_PASS_TYPE_OBJECT_COLOR = 3;
|
|
13
17
|
/**
|
|
14
18
|
* Builtin texture name for sheen LUT
|
|
15
19
|
* @public
|
|
@@ -46,6 +50,19 @@
|
|
|
46
50
|
* Transparent render queue type
|
|
47
51
|
* @public
|
|
48
52
|
*/ const QUEUE_TRANSPARENT = 2;
|
|
53
|
+
// Morph target attributes
|
|
54
|
+
/** @internal */ const MORPH_TARGET_POSITION = 0;
|
|
55
|
+
/** @internal */ const MORPH_TARGET_NORMAL = 1;
|
|
56
|
+
/** @internal */ const MORPH_TARGET_TANGENT = 2;
|
|
57
|
+
/** @internal */ const MORPH_TARGET_COLOR = 3;
|
|
58
|
+
/** @internal */ const MORPH_TARGET_TEX0 = 4;
|
|
59
|
+
/** @internal */ const MORPH_TARGET_TEX1 = 5;
|
|
60
|
+
/** @internal */ const MORPH_TARGET_TEX2 = 6;
|
|
61
|
+
/** @internal */ const MORPH_TARGET_TEX3 = 7;
|
|
62
|
+
/** @internal */ const MAX_MORPH_ATTRIBUTES = 8;
|
|
63
|
+
/** @internal */ const MAX_MORPH_TARGETS = 256;
|
|
64
|
+
/** @internal */ const MORPH_WEIGHTS_VECTOR_COUNT = MAX_MORPH_TARGETS + 3 >> 2;
|
|
65
|
+
/** @internal */ const MORPH_ATTRIBUTE_VECTOR_COUNT = MAX_MORPH_ATTRIBUTES + 3 >> 2;
|
|
49
66
|
|
|
50
|
-
export { BUILTIN_ASSET_TEST_CUBEMAP, BUILTIN_ASSET_TEXTURE_SHEEN_LUT, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_NONE, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, MAX_CLUSTERED_LIGHTS, QUEUE_OPAQUE, QUEUE_TRANSPARENT, RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_LIGHT, RENDER_PASS_TYPE_SHADOWMAP };
|
|
67
|
+
export { BUILTIN_ASSET_TEST_CUBEMAP, BUILTIN_ASSET_TEXTURE_SHEEN_LUT, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_NONE, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, MAX_CLUSTERED_LIGHTS, MAX_MORPH_ATTRIBUTES, MAX_MORPH_TARGETS, MORPH_ATTRIBUTE_VECTOR_COUNT, MORPH_TARGET_COLOR, MORPH_TARGET_NORMAL, MORPH_TARGET_POSITION, MORPH_TARGET_TANGENT, MORPH_TARGET_TEX0, MORPH_TARGET_TEX1, MORPH_TARGET_TEX2, MORPH_TARGET_TEX3, MORPH_WEIGHTS_VECTOR_COUNT, QUEUE_OPAQUE, QUEUE_TRANSPARENT, RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_LIGHT, RENDER_PASS_TYPE_OBJECT_COLOR, RENDER_PASS_TYPE_SHADOWMAP };
|
|
51
68
|
//# sourceMappingURL=values.js.map
|
package/dist/values.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"values.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|