@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,166 @@
|
|
|
1
|
+
import { Blitter } from './blitter.js';
|
|
2
|
+
import '../shaders/framework.js';
|
|
3
|
+
import { decodeNormalizedFloatFromRGBA, encodeNormalizedFloatToRGBA } from '../shaders/misc.js';
|
|
4
|
+
import '../app.js';
|
|
5
|
+
import { Vector2 } from '@zephyr3d/base';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Bilateral blur blitter horizonal stage for ambient occlusion calculation
|
|
9
|
+
* @public
|
|
10
|
+
*/ class AOBilateralBlurBlitter extends Blitter {
|
|
11
|
+
_depthTex;
|
|
12
|
+
_sampler;
|
|
13
|
+
_kernelRadius;
|
|
14
|
+
_cameraNearFar;
|
|
15
|
+
_depthCutoff;
|
|
16
|
+
_packed;
|
|
17
|
+
_uvStep;
|
|
18
|
+
_size;
|
|
19
|
+
_stdDev;
|
|
20
|
+
_offsetsAndWeights;
|
|
21
|
+
_finalPhase;
|
|
22
|
+
constructor(finalPhase){
|
|
23
|
+
super();
|
|
24
|
+
this._depthTex = null;
|
|
25
|
+
this._depthCutoff = 0.001;
|
|
26
|
+
this._sampler = null;
|
|
27
|
+
this._packed = false;
|
|
28
|
+
this._kernelRadius = 8;
|
|
29
|
+
this._cameraNearFar = Vector2.zero();
|
|
30
|
+
this._size = Vector2.zero();
|
|
31
|
+
this._stdDev = 10;
|
|
32
|
+
this._offsetsAndWeights = new Float32Array(4 * (this._kernelRadius + 1));
|
|
33
|
+
this._finalPhase = !!finalPhase;
|
|
34
|
+
this._uvStep = this._finalPhase ? new Vector2(1, 0) : new Vector2(0, 1);
|
|
35
|
+
this.calcGaussion();
|
|
36
|
+
}
|
|
37
|
+
get depthTex() {
|
|
38
|
+
return this._depthTex;
|
|
39
|
+
}
|
|
40
|
+
set depthTex(tex) {
|
|
41
|
+
this._depthTex = tex;
|
|
42
|
+
}
|
|
43
|
+
get packed() {
|
|
44
|
+
return this._packed;
|
|
45
|
+
}
|
|
46
|
+
set packed(val) {
|
|
47
|
+
if (this._packed !== !!val) {
|
|
48
|
+
this._packed = !!val;
|
|
49
|
+
this.invalidateHash();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
get nearestSampler() {
|
|
53
|
+
return this._sampler;
|
|
54
|
+
}
|
|
55
|
+
set nearestSampler(sampler) {
|
|
56
|
+
this._sampler = sampler;
|
|
57
|
+
}
|
|
58
|
+
get cameraNearFar() {
|
|
59
|
+
return this._cameraNearFar;
|
|
60
|
+
}
|
|
61
|
+
set cameraNearFar(v) {
|
|
62
|
+
this._cameraNearFar.set(v);
|
|
63
|
+
}
|
|
64
|
+
get depthCutoff() {
|
|
65
|
+
return this._depthCutoff;
|
|
66
|
+
}
|
|
67
|
+
set depthCutoff(val) {
|
|
68
|
+
this._depthCutoff = val;
|
|
69
|
+
}
|
|
70
|
+
get size() {
|
|
71
|
+
return this._size;
|
|
72
|
+
}
|
|
73
|
+
set size(val) {
|
|
74
|
+
this._size.set(val);
|
|
75
|
+
}
|
|
76
|
+
get stdDev() {
|
|
77
|
+
return this._stdDev;
|
|
78
|
+
}
|
|
79
|
+
set stdDev(val) {
|
|
80
|
+
if (val !== this._stdDev) {
|
|
81
|
+
this._stdDev = val;
|
|
82
|
+
this.calcGaussion();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
get kernelRadius() {
|
|
86
|
+
return this._kernelRadius;
|
|
87
|
+
}
|
|
88
|
+
set kernelRadius(val) {
|
|
89
|
+
if (val !== this._kernelRadius) {
|
|
90
|
+
this._kernelRadius = val;
|
|
91
|
+
this._offsetsAndWeights = new Float32Array(4 * (this._kernelRadius + 1));
|
|
92
|
+
this.calcGaussion();
|
|
93
|
+
this.invalidateHash();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
calcHash() {
|
|
97
|
+
return `${this._kernelRadius}:${this._packed}:${this._finalPhase}`;
|
|
98
|
+
}
|
|
99
|
+
calcGaussion() {
|
|
100
|
+
for(let i = 0; i <= this.kernelRadius; i++){
|
|
101
|
+
this._offsetsAndWeights[i * 4] = this._uvStep.x * i;
|
|
102
|
+
this._offsetsAndWeights[i * 4 + 1] = this._uvStep.y * i;
|
|
103
|
+
this._offsetsAndWeights[i * 4 + 2] = Math.exp(-(i * i) / (2 * (this._stdDev * this._stdDev))) / (Math.sqrt(2.0 * Math.PI) * this._stdDev);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
setup(scope, type) {
|
|
107
|
+
super.setup(scope, type);
|
|
108
|
+
const pb = scope.$builder;
|
|
109
|
+
if (pb.shaderKind === 'fragment') {
|
|
110
|
+
scope.depthTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
111
|
+
scope.depthCutoff = pb.float().uniform(0);
|
|
112
|
+
scope.offsetsAndWeights = pb.vec4[this._kernelRadius + 1]().uniform(0);
|
|
113
|
+
scope.cameraNearFar = pb.vec2().uniform(0);
|
|
114
|
+
scope.size = pb.vec2().uniform(0);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
setUniforms(bindGroup, sourceTex) {
|
|
118
|
+
super.setUniforms(bindGroup, sourceTex);
|
|
119
|
+
bindGroup.setTexture('depthTex', this._depthTex, this._sampler);
|
|
120
|
+
bindGroup.setValue('depthCutoff', this._depthCutoff);
|
|
121
|
+
bindGroup.setValue('offsetsAndWeights', this._offsetsAndWeights);
|
|
122
|
+
bindGroup.setValue('cameraNearFar', this._cameraNearFar);
|
|
123
|
+
bindGroup.setValue('size', this._size);
|
|
124
|
+
}
|
|
125
|
+
filter(scope, type, srcTex, srcUV, srcLayer, sampleType) {
|
|
126
|
+
const that = this;
|
|
127
|
+
const pb = scope.$builder;
|
|
128
|
+
pb.func('getLinearDepth', [
|
|
129
|
+
pb.vec2('uv')
|
|
130
|
+
], function() {
|
|
131
|
+
this.$l.depthValue = pb.textureSample(this.depthTex, this.uv);
|
|
132
|
+
this.$return(pb.getDevice().type === 'webgl' ? decodeNormalizedFloatFromRGBA(this, this.depthValue) : this.depthValue.r);
|
|
133
|
+
});
|
|
134
|
+
scope.depth = scope.getLinearDepth(srcUV);
|
|
135
|
+
scope.weightSum = scope.offsetsAndWeights[0].z;
|
|
136
|
+
scope.srcTexel = that.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);
|
|
137
|
+
scope.ao = that._packed ? decodeNormalizedFloatFromRGBA(scope, scope.srcTexel) : scope.srcTexel.r;
|
|
138
|
+
scope.colorSum = pb.mul(scope.ao, scope.weightSum);
|
|
139
|
+
scope.$for(pb.int('i'), 0, that._kernelRadius, function() {
|
|
140
|
+
this.$l.offsetAndWeight = this.offsetsAndWeights.at(pb.add(this.i, 1));
|
|
141
|
+
this.$l.weight = this.offsetAndWeight.z;
|
|
142
|
+
this.$l.offset = pb.div(this.offsetAndWeight.xy, this.size);
|
|
143
|
+
this.$l.uvRight = pb.add(srcUV, this.offset);
|
|
144
|
+
this.$l.depthRight = this.getLinearDepth(this.uvRight);
|
|
145
|
+
this.$if(pb.lessThan(pb.abs(pb.sub(this.depthRight, this.depth)), this.depthCutoff), function() {
|
|
146
|
+
this.$l.srcTexelRight = that.readTexel(this, type, srcTex, this.uvRight, srcLayer, sampleType);
|
|
147
|
+
this.$l.aoRight = that._packed ? decodeNormalizedFloatFromRGBA(this, this.srcTexelRight) : this.srcTexelRight.r;
|
|
148
|
+
this.colorSum = pb.add(this.colorSum, pb.mul(this.aoRight, this.weight));
|
|
149
|
+
this.weightSum = pb.add(this.weightSum, this.weight);
|
|
150
|
+
});
|
|
151
|
+
this.$l.uvLeft = pb.sub(srcUV, this.offset);
|
|
152
|
+
this.$l.depthLeft = this.getLinearDepth(this.uvLeft);
|
|
153
|
+
this.$if(pb.lessThan(pb.abs(pb.sub(this.depthLeft, this.depth)), this.depthCutoff), function() {
|
|
154
|
+
this.$l.srcTexelLeft = that.readTexel(this, type, srcTex, this.uvLeft, srcLayer, sampleType);
|
|
155
|
+
this.$l.aoLeft = that._packed ? decodeNormalizedFloatFromRGBA(this, this.srcTexelLeft) : this.srcTexelLeft.r;
|
|
156
|
+
this.colorSum = pb.add(this.colorSum, pb.mul(this.aoLeft, this.weight));
|
|
157
|
+
this.weightSum = pb.add(this.weightSum, this.weight);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
scope.colorSum = pb.div(scope.colorSum, scope.weightSum);
|
|
161
|
+
return that._finalPhase || !that._packed ? pb.vec4(scope.colorSum, scope.colorSum, scope.colorSum, 1) : encodeNormalizedFloatToRGBA(scope, scope.colorSum);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { AOBilateralBlurBlitter };
|
|
166
|
+
//# sourceMappingURL=depthlimitedgaussion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"depthlimitedgaussion.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { Blitter } from './blitter.js';
|
|
2
|
+
import '../shaders/framework.js';
|
|
3
|
+
import { decodeNormalizedFloatFromRGBA } from '../shaders/misc.js';
|
|
4
|
+
import '../app.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gaussian blur blitter
|
|
8
|
+
* @public
|
|
9
|
+
*/ class GaussianBlurBlitter extends Blitter {
|
|
10
|
+
/** @internal */ _phase;
|
|
11
|
+
/** @internal */ _kernelSize;
|
|
12
|
+
/** @internal */ _sigma;
|
|
13
|
+
/** @internal */ _blurSize;
|
|
14
|
+
/** @internal */ _logSpace;
|
|
15
|
+
/** @internal */ _logSpaceMultiplier;
|
|
16
|
+
/** @internal */ _depthTex;
|
|
17
|
+
/** @internal */ _depthCutoff;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of GaussianBlurBlitter
|
|
20
|
+
* @param phase - Blitter phase
|
|
21
|
+
* @param kernalSize - kernel size
|
|
22
|
+
* @param sigma - Gaussian standard deviation
|
|
23
|
+
* @param blurSize - Blur radius
|
|
24
|
+
*/ constructor(phase, kernalSize, sigma, blurSize){
|
|
25
|
+
super();
|
|
26
|
+
this._phase = phase;
|
|
27
|
+
this._kernelSize = kernalSize;
|
|
28
|
+
this._sigma = sigma;
|
|
29
|
+
this._blurSize = blurSize;
|
|
30
|
+
this._logSpace = false;
|
|
31
|
+
this._logSpaceMultiplier = 1;
|
|
32
|
+
this._depthTex = null;
|
|
33
|
+
this._depthCutoff = 0.7;
|
|
34
|
+
}
|
|
35
|
+
/** Blur radius */ get blurSize() {
|
|
36
|
+
return this._blurSize;
|
|
37
|
+
}
|
|
38
|
+
set blurSize(val) {
|
|
39
|
+
this._blurSize = val;
|
|
40
|
+
}
|
|
41
|
+
/** Kernel size */ get kernelSize() {
|
|
42
|
+
return this._kernelSize;
|
|
43
|
+
}
|
|
44
|
+
set kernelSize(val) {
|
|
45
|
+
if (this._kernelSize !== val) {
|
|
46
|
+
this._kernelSize = val;
|
|
47
|
+
this.invalidateHash();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** true if the box filter will be applied in logarithmic space */ get logSpace() {
|
|
51
|
+
return this._logSpace;
|
|
52
|
+
}
|
|
53
|
+
set logSpace(val) {
|
|
54
|
+
if (this._logSpace !== !!val) {
|
|
55
|
+
this._logSpace = !!val;
|
|
56
|
+
this.invalidateHash();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Multiplier for logarithmic space blur */ get logSpaceMultiplier() {
|
|
60
|
+
return this._logSpaceMultiplier;
|
|
61
|
+
}
|
|
62
|
+
set logSpaceMultiplier(val) {
|
|
63
|
+
this._logSpaceMultiplier = val;
|
|
64
|
+
}
|
|
65
|
+
/** Linear depth texture */ get depthTexture() {
|
|
66
|
+
return this._depthTex;
|
|
67
|
+
}
|
|
68
|
+
set depthTexture(tex) {
|
|
69
|
+
if (this._depthTex !== tex) {
|
|
70
|
+
if (!tex || !this._depthTex) {
|
|
71
|
+
this.invalidateHash();
|
|
72
|
+
}
|
|
73
|
+
this._depthTex = tex;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Depth cutoff */ get depthCutoff() {
|
|
77
|
+
return this._depthCutoff;
|
|
78
|
+
}
|
|
79
|
+
set depthCutoff(val) {
|
|
80
|
+
this._depthCutoff = val;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* {@inheritDoc Blitter.setup}
|
|
84
|
+
* @override
|
|
85
|
+
*/ setup(scope, type) {
|
|
86
|
+
const pb = scope.$builder;
|
|
87
|
+
if (pb.shaderKind === 'fragment') {
|
|
88
|
+
if (this._depthTex) {
|
|
89
|
+
scope.depthTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
90
|
+
scope.depthCutoff = pb.float().uniform(0);
|
|
91
|
+
}
|
|
92
|
+
scope.sigma = pb.float().uniform(0);
|
|
93
|
+
scope.blurSize = pb.float().uniform(0);
|
|
94
|
+
if (this._logSpace && this._phase === 'horizonal') {
|
|
95
|
+
scope.multiplier = pb.float().uniform(0);
|
|
96
|
+
}
|
|
97
|
+
if (this._phase !== 'horizonal' && this._phase !== 'vertical') {
|
|
98
|
+
throw new Error(`GaussianBlurFilter.setupFilter() failed: invalid phase: ${this._phase}`);
|
|
99
|
+
}
|
|
100
|
+
if (!Number.isInteger(this._kernelSize) || this._kernelSize < 0 || (this._kernelSize & 1) === 0) {
|
|
101
|
+
throw new Error(`GaussianBlurFilter.setupFilter() failed: invalid kernel size: ${this._kernelSize}`);
|
|
102
|
+
}
|
|
103
|
+
scope.blurMultiplyVec = type === 'cube' ? this._phase === 'horizonal' ? pb.vec3(1, 0, 0) : pb.vec3(0, 1, 0) : this._phase === 'horizonal' ? pb.vec2(1, 0) : pb.vec2(0, 1);
|
|
104
|
+
scope.numBlurPixelsPerSide = pb.float((this._kernelSize + 1) / 2);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* {@inheritDoc Blitter.setUniforms}
|
|
109
|
+
* @override
|
|
110
|
+
*/ setUniforms(bindGroup) {
|
|
111
|
+
bindGroup.setValue('sigma', this._sigma);
|
|
112
|
+
bindGroup.setValue('blurSize', this._blurSize);
|
|
113
|
+
if (this._logSpace && this._phase === 'horizonal') {
|
|
114
|
+
bindGroup.setValue('multiplier', this._logSpaceMultiplier);
|
|
115
|
+
}
|
|
116
|
+
if (this._depthTex) {
|
|
117
|
+
bindGroup.setTexture('depthTex', this._depthTex);
|
|
118
|
+
bindGroup.setValue('depthCutoff', this._depthCutoff);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* {@inheritDoc Blitter.filter}
|
|
123
|
+
* @override
|
|
124
|
+
*/ filter(scope, type, srcTex, srcUV, srcLayer, sampleType) {
|
|
125
|
+
const that = this;
|
|
126
|
+
const pb = scope.$builder;
|
|
127
|
+
if (that._depthTex) {
|
|
128
|
+
pb.func('getLinearDepth', [
|
|
129
|
+
pb.vec2('uv')
|
|
130
|
+
], function() {
|
|
131
|
+
this.$l.depthValue = pb.textureSample(this.depthTex, this.uv);
|
|
132
|
+
if (pb.getDevice().type === 'webgl') {
|
|
133
|
+
this.$return(decodeNormalizedFloatFromRGBA(this, this.depthValue));
|
|
134
|
+
} else {
|
|
135
|
+
this.$return(this.depthValue.r);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
scope.incrementalGaussian = pb.vec3();
|
|
140
|
+
scope.incrementalGaussian.x = pb.div(1, pb.mul(scope.sigma, Math.sqrt(2 * Math.PI)));
|
|
141
|
+
scope.incrementalGaussian.y = pb.exp(pb.div(-0.5, pb.mul(scope.sigma, scope.sigma)));
|
|
142
|
+
scope.incrementalGaussian.z = pb.mul(scope.incrementalGaussian.y, scope.incrementalGaussian.y);
|
|
143
|
+
scope.coefficientSum = pb.float(0);
|
|
144
|
+
scope.minExpValue = pb.vec4(87, 87, 87, 87);
|
|
145
|
+
scope.d0 = that.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);
|
|
146
|
+
if (that._logSpace) {
|
|
147
|
+
scope.avgValue = pb.vec4(scope.incrementalGaussian.x);
|
|
148
|
+
} else {
|
|
149
|
+
scope.avgValue = pb.mul(that.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType), scope.incrementalGaussian.x);
|
|
150
|
+
}
|
|
151
|
+
if (that._depthTex) {
|
|
152
|
+
scope.centerDepth = scope.getLinearDepth(srcUV);
|
|
153
|
+
}
|
|
154
|
+
scope.coefficientSum = pb.add(scope.coefficientSum, scope.incrementalGaussian.x);
|
|
155
|
+
scope.incrementalGaussian = pb.vec3(pb.mul(scope.incrementalGaussian.xy, scope.incrementalGaussian.yz), scope.incrementalGaussian.z);
|
|
156
|
+
scope.$for(pb.float('i'), 1, scope.numBlurPixelsPerSide, function() {
|
|
157
|
+
this.$l.uv1 = pb.sub(srcUV, pb.mul(this.blurMultiplyVec, this.blurSize, this.i));
|
|
158
|
+
this.$l.d1 = pb.vec4();
|
|
159
|
+
if (that._depthTex) {
|
|
160
|
+
this.$l.depth1 = this.getLinearDepth(this.uv1);
|
|
161
|
+
this.$l.test1 = pb.lessThan(pb.abs(pb.sub(this.depth1, this.centerDepth)), this.depthCutoff);
|
|
162
|
+
} else {
|
|
163
|
+
this.$l.test1 = true;
|
|
164
|
+
}
|
|
165
|
+
this.$if(this.test1, function() {
|
|
166
|
+
this.d1 = that.readTexel(scope, type, srcTex, this.uv1, srcLayer, sampleType);
|
|
167
|
+
});
|
|
168
|
+
this.$l.uv2 = pb.add(srcUV, pb.mul(this.blurMultiplyVec, this.blurSize, this.i)), this.$l.d2 = pb.vec4();
|
|
169
|
+
if (that._depthTex) {
|
|
170
|
+
this.$l.depth2 = this.getLinearDepth(this.uv2);
|
|
171
|
+
this.$l.test2 = pb.lessThan(pb.abs(pb.sub(this.depth2, this.centerDepth)), this.depthCutoff);
|
|
172
|
+
} else {
|
|
173
|
+
this.$l.test2 = true;
|
|
174
|
+
}
|
|
175
|
+
this.$if(this.test2, function() {
|
|
176
|
+
this.d2 = that.readTexel(scope, type, srcTex, pb.add(srcUV, pb.mul(this.blurMultiplyVec, this.blurSize, this.i)), srcLayer, sampleType);
|
|
177
|
+
});
|
|
178
|
+
if (that._logSpace) {
|
|
179
|
+
if (that._phase === 'horizonal') {
|
|
180
|
+
this.$if(this.test1, function() {
|
|
181
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(pb.exp(pb.min(this.minExpValue, pb.mul(pb.sub(this.d1, this.d0), this.multiplier))), this.incrementalGaussian.x));
|
|
182
|
+
this.coefficientSum = pb.add(this.coefficientSum, this.incrementalGaussian.x);
|
|
183
|
+
});
|
|
184
|
+
this.$if(this.test2, function() {
|
|
185
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(pb.exp(pb.min(this.minExpValue, pb.mul(pb.sub(this.d2, this.d0), this.multiplier))), this.incrementalGaussian.x));
|
|
186
|
+
this.coefficientSum = pb.add(this.coefficientSum, this.incrementalGaussian.x);
|
|
187
|
+
});
|
|
188
|
+
} else {
|
|
189
|
+
this.$if(this.test1, function() {
|
|
190
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(pb.exp(pb.min(this.minExpValue, pb.sub(this.d1, this.d0))), this.incrementalGaussian.x));
|
|
191
|
+
this.coefficientSum = pb.add(this.coefficientSum, this.incrementalGaussian.x);
|
|
192
|
+
});
|
|
193
|
+
this.$if(this.test2, function() {
|
|
194
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(pb.exp(pb.min(this.minExpValue, pb.sub(this.d2, this.d0))), this.incrementalGaussian.x));
|
|
195
|
+
this.coefficientSum = pb.add(this.coefficientSum, this.incrementalGaussian.x);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
this.$if(this.test1, function() {
|
|
200
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(this.d1, this.incrementalGaussian.x));
|
|
201
|
+
this.coefficientSum = pb.add(this.coefficientSum, this.incrementalGaussian.x);
|
|
202
|
+
});
|
|
203
|
+
this.$if(this.test2, function() {
|
|
204
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(this.d2, this.incrementalGaussian.x));
|
|
205
|
+
this.coefficientSum = pb.add(this.coefficientSum, this.incrementalGaussian.x);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
this.incrementalGaussian = pb.vec3(pb.mul(this.incrementalGaussian.xy, this.incrementalGaussian.yz), this.incrementalGaussian.z);
|
|
209
|
+
});
|
|
210
|
+
scope.$l.outColor = pb.div(scope.avgValue, scope.coefficientSum);
|
|
211
|
+
if (that._logSpace) {
|
|
212
|
+
if (that._phase === 'horizonal') {
|
|
213
|
+
scope.outColor = pb.add(pb.mul(scope.multiplier, scope.d0), pb.log(scope.outColor));
|
|
214
|
+
} else {
|
|
215
|
+
scope.outColor = pb.add(scope.d0, pb.log(scope.outColor));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return scope.outColor;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* {@inheritDoc Blitter.calcHash}
|
|
222
|
+
* @override
|
|
223
|
+
*/ calcHash() {
|
|
224
|
+
return `${this._depthTex ? 1 : 0}-${this._phase}-${this._kernelSize}-${Number(!!this._logSpace)}`;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { GaussianBlurBlitter };
|
|
229
|
+
//# sourceMappingURL=gaussianblur.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gaussianblur.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for any kind of camera controllers
|
|
3
|
+
* @public
|
|
4
|
+
*/ class BaseCameraController {
|
|
5
|
+
/** @internal */ _camera;
|
|
6
|
+
/**
|
|
7
|
+
* Creates an instance of BaseCameraController
|
|
8
|
+
*/ constructor(){
|
|
9
|
+
this._camera = null;
|
|
10
|
+
this.reset();
|
|
11
|
+
}
|
|
12
|
+
/** @internal */ _getCamera() {
|
|
13
|
+
return this._camera;
|
|
14
|
+
}
|
|
15
|
+
/** @internal */ _setCamera(camera) {
|
|
16
|
+
if (this._camera !== camera) {
|
|
17
|
+
this._camera = camera;
|
|
18
|
+
this.reset();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resets state
|
|
23
|
+
*/ reset() {}
|
|
24
|
+
/** @internal */ onMouseDown(evt) {
|
|
25
|
+
return this._onMouseDown(evt);
|
|
26
|
+
}
|
|
27
|
+
/** @internal */ onMouseUp(evt) {
|
|
28
|
+
return this._onMouseUp(evt);
|
|
29
|
+
}
|
|
30
|
+
/** @internal */ onMouseWheel(evt) {
|
|
31
|
+
return this._onMouseWheel(evt);
|
|
32
|
+
}
|
|
33
|
+
/** @internal */ onMouseMove(evt) {
|
|
34
|
+
return this._onMouseMove(evt);
|
|
35
|
+
}
|
|
36
|
+
/** @internal */ onKeyDown(evt) {
|
|
37
|
+
return this._onKeyDown(evt);
|
|
38
|
+
}
|
|
39
|
+
/** @internal */ onKeyUp(evt) {
|
|
40
|
+
return this._onKeyUp(evt);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Updates state
|
|
44
|
+
*/ update() {}
|
|
45
|
+
/**
|
|
46
|
+
* Mouse down event handler
|
|
47
|
+
* @param evt - Mouse event
|
|
48
|
+
* @returns Boolean value indices whether this event was handled
|
|
49
|
+
*/ _onMouseDown(evt) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Mouse up event handler
|
|
54
|
+
* @param evt - Mouse event
|
|
55
|
+
* @returns Boolean value indices whether this event was handled
|
|
56
|
+
*/ _onMouseUp(evt) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Mouse wheel event handler
|
|
61
|
+
* @param evt - Mouse event
|
|
62
|
+
* @returns Boolean value indices whether this event was handled
|
|
63
|
+
*/ _onMouseWheel(evt) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Mouse move event handler
|
|
68
|
+
* @param evt - Mouse event
|
|
69
|
+
* @returns Boolean value indices whether this event was handled
|
|
70
|
+
*/ _onMouseMove(evt) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Key down event handler
|
|
75
|
+
* @param evt - Keyboard event
|
|
76
|
+
* @returns Boolean value indices whether this event was handled
|
|
77
|
+
*/ _onKeyDown(evt) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Key up event handler
|
|
82
|
+
* @param evt - Keyboard event
|
|
83
|
+
* @returns Boolean value indices whether this event was handled
|
|
84
|
+
*/ _onKeyUp(evt) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { BaseCameraController };
|
|
90
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|