@zephyr3d/scene 0.4.0 → 0.6.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 +191 -51
- 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 +70 -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 +107 -5
- 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/app.js +4 -26
- package/dist/app.js.map +1 -1
- package/dist/asset/assetmanager.js +60 -109
- 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 +287 -40
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/image/tga_Loader.js +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 +16 -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 +9 -3
- 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 +200 -4
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +6406 -5786
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +15 -4
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +26 -17
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +13 -2
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +103 -31
- 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 +16 -7
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -7
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +2 -2
- package/dist/material/mixins/pbr/common.js +454 -19
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/pbrmr.js +28 -6
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +27 -9
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +128 -23
- package/dist/material/shader/helper.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 -53
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +48 -58
- 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 +55 -48
- 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 +306 -340
- 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 +8 -6
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/depthpass.js +30 -14
- package/dist/render/depthpass.js.map +1 -1
- package/dist/render/drawable_mixin.js +70 -22
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/envlight.js +169 -33
- 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 +68 -28
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/objectcolorpass.js +51 -0
- package/dist/render/objectcolorpass.js.map +1 -0
- package/dist/render/render_queue.js +211 -158
- 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 +151 -35
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/renderpass.js +27 -20
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +20 -14
- 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/render/weightedblended_oit.js +11 -28
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/batchgroup.js +60 -14
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +24 -3
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +0 -14
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/light.js +5 -5
- package/dist/scene/mesh.js +62 -15
- 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 +6 -9
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +11 -8
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +10 -2
- 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 +10 -2
- package/dist/scene/terrain/patch.js.map +1 -1
- package/dist/scene/terrain/quadtree.js +2 -2
- 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/esm.js +4 -22
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/shadowmapper.js +56 -31
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +4 -24
- package/dist/shadow/vsm.js.map +1 -1
- 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/draco/decoder.js +116 -0
- package/dist/utility/draco/decoder.js.map +1 -0
- 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 +25 -1
- package/dist/values.js.map +1 -1
- package/package.json +5 -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/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
|
@@ -1,30 +1,15 @@
|
|
|
1
1
|
import { linearToGamma } from '../shaders/misc.js';
|
|
2
|
-
import '
|
|
3
|
-
import '
|
|
4
|
-
import '../
|
|
5
|
-
import '@zephyr3d/device';
|
|
6
|
-
import '../material/shader/helper.js';
|
|
7
|
-
import '../material/lambert.js';
|
|
8
|
-
import '../material/blinn.js';
|
|
9
|
-
import '../material/unlit.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 '../render/renderer.js';
|
|
16
|
-
import '../render/sky.js';
|
|
17
|
-
import '../render/clipmap.js';
|
|
18
|
-
import { TemporalCache } from '../render/temporalcache.js';
|
|
19
|
-
import '../render/watermesh.js';
|
|
2
|
+
import { MaterialVaryingFlags } from '../values.js';
|
|
3
|
+
import { SSR } from './ssr.js';
|
|
4
|
+
import { fetchSampler } from '../utility/misc.js';
|
|
20
5
|
|
|
21
6
|
/**
|
|
22
7
|
* Post processing compositor
|
|
23
8
|
* @public
|
|
24
9
|
*/ class Compositor {
|
|
10
|
+
/** @internal */ static _SSRPostEffect = null;
|
|
25
11
|
/** @internal */ _postEffectsOpaque;
|
|
26
12
|
/** @internal */ _postEffectsTransparency;
|
|
27
|
-
/** @internal */ static _blitSampler = null;
|
|
28
13
|
/** @internal */ static _blitProgram = null;
|
|
29
14
|
/** @internal */ static _blitBindgroup = null;
|
|
30
15
|
/** @internal */ static _blitRenderStates = null;
|
|
@@ -35,14 +20,14 @@ import '../render/watermesh.js';
|
|
|
35
20
|
this._postEffectsOpaque = [];
|
|
36
21
|
this._postEffectsTransparency = [];
|
|
37
22
|
}
|
|
38
|
-
/** @internal */ requireLinearDepth() {
|
|
23
|
+
/** @internal */ requireLinearDepth(ctx) {
|
|
39
24
|
for (const postEffect of this._postEffectsOpaque){
|
|
40
|
-
if (postEffect.requireLinearDepthTexture()) {
|
|
25
|
+
if (postEffect.requireLinearDepthTexture(ctx)) {
|
|
41
26
|
return true;
|
|
42
27
|
}
|
|
43
28
|
}
|
|
44
29
|
for (const postEffect of this._postEffectsTransparency){
|
|
45
|
-
if (postEffect.requireLinearDepthTexture()) {
|
|
30
|
+
if (postEffect.requireLinearDepthTexture(ctx)) {
|
|
46
31
|
return true;
|
|
47
32
|
}
|
|
48
33
|
}
|
|
@@ -94,26 +79,30 @@ import '../render/watermesh.js';
|
|
|
94
79
|
];
|
|
95
80
|
}
|
|
96
81
|
/** @internal */ begin(ctx) {
|
|
82
|
+
const ssr = !!(ctx.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS);
|
|
83
|
+
if (this._postEffectsOpaque.length === 0 && this._postEffectsTransparency.length === 0 && ctx.primaryCamera.sampleCount === 1 && !ssr) {
|
|
84
|
+
ctx.compositorContex = null;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
97
87
|
const device = ctx.device;
|
|
98
88
|
const format = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';
|
|
99
89
|
const finalFramebuffer = device.getFramebuffer();
|
|
100
90
|
const depth = finalFramebuffer?.getDepthAttachment();
|
|
101
|
-
let pingpongFramebuffers;
|
|
102
91
|
let msFramebuffer = null;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
pingpongFramebuffers = [
|
|
113
|
-
depth ? TemporalCache.getFramebufferFixedSizeWithDepth(depth, 1, format, '2d', false, 4) : TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, 4),
|
|
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
|
-
];
|
|
92
|
+
const w = depth ? depth.width : ctx.viewportWidth;
|
|
93
|
+
const h = depth ? depth.height : ctx.viewportHeight;
|
|
94
|
+
if (ctx.primaryCamera.sampleCount > 1 || ssr) {
|
|
95
|
+
const fmt2 = ssr ? device.type === 'webgl' ? format : 'rgba8unorm' : format;
|
|
96
|
+
msFramebuffer = device.pool.fetchTemporalFramebuffer(true, w, h, ssr ? [
|
|
97
|
+
format,
|
|
98
|
+
fmt2,
|
|
99
|
+
fmt2
|
|
100
|
+
] : format, depth, ssr, ctx.primaryCamera.sampleCount);
|
|
116
101
|
}
|
|
102
|
+
const pingpongFramebuffers = [
|
|
103
|
+
device.pool.fetchTemporalFramebuffer(true, w, h, format, depth ?? ctx.depthFormat, false),
|
|
104
|
+
device.pool.fetchTemporalFramebuffer(true, w, h, format, depth ?? ctx.depthFormat, false)
|
|
105
|
+
];
|
|
117
106
|
let writeIndex;
|
|
118
107
|
if (msFramebuffer) {
|
|
119
108
|
writeIndex = 3;
|
|
@@ -127,9 +116,17 @@ import '../render/watermesh.js';
|
|
|
127
116
|
ctx.compositorContex = {
|
|
128
117
|
finalFramebuffer,
|
|
129
118
|
pingpongFramebuffers,
|
|
130
|
-
msFramebuffer,
|
|
119
|
+
msTexture: msFramebuffer,
|
|
131
120
|
writeIndex
|
|
132
121
|
};
|
|
122
|
+
if (ssr) {
|
|
123
|
+
if (!Compositor._SSRPostEffect) {
|
|
124
|
+
Compositor._SSRPostEffect = new SSR();
|
|
125
|
+
}
|
|
126
|
+
Compositor._SSRPostEffect.roughnessTexture = msFramebuffer.getColorAttachments()[1];
|
|
127
|
+
Compositor._SSRPostEffect.normalTexture = msFramebuffer.getColorAttachments()[2];
|
|
128
|
+
this._postEffectsOpaque.unshift(Compositor._SSRPostEffect);
|
|
129
|
+
}
|
|
133
130
|
}
|
|
134
131
|
/** @internal */ drawPostEffects(ctx, opaque, sceneDepthTexture) {
|
|
135
132
|
const postEffects = opaque ? this._postEffectsOpaque : this._postEffectsTransparency;
|
|
@@ -142,7 +139,7 @@ import '../render/watermesh.js';
|
|
|
142
139
|
}
|
|
143
140
|
const inputTexture = device.getFramebuffer().getColorAttachments()[0];
|
|
144
141
|
const isLast = this.isLastPostEffect(opaque, i);
|
|
145
|
-
const finalEffect = isLast && (!postEffect.requireDepthAttachment() || !!ctx.compositorContex.finalFramebuffer);
|
|
142
|
+
const finalEffect = isLast && (!postEffect.requireDepthAttachment(ctx) || !!ctx.compositorContex.finalFramebuffer);
|
|
146
143
|
if (finalEffect) {
|
|
147
144
|
device.setFramebuffer(ctx.compositorContex.finalFramebuffer);
|
|
148
145
|
device.setViewport(null);
|
|
@@ -158,20 +155,20 @@ import '../render/watermesh.js';
|
|
|
158
155
|
}
|
|
159
156
|
}
|
|
160
157
|
/** @internal */ end(ctx) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
158
|
+
if (ctx.compositorContex) {
|
|
159
|
+
const device = ctx.device;
|
|
160
|
+
if (device.getFramebuffer() !== ctx.compositorContex.finalFramebuffer) {
|
|
161
|
+
const srcTex = device.getFramebuffer().getColorAttachments()[0];
|
|
162
|
+
device.setFramebuffer(ctx.compositorContex.finalFramebuffer);
|
|
163
|
+
device.setViewport(null);
|
|
164
|
+
device.setScissor(null);
|
|
165
|
+
Compositor._blit(device, srcTex, !ctx.compositorContex.finalFramebuffer);
|
|
166
|
+
}
|
|
167
|
+
ctx.compositorContex = null;
|
|
168
168
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (ctx.compositorContex.msFramebuffer) {
|
|
172
|
-
TemporalCache.releaseFramebuffer(ctx.compositorContex.msFramebuffer);
|
|
169
|
+
if (this._postEffectsOpaque[0] === Compositor._SSRPostEffect) {
|
|
170
|
+
this._postEffectsOpaque.shift();
|
|
173
171
|
}
|
|
174
|
-
ctx.compositorContex = null;
|
|
175
172
|
}
|
|
176
173
|
/** @internal */ isLastPostEffect(opaque, index) {
|
|
177
174
|
const list = opaque ? this._postEffectsOpaque : this._postEffectsTransparency;
|
|
@@ -246,18 +243,11 @@ import '../render/watermesh.js';
|
|
|
246
243
|
}
|
|
247
244
|
]
|
|
248
245
|
});
|
|
249
|
-
this._blitSampler = device.createSampler({
|
|
250
|
-
minFilter: 'nearest',
|
|
251
|
-
magFilter: 'nearest',
|
|
252
|
-
mipFilter: 'none',
|
|
253
|
-
addressU: 'clamp',
|
|
254
|
-
addressV: 'clamp'
|
|
255
|
-
});
|
|
256
246
|
this._blitRenderStates = device.createRenderStateSet();
|
|
257
247
|
this._blitRenderStates.useRasterizerState().setCullMode('none');
|
|
258
248
|
this._blitRenderStates.useDepthState().enableTest(false).enableWrite(false);
|
|
259
249
|
}
|
|
260
|
-
this._blitBindgroup.setTexture('srcTex', srcTex,
|
|
250
|
+
this._blitBindgroup.setTexture('srcTex', srcTex, fetchSampler('clamp_nearest_nomip'));
|
|
261
251
|
this._blitBindgroup.setValue('srgbOutput', srgbOutput ? 1 : 0);
|
|
262
252
|
this._blitBindgroup.setValue('flip', device.type === 'webgpu' && !!device.getFramebuffer() ? 1 : 0);
|
|
263
253
|
device.setRenderStates(this._blitRenderStates);
|
|
@@ -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,13 +1,14 @@
|
|
|
1
1
|
import { Vector2 } from '@zephyr3d/base';
|
|
2
2
|
import { AbstractPostEffect } from './posteffect.js';
|
|
3
3
|
import { linearToGamma } from '../shaders/misc.js';
|
|
4
|
+
import { fetchSampler } from '../utility/misc.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* FXAA post effect
|
|
7
8
|
* @public
|
|
8
9
|
*/ class FXAA extends AbstractPostEffect {
|
|
10
|
+
static className = 'FXAA';
|
|
9
11
|
static _program = null;
|
|
10
|
-
static _sampler = null;
|
|
11
12
|
_bindgroup;
|
|
12
13
|
_invTexSize;
|
|
13
14
|
/**
|
|
@@ -33,7 +34,7 @@ import { linearToGamma } from '../shaders/misc.js';
|
|
|
33
34
|
const device = ctx.device;
|
|
34
35
|
this._prepare(device);
|
|
35
36
|
this._invTexSize.setXY(1 / inputColorTexture.width, 1 / inputColorTexture.height);
|
|
36
|
-
this._bindgroup.setTexture('srcTex', inputColorTexture,
|
|
37
|
+
this._bindgroup.setTexture('srcTex', inputColorTexture, fetchSampler('clamp_linear_nomip'));
|
|
37
38
|
this._bindgroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
38
39
|
this._bindgroup.setValue('srgbOut', srgbOutput ? 1 : 0);
|
|
39
40
|
this._bindgroup.setValue('invTexSize', this._invTexSize);
|
|
@@ -271,15 +272,6 @@ import { linearToGamma } from '../shaders/misc.js';
|
|
|
271
272
|
}
|
|
272
273
|
});
|
|
273
274
|
}
|
|
274
|
-
if (!FXAA._sampler) {
|
|
275
|
-
FXAA._sampler = device.createSampler({
|
|
276
|
-
magFilter: 'linear',
|
|
277
|
-
minFilter: 'linear',
|
|
278
|
-
mipFilter: 'none',
|
|
279
|
-
addressU: 'clamp',
|
|
280
|
-
addressV: 'clamp'
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
275
|
if (!this._bindgroup) {
|
|
284
276
|
this._bindgroup = device.createBindGroup(FXAA._program.bindGroupLayouts[0]);
|
|
285
277
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fxaa.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fxaa.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { AbstractPostEffect } from './posteffect.js';
|
|
2
2
|
import { linearToGamma } from '../shaders/misc.js';
|
|
3
|
+
import { fetchSampler } from '../utility/misc.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Grayscale post effect
|
|
6
7
|
* @public
|
|
7
8
|
*/ class Grayscale extends AbstractPostEffect {
|
|
9
|
+
static className = 'Grayscale';
|
|
8
10
|
static _program = null;
|
|
9
|
-
static _sampler = null;
|
|
10
11
|
_bindgroup;
|
|
11
12
|
/**
|
|
12
13
|
* Creates an instance of grayscale post effect
|
|
@@ -29,7 +30,7 @@ import { linearToGamma } from '../shaders/misc.js';
|
|
|
29
30
|
/** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
30
31
|
const device = ctx.device;
|
|
31
32
|
this._prepare(device);
|
|
32
|
-
this._bindgroup.setTexture('srcTex', inputColorTexture,
|
|
33
|
+
this._bindgroup.setTexture('srcTex', inputColorTexture, fetchSampler('clamp_nearest_nomip'));
|
|
33
34
|
this._bindgroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
34
35
|
this._bindgroup.setValue('srgbOut', srgbOutput ? 1 : 0);
|
|
35
36
|
device.setProgram(Grayscale._program);
|
|
@@ -67,15 +68,6 @@ import { linearToGamma } from '../shaders/misc.js';
|
|
|
67
68
|
}
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
|
-
if (!Grayscale._sampler) {
|
|
71
|
-
Grayscale._sampler = device.createSampler({
|
|
72
|
-
magFilter: 'nearest',
|
|
73
|
-
minFilter: 'nearest',
|
|
74
|
-
mipFilter: 'none',
|
|
75
|
-
addressU: 'clamp',
|
|
76
|
-
addressV: 'clamp'
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
71
|
if (!this._bindgroup) {
|
|
80
72
|
this._bindgroup = device.createBindGroup(Grayscale._program.bindGroupLayouts[0]);
|
|
81
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grayscale.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"grayscale.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -4,6 +4,7 @@ import { drawFullscreenQuad } from '../render/fullscreenquad.js';
|
|
|
4
4
|
* Base class for any type of post effect
|
|
5
5
|
* @public
|
|
6
6
|
*/ class AbstractPostEffect {
|
|
7
|
+
static className;
|
|
7
8
|
_outputTexture;
|
|
8
9
|
_quadVertexLayout;
|
|
9
10
|
_quadRenderStateSet;
|
|
@@ -19,6 +20,9 @@ import { drawFullscreenQuad } from '../render/fullscreenquad.js';
|
|
|
19
20
|
this._enabled = true;
|
|
20
21
|
this._opaque = false;
|
|
21
22
|
}
|
|
23
|
+
/** Gets class name of this instance */ getClassName() {
|
|
24
|
+
return this.constructor.className;
|
|
25
|
+
}
|
|
22
26
|
/** Whether this post effect is enabled */ get enabled() {
|
|
23
27
|
return this._enabled;
|
|
24
28
|
}
|
|
@@ -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
|
@@ -2,32 +2,49 @@ import { isFloatTextureFormat } from '@zephyr3d/device';
|
|
|
2
2
|
import { AbstractPostEffect } from './posteffect.js';
|
|
3
3
|
import { decodeNormalizedFloatFromRGBA, encodeNormalizedFloatToRGBA } from '../shaders/misc.js';
|
|
4
4
|
import { Vector2, Vector4, Matrix4x4 } from '@zephyr3d/base';
|
|
5
|
-
import {
|
|
6
|
-
import '../
|
|
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/meshmaterial.js';
|
|
14
|
-
import '../material/grassmaterial.js';
|
|
15
|
-
import '../material/terrainmaterial.js';
|
|
16
|
-
import '../material/pbrmr.js';
|
|
17
|
-
import '../material/pbrsg.js';
|
|
18
|
-
import '../render/renderer.js';
|
|
19
|
-
import '../render/sky.js';
|
|
20
|
-
import '../render/clipmap.js';
|
|
21
|
-
import { TemporalCache } from '../render/temporalcache.js';
|
|
22
|
-
import '../render/watermesh.js';
|
|
5
|
+
import { BilateralBlurBlitter } from '../blitter/bilateralblur.js';
|
|
6
|
+
import { copyTexture, fetchSampler } from '../utility/misc.js';
|
|
23
7
|
|
|
24
8
|
const NUM_SAMPLES = 7;
|
|
25
9
|
const NUM_RINGS = 4;
|
|
10
|
+
class DepthLimitAOBlurBlitter extends BilateralBlurBlitter {
|
|
11
|
+
_packed;
|
|
12
|
+
constructor(finalPhase){
|
|
13
|
+
super(finalPhase);
|
|
14
|
+
this._packed = false;
|
|
15
|
+
}
|
|
16
|
+
get packed() {
|
|
17
|
+
return this._packed;
|
|
18
|
+
}
|
|
19
|
+
set packed(val) {
|
|
20
|
+
if (this._packed !== !!val) {
|
|
21
|
+
this._packed = !!val;
|
|
22
|
+
this.invalidateHash();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
calcHash() {
|
|
26
|
+
return `${this._packed}:${super.calcHash()}`;
|
|
27
|
+
}
|
|
28
|
+
readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType) {
|
|
29
|
+
const pb = scope.$builder;
|
|
30
|
+
const texel = super.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);
|
|
31
|
+
if (this._packed) {
|
|
32
|
+
return pb.vec4(pb.vec3(decodeNormalizedFloatFromRGBA(scope, texel)), 1);
|
|
33
|
+
} else {
|
|
34
|
+
return pb.vec4(texel.rrr, 1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
writeTexel(scope, type, uv, texel) {
|
|
38
|
+
const pb = scope.$builder;
|
|
39
|
+
const outTexel = super.writeTexel(scope, type, uv, pb.vec4(texel.rrr, 1));
|
|
40
|
+
return this._finalPhase || !this._packed ? pb.vec4(outTexel.rrr, 1) : encodeNormalizedFloatToRGBA(scope, outTexel.r);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
26
43
|
/**
|
|
27
44
|
* The Scalable Ambient Obscurance (SAO) post effect
|
|
28
45
|
* @public
|
|
29
46
|
*/ class SAO extends AbstractPostEffect {
|
|
30
|
-
static
|
|
47
|
+
static className = 'SAO';
|
|
31
48
|
static _program = null;
|
|
32
49
|
static _programPacked = null;
|
|
33
50
|
static _renderState = null;
|
|
@@ -43,7 +60,6 @@ const NUM_RINGS = 4;
|
|
|
43
60
|
_saoBlurDepthCutoff;
|
|
44
61
|
_blitterH;
|
|
45
62
|
_blitterV;
|
|
46
|
-
_copyBlitter;
|
|
47
63
|
_supported;
|
|
48
64
|
/**
|
|
49
65
|
* Creates an instance of SAO post effect
|
|
@@ -55,18 +71,17 @@ const NUM_RINGS = 4;
|
|
|
55
71
|
this._opaque = true;
|
|
56
72
|
this._saoScale = 10;
|
|
57
73
|
this._saoBias = 1;
|
|
58
|
-
this._saoIntensity = 0.
|
|
74
|
+
this._saoIntensity = 0.025;
|
|
59
75
|
this._saoRadius = 100;
|
|
60
76
|
this._saoMinResolution = 0;
|
|
61
77
|
this._saoRandomSeed = 0;
|
|
62
|
-
this._saoBlurDepthCutoff =
|
|
63
|
-
this._blitterH = new
|
|
78
|
+
this._saoBlurDepthCutoff = 2;
|
|
79
|
+
this._blitterH = new DepthLimitAOBlurBlitter(false);
|
|
64
80
|
this._blitterH.kernelRadius = 8;
|
|
65
81
|
this._blitterH.stdDev = 10;
|
|
66
|
-
this._blitterV = new
|
|
82
|
+
this._blitterV = new DepthLimitAOBlurBlitter(true);
|
|
67
83
|
this._blitterV.kernelRadius = 8;
|
|
68
84
|
this._blitterV.stdDev = 10;
|
|
69
|
-
this._copyBlitter = new CopyBlitter();
|
|
70
85
|
}
|
|
71
86
|
/** Scale value */ get scale() {
|
|
72
87
|
return this._saoScale;
|
|
@@ -129,19 +144,20 @@ const NUM_RINGS = 4;
|
|
|
129
144
|
const device = ctx.device;
|
|
130
145
|
const viewport = device.getViewport();
|
|
131
146
|
this._prepare(device, inputColorTexture);
|
|
132
|
-
|
|
133
|
-
this._copyBlitter.blit(inputColorTexture, device.getFramebuffer(), SAO._nearestSampler);
|
|
147
|
+
copyTexture(inputColorTexture, device.getFramebuffer(), fetchSampler('clamp_nearest_nomip'), null, 0, srgbOutput);
|
|
134
148
|
if (!this._supported) {
|
|
135
149
|
return;
|
|
136
150
|
}
|
|
137
151
|
const fmt = this._getIntermediateTextureFormat(device);
|
|
138
152
|
const depth = device.getFramebuffer().getDepthAttachment();
|
|
139
|
-
const fbao =
|
|
140
|
-
const fbblur =
|
|
141
|
-
const packed = fbao.
|
|
153
|
+
const fbao = device.pool.fetchTemporalTexture2D(false, fmt, depth.width, depth.height, false);
|
|
154
|
+
const fbblur = device.pool.fetchTemporalTexture2D(false, fmt, depth.width, depth.height, false);
|
|
155
|
+
const packed = fbao.format === 'rgba8unorm';
|
|
142
156
|
const cameraNearFar = new Vector2(ctx.camera.getNearPlane(), ctx.camera.getFarPlane());
|
|
143
157
|
device.pushDeviceStates();
|
|
144
|
-
device.setFramebuffer(
|
|
158
|
+
device.setFramebuffer([
|
|
159
|
+
fbao
|
|
160
|
+
], depth);
|
|
145
161
|
device.clearFrameBuffer(packed ? new Vector4(0, 0, 0, 1) : new Vector4(1, 0, 0, 1), null, null);
|
|
146
162
|
const bindgroup = packed ? this._bindgroupPacked : this._bindgroup;
|
|
147
163
|
bindgroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
@@ -161,24 +177,24 @@ const NUM_RINGS = 4;
|
|
|
161
177
|
this.drawFullscreenQuad(SAO._renderState);
|
|
162
178
|
this._blitterH.size = new Vector2(inputColorTexture.width, inputColorTexture.height);
|
|
163
179
|
this._blitterH.depthTex = sceneDepthTexture;
|
|
164
|
-
this._blitterH.depthCutoff = this._saoBlurDepthCutoff
|
|
165
|
-
this._blitterH.
|
|
180
|
+
this._blitterH.depthCutoff = this._saoBlurDepthCutoff;
|
|
181
|
+
this._blitterH.sampler = fetchSampler('clamp_nearest_nomip');
|
|
166
182
|
this._blitterH.cameraNearFar = cameraNearFar;
|
|
167
183
|
this._blitterH.packed = packed;
|
|
168
184
|
this._blitterH.renderStates = SAO._renderState;
|
|
169
185
|
this._blitterV.size = new Vector2(inputColorTexture.width, inputColorTexture.height);
|
|
170
186
|
this._blitterV.depthTex = sceneDepthTexture;
|
|
171
|
-
this._blitterV.depthCutoff = this._saoBlurDepthCutoff
|
|
172
|
-
this._blitterV.
|
|
187
|
+
this._blitterV.depthCutoff = this._saoBlurDepthCutoff;
|
|
188
|
+
this._blitterV.sampler = fetchSampler('clamp_nearest_nomip');
|
|
173
189
|
this._blitterV.cameraNearFar = cameraNearFar;
|
|
174
190
|
this._blitterV.packed = packed;
|
|
175
191
|
this._blitterV.srgbOut = srgbOutput;
|
|
176
192
|
this._blitterV.renderStates = SAO._renderStateBlend;
|
|
177
|
-
this._blitterH.blit(fbao
|
|
193
|
+
this._blitterH.blit(fbao, fbblur);
|
|
178
194
|
device.popDeviceStates();
|
|
179
|
-
this._blitterV.blit(fbblur
|
|
180
|
-
|
|
181
|
-
|
|
195
|
+
this._blitterV.blit(fbblur, device.getFramebuffer());
|
|
196
|
+
device.pool.releaseTexture(fbao);
|
|
197
|
+
device.pool.releaseTexture(fbblur);
|
|
182
198
|
}
|
|
183
199
|
_getIntermediateTextureFormat(device) {
|
|
184
200
|
const texCaps = device.getDeviceCaps().textureCaps;
|
|
@@ -189,15 +205,6 @@ const NUM_RINGS = 4;
|
|
|
189
205
|
const isFloatFramebuffer = fb && isFloatTextureFormat(fb.getColorAttachments()[0].format);
|
|
190
206
|
this._supported = !isFloatFramebuffer || device.getDeviceCaps().framebufferCaps.supportFloatBlending;
|
|
191
207
|
if (this._supported) {
|
|
192
|
-
if (!SAO._nearestSampler) {
|
|
193
|
-
SAO._nearestSampler = device.createSampler({
|
|
194
|
-
magFilter: 'nearest',
|
|
195
|
-
minFilter: 'nearest',
|
|
196
|
-
mipFilter: 'none',
|
|
197
|
-
addressU: 'clamp',
|
|
198
|
-
addressV: 'clamp'
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
208
|
if (!SAO._renderState) {
|
|
202
209
|
SAO._renderState = device.createRenderStateSet();
|
|
203
210
|
SAO._renderState.useDepthState().enableTest(true).enableWrite(false).setCompareFunc('gt');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sao.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sao.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|