@zephyr3d/scene 0.1.2 → 0.2.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 +124 -67
- 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 +10 -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 +1842 -2484
- package/dist/index.js +21 -10
- 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 +66 -194
- 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 +100 -59
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +227 -186
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +29 -100
- 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 +903 -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 +311 -103
- 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 +8 -6
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +14 -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 +10 -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/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/render_queue.js +2 -1
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +191 -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 +31 -15
- package/dist/render/sky.js.map +1 -1
- package/dist/scene/environment.js +8 -6
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +3 -0
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +13 -12
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/scene.js +11 -15
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +10 -16
- 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/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 +11 -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 +13 -15
- 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 +15 -13
- package/dist/shadow/vsm.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 +3 -3
package/dist/posteffect/water.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { Application } from '../app.js';
|
|
2
2
|
import { Vector4, Interpolator, Vector2, Plane, Matrix4x4, Vector3 } from '@zephyr3d/base';
|
|
3
3
|
import '../scene/octree.js';
|
|
4
|
-
import '../material/
|
|
5
|
-
import '@zephyr3d/device';
|
|
6
|
-
import '../shaders/framework.js';
|
|
7
|
-
import { decodeNormalizedFloatFromRGBA, linearToGamma } from '../shaders/misc.js';
|
|
8
|
-
import '../render/scatteringlut.js';
|
|
4
|
+
import '../material/shader/helper.js';
|
|
9
5
|
import '../material/lambert.js';
|
|
10
6
|
import '../material/blinn.js';
|
|
11
7
|
import '../material/unlit.js';
|
|
12
|
-
import '../material/
|
|
13
|
-
import '../
|
|
8
|
+
import '../material/material.js';
|
|
9
|
+
import '../material/meshmaterial.js';
|
|
10
|
+
import '../material/grassmaterial.js';
|
|
11
|
+
import '../material/terrainmaterial.js';
|
|
12
|
+
import '../material/pbrmr.js';
|
|
13
|
+
import '../material/pbrsg.js';
|
|
14
|
+
import '../render/renderer.js';
|
|
14
15
|
import '../render/sky.js';
|
|
15
16
|
import '../render/clipmap.js';
|
|
16
17
|
import { TemporalCache } from '../render/temporalcache.js';
|
|
17
18
|
import { WaterMesh } from '../render/watermesh.js';
|
|
18
19
|
import { AbstractPostEffect } from './posteffect.js';
|
|
20
|
+
import { decodeNormalizedFloatFromRGBA, linearToGamma } from '../shaders/misc.js';
|
|
19
21
|
import { Camera } from '../camera/camera.js';
|
|
20
22
|
import { CopyBlitter } from '../blitter/copy.js';
|
|
21
23
|
import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
@@ -105,7 +107,7 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
105
107
|
0.41,
|
|
106
108
|
0.34,
|
|
107
109
|
0.13,
|
|
108
|
-
0.
|
|
110
|
+
0.4,
|
|
109
111
|
0.45,
|
|
110
112
|
0.21,
|
|
111
113
|
0.5,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"water.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"water.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Vector4, Matrix4x4 } from '@zephyr3d/base';
|
|
2
2
|
import { Application } from '../app.js';
|
|
3
3
|
import { MAX_CLUSTERED_LIGHTS } from '../values.js';
|
|
4
|
+
import { ShaderHelper } from '../material/shader/helper.js';
|
|
4
5
|
|
|
5
6
|
class ClusteredLight {
|
|
6
7
|
_tileCountX;
|
|
@@ -90,7 +91,7 @@ class ClusteredLight {
|
|
|
90
91
|
this.viewMatrix = pb.mat4().uniform(0);
|
|
91
92
|
this.sizeParam = pb.vec4().uniform(0);
|
|
92
93
|
this.countParam = pb.ivec4().uniform(0);
|
|
93
|
-
this.
|
|
94
|
+
this[ShaderHelper.getLightBufferUniformName()] = pb.vec4[(MAX_CLUSTERED_LIGHTS + 1) * 3]().uniformBuffer(0);
|
|
94
95
|
pb.func('lineIntersectionToZPlane', [
|
|
95
96
|
pb.vec3('a'),
|
|
96
97
|
pb.vec3('b'),
|
|
@@ -173,7 +174,7 @@ class ClusteredLight {
|
|
|
173
174
|
this.$if(pb.equal(this.i, this.countParam.w), function() {
|
|
174
175
|
this.$break();
|
|
175
176
|
});
|
|
176
|
-
this.$l.light = this.
|
|
177
|
+
this.$l.light = this[ShaderHelper.getLightBufferUniformName()].at(pb.mul(this.i, 3));
|
|
177
178
|
this.$l.lightPos = pb.mul(this.viewMatrix, pb.vec4(this.light.xyz, 1));
|
|
178
179
|
this.$l.lightPos.w = this.light.w;
|
|
179
180
|
this.$if(this.sphereIntersectsAABB(this.lightPos, this.aabbMin, this.aabbMax), function() {
|
|
@@ -213,7 +214,7 @@ class ClusteredLight {
|
|
|
213
214
|
pb.uint(0)
|
|
214
215
|
];
|
|
215
216
|
this.$for(pb.uint('i'), 1, pb.uint(this.countParam.w), function() {
|
|
216
|
-
this.$l.light = this.
|
|
217
|
+
this.$l.light = this[ShaderHelper.getLightBufferUniformName()].at(pb.mul(this.i, 3));
|
|
217
218
|
this.$l.lightPos = pb.mul(this.viewMatrix, pb.vec4(this.light.xyz, 1));
|
|
218
219
|
this.$l.lightPos.w = this.light.w;
|
|
219
220
|
this.$if(this.sphereIntersectsAABB(this.lightPos, this.aabbMin, this.aabbMax), function() {
|
|
@@ -241,7 +242,7 @@ class ClusteredLight {
|
|
|
241
242
|
});
|
|
242
243
|
this._bindGroup = device.createBindGroup(this._lightIndexProgram.bindGroupLayouts[0]);
|
|
243
244
|
this._lightBuffer?.dispose();
|
|
244
|
-
const lightBufferType = this._lightIndexProgram.getBindingInfo(
|
|
245
|
+
const lightBufferType = this._lightIndexProgram.getBindingInfo(ShaderHelper.getLightBufferUniformName()).type;
|
|
245
246
|
this._lightBuffer = device.createStructuredBuffer(lightBufferType, {
|
|
246
247
|
usage: 'uniform'
|
|
247
248
|
});
|
|
@@ -300,7 +301,7 @@ class ClusteredLight {
|
|
|
300
301
|
this._bindGroup.setValue('viewMatrix', camera.viewMatrix);
|
|
301
302
|
this._bindGroup.setValue('sizeParam', this._sizeParam);
|
|
302
303
|
this._bindGroup.setValue('countParam', this._countParam);
|
|
303
|
-
this._bindGroup.setBuffer(
|
|
304
|
+
this._bindGroup.setBuffer(ShaderHelper.getLightBufferUniformName(), this._lightBuffer);
|
|
304
305
|
device.setProgram(this._lightIndexProgram);
|
|
305
306
|
device.setVertexLayout(this._lightIndexVertexLayout);
|
|
306
307
|
device.setBindGroup(0, this._bindGroup);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cluster_light.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cluster_light.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { RenderPass } from './renderpass.js';
|
|
2
|
+
import { RENDER_PASS_TYPE_DEPTH } from '../values.js';
|
|
3
|
+
import { Application } from '../app.js';
|
|
4
|
+
import { ShaderHelper } from '../material/shader/helper.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Depth render pass
|
|
8
|
+
*
|
|
9
|
+
* Scene depth render pass
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/ class DepthPass extends RenderPass {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of DepthRenderPass
|
|
15
|
+
*/ constructor(){
|
|
16
|
+
super(RENDER_PASS_TYPE_DEPTH);
|
|
17
|
+
}
|
|
18
|
+
/** @internal */ _getGlobalBindGroupHash(ctx) {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
/** @internal */ renderItems(ctx, renderQueue) {
|
|
22
|
+
ctx.target = null;
|
|
23
|
+
ctx.applyFog = false;
|
|
24
|
+
ctx.drawEnvLight = false;
|
|
25
|
+
ctx.env = null;
|
|
26
|
+
ctx.renderPassHash = null;
|
|
27
|
+
ctx.flip = this.isAutoFlip();
|
|
28
|
+
const device = Application.instance.device;
|
|
29
|
+
const bindGroup = this.getGlobalBindGroupInfo(ctx).bindGroup;
|
|
30
|
+
device.setBindGroup(0, bindGroup);
|
|
31
|
+
ShaderHelper.setCameraUniforms(bindGroup, ctx, true);
|
|
32
|
+
ctx.renderPassHash = this.getGlobalBindGroupHash(ctx);
|
|
33
|
+
const reverseWinding = ctx.camera.worldMatrixDet < 0;
|
|
34
|
+
for (const order of Object.keys(renderQueue.items).map((val)=>Number(val)).sort((a, b)=>a - b)){
|
|
35
|
+
const renderItems = renderQueue.items[order];
|
|
36
|
+
for (const item of renderItems.opaqueList){
|
|
37
|
+
ctx.instanceData = item.instanceData;
|
|
38
|
+
ctx.target = item.drawable;
|
|
39
|
+
this.drawItem(device, item, ctx, reverseWinding);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { DepthPass };
|
|
46
|
+
//# sourceMappingURL=depthpass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"depthpass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/render/envlight.js
CHANGED
|
@@ -28,9 +28,9 @@ import { Application } from '../app.js';
|
|
|
28
28
|
* IBL based environment lighting
|
|
29
29
|
* @public
|
|
30
30
|
*/ class EnvIBL extends EnvironmentLighting {
|
|
31
|
-
/** @internal */ static
|
|
32
|
-
/** @internal */ static
|
|
33
|
-
/** @internal */ static
|
|
31
|
+
/** @internal */ static UNIFORM_NAME_IBL_RADIANCE_MAP = 'zIBLRadianceMap';
|
|
32
|
+
/** @internal */ static UNIFORM_NAME_IBL_RADIANCE_MAP_MAX_LOD = 'zIBLRadianceMapMaxLOD';
|
|
33
|
+
/** @internal */ static UNIFORM_NAME_IBL_IRRADIANCE_MAP = 'zIBLIrradianceMap';
|
|
34
34
|
/** @internal */ _radianceMap;
|
|
35
35
|
/** @internal */ _irradianceMap;
|
|
36
36
|
/**
|
|
@@ -65,9 +65,13 @@ import { Application } from '../app.js';
|
|
|
65
65
|
* @override
|
|
66
66
|
*/ initShaderBindings(pb) {
|
|
67
67
|
if (pb.shaderKind === 'fragment') {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
if (this._radianceMap) {
|
|
69
|
+
pb.getGlobalScope()[EnvIBL.UNIFORM_NAME_IBL_RADIANCE_MAP] = pb.texCube().uniform(0);
|
|
70
|
+
pb.getGlobalScope()[EnvIBL.UNIFORM_NAME_IBL_RADIANCE_MAP_MAX_LOD] = pb.float().uniform(0);
|
|
71
|
+
}
|
|
72
|
+
if (this._irradianceMap) {
|
|
73
|
+
pb.getGlobalScope()[EnvIBL.UNIFORM_NAME_IBL_IRRADIANCE_MAP] = pb.texCube().uniform(0);
|
|
74
|
+
}
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
@@ -75,11 +79,11 @@ import { Application } from '../app.js';
|
|
|
75
79
|
* @override
|
|
76
80
|
*/ updateBindGroup(bg) {
|
|
77
81
|
if (this._radianceMap) {
|
|
78
|
-
bg.setValue(
|
|
79
|
-
bg.setTexture(
|
|
82
|
+
bg.setValue(EnvIBL.UNIFORM_NAME_IBL_RADIANCE_MAP_MAX_LOD, this._radianceMap.mipLevelCount - 1);
|
|
83
|
+
bg.setTexture(EnvIBL.UNIFORM_NAME_IBL_RADIANCE_MAP, this._radianceMap);
|
|
80
84
|
}
|
|
81
85
|
if (this._irradianceMap) {
|
|
82
|
-
bg.setTexture(
|
|
86
|
+
bg.setTexture(EnvIBL.UNIFORM_NAME_IBL_IRRADIANCE_MAP, this._irradianceMap);
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
/**
|
|
@@ -87,14 +91,14 @@ import { Application } from '../app.js';
|
|
|
87
91
|
* @override
|
|
88
92
|
*/ getRadiance(scope, refl, roughness) {
|
|
89
93
|
const pb = scope.$builder;
|
|
90
|
-
return Application.instance.device.getDeviceCaps().shaderCaps.supportShaderTextureLod ? pb.textureSampleLevel(scope.
|
|
94
|
+
return Application.instance.device.getDeviceCaps().shaderCaps.supportShaderTextureLod ? pb.textureSampleLevel(scope[EnvIBL.UNIFORM_NAME_IBL_RADIANCE_MAP], refl, pb.mul(roughness, scope[EnvIBL.UNIFORM_NAME_IBL_RADIANCE_MAP_MAX_LOD])).rgb : pb.textureSample(scope[EnvIBL.UNIFORM_NAME_IBL_RADIANCE_MAP], refl).rgb;
|
|
91
95
|
}
|
|
92
96
|
/**
|
|
93
97
|
* {@inheritDoc EnvironmentLighting.getIrradiance}
|
|
94
98
|
* @override
|
|
95
99
|
*/ getIrradiance(scope, normal) {
|
|
96
100
|
const pb = scope.$builder;
|
|
97
|
-
return pb.textureSampleLevel(scope.
|
|
101
|
+
return pb.textureSampleLevel(scope[EnvIBL.UNIFORM_NAME_IBL_IRRADIANCE_MAP], normal, 0).rgb;
|
|
98
102
|
}
|
|
99
103
|
/**
|
|
100
104
|
* {@inheritDoc EnvironmentLighting.hasRadiance}
|
|
@@ -119,8 +123,7 @@ import { Application } from '../app.js';
|
|
|
119
123
|
* Constant ambient light
|
|
120
124
|
* @public
|
|
121
125
|
*/ class EnvConstantAmbient extends EnvironmentLighting {
|
|
122
|
-
/** @internal */ static
|
|
123
|
-
/** @internal */ static funcNameGetAmbient = 'lib_getConstantAmbient';
|
|
126
|
+
/** @internal */ static UNIFORM_NAME_CONSTANT_AMBIENT = 'zConstantAmbient';
|
|
124
127
|
/** @internal */ _ambientColor;
|
|
125
128
|
/**
|
|
126
129
|
* Creates an instance of EnvConstantAmbient
|
|
@@ -148,14 +151,14 @@ import { Application } from '../app.js';
|
|
|
148
151
|
* @override
|
|
149
152
|
*/ initShaderBindings(pb) {
|
|
150
153
|
if (pb.shaderKind === 'fragment') {
|
|
151
|
-
pb.getGlobalScope().
|
|
154
|
+
pb.getGlobalScope()[EnvConstantAmbient.UNIFORM_NAME_CONSTANT_AMBIENT] = pb.vec4().uniform(0);
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
/**
|
|
155
158
|
* {@inheritDoc EnvironmentLighting.updateBindGroup}
|
|
156
159
|
* @override
|
|
157
160
|
*/ updateBindGroup(bg) {
|
|
158
|
-
bg.setValue(
|
|
161
|
+
bg.setValue(EnvConstantAmbient.UNIFORM_NAME_CONSTANT_AMBIENT, this._ambientColor);
|
|
159
162
|
}
|
|
160
163
|
/**
|
|
161
164
|
* {@inheritDoc EnvironmentLighting.getRadiance}
|
|
@@ -167,7 +170,7 @@ import { Application } from '../app.js';
|
|
|
167
170
|
* {@inheritDoc EnvironmentLighting.getIrradiance}
|
|
168
171
|
* @override
|
|
169
172
|
*/ getIrradiance(scope, normal) {
|
|
170
|
-
return scope.
|
|
173
|
+
return scope[EnvConstantAmbient.UNIFORM_NAME_CONSTANT_AMBIENT].rgb;
|
|
171
174
|
}
|
|
172
175
|
/**
|
|
173
176
|
* {@inheritDoc EnvironmentLighting.hasRadiance}
|
|
@@ -192,9 +195,8 @@ import { Application } from '../app.js';
|
|
|
192
195
|
* Hemispheric ambient light
|
|
193
196
|
* @public
|
|
194
197
|
*/ class EnvHemisphericAmbient extends EnvironmentLighting {
|
|
195
|
-
/** @internal */ static
|
|
196
|
-
/** @internal */ static
|
|
197
|
-
/** @internal */ static funcNameGetAmbient = 'lib_getConstantAmbient';
|
|
198
|
+
/** @internal */ static UNIFORM_NAME_AMBIENT_UP = 'zHemisphericAmbientUp';
|
|
199
|
+
/** @internal */ static UNIFORM_NAME_AMBIENT_DOWN = 'zHemisphericAmbientDown';
|
|
198
200
|
/** @internal */ _ambientUp;
|
|
199
201
|
/** @internal */ _ambientDown;
|
|
200
202
|
/**
|
|
@@ -233,16 +235,16 @@ import { Application } from '../app.js';
|
|
|
233
235
|
* @override
|
|
234
236
|
*/ initShaderBindings(pb) {
|
|
235
237
|
if (pb.shaderKind === 'fragment') {
|
|
236
|
-
pb.getGlobalScope().
|
|
237
|
-
pb.getGlobalScope().
|
|
238
|
+
pb.getGlobalScope()[EnvHemisphericAmbient.UNIFORM_NAME_AMBIENT_UP] = pb.vec4().uniform(0);
|
|
239
|
+
pb.getGlobalScope()[EnvHemisphericAmbient.UNIFORM_NAME_AMBIENT_DOWN] = pb.vec4().uniform(0);
|
|
238
240
|
}
|
|
239
241
|
}
|
|
240
242
|
/**
|
|
241
243
|
* {@inheritDoc EnvironmentLighting.updateBindGroup}
|
|
242
244
|
* @override
|
|
243
245
|
*/ updateBindGroup(bg) {
|
|
244
|
-
bg.setValue(
|
|
245
|
-
bg.setValue(
|
|
246
|
+
bg.setValue(EnvHemisphericAmbient.UNIFORM_NAME_AMBIENT_UP, this._ambientUp);
|
|
247
|
+
bg.setValue(EnvHemisphericAmbient.UNIFORM_NAME_AMBIENT_DOWN, this._ambientDown);
|
|
246
248
|
}
|
|
247
249
|
/**
|
|
248
250
|
* {@inheritDoc EnvironmentLighting.getRadiance}
|
|
@@ -256,7 +258,7 @@ import { Application } from '../app.js';
|
|
|
256
258
|
*/ getIrradiance(scope, normal) {
|
|
257
259
|
const pb = scope.$builder;
|
|
258
260
|
const factor = pb.add(pb.mul(normal.y, 0.5), 0.5);
|
|
259
|
-
return pb.mix(scope.
|
|
261
|
+
return pb.mix(scope[EnvHemisphericAmbient.UNIFORM_NAME_AMBIENT_DOWN], scope[EnvHemisphericAmbient.UNIFORM_NAME_AMBIENT_UP], factor).rgb;
|
|
260
262
|
}
|
|
261
263
|
/**
|
|
262
264
|
* {@inheritDoc EnvironmentLighting.hasRadiance}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envlight.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"envlight.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Application } from '../app.js';
|
|
2
|
+
|
|
3
|
+
let quadVertexLayout = null;
|
|
4
|
+
let quadRenderStateSet = null;
|
|
5
|
+
function drawFullscreenQuad(renderStates) {
|
|
6
|
+
const device = Application.instance.device;
|
|
7
|
+
if (!quadVertexLayout) {
|
|
8
|
+
quadVertexLayout = device.createVertexLayout({
|
|
9
|
+
vertexBuffers: [
|
|
10
|
+
{
|
|
11
|
+
buffer: device.createVertexBuffer('position_f32x2', new Float32Array([
|
|
12
|
+
-1,
|
|
13
|
+
-1,
|
|
14
|
+
1,
|
|
15
|
+
-1,
|
|
16
|
+
-1,
|
|
17
|
+
1,
|
|
18
|
+
1,
|
|
19
|
+
1
|
|
20
|
+
]))
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (!quadRenderStateSet) {
|
|
26
|
+
quadRenderStateSet = device.createRenderStateSet();
|
|
27
|
+
quadRenderStateSet.useRasterizerState().setCullMode('none');
|
|
28
|
+
quadRenderStateSet.useDepthState().enableTest(false).enableWrite(false);
|
|
29
|
+
}
|
|
30
|
+
const saveRenderStateSet = device.getRenderStates();
|
|
31
|
+
device.setRenderStates(renderStates ?? quadRenderStateSet);
|
|
32
|
+
device.setVertexLayout(quadVertexLayout);
|
|
33
|
+
device.draw('triangle-strip', 0, 4);
|
|
34
|
+
device.setRenderStates(saveRenderStateSet);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { drawFullscreenQuad };
|
|
38
|
+
//# sourceMappingURL=fullscreenquad.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fullscreenquad.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { RenderPass } from './renderpass.js';
|
|
2
|
+
import { RENDER_PASS_TYPE_LIGHT, QUEUE_OPAQUE, QUEUE_TRANSPARENT } from '../values.js';
|
|
3
|
+
import { Application } from '../app.js';
|
|
4
|
+
import { Vector4 } from '@zephyr3d/base';
|
|
5
|
+
import { ShaderHelper } from '../material/shader/helper.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Forward render pass
|
|
9
|
+
* @internal
|
|
10
|
+
*/ class LightPass extends RenderPass {
|
|
11
|
+
/** @internal */ _shadowMapHash;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of ForwardRenderPass
|
|
14
|
+
*/ constructor(){
|
|
15
|
+
super(RENDER_PASS_TYPE_LIGHT);
|
|
16
|
+
this._shadowMapHash = null;
|
|
17
|
+
}
|
|
18
|
+
/** @internal */ _getGlobalBindGroupHash(ctx) {
|
|
19
|
+
return `${this._shadowMapHash}:${ctx.env.getHash(ctx)}`;
|
|
20
|
+
}
|
|
21
|
+
/** @internal */ renderLightPass(ctx, items, lights) {
|
|
22
|
+
const device = Application.instance.device;
|
|
23
|
+
const baseLightPass = !ctx.lightBlending;
|
|
24
|
+
ctx.drawEnvLight = baseLightPass && ctx.env.light.type !== 'none' && (ctx.env.light.envLight.hasRadiance() || ctx.env.light.envLight.hasIrradiance());
|
|
25
|
+
ctx.renderPassHash = this.getGlobalBindGroupHash(ctx);
|
|
26
|
+
const info = this.getGlobalBindGroupInfo(ctx);
|
|
27
|
+
ShaderHelper.setCameraUniforms(info.bindGroup, ctx, !!device.getFramebuffer());
|
|
28
|
+
if (ctx.currentShadowLight) {
|
|
29
|
+
ShaderHelper.setLightUniformsShadow(info.bindGroup, ctx, lights[0]);
|
|
30
|
+
} else {
|
|
31
|
+
ShaderHelper.setLightUniforms(info.bindGroup, ctx, ctx.clusteredLight.clusterParam, ctx.clusteredLight.countParam, ctx.clusteredLight.lightBuffer, ctx.clusteredLight.lightIndexTexture);
|
|
32
|
+
}
|
|
33
|
+
if (ctx.applyFog) {
|
|
34
|
+
ShaderHelper.setFogUniforms(info.bindGroup, ctx.env.sky.mappedFogType, baseLightPass ? ctx.env.sky.fogColor : Vector4.zero(), ctx.env.sky.fogParams, ctx.env.sky.aerialPerspectiveDensity * ctx.env.sky.aerialPerspectiveDensity, ctx.env.sky.getAerialPerspectiveLUT(ctx));
|
|
35
|
+
}
|
|
36
|
+
device.setBindGroup(0, info.bindGroup);
|
|
37
|
+
const reverseWinding = ctx.camera.worldMatrixDet < 0;
|
|
38
|
+
for (const item of items){
|
|
39
|
+
// unlit objects should only be drawn once
|
|
40
|
+
if (!ctx.lightBlending || !item.drawable.isUnlit()) {
|
|
41
|
+
ctx.instanceData = item.instanceData;
|
|
42
|
+
ctx.target = item.drawable;
|
|
43
|
+
this.drawItem(device, item, ctx, reverseWinding);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** @internal */ renderItems(ctx, renderQueue) {
|
|
48
|
+
ctx.applyFog = false;
|
|
49
|
+
ctx.target = null;
|
|
50
|
+
ctx.renderPassHash = null;
|
|
51
|
+
ctx.env = ctx.scene.env;
|
|
52
|
+
ctx.drawEnvLight = false;
|
|
53
|
+
ctx.flip = this.isAutoFlip();
|
|
54
|
+
renderQueue.sortItems();
|
|
55
|
+
const orders = Object.keys(renderQueue.items).map((val)=>Number(val)).sort((a, b)=>a - b);
|
|
56
|
+
for(let i = 0; i < 2; i++){
|
|
57
|
+
ctx.applyFog = i === 1 && ctx.env.sky.fogType !== 'none';
|
|
58
|
+
ctx.queue = i === 0 ? QUEUE_OPAQUE : QUEUE_TRANSPARENT;
|
|
59
|
+
for (const order of orders){
|
|
60
|
+
const items = renderQueue.items[order];
|
|
61
|
+
const lists = [
|
|
62
|
+
items.opaqueList,
|
|
63
|
+
items.transList
|
|
64
|
+
];
|
|
65
|
+
const list = lists[i];
|
|
66
|
+
let lightIndex = 0;
|
|
67
|
+
if (ctx.shadowMapInfo) {
|
|
68
|
+
for (const k of ctx.shadowMapInfo.keys()){
|
|
69
|
+
ctx.currentShadowLight = k;
|
|
70
|
+
ctx.lightBlending = lightIndex > 0;
|
|
71
|
+
this._shadowMapHash = ctx.shadowMapInfo.get(k).shaderHash;
|
|
72
|
+
this.renderLightPass(ctx, list, [
|
|
73
|
+
k
|
|
74
|
+
]);
|
|
75
|
+
lightIndex++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (lightIndex === 0 || renderQueue.unshadowedLights.length > 0) {
|
|
79
|
+
ctx.currentShadowLight = null;
|
|
80
|
+
ctx.lightBlending = lightIndex > 0;
|
|
81
|
+
this._shadowMapHash = '';
|
|
82
|
+
this.renderLightPass(ctx, list, renderQueue.unshadowedLights);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (i === 0) {
|
|
86
|
+
ctx.env.sky.skyWorldMatrix = ctx.scene.rootNode.worldMatrix;
|
|
87
|
+
ctx.env.sky.renderSky(ctx);
|
|
88
|
+
}
|
|
89
|
+
ctx.compositor?.drawPostEffects(ctx, i === 0, ctx.linearDepthTexture);
|
|
90
|
+
if (i === 0) {
|
|
91
|
+
ctx.env.sky.renderFog(ctx);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { LightPass };
|
|
98
|
+
//# sourceMappingURL=lightpass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightpass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Application } from '../app.js';
|
|
2
|
+
import { QUEUE_TRANSPARENT } from '../values.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* A queue that contains the items to be rendered
|
|
@@ -81,7 +82,7 @@ import { Application } from '../app.js';
|
|
|
81
82
|
};
|
|
82
83
|
this._itemLists[renderOrder] = itemList;
|
|
83
84
|
}
|
|
84
|
-
const trans = drawable.
|
|
85
|
+
const trans = drawable.getQueueType() === QUEUE_TRANSPARENT;
|
|
85
86
|
const list = trans ? itemList.transList : itemList.opaqueList;
|
|
86
87
|
if (drawable.isBatchable()) {
|
|
87
88
|
const instanceList = trans ? itemList.transInstanceList : itemList.opaqueInstanceList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render_queue.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render_queue.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { LightPass } from './lightpass.js';
|
|
2
|
+
import { ShadowMapPass } from './shadowmap_pass.js';
|
|
3
|
+
import { DepthPass } from './depthpass.js';
|
|
4
|
+
import { Vector4 } from '@zephyr3d/base';
|
|
5
|
+
import { Application } from '../app.js';
|
|
6
|
+
import '@zephyr3d/device';
|
|
7
|
+
import { CopyBlitter } from '../blitter/copy.js';
|
|
8
|
+
import '../scene/octree.js';
|
|
9
|
+
import '../material/shader/helper.js';
|
|
10
|
+
import '../material/lambert.js';
|
|
11
|
+
import '../material/blinn.js';
|
|
12
|
+
import '../material/unlit.js';
|
|
13
|
+
import '../material/material.js';
|
|
14
|
+
import '../material/meshmaterial.js';
|
|
15
|
+
import '../material/grassmaterial.js';
|
|
16
|
+
import '../material/terrainmaterial.js';
|
|
17
|
+
import '../material/pbrmr.js';
|
|
18
|
+
import '../material/pbrsg.js';
|
|
19
|
+
import './sky.js';
|
|
20
|
+
import './clipmap.js';
|
|
21
|
+
import { TemporalCache } from './temporalcache.js';
|
|
22
|
+
import './watermesh.js';
|
|
23
|
+
import { ShadowMapper } from '../shadow/shadowmapper.js';
|
|
24
|
+
import { ClusteredLight } from './cluster_light.js';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Forward render scheme
|
|
28
|
+
* @internal
|
|
29
|
+
*/ class SceneRenderer {
|
|
30
|
+
/** @internal */ static _scenePass = new LightPass();
|
|
31
|
+
/** @internal */ static _depthPass = new DepthPass();
|
|
32
|
+
/** @internal */ static _shadowMapPass = new ShadowMapPass();
|
|
33
|
+
/** @internal */ static _enableDepthPass = false;
|
|
34
|
+
/** @internal */ static _clusters = [];
|
|
35
|
+
/** @internal */ static setClearColor(color) {
|
|
36
|
+
this._scenePass.clearColor = color;
|
|
37
|
+
}
|
|
38
|
+
/** @internal */ static getClusteredLight() {
|
|
39
|
+
if (this._clusters.length > 0) {
|
|
40
|
+
return this._clusters.pop();
|
|
41
|
+
}
|
|
42
|
+
return new ClusteredLight();
|
|
43
|
+
}
|
|
44
|
+
/** @internal */ static freeClusteredLight(clusteredLight) {
|
|
45
|
+
this._clusters.push(clusteredLight);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Renders a scene by given camera
|
|
49
|
+
* @param scene - The scene to be rendered
|
|
50
|
+
* @param camera - The camera that will be used to render the scene
|
|
51
|
+
* @param compositor - The compositor that will be used to apply postprocess effects
|
|
52
|
+
*/ static renderScene(scene, camera, compositor, logger) {
|
|
53
|
+
const device = Application.instance.device;
|
|
54
|
+
const ctx = {
|
|
55
|
+
scene,
|
|
56
|
+
primaryCamera: camera,
|
|
57
|
+
camera,
|
|
58
|
+
compositor: compositor?.needDrawPostEffects() ? compositor : null,
|
|
59
|
+
timestamp: device.frameInfo.frameTimestamp,
|
|
60
|
+
logger,
|
|
61
|
+
queue: 0,
|
|
62
|
+
lightBlending: false,
|
|
63
|
+
target: null,
|
|
64
|
+
renderPass: null,
|
|
65
|
+
renderPassHash: null,
|
|
66
|
+
applyFog: false,
|
|
67
|
+
flip: false,
|
|
68
|
+
drawEnvLight: false,
|
|
69
|
+
env: null
|
|
70
|
+
};
|
|
71
|
+
scene.frameUpdate();
|
|
72
|
+
if (camera && !device.isContextLost()) {
|
|
73
|
+
this._renderScene(ctx);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** @internal */ static _renderSceneDepth(ctx, renderQueue, depthFramebuffer) {
|
|
77
|
+
const device = Application.instance.device;
|
|
78
|
+
device.pushDeviceStates();
|
|
79
|
+
device.setFramebuffer(depthFramebuffer);
|
|
80
|
+
this._depthPass.clearColor = device.type === 'webgl' ? new Vector4(0, 0, 0, 1) : new Vector4(1, 1, 1, 1);
|
|
81
|
+
this._depthPass.render(ctx, null, renderQueue);
|
|
82
|
+
device.popDeviceStates();
|
|
83
|
+
}
|
|
84
|
+
/** @internal */ static _renderScene(ctx) {
|
|
85
|
+
const device = Application.instance.device;
|
|
86
|
+
const vp = ctx.camera.viewport;
|
|
87
|
+
const scissor = ctx.camera.scissor;
|
|
88
|
+
const finalFramebuffer = device.getFramebuffer();
|
|
89
|
+
const drawingBufferWidth = device.getDrawingBufferWidth();
|
|
90
|
+
const drawingBufferHeight = device.getDrawingBufferHeight();
|
|
91
|
+
ctx.depthFormat = 'd24s8';
|
|
92
|
+
ctx.viewportX = finalFramebuffer ? vp?.[0] ?? 0 : device.screenToDevice(vp?.[0] ?? 0);
|
|
93
|
+
ctx.viewportY = finalFramebuffer ? vp?.[1] ?? 0 : device.screenToDevice(vp?.[1] ?? 0);
|
|
94
|
+
ctx.viewportWidth = finalFramebuffer ? vp?.[2] ?? finalFramebuffer.getWidth() : vp ? device.screenToDevice(vp[2]) : device.getDrawingBufferWidth();
|
|
95
|
+
ctx.viewportHeight = finalFramebuffer ? vp?.[3] ?? finalFramebuffer.getHeight() : vp ? device.screenToDevice(vp[3]) : device.getDrawingBufferHeight();
|
|
96
|
+
ctx.defaultViewport = !finalFramebuffer && !vp;
|
|
97
|
+
const oversizedViewport = vp && !device.getDeviceCaps().miscCaps.supportOversizedViewport && (ctx.viewportX < 0 || ctx.viewportY < 0 || ctx.viewportX + ctx.viewportWidth > drawingBufferWidth || ctx.viewportY + ctx.viewportHeight > drawingBufferHeight);
|
|
98
|
+
// TODO: determin the color buffer format
|
|
99
|
+
const colorFmt = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';
|
|
100
|
+
let tempFramebuffer = null;
|
|
101
|
+
let depthFramebuffer = null;
|
|
102
|
+
const renderQueue = this._scenePass.cullScene(ctx, ctx.camera);
|
|
103
|
+
ctx.sunLight = renderQueue.sunLight;
|
|
104
|
+
ctx.clusteredLight = this.getClusteredLight();
|
|
105
|
+
ctx.clusteredLight.calculateLightIndex(ctx.camera, renderQueue);
|
|
106
|
+
this.renderShadowMaps(ctx, renderQueue.shadowedLights);
|
|
107
|
+
const sampleCount = ctx.compositor ? 1 : ctx.primaryCamera.sampleCount;
|
|
108
|
+
if (this._enableDepthPass || oversizedViewport || ctx.scene.env.needSceneDepthTexture() || ctx.compositor?.requireLinearDepth()) {
|
|
109
|
+
const format = device.type === 'webgl' ? 'rgba8unorm' : 'r32f';
|
|
110
|
+
if (!finalFramebuffer && !vp) {
|
|
111
|
+
depthFramebuffer = TemporalCache.getFramebufferVariantSize(drawingBufferWidth, drawingBufferHeight, 1, format, ctx.depthFormat, '2d', '2d', false);
|
|
112
|
+
} else {
|
|
113
|
+
const originDepth = finalFramebuffer?.getDepthAttachment();
|
|
114
|
+
depthFramebuffer = originDepth?.isTexture2D() ? TemporalCache.getFramebufferFixedSizeWithDepth(originDepth, 1, format, '2d', false) : TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false);
|
|
115
|
+
}
|
|
116
|
+
this._renderSceneDepth(ctx, renderQueue, depthFramebuffer);
|
|
117
|
+
ctx.linearDepthTexture = depthFramebuffer.getColorAttachments()[0];
|
|
118
|
+
ctx.depthTexture = depthFramebuffer.getDepthAttachment();
|
|
119
|
+
if (ctx.depthTexture === finalFramebuffer?.getDepthAttachment()) {
|
|
120
|
+
tempFramebuffer = finalFramebuffer;
|
|
121
|
+
} else {
|
|
122
|
+
if (ctx.defaultViewport) {
|
|
123
|
+
tempFramebuffer = TemporalCache.getFramebufferVariantSize(ctx.depthTexture.width, ctx.depthTexture.height, 1, colorFmt, ctx.depthFormat, '2d', '2d', false, sampleCount);
|
|
124
|
+
} else {
|
|
125
|
+
tempFramebuffer = TemporalCache.getFramebufferFixedSize(ctx.depthTexture.width, ctx.depthTexture.height, 1, colorFmt, ctx.depthFormat, '2d', '2d', false, sampleCount);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
ctx.linearDepthTexture = null;
|
|
130
|
+
ctx.depthTexture = null;
|
|
131
|
+
if (!vp) {
|
|
132
|
+
tempFramebuffer = finalFramebuffer;
|
|
133
|
+
} else {
|
|
134
|
+
tempFramebuffer = TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, colorFmt, ctx.depthFormat, '2d', '2d', false, sampleCount);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (tempFramebuffer && tempFramebuffer !== finalFramebuffer) {
|
|
138
|
+
device.pushDeviceStates();
|
|
139
|
+
device.setFramebuffer(tempFramebuffer);
|
|
140
|
+
} else {
|
|
141
|
+
device.setViewport(vp);
|
|
142
|
+
device.setScissor(scissor);
|
|
143
|
+
}
|
|
144
|
+
this._scenePass.clearDepth = 1; //ctx.depthTexture ? null : 1;
|
|
145
|
+
this._scenePass.clearStencil = 0; //ctx.depthTexture ? null : 0;
|
|
146
|
+
ctx.compositor?.begin(ctx);
|
|
147
|
+
this._scenePass.render(ctx, null, renderQueue);
|
|
148
|
+
ctx.compositor?.end(ctx);
|
|
149
|
+
if (tempFramebuffer && tempFramebuffer !== finalFramebuffer) {
|
|
150
|
+
const blitter = new CopyBlitter();
|
|
151
|
+
if (oversizedViewport) {
|
|
152
|
+
blitter.destRect = [
|
|
153
|
+
ctx.viewportX,
|
|
154
|
+
ctx.viewportY,
|
|
155
|
+
ctx.viewportWidth,
|
|
156
|
+
ctx.viewportHeight
|
|
157
|
+
];
|
|
158
|
+
} else {
|
|
159
|
+
blitter.viewport = vp;
|
|
160
|
+
}
|
|
161
|
+
blitter.scissor = scissor;
|
|
162
|
+
blitter.srgbOut = !finalFramebuffer;
|
|
163
|
+
const srcTex = tempFramebuffer.getColorAttachments()[0];
|
|
164
|
+
blitter.blit(srcTex, finalFramebuffer ?? null, device.createSampler({
|
|
165
|
+
magFilter: 'nearest',
|
|
166
|
+
minFilter: 'nearest',
|
|
167
|
+
mipFilter: 'none'
|
|
168
|
+
}));
|
|
169
|
+
device.popDeviceStates();
|
|
170
|
+
}
|
|
171
|
+
if (depthFramebuffer) {
|
|
172
|
+
TemporalCache.releaseFramebuffer(depthFramebuffer);
|
|
173
|
+
}
|
|
174
|
+
if (tempFramebuffer && tempFramebuffer !== finalFramebuffer) {
|
|
175
|
+
TemporalCache.releaseFramebuffer(tempFramebuffer);
|
|
176
|
+
}
|
|
177
|
+
ShadowMapper.releaseTemporalResources(ctx);
|
|
178
|
+
this.freeClusteredLight(ctx.clusteredLight);
|
|
179
|
+
}
|
|
180
|
+
/** @internal */ static renderShadowMaps(ctx, lights) {
|
|
181
|
+
ctx.renderPass = this._shadowMapPass;
|
|
182
|
+
Application.instance.device.pushDeviceStates();
|
|
183
|
+
for (const light of lights){
|
|
184
|
+
light.shadow.render(ctx, this._shadowMapPass);
|
|
185
|
+
}
|
|
186
|
+
Application.instance.device.popDeviceStates();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { SceneRenderer };
|
|
191
|
+
//# sourceMappingURL=renderer.js.map
|