@zephyr3d/scene 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/animation.js +25 -117
- package/dist/animation/animation.js.map +1 -1
- package/dist/animation/animationset.js +164 -24
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/animationtrack.js +6 -18
- package/dist/animation/animationtrack.js.map +1 -1
- package/dist/animation/eulerrotationtrack.js +16 -6
- package/dist/animation/eulerrotationtrack.js.map +1 -1
- package/dist/animation/morphtarget.js +104 -0
- package/dist/animation/morphtarget.js.map +1 -0
- package/dist/animation/morphtrack.js +68 -0
- package/dist/animation/morphtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +15 -7
- package/dist/animation/rotationtrack.js.map +1 -1
- package/dist/animation/scaletrack.js +15 -7
- package/dist/animation/scaletrack.js.map +1 -1
- package/dist/animation/skeleton.js +101 -1
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/translationtrack.js +15 -7
- package/dist/animation/translationtrack.js.map +1 -1
- package/dist/animation/usertrack.js +2 -2
- package/dist/app.js +4 -26
- package/dist/app.js.map +1 -1
- package/dist/asset/assetmanager.js +58 -107
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/loaders/dds/dds.js +77 -3
- package/dist/asset/loaders/dds/dds.js.map +1 -1
- package/dist/asset/loaders/dds/dds_loader.js +1 -1
- package/dist/asset/loaders/gltf/gltf_loader.js +284 -45
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/image/tga_Loader.js +1 -1
- package/dist/asset/model.js +13 -0
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/blitter.js +2 -2
- package/dist/camera/camera.js +83 -5
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +5212 -4785
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +9 -4
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/grassmat.js +127 -0
- package/dist/material/grassmat.js.map +1 -0
- package/dist/material/grassmaterial.js +15 -0
- package/dist/material/grassmaterial.js.map +1 -1
- package/dist/material/lambert.js +22 -17
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/lightmodel.js +7 -6
- package/dist/material/lightmodel.js.map +1 -1
- package/dist/material/lit.js +99 -5
- package/dist/material/lit.js.map +1 -1
- package/dist/material/material.js +88 -347
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +122 -102
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +11 -3
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +3 -3
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +3 -3
- package/dist/material/mixins/lit.js +2 -2
- package/dist/material/mixins/pbr/common.js +433 -10
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/pbrmr.js +17 -6
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +16 -9
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +186 -117
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/terrainlightmodel.js +3 -1
- package/dist/material/terrainlightmodel.js.map +1 -1
- package/dist/material/terrainmat.js +357 -0
- package/dist/material/terrainmat.js.map +1 -0
- package/dist/material/terrainmaterial.js +16 -0
- package/dist/material/terrainmaterial.js.map +1 -1
- package/dist/material/unlit.js +8 -4
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/bloom.js +34 -45
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +11 -41
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/fxaa.js +1 -2
- package/dist/posteffect/fxaa.js.map +1 -1
- package/dist/posteffect/grayscale.js +1 -2
- package/dist/posteffect/grayscale.js.map +1 -1
- package/dist/posteffect/posteffect.js +0 -74
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +13 -29
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/tonemap.js +1 -2
- package/dist/posteffect/tonemap.js.map +1 -1
- package/dist/posteffect/water.js +20 -18
- package/dist/posteffect/water.js.map +1 -1
- package/dist/render/abuffer_oit.js +352 -0
- package/dist/render/abuffer_oit.js.map +1 -0
- package/dist/render/cull_visitor.js +3 -3
- package/dist/render/depth_pass.js +3 -2
- package/dist/render/depth_pass.js.map +1 -1
- package/dist/render/depthpass.js +16 -19
- package/dist/render/depthpass.js.map +1 -1
- package/dist/render/drawable_mixin.js +152 -0
- package/dist/render/drawable_mixin.js.map +1 -0
- package/dist/render/envlight.js +165 -31
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/forward.js +3 -6
- package/dist/render/forward.js.map +1 -1
- package/dist/render/forward_pass.js +6 -5
- package/dist/render/forward_pass.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +58 -0
- package/dist/render/globalbindgroup_allocator.js.map +1 -0
- package/dist/render/lightpass.js +83 -49
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/objectcolorpass.js +50 -0
- package/dist/render/objectcolorpass.js.map +1 -0
- package/dist/render/objectpool.js +295 -0
- package/dist/render/objectpool.js.map +1 -0
- package/dist/render/oit.js +16 -0
- package/dist/render/oit.js.map +1 -0
- package/dist/render/render_queue.js +294 -107
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderbundle_wrapper.js +20 -0
- package/dist/render/renderbundle_wrapper.js.map +1 -0
- package/dist/render/renderer.js +108 -28
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/renderpass.js +96 -34
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +18 -37
- package/dist/render/shadowmap_pass.js.map +1 -1
- package/dist/render/sky.js +2 -2
- package/dist/render/watermesh.js +140 -48
- package/dist/render/watermesh.js.map +1 -1
- package/dist/render/weightedblended_oit.js +171 -0
- package/dist/render/weightedblended_oit.js.map +1 -0
- package/dist/scene/batchgroup.js +8 -35
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +24 -4
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +1 -10
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +42 -32
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/scene.js +7 -37
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +6 -2
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +26 -11
- package/dist/scene/terrain/grass.js.map +1 -1
- package/dist/scene/terrain/patch.js +27 -15
- package/dist/scene/terrain/patch.js.map +1 -1
- package/dist/scene/terrain/quadtree.js +3 -3
- package/dist/scene/terrain/terrain.js +0 -8
- package/dist/scene/terrain/terrain.js.map +1 -1
- package/dist/shaders/lighting.js +14 -10
- package/dist/shaders/lighting.js.map +1 -1
- package/dist/shaders/water.js +4 -4
- package/dist/shadow/esm.js +4 -23
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/shadowmapper.js +45 -21
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +4 -25
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/draco/decoder.js +116 -0
- package/dist/utility/draco/decoder.js.map +1 -0
- package/dist/utility/sheenlut.js +196 -0
- package/dist/utility/sheenlut.js.map +1 -0
- package/dist/values.js +18 -1
- package/dist/values.js.map +1 -1
- package/package.json +7 -6
- package/dist/utility/noisetexture.js +0 -66
- package/dist/utility/noisetexture.js.map +0 -1
- package/dist/utility/textures/gradientnoise.js +0 -66
- package/dist/utility/textures/gradientnoise.js.map +0 -1
- package/dist/utility/textures/randomnoise.js +0 -41
- package/dist/utility/textures/randomnoise.js.map +0 -1
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
import { Application } from '../app.js';
|
|
2
1
|
import { linearToGamma } from '../shaders/misc.js';
|
|
3
|
-
import '@zephyr3d/base';
|
|
4
|
-
import '../scene/octree.js';
|
|
5
|
-
import '../material/shader/helper.js';
|
|
6
|
-
import '../material/lambert.js';
|
|
7
|
-
import '../material/blinn.js';
|
|
8
|
-
import '../material/unlit.js';
|
|
9
|
-
import '../material/material.js';
|
|
10
|
-
import '../material/meshmaterial.js';
|
|
11
|
-
import '../material/grassmaterial.js';
|
|
12
|
-
import '../material/terrainmaterial.js';
|
|
13
|
-
import '../material/pbrmr.js';
|
|
14
|
-
import '../material/pbrsg.js';
|
|
15
|
-
import '@zephyr3d/device';
|
|
16
|
-
import '../render/renderer.js';
|
|
17
|
-
import '../render/sky.js';
|
|
18
|
-
import '../render/clipmap.js';
|
|
19
|
-
import { TemporalCache } from '../render/temporalcache.js';
|
|
20
|
-
import '../render/watermesh.js';
|
|
21
2
|
|
|
22
3
|
/**
|
|
23
4
|
* Post processing compositor
|
|
@@ -95,26 +76,20 @@ import '../render/watermesh.js';
|
|
|
95
76
|
];
|
|
96
77
|
}
|
|
97
78
|
/** @internal */ begin(ctx) {
|
|
98
|
-
const device =
|
|
79
|
+
const device = ctx.device;
|
|
99
80
|
const format = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';
|
|
100
81
|
const finalFramebuffer = device.getFramebuffer();
|
|
101
82
|
const depth = finalFramebuffer?.getDepthAttachment();
|
|
102
|
-
let pingpongFramebuffers;
|
|
103
83
|
let msFramebuffer = null;
|
|
84
|
+
const w = depth ? depth.width : ctx.viewportWidth;
|
|
85
|
+
const h = depth ? depth.height : ctx.viewportHeight;
|
|
104
86
|
if (ctx.primaryCamera.sampleCount > 1) {
|
|
105
|
-
msFramebuffer =
|
|
106
|
-
}
|
|
107
|
-
if (ctx.defaultViewport) {
|
|
108
|
-
pingpongFramebuffers = [
|
|
109
|
-
depth ? TemporalCache.getFramebufferVariantSizeWithDepth(depth, 1, format, '2d', false, 1) : TemporalCache.getFramebufferVariantSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, 1),
|
|
110
|
-
depth ? TemporalCache.getFramebufferVariantSizeWithDepth(depth, 1, format, '2d', false, 1) : TemporalCache.getFramebufferVariantSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, 1)
|
|
111
|
-
];
|
|
112
|
-
} else {
|
|
113
|
-
pingpongFramebuffers = [
|
|
114
|
-
depth ? TemporalCache.getFramebufferFixedSizeWithDepth(depth, 1, format, '2d', false, 4) : TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, 4),
|
|
115
|
-
depth ? TemporalCache.getFramebufferFixedSizeWithDepth(depth, 1, format, '2d', false, 4) : TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, 4)
|
|
116
|
-
];
|
|
87
|
+
msFramebuffer = device.pool.fetchTemporalFramebuffer(true, w, h, format, depth, false, ctx.primaryCamera.sampleCount);
|
|
117
88
|
}
|
|
89
|
+
const pingpongFramebuffers = [
|
|
90
|
+
device.pool.fetchTemporalFramebuffer(true, w, h, format, depth ?? ctx.depthFormat, false),
|
|
91
|
+
device.pool.fetchTemporalFramebuffer(true, w, h, format, depth ?? ctx.depthFormat, false)
|
|
92
|
+
];
|
|
118
93
|
let writeIndex;
|
|
119
94
|
if (msFramebuffer) {
|
|
120
95
|
writeIndex = 3;
|
|
@@ -128,14 +103,14 @@ import '../render/watermesh.js';
|
|
|
128
103
|
ctx.compositorContex = {
|
|
129
104
|
finalFramebuffer,
|
|
130
105
|
pingpongFramebuffers,
|
|
131
|
-
msFramebuffer,
|
|
106
|
+
msTexture: msFramebuffer,
|
|
132
107
|
writeIndex
|
|
133
108
|
};
|
|
134
109
|
}
|
|
135
110
|
/** @internal */ drawPostEffects(ctx, opaque, sceneDepthTexture) {
|
|
136
111
|
const postEffects = opaque ? this._postEffectsOpaque : this._postEffectsTransparency;
|
|
137
112
|
if (postEffects.length > 0) {
|
|
138
|
-
const device =
|
|
113
|
+
const device = ctx.device;
|
|
139
114
|
for(let i = 0; i < postEffects.length; i++){
|
|
140
115
|
const postEffect = postEffects[i];
|
|
141
116
|
if (!postEffect.enabled) {
|
|
@@ -159,7 +134,7 @@ import '../render/watermesh.js';
|
|
|
159
134
|
}
|
|
160
135
|
}
|
|
161
136
|
/** @internal */ end(ctx) {
|
|
162
|
-
const device =
|
|
137
|
+
const device = ctx.device;
|
|
163
138
|
if (device.getFramebuffer() !== ctx.compositorContex.finalFramebuffer) {
|
|
164
139
|
const srcTex = device.getFramebuffer().getColorAttachments()[0];
|
|
165
140
|
device.setFramebuffer(ctx.compositorContex.finalFramebuffer);
|
|
@@ -167,11 +142,6 @@ import '../render/watermesh.js';
|
|
|
167
142
|
device.setScissor(null);
|
|
168
143
|
Compositor._blit(device, srcTex, !ctx.compositorContex.finalFramebuffer);
|
|
169
144
|
}
|
|
170
|
-
TemporalCache.releaseFramebuffer(ctx.compositorContex.pingpongFramebuffers[0]);
|
|
171
|
-
TemporalCache.releaseFramebuffer(ctx.compositorContex.pingpongFramebuffers[1]);
|
|
172
|
-
if (ctx.compositorContex.msFramebuffer) {
|
|
173
|
-
TemporalCache.releaseFramebuffer(ctx.compositorContex.msFramebuffer);
|
|
174
|
-
}
|
|
175
145
|
ctx.compositorContex = null;
|
|
176
146
|
}
|
|
177
147
|
/** @internal */ isLastPostEffect(opaque, index) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compositor.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compositor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/posteffect/fxaa.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Vector2 } from '@zephyr3d/base';
|
|
2
|
-
import { Application } from '../app.js';
|
|
3
2
|
import { AbstractPostEffect } from './posteffect.js';
|
|
4
3
|
import { linearToGamma } from '../shaders/misc.js';
|
|
5
4
|
|
|
@@ -31,7 +30,7 @@ import { linearToGamma } from '../shaders/misc.js';
|
|
|
31
30
|
return false;
|
|
32
31
|
}
|
|
33
32
|
/** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
34
|
-
const device =
|
|
33
|
+
const device = ctx.device;
|
|
35
34
|
this._prepare(device);
|
|
36
35
|
this._invTexSize.setXY(1 / inputColorTexture.width, 1 / inputColorTexture.height);
|
|
37
36
|
this._bindgroup.setTexture('srcTex', inputColorTexture, FXAA._sampler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fxaa.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fxaa.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Application } from '../app.js';
|
|
2
1
|
import { AbstractPostEffect } from './posteffect.js';
|
|
3
2
|
import { linearToGamma } from '../shaders/misc.js';
|
|
4
3
|
|
|
@@ -28,7 +27,7 @@ import { linearToGamma } from '../shaders/misc.js';
|
|
|
28
27
|
return false;
|
|
29
28
|
}
|
|
30
29
|
/** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
31
|
-
const device =
|
|
30
|
+
const device = ctx.device;
|
|
32
31
|
this._prepare(device);
|
|
33
32
|
this._bindgroup.setTexture('srcTex', inputColorTexture, Grayscale._sampler);
|
|
34
33
|
this._bindgroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grayscale.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"grayscale.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Application } from '../app.js';
|
|
2
1
|
import { drawFullscreenQuad } from '../render/fullscreenquad.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -10,7 +9,6 @@ import { drawFullscreenQuad } from '../render/fullscreenquad.js';
|
|
|
10
9
|
_quadRenderStateSet;
|
|
11
10
|
_enabled;
|
|
12
11
|
_opaque;
|
|
13
|
-
_intermediateFramebuffers;
|
|
14
12
|
/**
|
|
15
13
|
* Creates an instance of a post effect
|
|
16
14
|
* @param name - Name of the post effect
|
|
@@ -20,7 +18,6 @@ import { drawFullscreenQuad } from '../render/fullscreenquad.js';
|
|
|
20
18
|
this._quadRenderStateSet = null;
|
|
21
19
|
this._enabled = true;
|
|
22
20
|
this._opaque = false;
|
|
23
|
-
this._intermediateFramebuffers = {};
|
|
24
21
|
}
|
|
25
22
|
/** Whether this post effect is enabled */ get enabled() {
|
|
26
23
|
return this._enabled;
|
|
@@ -39,82 +36,11 @@ import { drawFullscreenQuad } from '../render/fullscreenquad.js';
|
|
|
39
36
|
return device.type === 'webgpu' && !!device.getFramebuffer();
|
|
40
37
|
}
|
|
41
38
|
/**
|
|
42
|
-
* Adds an intermediate frame buffer
|
|
43
|
-
* @param name - Name of the frame buffer
|
|
44
|
-
* @param format - Render target texture format
|
|
45
|
-
* @param useDepth - Whether the scene depth buffer should be attached to the frame buffer
|
|
46
|
-
*/ addIntermediateFramebuffer(name, depth) {
|
|
47
|
-
if (this._intermediateFramebuffers[name]) {
|
|
48
|
-
throw new Error(`Intermediate framebuffer already exists: ${name}`);
|
|
49
|
-
}
|
|
50
|
-
this._intermediateFramebuffers[name] = {
|
|
51
|
-
depth,
|
|
52
|
-
framebuffer: null
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Gets the intermediate frame buffer by name
|
|
57
|
-
* @param name - Name of the intermediate frame buffer
|
|
58
|
-
* @param width - Width of the frame buffer
|
|
59
|
-
* @param height - Height of the frame buffer
|
|
60
|
-
* @returns The intermediate frame buffer or null if not exists
|
|
61
|
-
*
|
|
62
|
-
* @remarks
|
|
63
|
-
* The intemediate buffer will be resized to fit the given size if needed
|
|
64
|
-
*/ getIntermediateFramebuffer(name, format, width, height) {
|
|
65
|
-
const fb = this._intermediateFramebuffers[name];
|
|
66
|
-
if (!fb) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
const device = Application.instance.device;
|
|
70
|
-
const currentDepthBuffer = device.getFramebuffer().getDepthAttachment();
|
|
71
|
-
if (fb.framebuffer) {
|
|
72
|
-
const colorTex = fb.framebuffer.getColorAttachments()[0];
|
|
73
|
-
const depthTex = fb.framebuffer.getDepthAttachment();
|
|
74
|
-
if (colorTex.width !== width || colorTex.height !== height || colorTex.format !== format) {
|
|
75
|
-
fb.framebuffer.dispose();
|
|
76
|
-
colorTex.dispose();
|
|
77
|
-
if (depthTex && depthTex !== currentDepthBuffer) {
|
|
78
|
-
depthTex.dispose();
|
|
79
|
-
}
|
|
80
|
-
fb.framebuffer = null;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (!fb.framebuffer) {
|
|
84
|
-
const colorTex = device.createTexture2D(format, width, height, {
|
|
85
|
-
samplerOptions: {
|
|
86
|
-
mipFilter: 'none'
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
colorTex.name = `Intermediate-<${name}>`;
|
|
90
|
-
let depthTex = null;
|
|
91
|
-
if (fb.depth === 'current') {
|
|
92
|
-
depthTex = currentDepthBuffer;
|
|
93
|
-
} else if (fb.depth === 'temporal') {
|
|
94
|
-
depthTex = device.createTexture2D('d24s8', width, height);
|
|
95
|
-
depthTex.name = `Intermediate-<${name}>-depth`;
|
|
96
|
-
}
|
|
97
|
-
fb.framebuffer = device.createFrameBuffer([
|
|
98
|
-
colorTex
|
|
99
|
-
], depthTex);
|
|
100
|
-
}
|
|
101
|
-
return fb.framebuffer;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
39
|
* Disposes the post effect.
|
|
105
40
|
*/ dispose() {
|
|
106
41
|
this._quadVertexLayout?.dispose();
|
|
107
42
|
this._quadVertexLayout = null;
|
|
108
43
|
this._quadRenderStateSet = null;
|
|
109
|
-
for(const k in this._intermediateFramebuffers){
|
|
110
|
-
const fb = this._intermediateFramebuffers[k];
|
|
111
|
-
if (fb) {
|
|
112
|
-
const colorAttachment = fb.framebuffer.getColorAttachments()[0];
|
|
113
|
-
fb.framebuffer.dispose();
|
|
114
|
-
colorAttachment.dispose();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
this._intermediateFramebuffers = {};
|
|
118
44
|
}
|
|
119
45
|
/**
|
|
120
46
|
* Draws a fullscreen quad
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posteffect.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"posteffect.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/posteffect/sao.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
import { isFloatTextureFormat } from '@zephyr3d/device';
|
|
2
|
-
import { Application } from '../app.js';
|
|
3
2
|
import { AbstractPostEffect } from './posteffect.js';
|
|
4
3
|
import { decodeNormalizedFloatFromRGBA, encodeNormalizedFloatToRGBA } from '../shaders/misc.js';
|
|
5
4
|
import { Vector2, Vector4, Matrix4x4 } from '@zephyr3d/base';
|
|
6
5
|
import { AOBilateralBlurBlitter } from '../blitter/depthlimitedgaussion.js';
|
|
6
|
+
import '../app.js';
|
|
7
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 '../render/renderer.js';
|
|
20
|
-
import '../render/sky.js';
|
|
21
|
-
import '../render/clipmap.js';
|
|
22
|
-
import { TemporalCache } from '../render/temporalcache.js';
|
|
23
|
-
import '../render/watermesh.js';
|
|
24
8
|
|
|
25
9
|
const NUM_SAMPLES = 7;
|
|
26
10
|
const NUM_RINGS = 4;
|
|
@@ -56,7 +40,7 @@ const NUM_RINGS = 4;
|
|
|
56
40
|
this._opaque = true;
|
|
57
41
|
this._saoScale = 10;
|
|
58
42
|
this._saoBias = 1;
|
|
59
|
-
this._saoIntensity = 0.
|
|
43
|
+
this._saoIntensity = 0.025;
|
|
60
44
|
this._saoRadius = 100;
|
|
61
45
|
this._saoMinResolution = 0;
|
|
62
46
|
this._saoRandomSeed = 0;
|
|
@@ -68,8 +52,6 @@ const NUM_RINGS = 4;
|
|
|
68
52
|
this._blitterV.kernelRadius = 8;
|
|
69
53
|
this._blitterV.stdDev = 10;
|
|
70
54
|
this._copyBlitter = new CopyBlitter();
|
|
71
|
-
this.addIntermediateFramebuffer('ao', 'current');
|
|
72
|
-
this.addIntermediateFramebuffer('blur', 'current');
|
|
73
55
|
}
|
|
74
56
|
/** Scale value */ get scale() {
|
|
75
57
|
return this._saoScale;
|
|
@@ -129,7 +111,7 @@ const NUM_RINGS = 4;
|
|
|
129
111
|
return true;
|
|
130
112
|
}
|
|
131
113
|
/** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
132
|
-
const device =
|
|
114
|
+
const device = ctx.device;
|
|
133
115
|
const viewport = device.getViewport();
|
|
134
116
|
this._prepare(device, inputColorTexture);
|
|
135
117
|
this._copyBlitter.srgbOut = srgbOutput;
|
|
@@ -139,12 +121,14 @@ const NUM_RINGS = 4;
|
|
|
139
121
|
}
|
|
140
122
|
const fmt = this._getIntermediateTextureFormat(device);
|
|
141
123
|
const depth = device.getFramebuffer().getDepthAttachment();
|
|
142
|
-
const fbao =
|
|
143
|
-
const fbblur =
|
|
144
|
-
const packed = fbao.
|
|
124
|
+
const fbao = device.pool.fetchTemporalTexture2D(false, fmt, depth.width, depth.height, false);
|
|
125
|
+
const fbblur = device.pool.fetchTemporalTexture2D(false, fmt, depth.width, depth.height, false);
|
|
126
|
+
const packed = fbao.format === 'rgba8unorm';
|
|
145
127
|
const cameraNearFar = new Vector2(ctx.camera.getNearPlane(), ctx.camera.getFarPlane());
|
|
146
128
|
device.pushDeviceStates();
|
|
147
|
-
device.setFramebuffer(
|
|
129
|
+
device.setFramebuffer([
|
|
130
|
+
fbao
|
|
131
|
+
], depth);
|
|
148
132
|
device.clearFrameBuffer(packed ? new Vector4(0, 0, 0, 1) : new Vector4(1, 0, 0, 1), null, null);
|
|
149
133
|
const bindgroup = packed ? this._bindgroupPacked : this._bindgroup;
|
|
150
134
|
bindgroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
@@ -177,11 +161,11 @@ const NUM_RINGS = 4;
|
|
|
177
161
|
this._blitterV.packed = packed;
|
|
178
162
|
this._blitterV.srgbOut = srgbOutput;
|
|
179
163
|
this._blitterV.renderStates = SAO._renderStateBlend;
|
|
180
|
-
this._blitterH.blit(fbao
|
|
164
|
+
this._blitterH.blit(fbao, fbblur);
|
|
181
165
|
device.popDeviceStates();
|
|
182
|
-
this._blitterV.blit(fbblur
|
|
183
|
-
|
|
184
|
-
|
|
166
|
+
this._blitterV.blit(fbblur, device.getFramebuffer());
|
|
167
|
+
device.pool.releaseTexture(fbao);
|
|
168
|
+
device.pool.releaseTexture(fbblur);
|
|
185
169
|
}
|
|
186
170
|
_getIntermediateTextureFormat(device) {
|
|
187
171
|
const texCaps = device.getDeviceCaps().textureCaps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sao.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sao.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Application } from '../app.js';
|
|
2
1
|
import { AbstractPostEffect } from './posteffect.js';
|
|
3
2
|
import { linearToGamma } from '../shaders/misc.js';
|
|
4
3
|
|
|
@@ -31,7 +30,7 @@ import { linearToGamma } from '../shaders/misc.js';
|
|
|
31
30
|
return false;
|
|
32
31
|
}
|
|
33
32
|
/** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
34
|
-
const device =
|
|
33
|
+
const device = ctx.device;
|
|
35
34
|
this._prepare(device, inputColorTexture);
|
|
36
35
|
this._tonemap(device, inputColorTexture, srgbOutput);
|
|
37
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tonemap.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tonemap.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/posteffect/water.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { Application } from '../app.js';
|
|
2
1
|
import { Vector4, Interpolator, Vector2, Plane, Matrix4x4, Vector3 } from '@zephyr3d/base';
|
|
3
2
|
import '../scene/octree.js';
|
|
3
|
+
import '../app.js';
|
|
4
|
+
import '@zephyr3d/device';
|
|
4
5
|
import '../material/shader/helper.js';
|
|
5
6
|
import '../material/lambert.js';
|
|
6
7
|
import '../material/blinn.js';
|
|
7
8
|
import '../material/unlit.js';
|
|
8
|
-
import '../material/material.js';
|
|
9
9
|
import '../material/meshmaterial.js';
|
|
10
10
|
import '../material/grassmaterial.js';
|
|
11
11
|
import '../material/terrainmaterial.js';
|
|
12
12
|
import '../material/pbrmr.js';
|
|
13
13
|
import '../material/pbrsg.js';
|
|
14
|
-
import '@zephyr3d/device';
|
|
15
14
|
import '../render/renderer.js';
|
|
16
15
|
import '../render/sky.js';
|
|
17
16
|
import '../render/clipmap.js';
|
|
18
|
-
import { TemporalCache } from '../render/temporalcache.js';
|
|
19
17
|
import { WaterMesh } from '../render/watermesh.js';
|
|
20
18
|
import { AbstractPostEffect } from './posteffect.js';
|
|
21
19
|
import { decodeNormalizedFloatFromRGBA, linearToGamma } from '../shaders/misc.js';
|
|
@@ -115,7 +113,6 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
115
113
|
0.6
|
|
116
114
|
]));
|
|
117
115
|
this._rampTex = null;
|
|
118
|
-
this.addIntermediateFramebuffer('reflection', 'temporal');
|
|
119
116
|
this._foamWidth = 1.2;
|
|
120
117
|
this._foamContrast = 7.2;
|
|
121
118
|
this._waterWireframe = false;
|
|
@@ -312,7 +309,7 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
312
309
|
return true;
|
|
313
310
|
}
|
|
314
311
|
/** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
315
|
-
const device =
|
|
312
|
+
const device = ctx.device;
|
|
316
313
|
const rampTex = this._getRampTexture(device);
|
|
317
314
|
this._copyBlitter.srgbOut = srgbOutput;
|
|
318
315
|
this._copyBlitter.blit(inputColorTexture, device.getFramebuffer(), device.createSampler({
|
|
@@ -326,7 +323,7 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
326
323
|
return;
|
|
327
324
|
}
|
|
328
325
|
this._renderingReflections = true;
|
|
329
|
-
const fbRefl =
|
|
326
|
+
const fbRefl = ctx.device.pool.fetchTemporalFramebuffer(true, this._reflectSize, this._reflectSize, inputColorTexture.format, ctx.depthFormat, false);
|
|
330
327
|
const plane = new Plane(0, -1, 0, this._elevation);
|
|
331
328
|
const clipPlane = new Plane(0, -1, 0, this._elevation - this._antiReflectanceLeak);
|
|
332
329
|
const matReflectionR = Matrix4x4.invert(Matrix4x4.reflection(-plane.a, -plane.b, -plane.c, -plane.d));
|
|
@@ -371,7 +368,6 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
371
368
|
waterMesh.bindGroup.setValue('depthMulti', this._depthMulti);
|
|
372
369
|
waterMesh.bindGroup.setValue('refractionStrength', this._refractionStrength);
|
|
373
370
|
waterMesh.bindGroup.setValue('targetSize', new Vector2(device.getViewport().width, device.getViewport().height));
|
|
374
|
-
waterMesh.bindGroup.setValue('envLightStrength', ctx.env.light.strength);
|
|
375
371
|
waterMesh.bindGroup.setValue('waterLevel', this._elevation);
|
|
376
372
|
waterMesh.bindGroup.setValue('srgbOut', srgbOutput ? 1 : 0);
|
|
377
373
|
if (ctx.sunLight) {
|
|
@@ -379,9 +375,11 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
379
375
|
waterMesh.bindGroup.setValue('lightShininess', 0.7);
|
|
380
376
|
waterMesh.bindGroup.setValue('lightDiffuseAndIntensity', ctx.sunLight.diffuseAndIntensity);
|
|
381
377
|
}
|
|
382
|
-
ctx.env.light.envLight
|
|
378
|
+
if (ctx.env.light.envLight) {
|
|
379
|
+
waterMesh.bindGroup.setValue('envLightStrength', ctx.env.light.strength);
|
|
380
|
+
ctx.env.light.envLight.updateBindGroup(waterMesh.bindGroup);
|
|
381
|
+
}
|
|
383
382
|
waterMesh.render(ctx.camera, this.needFlip(device));
|
|
384
|
-
TemporalCache.releaseFramebuffer(fbRefl);
|
|
385
383
|
}
|
|
386
384
|
/** @internal */ _getRampTexture(device) {
|
|
387
385
|
if (!this._rampTex) {
|
|
@@ -397,7 +395,7 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
397
395
|
const tmpcolor = new Vector3();
|
|
398
396
|
for(let i = 0; i < numTexels; i++){
|
|
399
397
|
const grad = i >= numTexels / 2 ? this._scatterGrad : this._absorptionGrad;
|
|
400
|
-
grad.interpolate(i % width / width,
|
|
398
|
+
grad.interpolate(i % width / width, tmpcolor);
|
|
401
399
|
data[i * 4 + 0] = tmpcolor.x * 255 >> 0;
|
|
402
400
|
data[i * 4 + 1] = tmpcolor.y * 255 >> 0;
|
|
403
401
|
data[i * 4 + 2] = tmpcolor.z * 255 >> 0;
|
|
@@ -412,7 +410,7 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
412
410
|
const hash = `${ctx.sunLight ? 1 : 0}:${ctx.env.light.getHash(ctx)}`;
|
|
413
411
|
let waterMesh = this._waterMeshes[hash];
|
|
414
412
|
if (!waterMesh) {
|
|
415
|
-
const device =
|
|
413
|
+
const device = ctx.device;
|
|
416
414
|
waterMesh = new WaterMesh(device, {
|
|
417
415
|
setupUniforms (scope) {
|
|
418
416
|
const pb = scope.$builder;
|
|
@@ -428,7 +426,6 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
428
426
|
scope.cameraPos = pb.vec3().uniform(0);
|
|
429
427
|
scope.invViewProj = pb.mat4().uniform(0);
|
|
430
428
|
scope.targetSize = pb.vec2().uniform(0);
|
|
431
|
-
scope.envLightStrength = pb.float().uniform(0);
|
|
432
429
|
scope.waterLevel = pb.float().uniform(0);
|
|
433
430
|
scope.srgbOut = pb.int().uniform(0);
|
|
434
431
|
if (ctx.sunLight) {
|
|
@@ -437,7 +434,10 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
437
434
|
scope.lightDiffuseAndIntensity = pb.vec4().uniform(0);
|
|
438
435
|
}
|
|
439
436
|
}
|
|
440
|
-
ctx.env.light.envLight
|
|
437
|
+
if (ctx.env.light.envLight) {
|
|
438
|
+
scope.envLightStrength = pb.float().uniform(0);
|
|
439
|
+
ctx.env.light.envLight.initShaderBindings(pb);
|
|
440
|
+
}
|
|
441
441
|
},
|
|
442
442
|
shading (scope, worldPos, worldNormal, foamFactor) {
|
|
443
443
|
const pb = scope.$builder;
|
|
@@ -513,10 +513,12 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
513
513
|
this.$l.specular = pb.mul(this.D, this.VIS, this.F, this.lightDiffuseAndIntensity.rgb, this.lightDiffuseAndIntensity.a);
|
|
514
514
|
this.finalColor = pb.add(this.finalColor, this.specular);
|
|
515
515
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
516
|
+
if (ctx.env.light.envLight) {
|
|
517
|
+
const irradiance = ctx.env.light.envLight.getIrradiance(this, this.myNormal);
|
|
518
|
+
if (irradiance) {
|
|
519
|
+
this.$l.sss = pb.mul(this.getScattering(this.depth), irradiance, this.envLightStrength);
|
|
520
|
+
this.finalColor = pb.add(this.finalColor, this.sss);
|
|
521
|
+
}
|
|
520
522
|
}
|
|
521
523
|
this.$if(pb.notEqual(this.srgbOut, 0), function() {
|
|
522
524
|
this.finalColor = linearToGamma(this, this.finalColor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"water.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"water.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|