@zephyr3d/scene 0.1.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 +173 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/animationset.js +95 -0
- package/dist/animation/animationset.js.map +1 -0
- package/dist/animation/animationtrack.js +38 -0
- package/dist/animation/animationtrack.js.map +1 -0
- package/dist/animation/eulerrotationtrack.js +33 -0
- package/dist/animation/eulerrotationtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +37 -0
- package/dist/animation/rotationtrack.js.map +1 -0
- package/dist/animation/scaletrack.js +36 -0
- package/dist/animation/scaletrack.js.map +1 -0
- package/dist/animation/skeleton.js +97 -0
- package/dist/animation/skeleton.js.map +1 -0
- package/dist/animation/translationtrack.js +36 -0
- package/dist/animation/translationtrack.js.map +1 -0
- package/dist/animation/usertrack.js +47 -0
- package/dist/animation/usertrack.js.map +1 -0
- package/dist/app.js +173 -0
- package/dist/app.js.map +1 -0
- package/dist/asset/assetmanager.js +476 -0
- package/dist/asset/assetmanager.js.map +1 -0
- package/dist/asset/builtin.js +373 -0
- package/dist/asset/builtin.js.map +1 -0
- package/dist/asset/loaders/dds/dds.js +472 -0
- package/dist/asset/loaders/dds/dds.js.map +1 -0
- package/dist/asset/loaders/dds/dds_loader.js +38 -0
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/helpers.js +314 -0
- package/dist/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/asset/loaders/hdr/hdr.js +175 -0
- package/dist/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/asset/loaders/image/tga_Loader.js +117 -0
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/asset/loaders/image/webimage_loader.js +50 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/asset/loaders/loader.js +45 -0
- package/dist/asset/loaders/loader.js.map +1 -0
- package/dist/asset/model.js +264 -0
- package/dist/asset/model.js.map +1 -0
- package/dist/blitter/blitter.js +389 -0
- package/dist/blitter/blitter.js.map +1 -0
- package/dist/blitter/box.js +118 -0
- package/dist/blitter/box.js.map +1 -0
- package/dist/blitter/copy.js +22 -0
- package/dist/blitter/copy.js.map +1 -0
- package/dist/blitter/depthlimitedgaussion.js +166 -0
- package/dist/blitter/depthlimitedgaussion.js.map +1 -0
- package/dist/blitter/gaussianblur.js +229 -0
- package/dist/blitter/gaussianblur.js.map +1 -0
- package/dist/camera/base.js +90 -0
- package/dist/camera/base.js.map +1 -0
- package/dist/camera/camera.js +358 -0
- package/dist/camera/camera.js.map +1 -0
- package/dist/camera/fps.js +246 -0
- package/dist/camera/fps.js.map +1 -0
- package/dist/camera/orbit.js +157 -0
- package/dist/camera/orbit.js.map +1 -0
- package/dist/camera/orthocamera.js +126 -0
- package/dist/camera/orthocamera.js.map +1 -0
- package/dist/camera/perspectivecamera.js +133 -0
- package/dist/camera/perspectivecamera.js.map +1 -0
- package/dist/index.d.ts +8402 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/input/inputmgr.js +242 -0
- package/dist/input/inputmgr.js.map +1 -0
- package/dist/material/blinn.js +75 -0
- package/dist/material/blinn.js.map +1 -0
- package/dist/material/grassmaterial.js +221 -0
- package/dist/material/grassmaterial.js.map +1 -0
- package/dist/material/lambert.js +52 -0
- package/dist/material/lambert.js.map +1 -0
- package/dist/material/lightmodel.js +2074 -0
- package/dist/material/lightmodel.js.map +1 -0
- package/dist/material/lit.js +578 -0
- package/dist/material/lit.js.map +1 -0
- package/dist/material/material.js +458 -0
- package/dist/material/material.js.map +1 -0
- package/dist/material/meshmaterial.js +311 -0
- package/dist/material/meshmaterial.js.map +1 -0
- package/dist/material/mixins/albedocolor.js +130 -0
- package/dist/material/mixins/albedocolor.js.map +1 -0
- package/dist/material/mixins/texture.js +110 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +45 -0
- package/dist/material/mixins/vertexcolor.js.map +1 -0
- package/dist/material/pbr.js +27 -0
- package/dist/material/pbr.js.map +1 -0
- package/dist/material/standard.js +282 -0
- package/dist/material/standard.js.map +1 -0
- package/dist/material/terrainlightmodel.js +259 -0
- package/dist/material/terrainlightmodel.js.map +1 -0
- package/dist/material/terrainmaterial.js +139 -0
- package/dist/material/terrainmaterial.js.map +1 -0
- package/dist/material/unlit.js +29 -0
- package/dist/material/unlit.js.map +1 -0
- package/dist/posteffect/bloom.js +398 -0
- package/dist/posteffect/bloom.js.map +1 -0
- package/dist/posteffect/compositor.js +264 -0
- package/dist/posteffect/compositor.js.map +1 -0
- package/dist/posteffect/fxaa.js +291 -0
- package/dist/posteffect/fxaa.js.map +1 -0
- package/dist/posteffect/grayscale.js +87 -0
- package/dist/posteffect/grayscale.js.map +1 -0
- package/dist/posteffect/posteffect.js +165 -0
- package/dist/posteffect/posteffect.js.map +1 -0
- package/dist/posteffect/sao.js +327 -0
- package/dist/posteffect/sao.js.map +1 -0
- package/dist/posteffect/tonemap.js +112 -0
- package/dist/posteffect/tonemap.js.map +1 -0
- package/dist/posteffect/water.js +535 -0
- package/dist/posteffect/water.js.map +1 -0
- package/dist/render/clipmap.js +462 -0
- package/dist/render/clipmap.js.map +1 -0
- package/dist/render/cluster_light.js +329 -0
- package/dist/render/cluster_light.js.map +1 -0
- package/dist/render/cull_visitor.js +124 -0
- package/dist/render/cull_visitor.js.map +1 -0
- package/dist/render/depth_pass.js +47 -0
- package/dist/render/depth_pass.js.map +1 -0
- package/dist/render/envlight.js +282 -0
- package/dist/render/envlight.js.map +1 -0
- package/dist/render/forward.js +186 -0
- package/dist/render/forward.js.map +1 -0
- package/dist/render/forward_pass.js +137 -0
- package/dist/render/forward_pass.js.map +1 -0
- package/dist/render/helper.js +38 -0
- package/dist/render/helper.js.map +1 -0
- package/dist/render/primitive.js +246 -0
- package/dist/render/primitive.js.map +1 -0
- package/dist/render/render_queue.js +163 -0
- package/dist/render/render_queue.js.map +1 -0
- package/dist/render/renderpass.js +151 -0
- package/dist/render/renderpass.js.map +1 -0
- package/dist/render/renderscheme.js +61 -0
- package/dist/render/renderscheme.js.map +1 -0
- package/dist/render/scatteringlut.js +634 -0
- package/dist/render/scatteringlut.js.map +1 -0
- package/dist/render/shadowmap_pass.js +70 -0
- package/dist/render/shadowmap_pass.js.map +1 -0
- package/dist/render/sky.js +881 -0
- package/dist/render/sky.js.map +1 -0
- package/dist/render/temporalcache.js +222 -0
- package/dist/render/temporalcache.js.map +1 -0
- package/dist/render/watermesh.js +835 -0
- package/dist/render/watermesh.js.map +1 -0
- package/dist/scene/environment.js +146 -0
- package/dist/scene/environment.js.map +1 -0
- package/dist/scene/graph_node.js +69 -0
- package/dist/scene/graph_node.js.map +1 -0
- package/dist/scene/light.js +436 -0
- package/dist/scene/light.js.map +1 -0
- package/dist/scene/mesh.js +215 -0
- package/dist/scene/mesh.js.map +1 -0
- package/dist/scene/model.js +111 -0
- package/dist/scene/model.js.map +1 -0
- package/dist/scene/octree.js +651 -0
- package/dist/scene/octree.js.map +1 -0
- package/dist/scene/octree_update_visitor.js +16 -0
- package/dist/scene/octree_update_visitor.js.map +1 -0
- package/dist/scene/raycast_visitor.js +72 -0
- package/dist/scene/raycast_visitor.js.map +1 -0
- package/dist/scene/scene.js +225 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/scene/scene_node.js +299 -0
- package/dist/scene/scene_node.js.map +1 -0
- package/dist/scene/terrain/grass.js +277 -0
- package/dist/scene/terrain/grass.js.map +1 -0
- package/dist/scene/terrain/heightfield.js +391 -0
- package/dist/scene/terrain/heightfield.js.map +1 -0
- package/dist/scene/terrain/patch.js +530 -0
- package/dist/scene/terrain/patch.js.map +1 -0
- package/dist/scene/terrain/quadtree.js +430 -0
- package/dist/scene/terrain/quadtree.js.map +1 -0
- package/dist/scene/terrain/terrain.js +258 -0
- package/dist/scene/terrain/terrain.js.map +1 -0
- package/dist/scene/xform.js +224 -0
- package/dist/scene/xform.js.map +1 -0
- package/dist/shaders/builtins.js +110 -0
- package/dist/shaders/builtins.js.map +1 -0
- package/dist/shaders/framework.js +709 -0
- package/dist/shaders/framework.js.map +1 -0
- package/dist/shaders/lighting.js +335 -0
- package/dist/shaders/lighting.js.map +1 -0
- package/dist/shaders/misc.js +405 -0
- package/dist/shaders/misc.js.map +1 -0
- package/dist/shaders/noise.js +157 -0
- package/dist/shaders/noise.js.map +1 -0
- package/dist/shaders/pbr.js +132 -0
- package/dist/shaders/pbr.js.map +1 -0
- package/dist/shaders/shadow.js +642 -0
- package/dist/shaders/shadow.js.map +1 -0
- package/dist/shaders/water.js +630 -0
- package/dist/shaders/water.js.map +1 -0
- package/dist/shadow/esm.js +235 -0
- package/dist/shadow/esm.js.map +1 -0
- package/dist/shadow/pcf_opt.js +182 -0
- package/dist/shadow/pcf_opt.js.map +1 -0
- package/dist/shadow/pcf_pd.js +190 -0
- package/dist/shadow/pcf_pd.js.map +1 -0
- package/dist/shadow/shadow_impl.js +15 -0
- package/dist/shadow/shadow_impl.js.map +1 -0
- package/dist/shadow/shadowmapper.js +709 -0
- package/dist/shadow/shadowmapper.js.map +1 -0
- package/dist/shadow/ssm.js +194 -0
- package/dist/shadow/ssm.js.map +1 -0
- package/dist/shadow/vsm.js +298 -0
- package/dist/shadow/vsm.js.map +1 -0
- package/dist/shapes/box.js +313 -0
- package/dist/shapes/box.js.map +1 -0
- package/dist/shapes/cylinder.js +74 -0
- package/dist/shapes/cylinder.js.map +1 -0
- package/dist/shapes/plane.js +48 -0
- package/dist/shapes/plane.js.map +1 -0
- package/dist/shapes/shape.js +33 -0
- package/dist/shapes/shape.js.map +1 -0
- package/dist/shapes/sphere.js +91 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/torus.js +100 -0
- package/dist/shapes/torus.js.map +1 -0
- package/dist/utility/aabbtree.js +390 -0
- package/dist/utility/aabbtree.js.map +1 -0
- package/dist/utility/bounding_volume.js +78 -0
- package/dist/utility/bounding_volume.js.map +1 -0
- package/dist/utility/panorama.js +163 -0
- package/dist/utility/panorama.js.map +1 -0
- package/dist/utility/pmrem.js +345 -0
- package/dist/utility/pmrem.js.map +1 -0
- package/dist/utility/shprojection.js +448 -0
- package/dist/utility/shprojection.js.map +1 -0
- package/dist/values.js +48 -0
- package/dist/values.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { Application } from '../app.js';
|
|
2
|
+
import { linearToGamma } from '../shaders/misc.js';
|
|
3
|
+
import '@zephyr3d/base';
|
|
4
|
+
import '../scene/octree.js';
|
|
5
|
+
import '../material/material.js';
|
|
6
|
+
import '@zephyr3d/device';
|
|
7
|
+
import '../shaders/framework.js';
|
|
8
|
+
import '../render/scatteringlut.js';
|
|
9
|
+
import '../material/lambert.js';
|
|
10
|
+
import '../material/blinn.js';
|
|
11
|
+
import '../material/unlit.js';
|
|
12
|
+
import '../material/lightmodel.js';
|
|
13
|
+
import '../render/forward.js';
|
|
14
|
+
import '../render/sky.js';
|
|
15
|
+
import '../render/clipmap.js';
|
|
16
|
+
import { TemporalCache } from '../render/temporalcache.js';
|
|
17
|
+
import '../render/watermesh.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Post processing compositor
|
|
21
|
+
* @public
|
|
22
|
+
*/ class Compositor {
|
|
23
|
+
/** @internal */ _postEffectsOpaque;
|
|
24
|
+
/** @internal */ _postEffectsTransparency;
|
|
25
|
+
/** @internal */ static _blitSampler = null;
|
|
26
|
+
/** @internal */ static _blitProgram = null;
|
|
27
|
+
/** @internal */ static _blitBindgroup = null;
|
|
28
|
+
/** @internal */ static _blitRenderStates = null;
|
|
29
|
+
/** @internal */ static _blitVertexLayout = null;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an instance of Compositor
|
|
32
|
+
*/ constructor(){
|
|
33
|
+
this._postEffectsOpaque = [];
|
|
34
|
+
this._postEffectsTransparency = [];
|
|
35
|
+
}
|
|
36
|
+
/** @internal */ requireLinearDepth() {
|
|
37
|
+
for (const postEffect of this._postEffectsOpaque){
|
|
38
|
+
if (postEffect.requireLinearDepthTexture()) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
for (const postEffect of this._postEffectsTransparency){
|
|
43
|
+
if (postEffect.requireLinearDepthTexture()) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Adds a posteffect
|
|
51
|
+
*
|
|
52
|
+
* @param postEffect - The post effect to add
|
|
53
|
+
* @param opaque - true if the post effect should be applied after the opaque pass and before the transparent pass, otherwise the post effect should be applied after the transparent pass
|
|
54
|
+
*/ appendPostEffect(postEffect) {
|
|
55
|
+
if (postEffect) {
|
|
56
|
+
if (this._postEffectsOpaque.indexOf(postEffect) >= 0 || this._postEffectsTransparency.indexOf(postEffect) >= 0) {
|
|
57
|
+
console.error(`Posteffect cannot be added to same compositor multiple times`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const postEffects = postEffect.opaque ? this._postEffectsOpaque : this._postEffectsTransparency;
|
|
61
|
+
postEffects.push(postEffect);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Removes a posteffect that was previously added
|
|
66
|
+
*
|
|
67
|
+
* @param postEffect - The posteffect to be remove.
|
|
68
|
+
*/ removePostEffect(postEffect) {
|
|
69
|
+
for (const list of [
|
|
70
|
+
this._postEffectsOpaque,
|
|
71
|
+
this._postEffectsTransparency
|
|
72
|
+
]){
|
|
73
|
+
const index = list.indexOf(postEffect);
|
|
74
|
+
if (index >= 0) {
|
|
75
|
+
list.splice(index, 1);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets all post effects
|
|
82
|
+
*/ getPostEffects() {
|
|
83
|
+
return [
|
|
84
|
+
...this._postEffectsOpaque,
|
|
85
|
+
...this._postEffectsTransparency
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
/** @internal */ begin(ctx) {
|
|
89
|
+
const device = Application.instance.device;
|
|
90
|
+
const format = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';
|
|
91
|
+
const finalFramebuffer = device.getFramebuffer();
|
|
92
|
+
const depth = finalFramebuffer?.getDepthAttachment();
|
|
93
|
+
let pingpongFramebuffers;
|
|
94
|
+
let msFramebuffer = null;
|
|
95
|
+
if (ctx.primaryCamera.sampleCount > 1) {
|
|
96
|
+
msFramebuffer = depth ? TemporalCache.getFramebufferVariantSizeWithDepth(depth, 1, format, '2d', false, ctx.primaryCamera.sampleCount) : TemporalCache.getFramebufferVariantSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, ctx.primaryCamera.sampleCount);
|
|
97
|
+
}
|
|
98
|
+
if (ctx.defaultViewport) {
|
|
99
|
+
pingpongFramebuffers = [
|
|
100
|
+
depth ? TemporalCache.getFramebufferVariantSizeWithDepth(depth, 1, format, '2d', false, 1) : TemporalCache.getFramebufferVariantSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, 1),
|
|
101
|
+
depth ? TemporalCache.getFramebufferVariantSizeWithDepth(depth, 1, format, '2d', false, 1) : TemporalCache.getFramebufferVariantSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, 1)
|
|
102
|
+
];
|
|
103
|
+
} else {
|
|
104
|
+
pingpongFramebuffers = [
|
|
105
|
+
depth ? TemporalCache.getFramebufferFixedSizeWithDepth(depth, 1, format, '2d', false, 4) : TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, 4),
|
|
106
|
+
depth ? TemporalCache.getFramebufferFixedSizeWithDepth(depth, 1, format, '2d', false, 4) : TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false, 4)
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
let writeIndex;
|
|
110
|
+
if (msFramebuffer) {
|
|
111
|
+
writeIndex = 3;
|
|
112
|
+
device.setFramebuffer(msFramebuffer);
|
|
113
|
+
} else {
|
|
114
|
+
writeIndex = 0;
|
|
115
|
+
device.setFramebuffer(pingpongFramebuffers[writeIndex]);
|
|
116
|
+
}
|
|
117
|
+
device.setViewport(null);
|
|
118
|
+
device.setScissor(null);
|
|
119
|
+
ctx.compositorContex = {
|
|
120
|
+
finalFramebuffer,
|
|
121
|
+
pingpongFramebuffers,
|
|
122
|
+
msFramebuffer,
|
|
123
|
+
writeIndex
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** @internal */ drawPostEffects(ctx, opaque, sceneDepthTexture) {
|
|
127
|
+
const postEffects = opaque ? this._postEffectsOpaque : this._postEffectsTransparency;
|
|
128
|
+
if (postEffects.length > 0) {
|
|
129
|
+
const device = Application.instance.device;
|
|
130
|
+
for(let i = 0; i < postEffects.length; i++){
|
|
131
|
+
const postEffect = postEffects[i];
|
|
132
|
+
if (!postEffect.enabled) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const inputTexture = device.getFramebuffer().getColorAttachments()[0];
|
|
136
|
+
const isLast = this.isLastPostEffect(opaque, i);
|
|
137
|
+
const finalEffect = isLast && (!postEffect.requireDepthAttachment() || !!ctx.compositorContex.finalFramebuffer);
|
|
138
|
+
if (finalEffect) {
|
|
139
|
+
device.setFramebuffer(ctx.compositorContex.finalFramebuffer);
|
|
140
|
+
device.setViewport(null);
|
|
141
|
+
device.setScissor(null);
|
|
142
|
+
} else {
|
|
143
|
+
ctx.compositorContex.writeIndex = (1 + ctx.compositorContex.writeIndex) % 2;
|
|
144
|
+
device.setFramebuffer(ctx.compositorContex.pingpongFramebuffers[ctx.compositorContex.writeIndex]);
|
|
145
|
+
device.setViewport(null);
|
|
146
|
+
device.setScissor(null);
|
|
147
|
+
}
|
|
148
|
+
postEffect.apply(ctx, inputTexture, sceneDepthTexture, !device.getFramebuffer());
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** @internal */ end(ctx) {
|
|
153
|
+
const device = Application.instance.device;
|
|
154
|
+
if (device.getFramebuffer() !== ctx.compositorContex.finalFramebuffer) {
|
|
155
|
+
const srcTex = device.getFramebuffer().getColorAttachments()[0];
|
|
156
|
+
device.setFramebuffer(ctx.compositorContex.finalFramebuffer);
|
|
157
|
+
device.setViewport(null);
|
|
158
|
+
device.setScissor(null);
|
|
159
|
+
Compositor._blit(device, srcTex, !ctx.compositorContex.finalFramebuffer);
|
|
160
|
+
}
|
|
161
|
+
TemporalCache.releaseFramebuffer(ctx.compositorContex.pingpongFramebuffers[0]);
|
|
162
|
+
TemporalCache.releaseFramebuffer(ctx.compositorContex.pingpongFramebuffers[1]);
|
|
163
|
+
if (ctx.compositorContex.msFramebuffer) {
|
|
164
|
+
TemporalCache.releaseFramebuffer(ctx.compositorContex.msFramebuffer);
|
|
165
|
+
}
|
|
166
|
+
ctx.compositorContex = null;
|
|
167
|
+
}
|
|
168
|
+
/** @internal */ isLastPostEffect(opaque, index) {
|
|
169
|
+
const list = opaque ? this._postEffectsOpaque : this._postEffectsTransparency;
|
|
170
|
+
for(let i = index; i < list.length; i++){
|
|
171
|
+
if (list[i].enabled) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (opaque) {
|
|
176
|
+
for(let i = 0; i < this._postEffectsTransparency.length; i++){
|
|
177
|
+
if (this._postEffectsTransparency[i].enabled) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
/** @internal */ needDrawPostEffects() {
|
|
185
|
+
for(let i = 0; i < this._postEffectsOpaque.length; i++){
|
|
186
|
+
if (this._postEffectsOpaque[i].enabled) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
for(let i = 0; i < this._postEffectsTransparency.length; i++){
|
|
191
|
+
if (this._postEffectsTransparency[i].enabled) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
/** @internal */ static _blit(device, srcTex, srgbOutput) {
|
|
198
|
+
if (!this._blitProgram) {
|
|
199
|
+
this._blitProgram = device.buildRenderProgram({
|
|
200
|
+
vertex (pb) {
|
|
201
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
202
|
+
this.$outputs.uv = pb.vec2();
|
|
203
|
+
this.flip = pb.int().uniform(0);
|
|
204
|
+
pb.main(function() {
|
|
205
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
|
|
206
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
207
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
208
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
fragment (pb) {
|
|
213
|
+
this.srcTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
214
|
+
this.srgbOutput = pb.int().uniform(0);
|
|
215
|
+
this.$outputs.outColor = pb.vec4();
|
|
216
|
+
pb.main(function() {
|
|
217
|
+
this.$outputs.outColor = pb.textureSample(this.srcTex, this.$inputs.uv);
|
|
218
|
+
this.$if(pb.notEqual(this.srgbOutput, 0), function() {
|
|
219
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.$outputs.outColor.rgb), 1);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
this._blitBindgroup = device.createBindGroup(this._blitProgram.bindGroupLayouts[0]);
|
|
225
|
+
this._blitVertexLayout = device.createVertexLayout({
|
|
226
|
+
vertexBuffers: [
|
|
227
|
+
{
|
|
228
|
+
buffer: device.createVertexBuffer('position_f32x2', new Float32Array([
|
|
229
|
+
-1,
|
|
230
|
+
-1,
|
|
231
|
+
1,
|
|
232
|
+
-1,
|
|
233
|
+
-1,
|
|
234
|
+
1,
|
|
235
|
+
1,
|
|
236
|
+
1
|
|
237
|
+
]))
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
});
|
|
241
|
+
this._blitSampler = device.createSampler({
|
|
242
|
+
minFilter: 'nearest',
|
|
243
|
+
magFilter: 'nearest',
|
|
244
|
+
mipFilter: 'none',
|
|
245
|
+
addressU: 'clamp',
|
|
246
|
+
addressV: 'clamp'
|
|
247
|
+
});
|
|
248
|
+
this._blitRenderStates = device.createRenderStateSet();
|
|
249
|
+
this._blitRenderStates.useRasterizerState().setCullMode('none');
|
|
250
|
+
this._blitRenderStates.useDepthState().enableTest(false).enableWrite(false);
|
|
251
|
+
}
|
|
252
|
+
this._blitBindgroup.setTexture('srcTex', srcTex, this._blitSampler);
|
|
253
|
+
this._blitBindgroup.setValue('srgbOutput', srgbOutput ? 1 : 0);
|
|
254
|
+
this._blitBindgroup.setValue('flip', device.type === 'webgpu' && !!device.getFramebuffer() ? 1 : 0);
|
|
255
|
+
device.setRenderStates(this._blitRenderStates);
|
|
256
|
+
device.setProgram(this._blitProgram);
|
|
257
|
+
device.setBindGroup(0, this._blitBindgroup);
|
|
258
|
+
device.setVertexLayout(this._blitVertexLayout);
|
|
259
|
+
device.draw('triangle-strip', 0, 4);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export { Compositor };
|
|
264
|
+
//# sourceMappingURL=compositor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compositor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { Vector2 } from '@zephyr3d/base';
|
|
2
|
+
import { Application } from '../app.js';
|
|
3
|
+
import { AbstractPostEffect } from './posteffect.js';
|
|
4
|
+
import { linearToGamma } from '../shaders/misc.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* FXAA post effect
|
|
8
|
+
* @public
|
|
9
|
+
*/ class FXAA extends AbstractPostEffect {
|
|
10
|
+
static _program = null;
|
|
11
|
+
static _sampler = null;
|
|
12
|
+
_bindgroup;
|
|
13
|
+
_invTexSize;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of grayscale post effect
|
|
16
|
+
*/ constructor(){
|
|
17
|
+
super();
|
|
18
|
+
this._opaque = false;
|
|
19
|
+
this._bindgroup = null;
|
|
20
|
+
this._invTexSize = new Vector2();
|
|
21
|
+
}
|
|
22
|
+
/** {@inheritDoc AbstractPostEffect.dispose} */ dispose() {
|
|
23
|
+
super.dispose();
|
|
24
|
+
this._bindgroup?.dispose();
|
|
25
|
+
this._bindgroup = null;
|
|
26
|
+
}
|
|
27
|
+
/** {@inheritDoc AbstractPostEffect.requireLinearDepthTexture} */ requireLinearDepthTexture() {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
/** {@inheritDoc AbstractPostEffect.requireDepthAttachment} */ requireDepthAttachment() {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
34
|
+
const device = Application.instance.device;
|
|
35
|
+
this._prepare(device);
|
|
36
|
+
this._invTexSize.setXY(1 / inputColorTexture.width, 1 / inputColorTexture.height);
|
|
37
|
+
this._bindgroup.setTexture('srcTex', inputColorTexture, FXAA._sampler);
|
|
38
|
+
this._bindgroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
39
|
+
this._bindgroup.setValue('srgbOut', srgbOutput ? 1 : 0);
|
|
40
|
+
this._bindgroup.setValue('invTexSize', this._invTexSize);
|
|
41
|
+
device.setProgram(FXAA._program);
|
|
42
|
+
device.setBindGroup(0, this._bindgroup);
|
|
43
|
+
this.drawFullscreenQuad();
|
|
44
|
+
}
|
|
45
|
+
/** @internal */ _prepare(device) {
|
|
46
|
+
if (!FXAA._program) {
|
|
47
|
+
FXAA._program = device.buildRenderProgram({
|
|
48
|
+
vertex (pb) {
|
|
49
|
+
this.flip = pb.int().uniform(0);
|
|
50
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
51
|
+
this.$outputs.uv = pb.vec2();
|
|
52
|
+
pb.main(function() {
|
|
53
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
|
|
54
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
55
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
56
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
fragment (pb) {
|
|
61
|
+
this.srcTex = pb.tex2D().uniform(0);
|
|
62
|
+
this.srgbOut = pb.int().uniform(0);
|
|
63
|
+
this.invTexSize = pb.vec2().uniform(0);
|
|
64
|
+
this.$outputs.outColor = pb.vec4();
|
|
65
|
+
pb.func('getLuma', [
|
|
66
|
+
pb.vec3('vSample')
|
|
67
|
+
], function() {
|
|
68
|
+
this.$return(pb.dot(this.vSample, pb.vec3(0.299, 0.587, 0.114)));
|
|
69
|
+
});
|
|
70
|
+
pb.func('FXAA', [
|
|
71
|
+
pb.vec2('uv')
|
|
72
|
+
], function() {
|
|
73
|
+
this.$l.posM = this.uv;
|
|
74
|
+
this.$l.rgbyM = pb.textureSampleLevel(this.srcTex, this.uv, 0);
|
|
75
|
+
this.$l.lumaM = this.getLuma(this.rgbyM.rgb);
|
|
76
|
+
this.$l.lumaN = this.getLuma(pb.textureSampleLevel(this.srcTex, pb.add(this.uv, pb.mul(pb.vec2(0, -1), this.invTexSize)), 0).rgb);
|
|
77
|
+
this.$l.lumaW = this.getLuma(pb.textureSampleLevel(this.srcTex, pb.add(this.uv, pb.mul(pb.vec2(-1, 0), this.invTexSize)), 0).rgb);
|
|
78
|
+
this.$l.lumaE = this.getLuma(pb.textureSampleLevel(this.srcTex, pb.add(this.uv, pb.mul(pb.vec2(1, 0), this.invTexSize)), 0).rgb);
|
|
79
|
+
this.$l.lumaS = this.getLuma(pb.textureSampleLevel(this.srcTex, pb.add(this.uv, pb.mul(pb.vec2(0, 1), this.invTexSize)), 0).rgb);
|
|
80
|
+
this.$l.rangeMin = pb.min(this.lumaM, pb.min(pb.min(this.lumaN, this.lumaW), pb.min(this.lumaS, this.lumaE)));
|
|
81
|
+
this.$l.rangeMax = pb.max(this.lumaM, pb.max(pb.max(this.lumaN, this.lumaW), pb.max(this.lumaS, this.lumaE)));
|
|
82
|
+
this.$l.range = pb.sub(this.rangeMax, this.rangeMin);
|
|
83
|
+
this.$if(pb.lessThan(this.range, pb.max(1 / 16, pb.div(this.rangeMax, 8))), function() {
|
|
84
|
+
this.$return(this.rgbyM);
|
|
85
|
+
});
|
|
86
|
+
this.$l.lumaNW = this.getLuma(pb.textureSampleLevel(this.srcTex, pb.add(this.uv, pb.mul(pb.vec2(-1, -1), this.invTexSize)), 0).rgb);
|
|
87
|
+
this.$l.lumaNE = this.getLuma(pb.textureSampleLevel(this.srcTex, pb.add(this.uv, pb.mul(pb.vec2(1, -1), this.invTexSize)), 0).rgb);
|
|
88
|
+
this.$l.lumaSW = this.getLuma(pb.textureSampleLevel(this.srcTex, pb.add(this.uv, pb.mul(pb.vec2(-1, 1), this.invTexSize)), 0).rgb);
|
|
89
|
+
this.$l.lumaSE = this.getLuma(pb.textureSampleLevel(this.srcTex, pb.add(this.uv, pb.mul(pb.vec2(1, 1), this.invTexSize)), 0).rgb);
|
|
90
|
+
this.$l.lumaNS = pb.add(this.lumaN, this.lumaS);
|
|
91
|
+
this.$l.lumaWE = pb.add(this.lumaW, this.lumaE);
|
|
92
|
+
this.$l.subpixRcpRange = pb.div(1, this.range);
|
|
93
|
+
this.$l.subpixNSWE = pb.add(this.lumaNS, this.lumaWE);
|
|
94
|
+
this.$l.edgeHorz1 = pb.add(pb.mul(-2, this.lumaM), this.lumaNS);
|
|
95
|
+
this.$l.edgeVert1 = pb.add(pb.mul(-2, this.lumaM), this.lumaWE);
|
|
96
|
+
this.$l.lumaNESE = pb.add(this.lumaNE, this.lumaSE);
|
|
97
|
+
this.$l.lumaNWNE = pb.add(this.lumaNW, this.lumaNE);
|
|
98
|
+
this.$l.edgeHorz2 = pb.add(pb.mul(-2, this.lumaE), this.lumaNESE);
|
|
99
|
+
this.$l.edgeVert2 = pb.add(pb.mul(-2, this.lumaN), this.lumaNWNE);
|
|
100
|
+
this.$l.lumaNWSW = pb.add(this.lumaNW, this.lumaSW);
|
|
101
|
+
this.$l.lumaSWSE = pb.add(this.lumaSW, this.lumaSE);
|
|
102
|
+
this.$l.edgeHorz4 = pb.add(pb.mul(pb.abs(this.edgeHorz1), 2), pb.abs(this.edgeHorz2));
|
|
103
|
+
this.$l.edgeVert4 = pb.add(pb.mul(pb.abs(this.edgeVert1), 2), pb.abs(this.edgeVert2));
|
|
104
|
+
this.$l.edgeHorz3 = pb.add(pb.mul(-2, this.lumaW), this.lumaNWSW);
|
|
105
|
+
this.$l.edgeVert3 = pb.add(pb.mul(-2, this.lumaS), this.lumaSWSE);
|
|
106
|
+
this.$l.edgeHorz = pb.add(pb.abs(this.edgeHorz3), this.edgeHorz4);
|
|
107
|
+
this.$l.edgeVert = pb.add(pb.abs(this.edgeVert3), this.edgeVert4);
|
|
108
|
+
this.$l.subpixNWSWNESE = pb.add(this.lumaNWSW, this.lumaNESE);
|
|
109
|
+
this.$l.lengthSign = this.invTexSize.x;
|
|
110
|
+
this.$l.horzSpan = pb.greaterThanEqual(this.edgeHorz, this.edgeVert);
|
|
111
|
+
this.$l.subpixA = pb.add(pb.mul(this.subpixNSWE, 2), this.subpixNWSWNESE);
|
|
112
|
+
this.$if(pb.not(this.horzSpan), function() {
|
|
113
|
+
this.lumaN = this.lumaW;
|
|
114
|
+
this.lumaS = this.lumaE;
|
|
115
|
+
}).$else(function() {
|
|
116
|
+
this.lengthSign = this.invTexSize.y;
|
|
117
|
+
});
|
|
118
|
+
this.$l.subpixB = pb.sub(pb.div(this.subpixA, 12), this.lumaM);
|
|
119
|
+
this.$l.gradientN = pb.sub(this.lumaN, this.lumaM);
|
|
120
|
+
this.$l.gradientS = pb.sub(this.lumaS, this.lumaM);
|
|
121
|
+
this.$l.lumaNN = pb.add(this.lumaN, this.lumaM);
|
|
122
|
+
this.$l.lumaSS = pb.add(this.lumaS, this.lumaM);
|
|
123
|
+
this.$l.pairN = pb.greaterThanEqual(pb.abs(this.gradientN), pb.abs(this.gradientS));
|
|
124
|
+
this.$l.gradient = pb.max(pb.abs(this.gradientN), pb.abs(this.gradientS));
|
|
125
|
+
this.$if(this.pairN, function() {
|
|
126
|
+
this.lengthSign = pb.neg(this.lengthSign);
|
|
127
|
+
});
|
|
128
|
+
this.$l.subpixC = pb.clamp(pb.mul(pb.abs(this.subpixB), this.subpixRcpRange), 0, 1);
|
|
129
|
+
this.$l.posB = this.posM;
|
|
130
|
+
this.$l.offNP = pb.vec2();
|
|
131
|
+
this.$if(pb.not(this.horzSpan), function() {
|
|
132
|
+
this.offNP.x = 0;
|
|
133
|
+
this.offNP.y = this.invTexSize.y;
|
|
134
|
+
this.posB.x = pb.add(this.posB.x, pb.mul(this.lengthSign, 0.5));
|
|
135
|
+
}).$else(function() {
|
|
136
|
+
this.offNP.x = this.invTexSize.x;
|
|
137
|
+
this.offNP.y = 0;
|
|
138
|
+
this.posB.y = pb.add(this.posB.y, pb.mul(this.lengthSign, 0.5));
|
|
139
|
+
});
|
|
140
|
+
this.$l.posN = pb.sub(this.posB, this.offNP);
|
|
141
|
+
this.$l.posP = pb.add(this.posB, this.offNP);
|
|
142
|
+
this.$l.subpixD = pb.add(pb.mul(-2, this.subpixC), 3);
|
|
143
|
+
this.$l.lumaEndN = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posN, 0).rgb);
|
|
144
|
+
this.$l.subpixE = pb.mul(this.subpixC, this.subpixC);
|
|
145
|
+
this.$l.lumaEndP = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posP, 0).rgb);
|
|
146
|
+
this.$if(pb.not(this.pairN), function() {
|
|
147
|
+
this.lumaNN = this.lumaSS;
|
|
148
|
+
});
|
|
149
|
+
this.$l.gradientScaled = pb.div(this.gradient, 4);
|
|
150
|
+
this.$l.lumaMM = pb.sub(this.lumaM, pb.mul(this.lumaNN, 0.5));
|
|
151
|
+
this.$l.subpixF = pb.mul(this.subpixD, this.subpixE);
|
|
152
|
+
this.$l.lumaMLTZero = pb.lessThan(this.lumaMM, 0);
|
|
153
|
+
this.lumaEndN = pb.sub(this.lumaEndN, pb.mul(this.lumaNN, 0.5));
|
|
154
|
+
this.lumaEndP = pb.sub(this.lumaEndP, pb.mul(this.lumaNN, 0.5));
|
|
155
|
+
this.$l.doneN = pb.greaterThanEqual(pb.abs(this.lumaEndN), this.gradientScaled);
|
|
156
|
+
this.$l.doneP = pb.greaterThanEqual(pb.abs(this.lumaEndP), this.gradientScaled);
|
|
157
|
+
this.$if(pb.not(this.doneN), function() {
|
|
158
|
+
this.posN = pb.sub(this.posN, pb.mul(this.offNP, 1.5));
|
|
159
|
+
});
|
|
160
|
+
this.$l.doneNP = pb.or(pb.not(this.doneN), pb.not(this.doneP));
|
|
161
|
+
this.$if(pb.not(this.doneP), function() {
|
|
162
|
+
this.posP = pb.add(this.posP, pb.mul(this.offNP, 1.5));
|
|
163
|
+
});
|
|
164
|
+
this.$if(this.doneNP, function() {
|
|
165
|
+
this.$if(pb.not(this.doneN), function() {
|
|
166
|
+
this.lumaEndN = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posN.xy, 0).rgb);
|
|
167
|
+
this.lumaEndN = pb.sub(this.lumaEndN, pb.mul(this.lumaNN, 0.5));
|
|
168
|
+
});
|
|
169
|
+
this.$if(pb.not(this.doneP), function() {
|
|
170
|
+
this.lumaEndP = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posP.xy, 0).rgb);
|
|
171
|
+
this.lumaEndP = pb.sub(this.lumaEndP, pb.mul(this.lumaNN, 0.5));
|
|
172
|
+
});
|
|
173
|
+
this.doneN = pb.greaterThanEqual(pb.abs(this.lumaEndN), this.gradientScaled);
|
|
174
|
+
this.doneP = pb.greaterThanEqual(pb.abs(this.lumaEndP), this.gradientScaled);
|
|
175
|
+
this.$if(pb.not(this.doneN), function() {
|
|
176
|
+
this.posN = pb.sub(this.posN, pb.mul(this.offNP, 2.0));
|
|
177
|
+
});
|
|
178
|
+
this.doneNP = pb.or(pb.not(this.doneN), pb.not(this.doneP));
|
|
179
|
+
this.$if(pb.not(this.doneP), function() {
|
|
180
|
+
this.posP = pb.add(this.posP, pb.mul(this.offNP, 2.0));
|
|
181
|
+
});
|
|
182
|
+
this.$if(this.doneNP, function() {
|
|
183
|
+
this.$if(pb.not(this.doneN), function() {
|
|
184
|
+
this.lumaEndN = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posN.xy, 0).rgb);
|
|
185
|
+
this.lumaEndN = pb.sub(this.lumaEndN, pb.mul(this.lumaNN, 0.5));
|
|
186
|
+
});
|
|
187
|
+
this.$if(pb.not(this.doneP), function() {
|
|
188
|
+
this.lumaEndP = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posP.xy, 0).rgb);
|
|
189
|
+
this.lumaEndP = pb.sub(this.lumaEndP, pb.mul(this.lumaNN, 0.5));
|
|
190
|
+
});
|
|
191
|
+
this.doneN = pb.greaterThanEqual(pb.abs(this.lumaEndN), this.gradientScaled);
|
|
192
|
+
this.doneP = pb.greaterThanEqual(pb.abs(this.lumaEndP), this.gradientScaled);
|
|
193
|
+
this.$if(pb.not(this.doneN), function() {
|
|
194
|
+
this.posN = pb.sub(this.posN, pb.mul(this.offNP, 2.0));
|
|
195
|
+
});
|
|
196
|
+
this.doneNP = pb.or(pb.not(this.doneN), pb.not(this.doneP));
|
|
197
|
+
this.$if(pb.not(this.doneP), function() {
|
|
198
|
+
this.posP = pb.add(this.posP, pb.mul(this.offNP, 2.0));
|
|
199
|
+
});
|
|
200
|
+
this.$if(this.doneNP, function() {
|
|
201
|
+
this.$if(pb.not(this.doneN), function() {
|
|
202
|
+
this.lumaEndN = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posN.xy, 0).rgb);
|
|
203
|
+
this.lumaEndN = pb.sub(this.lumaEndN, pb.mul(this.lumaNN, 0.5));
|
|
204
|
+
});
|
|
205
|
+
this.$if(pb.not(this.doneP), function() {
|
|
206
|
+
this.lumaEndP = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posP.xy, 0).rgb);
|
|
207
|
+
this.lumaEndP = pb.sub(this.lumaEndP, pb.mul(this.lumaNN, 0.5));
|
|
208
|
+
});
|
|
209
|
+
this.doneN = pb.greaterThanEqual(pb.abs(this.lumaEndN), this.gradientScaled);
|
|
210
|
+
this.doneP = pb.greaterThanEqual(pb.abs(this.lumaEndP), this.gradientScaled);
|
|
211
|
+
this.$if(pb.not(this.doneN), function() {
|
|
212
|
+
this.posN = pb.sub(this.posN, pb.mul(this.offNP, 4.0));
|
|
213
|
+
});
|
|
214
|
+
this.doneNP = pb.or(pb.not(this.doneN), pb.not(this.doneP));
|
|
215
|
+
this.$if(pb.not(this.doneP), function() {
|
|
216
|
+
this.posP = pb.add(this.posP, pb.mul(this.offNP, 4.0));
|
|
217
|
+
});
|
|
218
|
+
this.$if(this.doneNP, function() {
|
|
219
|
+
this.$if(pb.not(this.doneN), function() {
|
|
220
|
+
this.lumaEndN = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posN.xy, 0).rgb);
|
|
221
|
+
this.lumaEndN = pb.sub(this.lumaEndN, pb.mul(this.lumaNN, 0.5));
|
|
222
|
+
});
|
|
223
|
+
this.$if(pb.not(this.doneP), function() {
|
|
224
|
+
this.lumaEndP = this.getLuma(pb.textureSampleLevel(this.srcTex, this.posP.xy, 0).rgb);
|
|
225
|
+
this.lumaEndP = pb.sub(this.lumaEndP, pb.mul(this.lumaNN, 0.5));
|
|
226
|
+
});
|
|
227
|
+
this.doneN = pb.greaterThanEqual(pb.abs(this.lumaEndN), this.gradientScaled);
|
|
228
|
+
this.doneP = pb.greaterThanEqual(pb.abs(this.lumaEndP), this.gradientScaled);
|
|
229
|
+
this.$if(pb.not(this.doneN), function() {
|
|
230
|
+
this.posN = pb.sub(this.posN, pb.mul(this.offNP, 2.0));
|
|
231
|
+
});
|
|
232
|
+
this.$if(pb.not(this.doneP), function() {
|
|
233
|
+
this.posP = pb.add(this.posP, pb.mul(this.offNP, 2.0));
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
this.$l.dstN = pb.sub(this.posM.x, this.posN.x);
|
|
240
|
+
this.$l.dstP = pb.sub(this.posP.x, this.posM.x);
|
|
241
|
+
this.$if(pb.not(this.horzSpan), function() {
|
|
242
|
+
this.dstN = pb.sub(this.posM.y, this.posN.y);
|
|
243
|
+
this.dstP = pb.sub(this.posP.y, this.posM.y);
|
|
244
|
+
});
|
|
245
|
+
this.$l.goodSpanN = pb.notEqual(pb.lessThan(this.lumaEndN, 0), this.lumaMLTZero);
|
|
246
|
+
this.$l.spanLength = pb.add(this.dstP, this.dstN);
|
|
247
|
+
this.$l.goodSpanP = pb.notEqual(pb.lessThan(this.lumaEndP, 0), this.lumaMLTZero);
|
|
248
|
+
this.$l.spanLengthRcp = pb.div(1, this.spanLength);
|
|
249
|
+
this.$l.directionN = pb.lessThan(this.dstN, this.dstP);
|
|
250
|
+
this.$l.dst = pb.min(this.dstN, this.dstP);
|
|
251
|
+
this.$l.goodSpan = this.$choice(this.directionN, this.goodSpanN, this.goodSpanP);
|
|
252
|
+
this.$l.subpixG = pb.mul(this.subpixF, this.subpixF);
|
|
253
|
+
this.$l.pixelOffset = pb.add(pb.mul(this.dst, pb.neg(this.spanLengthRcp)), 0.5);
|
|
254
|
+
this.$l.subpixH = pb.mul(this.subpixG, 0.75);
|
|
255
|
+
this.$l.pixelOffsetGood = this.$choice(this.goodSpan, this.pixelOffset, 0);
|
|
256
|
+
this.$l.pixelOffsetSubpix = pb.max(this.pixelOffsetGood, this.subpixH);
|
|
257
|
+
this.$if(pb.not(this.horzSpan), function() {
|
|
258
|
+
this.posM.x = pb.add(this.posM.x, pb.mul(this.pixelOffsetSubpix, this.lengthSign));
|
|
259
|
+
}).$else(function() {
|
|
260
|
+
this.posM.y = pb.add(this.posM.y, pb.mul(this.pixelOffsetSubpix, this.lengthSign));
|
|
261
|
+
});
|
|
262
|
+
this.$return(pb.textureSampleLevel(this.srcTex, this.posM, 0).xyzw);
|
|
263
|
+
});
|
|
264
|
+
pb.main(function() {
|
|
265
|
+
this.$l.color = this.FXAA(this.$inputs.uv);
|
|
266
|
+
this.$if(pb.equal(this.srgbOut, 0), function() {
|
|
267
|
+
this.$outputs.outColor = this.color;
|
|
268
|
+
}).$else(function() {
|
|
269
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.color.rgb), this.color.a);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
if (!FXAA._sampler) {
|
|
276
|
+
FXAA._sampler = device.createSampler({
|
|
277
|
+
magFilter: 'linear',
|
|
278
|
+
minFilter: 'linear',
|
|
279
|
+
mipFilter: 'none',
|
|
280
|
+
addressU: 'clamp',
|
|
281
|
+
addressV: 'clamp'
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if (!this._bindgroup) {
|
|
285
|
+
this._bindgroup = device.createBindGroup(FXAA._program.bindGroupLayouts[0]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { FXAA };
|
|
291
|
+
//# sourceMappingURL=fxaa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fxaa.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Application } from '../app.js';
|
|
2
|
+
import { AbstractPostEffect } from './posteffect.js';
|
|
3
|
+
import { linearToGamma } from '../shaders/misc.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Grayscale post effect
|
|
7
|
+
* @public
|
|
8
|
+
*/ class Grayscale extends AbstractPostEffect {
|
|
9
|
+
static _program = null;
|
|
10
|
+
static _sampler = null;
|
|
11
|
+
_bindgroup;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of grayscale post effect
|
|
14
|
+
*/ constructor(){
|
|
15
|
+
super();
|
|
16
|
+
this._opaque = false;
|
|
17
|
+
this._bindgroup = null;
|
|
18
|
+
}
|
|
19
|
+
/** {@inheritDoc AbstractPostEffect.dispose} */ dispose() {
|
|
20
|
+
super.dispose();
|
|
21
|
+
this._bindgroup?.dispose();
|
|
22
|
+
this._bindgroup = null;
|
|
23
|
+
}
|
|
24
|
+
/** {@inheritDoc AbstractPostEffect.requireLinearDepthTexture} */ requireLinearDepthTexture() {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
/** {@inheritDoc AbstractPostEffect.requireDepthAttachment} */ requireDepthAttachment() {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
/** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
31
|
+
const device = Application.instance.device;
|
|
32
|
+
this._prepare(device);
|
|
33
|
+
this._bindgroup.setTexture('srcTex', inputColorTexture, Grayscale._sampler);
|
|
34
|
+
this._bindgroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
35
|
+
this._bindgroup.setValue('srgbOut', srgbOutput ? 1 : 0);
|
|
36
|
+
device.setProgram(Grayscale._program);
|
|
37
|
+
device.setBindGroup(0, this._bindgroup);
|
|
38
|
+
this.drawFullscreenQuad();
|
|
39
|
+
}
|
|
40
|
+
/** @internal */ _prepare(device) {
|
|
41
|
+
if (!Grayscale._program) {
|
|
42
|
+
Grayscale._program = device.buildRenderProgram({
|
|
43
|
+
vertex (pb) {
|
|
44
|
+
this.flip = pb.int().uniform(0);
|
|
45
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
46
|
+
this.$outputs.uv = pb.vec2();
|
|
47
|
+
pb.main(function() {
|
|
48
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
|
|
49
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
50
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
51
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
fragment (pb) {
|
|
56
|
+
this.srcTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
57
|
+
this.srgbOut = pb.int().uniform(0);
|
|
58
|
+
this.$outputs.outColor = pb.vec4();
|
|
59
|
+
pb.main(function() {
|
|
60
|
+
this.$l.color = pb.textureSample(this.srcTex, this.$inputs.uv);
|
|
61
|
+
this.$l.grayscaleColor = pb.vec3(pb.dot(this.$l.color.rgb, pb.vec3(0.299, 0.587, 0.114)));
|
|
62
|
+
this.$if(pb.equal(this.srgbOut, 0), function() {
|
|
63
|
+
this.$outputs.outColor = pb.vec4(this.grayscaleColor, this.color.a);
|
|
64
|
+
}).$else(function() {
|
|
65
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.grayscaleColor), this.color.a);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (!Grayscale._sampler) {
|
|
72
|
+
Grayscale._sampler = device.createSampler({
|
|
73
|
+
magFilter: 'nearest',
|
|
74
|
+
minFilter: 'nearest',
|
|
75
|
+
mipFilter: 'none',
|
|
76
|
+
addressU: 'clamp',
|
|
77
|
+
addressV: 'clamp'
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (!this._bindgroup) {
|
|
81
|
+
this._bindgroup = device.createBindGroup(Grayscale._program.bindGroupLayouts[0]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { Grayscale };
|
|
87
|
+
//# sourceMappingURL=grayscale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grayscale.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|