@zephyr3d/scene 0.2.0 → 0.3.1
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 +85 -93
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/camera/camera.js +1 -0
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +2538 -2326
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +5 -5
- package/dist/material/grassmaterial.js +14 -14
- package/dist/material/lightmodel.js +6 -7
- package/dist/material/lightmodel.js.map +1 -1
- package/dist/material/lit.js +5 -99
- package/dist/material/lit.js.map +1 -1
- package/dist/material/material.js +32 -54
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +215 -80
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +11 -7
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/foliage.js +7 -7
- package/dist/material/mixins/lightmodel/blinnphong.js +5 -5
- package/dist/material/mixins/lightmodel/lambert.js +5 -5
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +5 -5
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +8 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +72 -72
- package/dist/material/mixins/pbr/common.js +6 -4
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mixins/texture.js +6 -6
- package/dist/material/mixins/vertexcolor.js +7 -5
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/pbrmr.js +5 -5
- package/dist/material/pbrsg.js +9 -4
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +20 -18
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/terrainlightmodel.js +1 -3
- package/dist/material/terrainlightmodel.js.map +1 -1
- package/dist/material/terrainmaterial.js +12 -12
- package/dist/posteffect/bloom.js +1 -0
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +1 -0
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/water.js +1 -0
- package/dist/posteffect/water.js.map +1 -1
- package/dist/render/cull_visitor.js +24 -3
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/depth_pass.js +2 -3
- package/dist/render/depth_pass.js.map +1 -1
- package/dist/render/forward.js +6 -3
- package/dist/render/forward.js.map +1 -1
- package/dist/render/forward_pass.js +5 -6
- package/dist/render/forward_pass.js.map +1 -1
- package/dist/render/primitive.js +31 -0
- package/dist/render/primitive.js.map +1 -1
- package/dist/render/render_queue.js +111 -38
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +9 -0
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/sky.js +2 -4
- 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 +1 -0
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +8 -0
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +35 -2
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/octree.js +40 -75
- 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 +7 -17
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +57 -44
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/xform.js +61 -36
- package/dist/scene/xform.js.map +1 -1
- package/dist/shaders/lighting.js +10 -14
- package/dist/shaders/lighting.js.map +1 -1
- package/dist/shadow/esm.js +1 -0
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/shadowmapper.js +22 -6
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +1 -0
- 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/utility/noisetexture.js +66 -0
- package/dist/utility/noisetexture.js.map +1 -0
- package/dist/utility/textures/gradientnoise.js +66 -0
- package/dist/utility/textures/gradientnoise.js.map +1 -0
- package/dist/utility/textures/randomnoise.js +41 -0
- package/dist/utility/textures/randomnoise.js.map +1 -0
- package/package.json +6 -6
- package/dist/material/grassmat.js +0 -127
- package/dist/material/grassmat.js.map +0 -1
- package/dist/material/terrainmat.js +0 -357
- package/dist/material/terrainmat.js.map +0 -1
- package/dist/utility/sheenlut.js +0 -196
- package/dist/utility/sheenlut.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export { SceneRenderer } from './render/renderer.js';
|
|
|
15
15
|
export { LightPass } from './render/lightpass.js';
|
|
16
16
|
export { ShadowMapPass } from './render/shadowmap_pass.js';
|
|
17
17
|
export { DepthPass } from './render/depthpass.js';
|
|
18
|
-
export { RenderQueue } from './render/render_queue.js';
|
|
18
|
+
export { InstanceBindGroupAllocator, RenderQueue } from './render/render_queue.js';
|
|
19
19
|
export { SkyRenderer } from './render/sky.js';
|
|
20
20
|
export { Clipmap } from './render/clipmap.js';
|
|
21
21
|
export { EnvConstantAmbient, EnvHemisphericAmbient, EnvIBL, EnvironmentLighting } from './render/envlight.js';
|
|
@@ -51,6 +51,7 @@ export { Mesh } from './scene/mesh.js';
|
|
|
51
51
|
export { Model } from './scene/model.js';
|
|
52
52
|
export { Octree, OctreeNode, OctreeNodeChunk, OctreePlacement } from './scene/octree.js';
|
|
53
53
|
export { SceneNode } from './scene/scene_node.js';
|
|
54
|
+
export { BatchGroup } from './scene/batchgroup.js';
|
|
54
55
|
export { Terrain } from './scene/terrain/terrain.js';
|
|
55
56
|
export { HeightField, HeightfieldBBoxTree } from './scene/terrain/heightfield.js';
|
|
56
57
|
export { TerrainPatch } from './scene/terrain/patch.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/material/blinn.js
CHANGED
|
@@ -3,14 +3,14 @@ import { mixinVertexColor } from './mixins/vertexcolor.js';
|
|
|
3
3
|
import { mixinBlinnPhong } from './mixins/lightmodel/blinnphong.js';
|
|
4
4
|
import { ShaderHelper } from './shader/helper.js';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Blinn material
|
|
8
|
-
* @public
|
|
6
|
+
/**
|
|
7
|
+
* Blinn material
|
|
8
|
+
* @public
|
|
9
9
|
*/ class BlinnMaterial extends applyMaterialMixins(MeshMaterial, mixinBlinnPhong, mixinVertexColor) {
|
|
10
10
|
/** @internal */ static FEATURE_VERTEX_NORMAL = this.defineFeature();
|
|
11
11
|
/** @internal */ static FEATURE_VERTEX_TANGENT = this.defineFeature();
|
|
12
|
-
/**
|
|
13
|
-
* Creates an instance of BlinnMaterial class
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of BlinnMaterial class
|
|
14
14
|
*/ constructor(){
|
|
15
15
|
super();
|
|
16
16
|
this.useFeature(BlinnMaterial.FEATURE_VERTEX_NORMAL, true);
|
|
@@ -5,18 +5,18 @@ import { RENDER_PASS_TYPE_LIGHT } from '../values.js';
|
|
|
5
5
|
import { ShaderHelper } from './shader/helper.js';
|
|
6
6
|
import { mixinFoliage } from './mixins/foliage.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Terrain grass material
|
|
10
|
-
* @public
|
|
8
|
+
/**
|
|
9
|
+
* Terrain grass material
|
|
10
|
+
* @public
|
|
11
11
|
*/ class GrassMaterial extends applyMaterialMixins(MeshMaterial, mixinPBRMetallicRoughness, mixinFoliage) {
|
|
12
12
|
/** @internal */ _terrainSize;
|
|
13
13
|
/** @internal */ _terrainNormalMap;
|
|
14
14
|
/** @internal */ _textureSize;
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of GrassMaterial class
|
|
17
|
-
* @param terrainSize - terrain size
|
|
18
|
-
* @param normalMap - normal map
|
|
19
|
-
* @param grassTexture - grass texture
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of GrassMaterial class
|
|
17
|
+
* @param terrainSize - terrain size
|
|
18
|
+
* @param normalMap - normal map
|
|
19
|
+
* @param grassTexture - grass texture
|
|
20
20
|
*/ constructor(terrainSize, normalMap, grassTexture){
|
|
21
21
|
super();
|
|
22
22
|
this.metallic = 0;
|
|
@@ -31,15 +31,15 @@ import { mixinFoliage } from './mixins/foliage.js';
|
|
|
31
31
|
this._textureSize.setXY(grassTexture.width, grassTexture.height);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
35
|
-
* {@inheritDoc MeshMaterial.isTransparentPass}
|
|
36
|
-
* @override
|
|
34
|
+
/**
|
|
35
|
+
* {@inheritDoc MeshMaterial.isTransparentPass}
|
|
36
|
+
* @override
|
|
37
37
|
*/ isTransparentPass(pass) {
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
41
|
-
* {@inheritDoc Material.supportLighting}
|
|
42
|
-
* @override
|
|
40
|
+
/**
|
|
41
|
+
* {@inheritDoc Material.supportLighting}
|
|
42
|
+
* @override
|
|
43
43
|
*/ supportLighting() {
|
|
44
44
|
return true;
|
|
45
45
|
}
|
|
@@ -699,6 +699,7 @@ const TEX_NAME_CLEARCOAT_NORMAL = 'clearcoatNormal';
|
|
|
699
699
|
* Unlit light model
|
|
700
700
|
* @public
|
|
701
701
|
*/ class UnlitLightModel extends LightModel {
|
|
702
|
+
/** @internal */ static funcNameBRDFUnlit = 'libLM_brdfUnlit';
|
|
702
703
|
/**
|
|
703
704
|
* {@inheritDoc LightModel.supportLighting}
|
|
704
705
|
* @override
|
|
@@ -906,10 +907,10 @@ const TEX_NAME_CLEARCOAT_NORMAL = 'clearcoatNormal';
|
|
|
906
907
|
], function() {
|
|
907
908
|
this.$l.n = this.bits;
|
|
908
909
|
this.n = pb.compOr(pb.sal(this.n, 16), pb.sar(this.n, 16));
|
|
909
|
-
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x55555555), 1), pb.sar(pb.compAnd(this.n,
|
|
910
|
-
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x33333333), 2), pb.sar(pb.compAnd(this.n,
|
|
911
|
-
this.n = pb.compOr(pb.sal(pb.compAnd(this.n,
|
|
912
|
-
this.n = pb.compOr(pb.sal(pb.compAnd(this.n,
|
|
910
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x55555555), 1), pb.sar(pb.compAnd(this.n, 0xAAAAAAAA), 1));
|
|
911
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x33333333), 2), pb.sar(pb.compAnd(this.n, 0xCCCCCCCC), 2));
|
|
912
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x0F0F0F0F), 4), pb.sar(pb.compAnd(this.n, 0xF0F0F0F0), 4));
|
|
913
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x00FF00FF), 8), pb.sar(pb.compAnd(this.n, 0xFF00FF00), 8));
|
|
913
914
|
this.$return(pb.mul(pb.float(this.n), 2.3283064365386963e-10));
|
|
914
915
|
});
|
|
915
916
|
pb.func('hammersley2d', [
|
|
@@ -1038,9 +1039,7 @@ const TEX_NAME_CLEARCOAT_NORMAL = 'clearcoatNormal';
|
|
|
1038
1039
|
rs.useRasterizerState().setCullMode('none');
|
|
1039
1040
|
rs.useDepthState().enableTest(false).enableWrite(false);
|
|
1040
1041
|
const tex = device.createTexture2D('rgba8unorm', size, size, {
|
|
1041
|
-
|
|
1042
|
-
mipFilter: 'none'
|
|
1043
|
-
}
|
|
1042
|
+
noMipmap: true
|
|
1044
1043
|
});
|
|
1045
1044
|
tex.name = 'GGXLUT';
|
|
1046
1045
|
const fb = device.createFrameBuffer([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lightmodel.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lightmodel.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/material/lit.js
CHANGED
|
@@ -30,10 +30,7 @@ class LitMaterial extends MeshMaterial {
|
|
|
30
30
|
return this._normalScale;
|
|
31
31
|
}
|
|
32
32
|
set normalScale(val) {
|
|
33
|
-
|
|
34
|
-
this._normalScale = val;
|
|
35
|
-
this.optionChanged(false);
|
|
36
|
-
}
|
|
33
|
+
this._normalScale = val;
|
|
37
34
|
}
|
|
38
35
|
get normalMapMode() {
|
|
39
36
|
return this.featureUsed(LitMaterial.FEATURE_OBJECT_SPACE_NORMALMAP, RENDER_PASS_TYPE_FORWARD);
|
|
@@ -63,15 +60,11 @@ class LitMaterial extends MeshMaterial {
|
|
|
63
60
|
return this._normalTexture;
|
|
64
61
|
}
|
|
65
62
|
set normalTexture(tex) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXCOORD_INDEX, this._normalTexCoordIndex);
|
|
70
|
-
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXTURE_MATRIX, !!this._normalTexCoordMatrix);
|
|
71
|
-
}
|
|
72
|
-
this._normalTexture = tex ?? null;
|
|
73
|
-
this.optionChanged(false);
|
|
63
|
+
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXTURE, !!tex);
|
|
64
|
+
if (tex) {
|
|
65
|
+
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXCOORD_INDEX, this._normalTexCoordIndex);
|
|
74
66
|
}
|
|
67
|
+
this._normalTexture = tex ?? null;
|
|
75
68
|
}
|
|
76
69
|
/** Normal texture sampler */ get normalTextureSampler() {
|
|
77
70
|
return this._normalSampler;
|
|
@@ -99,7 +92,6 @@ class LitMaterial extends MeshMaterial {
|
|
|
99
92
|
if (this._normalTexture) {
|
|
100
93
|
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXTURE_MATRIX, !!this._normalTexCoordMatrix);
|
|
101
94
|
}
|
|
102
|
-
this.optionChanged(false);
|
|
103
95
|
}
|
|
104
96
|
}
|
|
105
97
|
/**
|
|
@@ -205,92 +197,6 @@ class LitMaterial extends MeshMaterial {
|
|
|
205
197
|
return pb.getGlobalScope().kkCalculateNormal(...args);
|
|
206
198
|
}
|
|
207
199
|
/**
|
|
208
|
-
* Calculate the normal vector for current fragment
|
|
209
|
-
* @param scope - The shader scope
|
|
210
|
-
* @param ctx - The drawing context
|
|
211
|
-
* @returns Structure that contains normal vector and TBN matrix
|
|
212
|
-
*/ calculateNormalAndTBN(scope, ctx) {
|
|
213
|
-
const pb = scope.$builder;
|
|
214
|
-
const NormalStruct = pb.defineStruct([
|
|
215
|
-
pb.mat3('TBN'),
|
|
216
|
-
pb.vec3('normal')
|
|
217
|
-
]);
|
|
218
|
-
const that = this;
|
|
219
|
-
const args = [];
|
|
220
|
-
const params = [];
|
|
221
|
-
const worldNormal = ShaderFramework.getWorldNormal(scope);
|
|
222
|
-
const worldTangent = ShaderFramework.getWorldTangent(scope);
|
|
223
|
-
const worldBinormal = ShaderFramework.getWorldBinormal(scope);
|
|
224
|
-
if (worldNormal) {
|
|
225
|
-
params.push(pb.vec3('worldNormal'));
|
|
226
|
-
args.push(worldNormal);
|
|
227
|
-
if (worldTangent) {
|
|
228
|
-
params.push(pb.vec3('worldTangent'), pb.vec3('worldBinormal'));
|
|
229
|
-
args.push(worldTangent, worldBinormal);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
pb.func('kkCalculateNormalAndTBN', params, function() {
|
|
233
|
-
const posW = ShaderFramework.getWorldPosition(this).xyz;
|
|
234
|
-
this.$l.uv = that.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type) ? scope.$inputs.kkNormalTexCoord ?? pb.vec2(0) : that.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type) ? scope.$inputs.kkAlbedoTexCoord ?? pb.vec2(0) : pb.vec2(0);
|
|
235
|
-
this.$l.TBN = pb.mat3();
|
|
236
|
-
if (!worldNormal) {
|
|
237
|
-
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
238
|
-
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
239
|
-
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
240
|
-
this.uv_dx = pb.vec3(1, 0, 0);
|
|
241
|
-
this.uv_dy = pb.vec3(0, 1, 0);
|
|
242
|
-
});
|
|
243
|
-
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(posW), this.uv_dy.y), pb.mul(pb.dpdy(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)));
|
|
244
|
-
this.$l.ng = pb.normalize(pb.cross(pb.dpdx(posW), pb.dpdy(posW)));
|
|
245
|
-
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
246
|
-
this.$l.b = pb.cross(this.ng, this.t);
|
|
247
|
-
if (that.doubleSidedLighting) {
|
|
248
|
-
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
249
|
-
this.t = pb.mul(this.t, -1);
|
|
250
|
-
this.b = pb.mul(this.b, -1);
|
|
251
|
-
this.ng = pb.mul(this.ng, -1);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
this.TBN = pb.mat3(this.t, this.b, this.ng);
|
|
255
|
-
} else if (!worldTangent) {
|
|
256
|
-
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
257
|
-
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
258
|
-
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
259
|
-
this.uv_dx = pb.vec3(1, 0, 0);
|
|
260
|
-
this.uv_dy = pb.vec3(0, 1, 0);
|
|
261
|
-
});
|
|
262
|
-
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(posW), this.uv_dy.y), pb.mul(pb.dpdy(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)));
|
|
263
|
-
this.$l.ng = pb.normalize(this.worldNormal);
|
|
264
|
-
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
265
|
-
this.$l.b = pb.cross(this.ng, this.t);
|
|
266
|
-
if (that.doubleSidedLighting) {
|
|
267
|
-
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
268
|
-
this.t = pb.mul(this.t, -1);
|
|
269
|
-
this.b = pb.mul(this.b, -1);
|
|
270
|
-
this.ng = pb.mul(this.ng, -1);
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
this.TBN = pb.mat3(this.t, this.b, this.ng);
|
|
274
|
-
} else {
|
|
275
|
-
this.TBN = pb.mat3(pb.normalize(this.worldTangent), pb.normalize(this.worldBinormal), pb.normalize(this.worldNormal));
|
|
276
|
-
}
|
|
277
|
-
if (that.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type)) {
|
|
278
|
-
if (that.normalMapMode === 'object-space') {
|
|
279
|
-
const pixel = pb.sub(pb.mul(pb.textureSample(this.kkNormalTexture, this.uv).rgb, 2), pb.vec3(1));
|
|
280
|
-
const normalTex = pb.mul(pixel, pb.vec3(pb.vec3(this.kkNormalScale).xx, 1));
|
|
281
|
-
this.$return(NormalStruct(this.TBN, pb.normalize(normalTex)));
|
|
282
|
-
} else {
|
|
283
|
-
const pixel = pb.sub(pb.mul(pb.textureSample(this.kkNormalTexture, this.uv).rgb, 2), pb.vec3(1));
|
|
284
|
-
const normalTex = pb.mul(pixel, pb.vec3(pb.vec3(this.kkNormalScale).xx, 1));
|
|
285
|
-
this.$return(NormalStruct(this.TBN, pb.normalize(pb.mul(this.TBN, normalTex))));
|
|
286
|
-
}
|
|
287
|
-
} else {
|
|
288
|
-
this.$return(NormalStruct(this.TBN, this.TBN[2]));
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
return pb.getGlobalScope().kkCalculateNormalAndTBN(...args);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
200
|
* {@inheritDoc MeshMaterial.applyUniformsValues}
|
|
295
201
|
* @override
|
|
296
202
|
*/ applyUniformValues(bindGroup, ctx) {
|
package/dist/material/lit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lit.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lit.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -4,48 +4,6 @@ import { Application } from '../app.js';
|
|
|
4
4
|
import { QUEUE_OPAQUE, RENDER_PASS_TYPE_LIGHT, RENDER_PASS_TYPE_SHADOWMAP, RENDER_PASS_TYPE_DEPTH } from '../values.js';
|
|
5
5
|
import { ShaderHelper } from './shader/helper.js';
|
|
6
6
|
|
|
7
|
-
class InstanceBindGroupPool {
|
|
8
|
-
_bindGroups;
|
|
9
|
-
_frameStamp;
|
|
10
|
-
constructor(){
|
|
11
|
-
this._bindGroups = [];
|
|
12
|
-
this._frameStamp = -1;
|
|
13
|
-
}
|
|
14
|
-
apply(hash, index, worldMatrices) {
|
|
15
|
-
const device = Application.instance.device;
|
|
16
|
-
const maxSize = device.getDeviceCaps().shaderCaps.maxUniformBufferSize;
|
|
17
|
-
if (device.frameInfo.frameCounter !== this._frameStamp) {
|
|
18
|
-
this._frameStamp = device.frameInfo.frameCounter;
|
|
19
|
-
for (const bindGroup of this._bindGroups){
|
|
20
|
-
bindGroup.freeSize = maxSize;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
let bindGroupIndex = -1;
|
|
24
|
-
for(let i = 0; i < this._bindGroups.length; i++){
|
|
25
|
-
if (this._bindGroups[i].freeSize >= worldMatrices.length * 64) {
|
|
26
|
-
bindGroupIndex = i;
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (bindGroupIndex < 0) {
|
|
31
|
-
const program = Material.getProgramByHashIndex(hash, index);
|
|
32
|
-
const bindGroup = program?.bindGroupLayouts[3] ? device.createBindGroup(program.bindGroupLayouts[3]) : null;
|
|
33
|
-
this._bindGroups.push({
|
|
34
|
-
bindGroup: bindGroup,
|
|
35
|
-
freeSize: maxSize
|
|
36
|
-
});
|
|
37
|
-
bindGroupIndex = this._bindGroups.length - 1;
|
|
38
|
-
}
|
|
39
|
-
const bindGroup = this._bindGroups[bindGroupIndex];
|
|
40
|
-
const offset = (maxSize - bindGroup.freeSize) / 64;
|
|
41
|
-
for (const matrix of worldMatrices){
|
|
42
|
-
bindGroup.bindGroup.setRawData(ShaderHelper.getWorldMatricesUniformName(), maxSize - bindGroup.freeSize, matrix);
|
|
43
|
-
bindGroup.freeSize -= 64;
|
|
44
|
-
}
|
|
45
|
-
device.setBindGroup(3, bindGroup.bindGroup);
|
|
46
|
-
return offset;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
7
|
/**
|
|
50
8
|
* Base class for any kind of materials
|
|
51
9
|
*
|
|
@@ -66,7 +24,7 @@ class InstanceBindGroupPool {
|
|
|
66
24
|
inactiveTimeDuration: 30000
|
|
67
25
|
};
|
|
68
26
|
/** @internal */ static _boneMatrixTextureSampler = null;
|
|
69
|
-
/** @internal */ static _instanceBindGroupPool = new InstanceBindGroupPool();
|
|
27
|
+
/** @internal */ //private static _instanceBindGroupPool: InstanceBindGroupPool = new InstanceBindGroupPool();
|
|
70
28
|
/** @internal */ static _drawableBindGroupMap = new WeakMap();
|
|
71
29
|
/** @internal */ _numPasses;
|
|
72
30
|
/** @internal */ _hash;
|
|
@@ -88,7 +46,7 @@ class InstanceBindGroupPool {
|
|
|
88
46
|
this._optionTag = 0;
|
|
89
47
|
this._materialBindGroup = null;
|
|
90
48
|
}
|
|
91
|
-
/** Unique identifier of the material */ get
|
|
49
|
+
/** Unique identifier of the material */ get instanceId() {
|
|
92
50
|
return this._id;
|
|
93
51
|
}
|
|
94
52
|
get numPasses() {
|
|
@@ -125,7 +83,7 @@ class InstanceBindGroupPool {
|
|
|
125
83
|
return true;
|
|
126
84
|
}
|
|
127
85
|
/** Returns true if this material supports geometry instancing */ isBatchable() {
|
|
128
|
-
return
|
|
86
|
+
return false;
|
|
129
87
|
}
|
|
130
88
|
/**
|
|
131
89
|
* Draws a primitive using this material
|
|
@@ -146,7 +104,6 @@ class InstanceBindGroupPool {
|
|
|
146
104
|
* @param ctx - The context of current drawing task
|
|
147
105
|
* @returns true if succeeded, otherwise false
|
|
148
106
|
*/ beginDraw(pass, ctx) {
|
|
149
|
-
const numInstances = ctx.instanceData?.worldMatrices?.length || 1;
|
|
150
107
|
const device = Application.instance.device;
|
|
151
108
|
const programInfo = this.getOrCreateProgram(ctx, pass);
|
|
152
109
|
if (programInfo) {
|
|
@@ -159,7 +116,7 @@ class InstanceBindGroupPool {
|
|
|
159
116
|
}
|
|
160
117
|
this._materialBindGroup = this.applyMaterialBindGroups(ctx, hash, pass);
|
|
161
118
|
if (pass === 0) {
|
|
162
|
-
if (
|
|
119
|
+
if (ctx.instanceData) {
|
|
163
120
|
this.applyInstanceBindGroups(ctx, hash);
|
|
164
121
|
} else {
|
|
165
122
|
this.applyDrawableBindGroups(ctx, hash);
|
|
@@ -203,7 +160,7 @@ class InstanceBindGroupPool {
|
|
|
203
160
|
*/ getOrCreateProgram(ctx, pass) {
|
|
204
161
|
const programMap = Material._programMap;
|
|
205
162
|
const renderPassType = ctx.renderPass.type;
|
|
206
|
-
const hash = `${this.getHash(renderPassType, pass)}:${!!ctx.target.getBoneMatrices()}:${Number(!!
|
|
163
|
+
const hash = `${this.getHash(renderPassType, pass)}:${!!ctx.target.getBoneMatrices()}:${Number(!!ctx.instanceData)}:${ctx.renderPassHash}`;
|
|
207
164
|
let programInfo = programMap[hash];
|
|
208
165
|
if (!programInfo || programInfo.programs[renderPassType] === undefined) {
|
|
209
166
|
const program = this.createProgram(ctx, pass) ?? null;
|
|
@@ -363,11 +320,20 @@ class InstanceBindGroupPool {
|
|
|
363
320
|
return drawableBindGroup;
|
|
364
321
|
}
|
|
365
322
|
/** @internal */ applyInstanceBindGroups(ctx, hash) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
323
|
+
if (ctx.instanceData) {
|
|
324
|
+
if (ctx.instanceData.bindGroup.dirty) {
|
|
325
|
+
ctx.instanceData.bindGroup.bindGroup.setRawData(ShaderHelper.getWorldMatricesUniformName(), 0, ctx.instanceData.bindGroup.buffer, 0, ctx.instanceData.currentSize * 4);
|
|
326
|
+
ctx.instanceData.bindGroup.dirty = false;
|
|
327
|
+
}
|
|
328
|
+
Application.instance.device.setBindGroup(3, ctx.instanceData.bindGroup.bindGroup ?? null);
|
|
329
|
+
} else {
|
|
330
|
+
Application.instance.device.setBindGroup(3, null);
|
|
331
|
+
}
|
|
332
|
+
const bindGroup = this.getDrawableBindGroup(ctx, hash).bindGroup?.[ctx.renderPass.type];
|
|
369
333
|
if (bindGroup) {
|
|
370
|
-
|
|
334
|
+
if (ctx.instanceData) {
|
|
335
|
+
bindGroup.setValue(ShaderHelper.getInstanceBufferStrideUniformName(), ctx.instanceData.stride);
|
|
336
|
+
}
|
|
371
337
|
Application.instance.device.setBindGroup(1, bindGroup);
|
|
372
338
|
} else {
|
|
373
339
|
Application.instance.device.setBindGroup(1, null);
|
|
@@ -460,8 +426,8 @@ class InstanceBindGroupPool {
|
|
|
460
426
|
*/ drawPrimitive(pass, primitive, ctx, numInstances) {
|
|
461
427
|
if (numInstances > 0) {
|
|
462
428
|
primitive.drawInstanced(numInstances);
|
|
463
|
-
} else if (ctx.instanceData
|
|
464
|
-
primitive.drawInstanced(ctx.instanceData.
|
|
429
|
+
} else if (ctx.instanceData) {
|
|
430
|
+
primitive.drawInstanced(ctx.instanceData.currentSize / ctx.instanceData.stride);
|
|
465
431
|
} else {
|
|
466
432
|
primitive.draw();
|
|
467
433
|
}
|
|
@@ -493,6 +459,18 @@ class InstanceBindGroupPool {
|
|
|
493
459
|
*/ _createHash(renderPassType) {
|
|
494
460
|
return '';
|
|
495
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* True if this is a material instance
|
|
464
|
+
* @internal
|
|
465
|
+
**/ get $isInstance() {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Returns the instance uniforms if this is a material instance
|
|
470
|
+
* @internal
|
|
471
|
+
**/ get $instanceUniforms() {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
496
474
|
}
|
|
497
475
|
|
|
498
476
|
export { Material };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"material.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"material.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|