@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/shapes/cylinder.js
CHANGED
|
@@ -19,9 +19,6 @@ import { Shape } from './shape.js';
|
|
|
19
19
|
options.heightDetail = 1;
|
|
20
20
|
options.radialDetail = 20;
|
|
21
21
|
options.height = 1;
|
|
22
|
-
options.anchorX = 0.5;
|
|
23
|
-
options.anchorY = 0;
|
|
24
|
-
options.anchorZ = 0.5;
|
|
25
22
|
return options;
|
|
26
23
|
}
|
|
27
24
|
/** @internal */ addPatch(x, y, indices) {
|
|
@@ -43,7 +40,7 @@ import { Shape } from './shape.js';
|
|
|
43
40
|
const sinTheta = Math.sin(theta);
|
|
44
41
|
const cosTheta = Math.cos(theta);
|
|
45
42
|
const m = 1 / Math.sqrt(sinTheta * sinTheta + slope * slope + cosTheta * cosTheta);
|
|
46
|
-
vertices.push(radius * sinTheta, v * this._options.height, radius * cosTheta);
|
|
43
|
+
vertices.push(radius * sinTheta, (v - 0.5) * this._options.height, radius * cosTheta);
|
|
47
44
|
normals.push(sinTheta * m, slope * m, cosTheta * m);
|
|
48
45
|
uvs.push(u, 1 - v);
|
|
49
46
|
if (y < this._options.heightDetail && x < this._options.radialDetail) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cylinder.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cylinder.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/shapes/shape.js
CHANGED
|
@@ -13,6 +13,11 @@ import { Primitive } from '../render/primitive.js';
|
|
|
13
13
|
this._options = this.createDefaultOptions();
|
|
14
14
|
this.create(options);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Creation options
|
|
18
|
+
*/ get options() {
|
|
19
|
+
return this._options;
|
|
20
|
+
}
|
|
16
21
|
/** @internal */ create(options) {
|
|
17
22
|
if (options) {
|
|
18
23
|
this._options = this.createDefaultOptions();
|
package/dist/shapes/shape.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shape.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/shapes/sphere.js
CHANGED
|
@@ -28,6 +28,9 @@ import { Shape } from './shape.js';
|
|
|
28
28
|
}
|
|
29
29
|
return a - Math.sqrt(rSquared - bSquared);
|
|
30
30
|
}
|
|
31
|
+
/** Sphere radius */ get radius() {
|
|
32
|
+
return this._options.radius ?? 1;
|
|
33
|
+
}
|
|
31
34
|
/** @internal */ createDefaultOptions() {
|
|
32
35
|
const options = super.createDefaultOptions();
|
|
33
36
|
options.radius = 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sphere.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sphere.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/shapes/torus.js
CHANGED
|
@@ -17,9 +17,9 @@ TC(n, m) = (m / M, n / N)
|
|
|
17
17
|
|
|
18
18
|
VIndex(n, m) = n * (M + 1) + m
|
|
19
19
|
Triangle(n, m) = (VIndex(n, m), VIndex(n+1, m), VIndex(n+1, m+1), VIndex(n, m), VIndex(n+1, m+1), VIndex(n, m+1))*/ /**
|
|
20
|
-
*
|
|
20
|
+
*
|
|
21
21
|
* Torus shape
|
|
22
|
-
*
|
|
22
|
+
*
|
|
23
23
|
* @public
|
|
24
24
|
*/ class TorusShape extends Shape {
|
|
25
25
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AABB, Frustum, ClipState } from '@zephyr3d/base';
|
|
2
2
|
import { AABBTree } from './aabbtree.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* The bounding box class
|
|
6
|
-
* @public
|
|
4
|
+
/**
|
|
5
|
+
* The bounding box class
|
|
6
|
+
* @public
|
|
7
7
|
*/ class BoundingBox extends AABB {
|
|
8
8
|
constructor(arg0, arg1){
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -25,9 +25,9 @@ import { AABBTree } from './aabbtree.js';
|
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Bounding box tree
|
|
30
|
-
* @public
|
|
28
|
+
/**
|
|
29
|
+
* Bounding box tree
|
|
30
|
+
* @public
|
|
31
31
|
*/ class BoundingBoxTree extends AABBTree {
|
|
32
32
|
constructor(arg){
|
|
33
33
|
super(arg);
|
|
@@ -54,27 +54,27 @@ import { AABBTree } from './aabbtree.js';
|
|
|
54
54
|
/** {@inheritDoc BoundingVolume.toAABB} */ toAABB() {
|
|
55
55
|
return this.getTopLevelAABB();
|
|
56
56
|
}
|
|
57
|
-
} /*
|
|
58
|
-
export class BoundingFrustum implements BoundingVolume {
|
|
59
|
-
protected _frustum: Frustum;
|
|
60
|
-
constructor ();
|
|
61
|
-
constructor (other: BoundingFrustum|Frustum|Matrix4x4);
|
|
62
|
-
constructor (arg0?: BoundingFrustum|Frustum|Matrix4x4) {
|
|
63
|
-
if (arg0 instanceof BoundingFrustum) {
|
|
64
|
-
this._frustum = arg0._frustum ? new Frustum (arg0._frustum) : null;
|
|
65
|
-
} else if (arg0 instanceof Frustum) {
|
|
66
|
-
this._frustum = new Frustum (arg0);
|
|
67
|
-
} else if (arg0 instanceof Matrix4x4) {
|
|
68
|
-
this._frustum = new Frustum (arg0);
|
|
69
|
-
} else {
|
|
70
|
-
this._frustum = null;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
clone (): BoundingVolume {
|
|
74
|
-
return new BoundingFrustum (this);
|
|
75
|
-
}
|
|
76
|
-
transform (matrix: Matrix4x4)
|
|
77
|
-
}
|
|
57
|
+
} /*
|
|
58
|
+
export class BoundingFrustum implements BoundingVolume {
|
|
59
|
+
protected _frustum: Frustum;
|
|
60
|
+
constructor ();
|
|
61
|
+
constructor (other: BoundingFrustum|Frustum|Matrix4x4);
|
|
62
|
+
constructor (arg0?: BoundingFrustum|Frustum|Matrix4x4) {
|
|
63
|
+
if (arg0 instanceof BoundingFrustum) {
|
|
64
|
+
this._frustum = arg0._frustum ? new Frustum (arg0._frustum) : null;
|
|
65
|
+
} else if (arg0 instanceof Frustum) {
|
|
66
|
+
this._frustum = new Frustum (arg0);
|
|
67
|
+
} else if (arg0 instanceof Matrix4x4) {
|
|
68
|
+
this._frustum = new Frustum (arg0);
|
|
69
|
+
} else {
|
|
70
|
+
this._frustum = null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
clone (): BoundingVolume {
|
|
74
|
+
return new BoundingFrustum (this);
|
|
75
|
+
}
|
|
76
|
+
transform (matrix: Matrix4x4)
|
|
77
|
+
}
|
|
78
78
|
*/
|
|
79
79
|
|
|
80
80
|
export { BoundingBox, BoundingBoxTree };
|
package/dist/utility/pmrem.js
CHANGED
|
@@ -140,10 +140,10 @@ function createPMREMProgram(type, numSamples) {
|
|
|
140
140
|
], function() {
|
|
141
141
|
this.$l.n = this.bits;
|
|
142
142
|
this.n = pb.compOr(pb.sal(this.n, 16), pb.sar(this.n, 16));
|
|
143
|
-
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x55555555), 1), pb.sar(pb.compAnd(this.n,
|
|
144
|
-
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x33333333), 2), pb.sar(pb.compAnd(this.n,
|
|
145
|
-
this.n = pb.compOr(pb.sal(pb.compAnd(this.n,
|
|
146
|
-
this.n = pb.compOr(pb.sal(pb.compAnd(this.n,
|
|
143
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x55555555), 1), pb.sar(pb.compAnd(this.n, 0xaaaaaaaa), 1));
|
|
144
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x33333333), 2), pb.sar(pb.compAnd(this.n, 0xcccccccc), 2));
|
|
145
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x0f0f0f0f), 4), pb.sar(pb.compAnd(this.n, 0xf0f0f0f0), 4));
|
|
146
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x00ff00ff), 8), pb.sar(pb.compAnd(this.n, 0xff00ff00), 8));
|
|
147
147
|
this.$return(pb.mul(pb.float(this.n), 2.3283064365386963e-10));
|
|
148
148
|
});
|
|
149
149
|
pb.func('hammersley2d', [
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Vector3, halfToFloat, unpackFloat3, SH, nextPowerOf2 } from '@zephyr3d/base';
|
|
2
2
|
import { Application } from '../app.js';
|
|
3
3
|
import { Blitter } from '../blitter/blitter.js';
|
|
4
|
-
import '../shaders/framework.js';
|
|
5
4
|
import '@zephyr3d/device';
|
|
6
5
|
import { CopyBlitter } from '../blitter/copy.js';
|
|
7
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shprojection.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shprojection.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/values.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Forward render pass type
|
|
3
3
|
* @public
|
|
4
|
-
*/ const
|
|
4
|
+
*/ const RENDER_PASS_TYPE_LIGHT = 0;
|
|
5
5
|
/**
|
|
6
6
|
* Shadow map render pass type
|
|
7
7
|
* @public
|
|
@@ -9,12 +9,7 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* Depth only render pass type
|
|
11
11
|
* @public
|
|
12
|
-
*/ const
|
|
13
|
-
/**
|
|
14
|
-
* Max light count for forward rendering
|
|
15
|
-
* @internal
|
|
16
|
-
*/ const MAX_FORWARD_LIGHT_COUNT = 8;
|
|
17
|
-
/** @internal */ const DEBUG_CASCADED_SHADOW_MAPS = false;
|
|
12
|
+
*/ const RENDER_PASS_TYPE_DEPTH = 2;
|
|
18
13
|
/**
|
|
19
14
|
* Builtin texture name for sheen LUT
|
|
20
15
|
* @public
|
|
@@ -43,6 +38,14 @@
|
|
|
43
38
|
* Max light size for clustered lighting
|
|
44
39
|
* @public
|
|
45
40
|
*/ const MAX_CLUSTERED_LIGHTS = 255;
|
|
41
|
+
/**
|
|
42
|
+
* Opaque render queue type
|
|
43
|
+
* @public
|
|
44
|
+
*/ const QUEUE_OPAQUE = 1;
|
|
45
|
+
/**
|
|
46
|
+
* Transparent render queue type
|
|
47
|
+
* @public
|
|
48
|
+
*/ const QUEUE_TRANSPARENT = 2;
|
|
46
49
|
|
|
47
|
-
export { BUILTIN_ASSET_TEST_CUBEMAP, BUILTIN_ASSET_TEXTURE_SHEEN_LUT,
|
|
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 };
|
|
48
51
|
//# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zephyr3d/scene",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Scene API for zephyr3d",
|
|
5
5
|
"homepage": "https://github.com/gavinyork/zephyr3d#readme",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@rollup/plugin-terser": "^0.4.0",
|
|
45
45
|
"@rollup/pluginutils": "^5.0.2",
|
|
46
46
|
"@swc/core": "^1.3.62",
|
|
47
|
-
"@zephyr3d/base": "^0.1.
|
|
48
|
-
"@zephyr3d/device": "^0.1
|
|
47
|
+
"@zephyr3d/base": "^0.1.3",
|
|
48
|
+
"@zephyr3d/device": "^0.2.1",
|
|
49
49
|
"cross-env": "^7.0.3",
|
|
50
50
|
"rollup": "^3.15.0",
|
|
51
51
|
"rollup-plugin-copy": "^3.4.0",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"typescript": "^5.1.3"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@zephyr3d/base": "^0.1.
|
|
60
|
-
"@zephyr3d/device": "^0.1
|
|
59
|
+
"@zephyr3d/base": "^0.1.3",
|
|
60
|
+
"@zephyr3d/device": "^0.2.1"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@webgpu/types": "^0.1.31"
|