@zephyr3d/scene 0.5.0 → 0.6.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/README.md +1 -1
- package/dist/animation/animationset.js +37 -37
- package/dist/animation/morphtrack.js +7 -5
- package/dist/animation/morphtrack.js.map +1 -1
- package/dist/animation/skeleton.js +11 -9
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/asset/assetmanager.js +2 -2
- package/dist/asset/loaders/gltf/gltf_loader.js +7 -3
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/image/webimage_loader.js +16 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
- package/dist/asset/model.js +3 -9
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/bilateralblur.js +222 -0
- package/dist/{render/temporalcache.js.map → blitter/bilateralblur.js.map} +1 -1
- package/dist/blitter/blitter.js +7 -1
- package/dist/blitter/blitter.js.map +1 -1
- package/dist/blitter/depthlimitedgaussion.js +96 -39
- package/dist/blitter/depthlimitedgaussion.js.map +1 -1
- package/dist/blitter/gaussianblur.js +21 -21
- package/dist/camera/camera.js +142 -1
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +1178 -745
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +9 -3
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +6 -2
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +3 -1
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +73 -33
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +5 -4
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +17 -7
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +5 -5
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +13 -4
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +13 -4
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +27 -15
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/pbrmr.js +14 -3
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +14 -3
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +36 -21
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/posteffect/bloom.js +1 -10
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +43 -24
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/fxaa.js +3 -11
- package/dist/posteffect/fxaa.js.map +1 -1
- package/dist/posteffect/grayscale.js +3 -11
- package/dist/posteffect/grayscale.js.map +1 -1
- package/dist/posteffect/posteffect.js +4 -0
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +44 -24
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/ssr.js +536 -0
- package/dist/{material/lit.js.map → posteffect/ssr.js.map} +1 -1
- package/dist/posteffect/tonemap.js +3 -11
- package/dist/posteffect/tonemap.js.map +1 -1
- package/dist/posteffect/water.js +305 -337
- package/dist/posteffect/water.js.map +1 -1
- package/dist/render/abuffer_oit.js +2 -2
- package/dist/render/clipmap.js +16 -19
- package/dist/render/clipmap.js.map +1 -1
- package/dist/render/cull_visitor.js +5 -3
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/depthpass.js +17 -1
- package/dist/render/depthpass.js.map +1 -1
- package/dist/render/drawable_mixin.js +25 -19
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/envlight.js +4 -2
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/fft_wavegenerator.js +989 -0
- package/dist/{shaders/framework.js.map → render/fft_wavegenerator.js.map} +1 -1
- package/dist/render/gerstner_wavegenerator.js +265 -0
- package/dist/{material/standard.js.map → render/gerstner_wavegenerator.js.map} +1 -1
- package/dist/render/globalbindgroup_allocator.js +2 -1
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/hzb.js +273 -0
- package/dist/{material/terrainlightmodel.js.map → render/hzb.js.map} +1 -1
- package/dist/render/lightpass.js +35 -3
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/objectcolorpass.js +2 -1
- package/dist/render/objectcolorpass.js.map +1 -1
- package/dist/render/render_queue.js +72 -52
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderbundle_wrapper.js +79 -0
- package/dist/render/renderbundle_wrapper.js.map +1 -1
- package/dist/render/renderer.js +75 -36
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/renderpass.js +16 -13
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +6 -0
- package/dist/render/shadowmap_pass.js.map +1 -1
- package/dist/render/sky.js +12 -13
- package/dist/render/sky.js.map +1 -1
- package/dist/render/watermesh.js +94 -828
- package/dist/render/watermesh.js.map +1 -1
- package/dist/render/wavegenerator.js +8 -0
- package/dist/render/wavegenerator.js.map +1 -0
- package/dist/scene/batchgroup.js +60 -14
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +2 -2
- package/dist/scene/graph_node.js +0 -5
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/light.js +5 -5
- package/dist/scene/mesh.js +34 -18
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/octree.js +5 -2
- package/dist/scene/octree.js.map +1 -1
- package/dist/scene/raycast_visitor.js +4 -2
- package/dist/scene/raycast_visitor.js.map +1 -1
- package/dist/scene/scene.js +1 -1
- package/dist/scene/scene_node.js +9 -5
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +3 -4
- package/dist/scene/terrain/grass.js.map +1 -1
- package/dist/scene/terrain/heightfield.js +135 -53
- package/dist/scene/terrain/heightfield.js.map +1 -1
- package/dist/scene/terrain/patch.js +3 -4
- package/dist/scene/terrain/patch.js.map +1 -1
- package/dist/scene/terrain/terrain.js +1 -1
- package/dist/scene/xform.js +7 -9
- package/dist/scene/xform.js.map +1 -1
- package/dist/shaders/misc.js +10 -1
- package/dist/shaders/misc.js.map +1 -1
- package/dist/shaders/noise.js +81 -16
- package/dist/shaders/noise.js.map +1 -1
- package/dist/shaders/shadow.js +1 -9
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/ssr.js +442 -0
- package/dist/{material/terrainmat.js.map → shaders/ssr.js.map} +1 -1
- package/dist/shaders/water.js +377 -250
- package/dist/shaders/water.js.map +1 -1
- package/dist/shadow/shadowmapper.js +11 -11
- package/dist/shapes/cylinder.js +6 -5
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/utility/bounding_volume.js +1 -53
- package/dist/utility/bounding_volume.js.map +1 -1
- package/dist/utility/misc.js +93 -0
- package/dist/utility/misc.js.map +1 -0
- package/dist/utility/shprojection.js +2 -7
- package/dist/utility/shprojection.js.map +1 -1
- package/dist/utility/textures/ggxlut.js +213 -0
- package/dist/utility/textures/ggxlut.js.map +1 -0
- package/dist/utility/textures/gradientnoise.js +61 -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/dist/values.js +8 -1
- package/dist/values.js.map +1 -1
- package/package.json +4 -8
- package/dist/animation/usertrack.js +0 -47
- package/dist/animation/usertrack.js.map +0 -1
- package/dist/material/grassmat.js +0 -127
- package/dist/material/grassmat.js.map +0 -1
- package/dist/material/lightmodel.js +0 -2074
- package/dist/material/lightmodel.js.map +0 -1
- package/dist/material/lit.js +0 -578
- package/dist/material/mixins/pbr/metallicroughness.js +0 -126
- package/dist/material/mixins/pbr/metallicroughness.js.map +0 -1
- package/dist/material/mixins/pbr/specularglossness.js +0 -104
- package/dist/material/mixins/pbr/specularglossness.js.map +0 -1
- package/dist/material/pbr.js +0 -27
- package/dist/material/pbr.js.map +0 -1
- package/dist/material/standard.js +0 -282
- package/dist/material/terrainlightmodel.js +0 -259
- package/dist/material/terrainmat.js +0 -357
- package/dist/render/depth_pass.js +0 -47
- package/dist/render/depth_pass.js.map +0 -1
- package/dist/render/forward.js +0 -186
- package/dist/render/forward.js.map +0 -1
- package/dist/render/forward_pass.js +0 -137
- package/dist/render/forward_pass.js.map +0 -1
- package/dist/render/helper.js +0 -38
- package/dist/render/helper.js.map +0 -1
- package/dist/render/objectpool.js +0 -295
- package/dist/render/objectpool.js.map +0 -1
- package/dist/render/renderscheme.js +0 -61
- package/dist/render/renderscheme.js.map +0 -1
- package/dist/render/temporalcache.js +0 -222
- package/dist/scene/model.js +0 -111
- package/dist/scene/model.js.map +0 -1
- package/dist/scene/octree_update_visitor.js +0 -20
- package/dist/scene/octree_update_visitor.js.map +0 -1
- package/dist/shaders/builtins.js +0 -110
- package/dist/shaders/builtins.js.map +0 -1
- package/dist/shaders/framework.js +0 -723
- package/dist/shaders/lighting.js +0 -335
- package/dist/shaders/lighting.js.map +0 -1
- package/dist/utility/sheenlut.js +0 -196
- package/dist/utility/sheenlut.js.map +0 -1
package/dist/render/forward.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { ForwardRenderPass } from './forward_pass.js';
|
|
2
|
-
import { ShadowMapPass } from './shadowmap_pass.js';
|
|
3
|
-
import { DepthRenderPass } from './depth_pass.js';
|
|
4
|
-
import { Vector4 } from '@zephyr3d/base';
|
|
5
|
-
import { Application } from '../app.js';
|
|
6
|
-
import '../shaders/framework.js';
|
|
7
|
-
import '@zephyr3d/device';
|
|
8
|
-
import { CopyBlitter } from '../blitter/copy.js';
|
|
9
|
-
import '../scene/octree.js';
|
|
10
|
-
import '../material/material.js';
|
|
11
|
-
import './scatteringlut.js';
|
|
12
|
-
import '../material/lambert.js';
|
|
13
|
-
import '../material/blinn.js';
|
|
14
|
-
import '../material/unlit.js';
|
|
15
|
-
import '../material/lightmodel.js';
|
|
16
|
-
import './sky.js';
|
|
17
|
-
import './clipmap.js';
|
|
18
|
-
import { TemporalCache } from './temporalcache.js';
|
|
19
|
-
import './watermesh.js';
|
|
20
|
-
import { ShadowMapper } from '../shadow/shadowmapper.js';
|
|
21
|
-
import { ClusteredLight } from './cluster_light.js';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Forward render scheme
|
|
25
|
-
* @internal
|
|
26
|
-
*/ class ForwardRenderScheme {
|
|
27
|
-
/** @internal */ static _scenePass = new ForwardRenderPass();
|
|
28
|
-
/** @internal */ static _depthPass = new DepthRenderPass();
|
|
29
|
-
/** @internal */ static _shadowMapPass = new ShadowMapPass();
|
|
30
|
-
/** @internal */ static _enableDepthPass = false;
|
|
31
|
-
/** @internal */ static _clusters = [];
|
|
32
|
-
/** @internal */ static setClearColor(color) {
|
|
33
|
-
this._scenePass.clearColor = color;
|
|
34
|
-
}
|
|
35
|
-
/** @internal */ static getClusteredLight() {
|
|
36
|
-
if (this._clusters.length > 0) {
|
|
37
|
-
return this._clusters.pop();
|
|
38
|
-
}
|
|
39
|
-
return new ClusteredLight();
|
|
40
|
-
}
|
|
41
|
-
/** @internal */ static freeClusteredLight(clusteredLight) {
|
|
42
|
-
this._clusters.push(clusteredLight);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Renders a scene by given camera
|
|
46
|
-
* @param scene - The scene to be rendered
|
|
47
|
-
* @param camera - The camera that will be used to render the scene
|
|
48
|
-
* @param compositor - The compositor that will be used to apply postprocess effects
|
|
49
|
-
*/ static renderScene(scene, camera, compositor, logger) {
|
|
50
|
-
const device = Application.instance.device;
|
|
51
|
-
const ctx = {
|
|
52
|
-
scene,
|
|
53
|
-
primaryCamera: camera,
|
|
54
|
-
camera,
|
|
55
|
-
compositor: compositor?.needDrawPostEffects() ? compositor : null,
|
|
56
|
-
timestamp: device.frameInfo.frameTimestamp,
|
|
57
|
-
logger,
|
|
58
|
-
target: null,
|
|
59
|
-
renderPass: null,
|
|
60
|
-
renderPassHash: null,
|
|
61
|
-
applyFog: false,
|
|
62
|
-
flip: false,
|
|
63
|
-
drawEnvLight: false,
|
|
64
|
-
env: null
|
|
65
|
-
};
|
|
66
|
-
scene.frameUpdate();
|
|
67
|
-
if (camera && !device.isContextLost()) {
|
|
68
|
-
this._renderScene(ctx);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/** @internal */ static _renderSceneDepth(ctx, renderQueue, depthFramebuffer) {
|
|
72
|
-
const device = Application.instance.device;
|
|
73
|
-
device.pushDeviceStates();
|
|
74
|
-
device.setFramebuffer(depthFramebuffer);
|
|
75
|
-
this._depthPass.clearColor = device.type === 'webgl' ? new Vector4(0, 0, 0, 1) : new Vector4(1, 1, 1, 1);
|
|
76
|
-
this._depthPass.render(ctx, null, renderQueue);
|
|
77
|
-
device.popDeviceStates();
|
|
78
|
-
}
|
|
79
|
-
/** @internal */ static _renderScene(ctx) {
|
|
80
|
-
const device = Application.instance.device;
|
|
81
|
-
const vp = ctx.camera.viewport;
|
|
82
|
-
const scissor = ctx.camera.scissor;
|
|
83
|
-
const finalFramebuffer = device.getFramebuffer();
|
|
84
|
-
const drawingBufferWidth = device.getDrawingBufferWidth();
|
|
85
|
-
const drawingBufferHeight = device.getDrawingBufferHeight();
|
|
86
|
-
ctx.depthFormat = 'd24s8';
|
|
87
|
-
ctx.viewportX = finalFramebuffer ? vp?.[0] ?? 0 : device.screenToDevice(vp?.[0] ?? 0);
|
|
88
|
-
ctx.viewportY = finalFramebuffer ? vp?.[1] ?? 0 : device.screenToDevice(vp?.[1] ?? 0);
|
|
89
|
-
ctx.viewportWidth = finalFramebuffer ? vp?.[2] ?? finalFramebuffer.getWidth() : vp ? device.screenToDevice(vp[2]) : device.getDrawingBufferWidth();
|
|
90
|
-
ctx.viewportHeight = finalFramebuffer ? vp?.[3] ?? finalFramebuffer.getHeight() : vp ? device.screenToDevice(vp[3]) : device.getDrawingBufferHeight();
|
|
91
|
-
ctx.defaultViewport = !finalFramebuffer && !vp;
|
|
92
|
-
const oversizedViewport = vp && !device.getDeviceCaps().miscCaps.supportOversizedViewport && (ctx.viewportX < 0 || ctx.viewportY < 0 || ctx.viewportX + ctx.viewportWidth > drawingBufferWidth || ctx.viewportY + ctx.viewportHeight > drawingBufferHeight);
|
|
93
|
-
// TODO: determin the color buffer format
|
|
94
|
-
const colorFmt = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';
|
|
95
|
-
let tempFramebuffer = null;
|
|
96
|
-
let depthFramebuffer = null;
|
|
97
|
-
const renderQueue = this._scenePass.cullScene(ctx, ctx.camera);
|
|
98
|
-
ctx.sunLight = renderQueue.sunLight;
|
|
99
|
-
ctx.clusteredLight = this.getClusteredLight();
|
|
100
|
-
ctx.clusteredLight.calculateLightIndex(ctx.camera, renderQueue);
|
|
101
|
-
this.renderShadowMaps(ctx, renderQueue.shadowedLights);
|
|
102
|
-
const sampleCount = ctx.compositor ? 1 : ctx.primaryCamera.sampleCount;
|
|
103
|
-
if (this._enableDepthPass || oversizedViewport || ctx.scene.env.needSceneDepthTexture() || ctx.compositor?.requireLinearDepth()) {
|
|
104
|
-
const format = device.type === 'webgl' ? 'rgba8unorm' : 'r32f';
|
|
105
|
-
if (!finalFramebuffer && !vp) {
|
|
106
|
-
depthFramebuffer = TemporalCache.getFramebufferVariantSize(drawingBufferWidth, drawingBufferHeight, 1, format, ctx.depthFormat, '2d', '2d', false);
|
|
107
|
-
} else {
|
|
108
|
-
const originDepth = finalFramebuffer?.getDepthAttachment();
|
|
109
|
-
depthFramebuffer = originDepth?.isTexture2D() ? TemporalCache.getFramebufferFixedSizeWithDepth(originDepth, 1, format, '2d', false) : TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false);
|
|
110
|
-
}
|
|
111
|
-
this._renderSceneDepth(ctx, renderQueue, depthFramebuffer);
|
|
112
|
-
ctx.linearDepthTexture = depthFramebuffer.getColorAttachments()[0];
|
|
113
|
-
ctx.depthTexture = depthFramebuffer.getDepthAttachment();
|
|
114
|
-
if (ctx.depthTexture === finalFramebuffer?.getDepthAttachment()) {
|
|
115
|
-
tempFramebuffer = finalFramebuffer;
|
|
116
|
-
} else {
|
|
117
|
-
if (ctx.defaultViewport) {
|
|
118
|
-
tempFramebuffer = TemporalCache.getFramebufferVariantSize(ctx.depthTexture.width, ctx.depthTexture.height, 1, colorFmt, ctx.depthFormat, '2d', '2d', false, sampleCount);
|
|
119
|
-
} else {
|
|
120
|
-
tempFramebuffer = TemporalCache.getFramebufferFixedSize(ctx.depthTexture.width, ctx.depthTexture.height, 1, colorFmt, ctx.depthFormat, '2d', '2d', false, sampleCount);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
ctx.linearDepthTexture = null;
|
|
125
|
-
ctx.depthTexture = null;
|
|
126
|
-
if (!vp) {
|
|
127
|
-
tempFramebuffer = finalFramebuffer;
|
|
128
|
-
} else {
|
|
129
|
-
tempFramebuffer = TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, colorFmt, ctx.depthFormat, '2d', '2d', false, sampleCount);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (tempFramebuffer && tempFramebuffer !== finalFramebuffer) {
|
|
133
|
-
device.pushDeviceStates();
|
|
134
|
-
device.setFramebuffer(tempFramebuffer);
|
|
135
|
-
} else {
|
|
136
|
-
device.setViewport(vp);
|
|
137
|
-
device.setScissor(scissor);
|
|
138
|
-
}
|
|
139
|
-
this._scenePass.clearDepth = 1; //ctx.depthTexture ? null : 1;
|
|
140
|
-
this._scenePass.clearStencil = 0; //ctx.depthTexture ? null : 0;
|
|
141
|
-
ctx.compositor?.begin(ctx);
|
|
142
|
-
this._scenePass.render(ctx, null, renderQueue);
|
|
143
|
-
ctx.compositor?.end(ctx);
|
|
144
|
-
if (tempFramebuffer && tempFramebuffer !== finalFramebuffer) {
|
|
145
|
-
const blitter = new CopyBlitter();
|
|
146
|
-
if (oversizedViewport) {
|
|
147
|
-
blitter.destRect = [
|
|
148
|
-
ctx.viewportX,
|
|
149
|
-
ctx.viewportY,
|
|
150
|
-
ctx.viewportWidth,
|
|
151
|
-
ctx.viewportHeight
|
|
152
|
-
];
|
|
153
|
-
} else {
|
|
154
|
-
blitter.viewport = vp;
|
|
155
|
-
}
|
|
156
|
-
blitter.scissor = scissor;
|
|
157
|
-
blitter.srgbOut = !finalFramebuffer;
|
|
158
|
-
const srcTex = tempFramebuffer.getColorAttachments()[0];
|
|
159
|
-
blitter.blit(srcTex, finalFramebuffer ?? null, device.createSampler({
|
|
160
|
-
magFilter: 'nearest',
|
|
161
|
-
minFilter: 'nearest',
|
|
162
|
-
mipFilter: 'none'
|
|
163
|
-
}));
|
|
164
|
-
device.popDeviceStates();
|
|
165
|
-
}
|
|
166
|
-
if (depthFramebuffer) {
|
|
167
|
-
TemporalCache.releaseFramebuffer(depthFramebuffer);
|
|
168
|
-
}
|
|
169
|
-
if (tempFramebuffer && tempFramebuffer !== finalFramebuffer) {
|
|
170
|
-
TemporalCache.releaseFramebuffer(tempFramebuffer);
|
|
171
|
-
}
|
|
172
|
-
ShadowMapper.releaseTemporalResources(ctx);
|
|
173
|
-
this.freeClusteredLight(ctx.clusteredLight);
|
|
174
|
-
}
|
|
175
|
-
/** @internal */ static renderShadowMaps(ctx, lights) {
|
|
176
|
-
ctx.renderPass = this._shadowMapPass;
|
|
177
|
-
Application.instance.device.pushDeviceStates();
|
|
178
|
-
for (const light of lights){
|
|
179
|
-
light.shadow.render(ctx, this._shadowMapPass);
|
|
180
|
-
}
|
|
181
|
-
Application.instance.device.popDeviceStates();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export { ForwardRenderScheme };
|
|
186
|
-
//# sourceMappingURL=forward.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forward.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { RenderPass } from './renderpass.js';
|
|
2
|
-
import { RENDER_PASS_TYPE_FORWARD } from '../values.js';
|
|
3
|
-
import { ShaderFramework } from '../shaders/framework.js';
|
|
4
|
-
import '@zephyr3d/device';
|
|
5
|
-
import { Application } from '../app.js';
|
|
6
|
-
import { Vector4 } from '@zephyr3d/base';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Forward render pass
|
|
10
|
-
* @internal
|
|
11
|
-
*/ class ForwardRenderPass extends RenderPass {
|
|
12
|
-
/** @internal */ _overridenState;
|
|
13
|
-
/** @internal */ _overridenStateTrans;
|
|
14
|
-
/** @internal */ _shadowMapHash;
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of ForwardRenderPass
|
|
17
|
-
*/ constructor(){
|
|
18
|
-
super(RENDER_PASS_TYPE_FORWARD);
|
|
19
|
-
this._overridenState = null;
|
|
20
|
-
this._overridenStateTrans = null;
|
|
21
|
-
this._shadowMapHash = null;
|
|
22
|
-
}
|
|
23
|
-
/** @internal */ applyRenderStates(device, stateSet, ctx) {
|
|
24
|
-
const overridenStateSet = ctx.userData;
|
|
25
|
-
if (overridenStateSet) {
|
|
26
|
-
const depthState = overridenStateSet.depthState;
|
|
27
|
-
const blendingState = overridenStateSet.blendingState;
|
|
28
|
-
overridenStateSet.copyFrom(stateSet);
|
|
29
|
-
overridenStateSet.useBlendingState(blendingState);
|
|
30
|
-
if (depthState) {
|
|
31
|
-
overridenStateSet.useDepthState(depthState);
|
|
32
|
-
}
|
|
33
|
-
stateSet = overridenStateSet;
|
|
34
|
-
}
|
|
35
|
-
device.setRenderStates(stateSet);
|
|
36
|
-
}
|
|
37
|
-
/** @internal */ get overridenState() {
|
|
38
|
-
if (!this._overridenState) {
|
|
39
|
-
this._overridenState = Application.instance.device.createRenderStateSet();
|
|
40
|
-
this._overridenState.useBlendingState().enable(true).setBlendFunc('one', 'one');
|
|
41
|
-
}
|
|
42
|
-
return this._overridenState;
|
|
43
|
-
}
|
|
44
|
-
/** @internal */ get overridenStateTrans() {
|
|
45
|
-
if (!this._overridenStateTrans) {
|
|
46
|
-
this._overridenStateTrans = Application.instance.device.createRenderStateSet();
|
|
47
|
-
this._overridenStateTrans.useBlendingState().enable(true).setBlendFunc('one', 'inv-src-alpha');
|
|
48
|
-
this._overridenStateTrans.useDepthState().enableTest(true).enableWrite(false);
|
|
49
|
-
}
|
|
50
|
-
return this._overridenStateTrans;
|
|
51
|
-
}
|
|
52
|
-
/** @internal */ _getGlobalBindGroupHash(ctx) {
|
|
53
|
-
//return `${ctx.environment?.constructor.name || ''}:${this._shadowMapHash}`;
|
|
54
|
-
//const envLightHash = ctx.drawEnvLight ? ctx.env.light.type : 'none';
|
|
55
|
-
//const fogHash = ctx.applyFog ? ctx.env.sky.fogType ?? 'none' : 'none';
|
|
56
|
-
return `${this._shadowMapHash}:${ctx.env.getHash(ctx)}`;
|
|
57
|
-
}
|
|
58
|
-
/** @internal */ renderLightPass(camera, renderQueue, ctx, items, lights, trans, blend) {
|
|
59
|
-
const device = Application.instance.device;
|
|
60
|
-
const baseLightPass = !blend;
|
|
61
|
-
ctx.drawEnvLight = baseLightPass && ctx.env.light.type !== 'none' && (ctx.env.light.envLight.hasRadiance() || ctx.env.light.envLight.hasIrradiance());
|
|
62
|
-
ctx.renderPassHash = this.getGlobalBindGroupHash(ctx);
|
|
63
|
-
const info = this.getGlobalBindGroupInfo(ctx);
|
|
64
|
-
ShaderFramework.setCameraUniforms(info.bindGroup, ctx, !!device.getFramebuffer());
|
|
65
|
-
if (ctx.currentShadowLight) {
|
|
66
|
-
ShaderFramework.setLightUniformsShadow(info.bindGroup, ctx, lights[0]);
|
|
67
|
-
} else {
|
|
68
|
-
ShaderFramework.setLightUniforms(info.bindGroup, ctx, ctx.clusteredLight.clusterParam, ctx.clusteredLight.countParam, ctx.clusteredLight.lightBuffer, ctx.clusteredLight.lightIndexTexture);
|
|
69
|
-
}
|
|
70
|
-
if (ctx.applyFog) {
|
|
71
|
-
ShaderFramework.setFogUniforms(info.bindGroup, ctx.env.sky.mappedFogType, baseLightPass ? ctx.env.sky.fogColor : Vector4.zero(), ctx.env.sky.fogParams, ctx.env.sky.getAerialPerspectiveLUT(ctx));
|
|
72
|
-
}
|
|
73
|
-
device.setBindGroup(0, info.bindGroup);
|
|
74
|
-
if (blend) {
|
|
75
|
-
ctx.userData = this.overridenState;
|
|
76
|
-
} else if (trans) {
|
|
77
|
-
ctx.userData = this.overridenStateTrans;
|
|
78
|
-
}
|
|
79
|
-
const reverseWinding = ctx.camera.worldMatrixDet < 0;
|
|
80
|
-
for (const item of items){
|
|
81
|
-
// unlit objects should only be drawn once
|
|
82
|
-
if (!blend || !item.drawable.isUnlit()) {
|
|
83
|
-
ctx.instanceData = item.instanceData;
|
|
84
|
-
ctx.target = item.drawable;
|
|
85
|
-
this.drawItem(device, item, ctx, reverseWinding);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/** @internal */ renderItems(ctx, renderQueue) {
|
|
90
|
-
ctx.applyFog = false;
|
|
91
|
-
ctx.target = null;
|
|
92
|
-
ctx.renderPassHash = null;
|
|
93
|
-
ctx.env = ctx.scene.env;
|
|
94
|
-
ctx.drawEnvLight = false;
|
|
95
|
-
ctx.flip = this.isAutoFlip();
|
|
96
|
-
renderQueue.sortItems();
|
|
97
|
-
const orders = Object.keys(renderQueue.items).map((val)=>Number(val)).sort((a, b)=>a - b);
|
|
98
|
-
for(let i = 0; i < 2; i++){
|
|
99
|
-
ctx.applyFog = i === 1 && ctx.env.sky.fogType !== 'none';
|
|
100
|
-
for (const order of orders){
|
|
101
|
-
const items = renderQueue.items[order];
|
|
102
|
-
const lists = [
|
|
103
|
-
items.opaqueList,
|
|
104
|
-
items.transList
|
|
105
|
-
];
|
|
106
|
-
const list = lists[i];
|
|
107
|
-
let lightIndex = 0;
|
|
108
|
-
if (ctx.shadowMapInfo) {
|
|
109
|
-
for (const k of ctx.shadowMapInfo.keys()){
|
|
110
|
-
ctx.currentShadowLight = k;
|
|
111
|
-
this._shadowMapHash = ctx.shadowMapInfo.get(k).shaderHash;
|
|
112
|
-
this.renderLightPass(ctx.camera, renderQueue, ctx, list, [
|
|
113
|
-
k
|
|
114
|
-
], i > 0, lightIndex > 0);
|
|
115
|
-
lightIndex++;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (lightIndex === 0 || renderQueue.unshadowedLights.length > 0) {
|
|
119
|
-
ctx.currentShadowLight = null;
|
|
120
|
-
this._shadowMapHash = '';
|
|
121
|
-
this.renderLightPass(ctx.camera, renderQueue, ctx, list, renderQueue.unshadowedLights, i > 0, lightIndex > 0);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (i === 0) {
|
|
125
|
-
ctx.env.sky.skyWorldMatrix = ctx.scene.rootNode.worldMatrix;
|
|
126
|
-
ctx.env.sky.renderSky(ctx);
|
|
127
|
-
}
|
|
128
|
-
ctx.compositor?.drawPostEffects(ctx, i === 0, ctx.linearDepthTexture);
|
|
129
|
-
if (i === 0) {
|
|
130
|
-
ctx.env.sky.renderFog(ctx);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export { ForwardRenderPass };
|
|
137
|
-
//# sourceMappingURL=forward_pass.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forward_pass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/render/helper.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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=helper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import { Application } from '../app.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ObjectPool class is responsible for managing and reusing textures and framebuffers.
|
|
5
|
-
* @public
|
|
6
|
-
*/ class ObjectPool {
|
|
7
|
-
/** @internal */ static _freeTextures = {};
|
|
8
|
-
/** @internal */ static _allocatedTextures = new WeakMap();
|
|
9
|
-
/** @internal */ static _autoReleaseTextures = new Set();
|
|
10
|
-
/** @internal */ static _freeFramebuffers = {};
|
|
11
|
-
/** @internal */ static _allocatedFramebuffers = new WeakMap();
|
|
12
|
-
/** @internal */ static _autoReleaseFramebuffers = new Set();
|
|
13
|
-
/** @internal */ static _lastFrameId = -1;
|
|
14
|
-
/**
|
|
15
|
-
* Fetch a temporal 2D texture from the object pool.
|
|
16
|
-
* @param autoRelease - Whether the texture should be automatically released at the next frame.
|
|
17
|
-
* @param format - The format of the texture.
|
|
18
|
-
* @param width - The width of the texture.
|
|
19
|
-
* @param height - The height of the texture.
|
|
20
|
-
* @param mipmapping - Whether this texture supports mipmapping
|
|
21
|
-
* @returns The fetched Texture2D object.
|
|
22
|
-
*/ static fetchTemporalTexture2D(autoRelease, format, width, height, mipmapping) {
|
|
23
|
-
return this.fetchTemporalTexture(autoRelease, '2d', format, width, height, 0, mipmapping);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Fetch a temporal Cube texture from the object pool.
|
|
27
|
-
* @param autoRelease - Whether the texture should be automatically released at the next frame.
|
|
28
|
-
* @param format - The format of the texture.
|
|
29
|
-
* @param size - Size of the texture.
|
|
30
|
-
* @param mipmapping - Whether this texture supports mipmapping
|
|
31
|
-
* @returns The fetched TextureCube object.
|
|
32
|
-
*/ static fetchTemporalTextureCube(autoRelease, format, size, mipmapping) {
|
|
33
|
-
return this.fetchTemporalTexture(autoRelease, 'cube', format, size, size, 0, mipmapping);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Fetch a temporal 3D texture from the object pool.
|
|
37
|
-
* @param autoRelease - Whether the texture should be automatically released at the next frame.
|
|
38
|
-
* @param format - The format of the texture.
|
|
39
|
-
* @param width - Width of the texture.
|
|
40
|
-
* @param height - Height of the texture.
|
|
41
|
-
* @param depth - Depth of the texture.
|
|
42
|
-
* @param mipmapping - Whether this texture supports mipmapping
|
|
43
|
-
* @returns The fetched Texture3D object.
|
|
44
|
-
*/ static fetchTemporalTexture3D(autoRelease, format, width, height, depth, mipmapping) {
|
|
45
|
-
return this.fetchTemporalTexture(autoRelease, '3d', format, width, height, depth, mipmapping);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Fetch a temporal 2D array texture from the object pool.
|
|
49
|
-
* @param autoRelease - Whether the texture should be automatically released at the next frame.
|
|
50
|
-
* @param format - The format of the texture.
|
|
51
|
-
* @param width - Width of the texture.
|
|
52
|
-
* @param height - Height of the texture.
|
|
53
|
-
* @param layers - Layers of the texture
|
|
54
|
-
* @param mipmapping - Whether this texture supports mipmapping
|
|
55
|
-
* @returns The fetched Texture2DArray object.
|
|
56
|
-
*/ static fetchTemporalTexture2DArray(autoRelease, format, width, height, layers, mipmapping) {
|
|
57
|
-
return this.fetchTemporalTexture(autoRelease, '2darray', format, width, height, layers, mipmapping);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Fetch a temporal framebuffer from the object pool.
|
|
61
|
-
* @param autoRelease - Whether the framebuffer should be automatically released at the next frame.
|
|
62
|
-
* @param colorAttachments - Array of color attachments for the framebuffer.
|
|
63
|
-
* @param depthAttachment - Depth attachment for the framebuffer.
|
|
64
|
-
* @param sampleCount - The sample count for the framebuffer.
|
|
65
|
-
* @param ignoreDepthStencil - Whether to ignore depth stencil.
|
|
66
|
-
* @returns The fetched FrameBuffer object.
|
|
67
|
-
*/ static fetchTemporalFramebuffer(autoRelease, colorAttachments, depthAttachment, sampleCount, ignoreDepthStencil) {
|
|
68
|
-
const device = Application.instance.device;
|
|
69
|
-
this.checkAutoRelease(device);
|
|
70
|
-
let hash = `${depthAttachment?.uid ?? 0}:${sampleCount ?? 1}:${ignoreDepthStencil ? 1 : 0}`;
|
|
71
|
-
for (const tex of colorAttachments){
|
|
72
|
-
hash += `:${tex.uid}`;
|
|
73
|
-
}
|
|
74
|
-
let fb = null;
|
|
75
|
-
const list = this._freeFramebuffers[hash];
|
|
76
|
-
if (!list) {
|
|
77
|
-
// Mark referenced textures
|
|
78
|
-
const info = this._allocatedTextures.get(depthAttachment);
|
|
79
|
-
if (info) {
|
|
80
|
-
info.refcount++;
|
|
81
|
-
}
|
|
82
|
-
for (const tex of colorAttachments){
|
|
83
|
-
const info = this._allocatedTextures.get(tex);
|
|
84
|
-
if (info) {
|
|
85
|
-
info.refcount++;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
fb = device.createFrameBuffer(colorAttachments, depthAttachment, {
|
|
89
|
-
ignoreDepthStencil,
|
|
90
|
-
sampleCount
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
fb = list.pop();
|
|
94
|
-
if (list.length === 0) {
|
|
95
|
-
delete this._freeFramebuffers[hash];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
this._allocatedFramebuffers.set(fb, hash);
|
|
99
|
-
if (autoRelease) {
|
|
100
|
-
this._autoReleaseFramebuffers.add(fb);
|
|
101
|
-
}
|
|
102
|
-
return fb;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Dispose a texture that is allocated from the object pool.
|
|
106
|
-
* @param texture - The texture to dispose.
|
|
107
|
-
*/ static disposeTexture(texture) {
|
|
108
|
-
this.safeReleaseTexture(texture, true);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Release a texture back to the object pool.
|
|
112
|
-
* @param texture - The texture to release.
|
|
113
|
-
*/ static releaseTexture(texture) {
|
|
114
|
-
const info = this._allocatedTextures.get(texture);
|
|
115
|
-
if (!info) {
|
|
116
|
-
console.error(`ObjectPool.releaseTexture(): texture is not allocated from pool`);
|
|
117
|
-
} else {
|
|
118
|
-
this.safeReleaseTexture(texture);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Dispose a framebuffer that is allocated from the object pool.
|
|
123
|
-
* @param fb - The framebuffer to dispose.
|
|
124
|
-
*/ static disposeFrameBuffer(fb) {
|
|
125
|
-
const hash = this._allocatedFramebuffers.get(fb);
|
|
126
|
-
if (!hash) {
|
|
127
|
-
console.error(`ObjectPool.disposeFrameBuffer(): framebuffer is not allocated from pool`);
|
|
128
|
-
} else {
|
|
129
|
-
this.internalDisposeFrameBuffer(fb);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Release a framebuffer back to the object pool.
|
|
134
|
-
* @param fb - The framebuffer to release.
|
|
135
|
-
*/ static releaseFrameBuffer(fb) {
|
|
136
|
-
const hash = this._allocatedFramebuffers.get(fb);
|
|
137
|
-
if (!hash) {
|
|
138
|
-
console.error(`ObjectPool.releaseFrameBuffer(): framebuffer is not allocated from pool`);
|
|
139
|
-
} else {
|
|
140
|
-
this._allocatedFramebuffers.delete(fb);
|
|
141
|
-
this._autoReleaseFramebuffers.delete(fb);
|
|
142
|
-
const list = this._freeFramebuffers[hash];
|
|
143
|
-
if (list) {
|
|
144
|
-
list.push(fb);
|
|
145
|
-
} else {
|
|
146
|
-
this._freeFramebuffers[hash] = [
|
|
147
|
-
fb
|
|
148
|
-
];
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Purge the object pool by disposing all free framebuffers and textures.
|
|
154
|
-
*/ static purge() {
|
|
155
|
-
for(const k in this._freeFramebuffers){
|
|
156
|
-
const list = this._freeFramebuffers[k];
|
|
157
|
-
if (list) {
|
|
158
|
-
for (const fb of this._freeFramebuffers[k]){
|
|
159
|
-
this.internalDisposeFrameBuffer(fb);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
this._freeFramebuffers = {};
|
|
164
|
-
for(const k in this._freeTextures){
|
|
165
|
-
const list = this._freeTextures[k];
|
|
166
|
-
for (const tex of list){
|
|
167
|
-
tex.dispose();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
this._freeTextures = {};
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Fetch a temporal 2D texture from the object pool.
|
|
174
|
-
* @param autoRelease - Whether the texture should be automatically released at the next frame.
|
|
175
|
-
* @param format - The format of the texture.
|
|
176
|
-
* @param width - The width of the texture.
|
|
177
|
-
* @param height - The height of the texture.
|
|
178
|
-
* @returns The fetched Texture2D object.
|
|
179
|
-
*/ static fetchTemporalTexture(autoRelease, type, format, width, height, depth, mipmapping) {
|
|
180
|
-
const device = Application.instance.device;
|
|
181
|
-
this.checkAutoRelease(device);
|
|
182
|
-
const hash = `${type}:${format}:${width}:${height}:${depth}:${mipmapping ? 1 : 0}`;
|
|
183
|
-
let texture = null;
|
|
184
|
-
const list = this._freeTextures[hash];
|
|
185
|
-
if (!list) {
|
|
186
|
-
switch(type){
|
|
187
|
-
case '2d':
|
|
188
|
-
texture = device.createTexture2D(format, width, height, mipmapping ? {} : {
|
|
189
|
-
samplerOptions: {
|
|
190
|
-
mipFilter: 'none'
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
break;
|
|
194
|
-
case '3d':
|
|
195
|
-
texture = device.createTexture3D(format, width, height, depth, mipmapping ? {} : {
|
|
196
|
-
samplerOptions: {
|
|
197
|
-
mipFilter: 'none'
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
break;
|
|
201
|
-
case '2darray':
|
|
202
|
-
texture = device.createTexture2DArray(format, width, height, depth, mipmapping ? {} : {
|
|
203
|
-
samplerOptions: {
|
|
204
|
-
mipFilter: 'none'
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
break;
|
|
208
|
-
case 'cube':
|
|
209
|
-
texture = device.createCubeTexture(format, width, mipmapping ? {} : {
|
|
210
|
-
samplerOptions: {
|
|
211
|
-
mipFilter: 'none'
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
break;
|
|
215
|
-
default:
|
|
216
|
-
throw new Error(`ObjectPool.fetchTemporalTexture(): invalid texture type: ${type}`);
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
219
|
-
texture = list.pop();
|
|
220
|
-
if (list.length === 0) {
|
|
221
|
-
delete this._freeTextures[hash];
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
this._allocatedTextures.set(texture, {
|
|
225
|
-
hash,
|
|
226
|
-
refcount: 1,
|
|
227
|
-
dispose: false
|
|
228
|
-
});
|
|
229
|
-
if (autoRelease) {
|
|
230
|
-
this._autoReleaseTextures.add(texture);
|
|
231
|
-
}
|
|
232
|
-
return texture;
|
|
233
|
-
}
|
|
234
|
-
/** @internal */ static internalDisposeFrameBuffer(fb) {
|
|
235
|
-
if (fb) {
|
|
236
|
-
// Release attachment textures
|
|
237
|
-
const colorAttachments = fb.getColorAttachments();
|
|
238
|
-
if (colorAttachments) {
|
|
239
|
-
for (const tex of colorAttachments){
|
|
240
|
-
this.safeReleaseTexture(tex);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
const depthAttachment = fb.getDepthAttachment();
|
|
244
|
-
if (depthAttachment) {
|
|
245
|
-
this.safeReleaseTexture(depthAttachment);
|
|
246
|
-
}
|
|
247
|
-
this._allocatedFramebuffers.delete(fb);
|
|
248
|
-
this._autoReleaseFramebuffers.delete(fb);
|
|
249
|
-
fb.dispose();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
/** @internal */ static checkAutoRelease(device) {
|
|
253
|
-
const frame = device.frameInfo.frameCounter;
|
|
254
|
-
if (frame !== this._lastFrameId) {
|
|
255
|
-
// frame changed
|
|
256
|
-
this._lastFrameId = frame;
|
|
257
|
-
// auto release objects
|
|
258
|
-
for (const tex of this._autoReleaseTextures){
|
|
259
|
-
this.releaseTexture(tex);
|
|
260
|
-
}
|
|
261
|
-
this._autoReleaseTextures.clear();
|
|
262
|
-
for (const fb of this._autoReleaseFramebuffers){
|
|
263
|
-
this.releaseFrameBuffer(fb);
|
|
264
|
-
}
|
|
265
|
-
this._autoReleaseFramebuffers.clear();
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/** @internal */ static safeReleaseTexture(texture, purge = false) {
|
|
269
|
-
const info = this._allocatedTextures.get(texture);
|
|
270
|
-
if (info) {
|
|
271
|
-
info.refcount--;
|
|
272
|
-
if (info.refcount === 0) {
|
|
273
|
-
this._allocatedTextures.delete(texture);
|
|
274
|
-
this._autoReleaseTextures.delete(texture);
|
|
275
|
-
if (purge || info.dispose) {
|
|
276
|
-
texture.dispose();
|
|
277
|
-
} else {
|
|
278
|
-
const list = this._freeTextures[info.hash];
|
|
279
|
-
if (list) {
|
|
280
|
-
list.push(texture);
|
|
281
|
-
} else {
|
|
282
|
-
this._freeTextures[info.hash] = [
|
|
283
|
-
texture
|
|
284
|
-
];
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
} else if (purge) {
|
|
288
|
-
info.dispose = true;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export { ObjectPool };
|
|
295
|
-
//# sourceMappingURL=objectpool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"objectpool.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|