@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,389 @@
|
|
|
1
|
+
import { Vector4 } from '@zephyr3d/base';
|
|
2
|
+
import { Application } from '../app.js';
|
|
3
|
+
import { Primitive } from '../render/primitive.js';
|
|
4
|
+
import '../shaders/framework.js';
|
|
5
|
+
import { linearToGamma } from '../shaders/misc.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base class for any kind of blitters
|
|
9
|
+
* @public
|
|
10
|
+
*/ class Blitter {
|
|
11
|
+
/** @internal */ _hash;
|
|
12
|
+
/** @internal */ _renderStates;
|
|
13
|
+
/** @internal */ _srgbOut;
|
|
14
|
+
/** @internal */ _flip;
|
|
15
|
+
/** @internal */ _viewport;
|
|
16
|
+
/** @internal */ _scissor;
|
|
17
|
+
/** @internal */ _destRect;
|
|
18
|
+
/** @internal */ _offsetParams;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an instance of Blitter
|
|
21
|
+
*/ constructor(){
|
|
22
|
+
this._hash = null;
|
|
23
|
+
this._renderStates = null;
|
|
24
|
+
this._srgbOut = false;
|
|
25
|
+
this._flip = false;
|
|
26
|
+
this._viewport = null;
|
|
27
|
+
this._scissor = null;
|
|
28
|
+
this._destRect = null;
|
|
29
|
+
this._offsetParams = new Vector4();
|
|
30
|
+
}
|
|
31
|
+
/** Viewport */ get viewport() {
|
|
32
|
+
return this._viewport;
|
|
33
|
+
}
|
|
34
|
+
set viewport(val) {
|
|
35
|
+
this._viewport = val ?? null;
|
|
36
|
+
}
|
|
37
|
+
/** Scissor rect */ get scissor() {
|
|
38
|
+
return this._scissor;
|
|
39
|
+
}
|
|
40
|
+
set scissor(val) {
|
|
41
|
+
this._scissor = val ?? null;
|
|
42
|
+
}
|
|
43
|
+
/** Destination rectangle */ get destRect() {
|
|
44
|
+
return this._destRect;
|
|
45
|
+
}
|
|
46
|
+
set destRect(val) {
|
|
47
|
+
if (!!this._destRect !== !!val) {
|
|
48
|
+
this.invalidateHash();
|
|
49
|
+
}
|
|
50
|
+
this._destRect = val ?? null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether output color value in gamma color space
|
|
54
|
+
*/ get srgbOut() {
|
|
55
|
+
return this._srgbOut;
|
|
56
|
+
}
|
|
57
|
+
set srgbOut(val) {
|
|
58
|
+
if (this._srgbOut !== !!val) {
|
|
59
|
+
this._srgbOut = !!val;
|
|
60
|
+
this.invalidateHash();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Render states used to do the blitting
|
|
65
|
+
*/ get renderStates() {
|
|
66
|
+
return this._renderStates;
|
|
67
|
+
}
|
|
68
|
+
set renderStates(rs) {
|
|
69
|
+
this._renderStates = rs;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Program hash code
|
|
73
|
+
*/ get hash() {
|
|
74
|
+
if (!this._hash) {
|
|
75
|
+
this._hash = `${this.constructor.name}:${this._srgbOut ? 1 : 0}:${this._flip ? 1 : 0}:${this._destRect ? 1 : 0}:${this.calcHash()}`;
|
|
76
|
+
}
|
|
77
|
+
return this._hash;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Force the hash code to be regenerated
|
|
81
|
+
*/ invalidateHash() {
|
|
82
|
+
this._hash = null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Reads a texel from the source texture
|
|
86
|
+
* @param scope - The shader scope
|
|
87
|
+
* @param type - The blit type
|
|
88
|
+
* @param srcTex - The source texture
|
|
89
|
+
* @param uv - The texture coordinate from where the texel will be read
|
|
90
|
+
* @param srcLayer - The layer of the source texture
|
|
91
|
+
* @returns The read texel
|
|
92
|
+
*/ readTexel(scope, type, srcTex, uv, srcLayer, sampleType) {
|
|
93
|
+
const pb = scope.$builder;
|
|
94
|
+
if (sampleType === 'float') {
|
|
95
|
+
switch(type){
|
|
96
|
+
case '2d':
|
|
97
|
+
case 'cube':
|
|
98
|
+
return Application.instance.device.getDeviceCaps().shaderCaps.supportShaderTextureLod ? pb.textureSampleLevel(srcTex, uv, 0) : pb.textureSample(srcTex, uv);
|
|
99
|
+
case '2d-array':
|
|
100
|
+
return pb.textureArraySampleLevel(srcTex, uv, srcLayer, 0);
|
|
101
|
+
default:
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
switch(type){
|
|
106
|
+
case '2d':
|
|
107
|
+
return pb.textureLoad(srcTex, pb.ivec2(pb.mul(pb.vec2(pb.textureDimensions(srcTex, 0)), uv)), 0);
|
|
108
|
+
case 'cube':
|
|
109
|
+
throw new Error('Integer format cube texture not supported');
|
|
110
|
+
case '2d-array':
|
|
111
|
+
return pb.textureArrayLoad(srcTex, pb.ivec2(pb.mul(pb.vec2(pb.textureDimensions(srcTex, 0)), uv)), srcLayer, 0);
|
|
112
|
+
default:
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Writes a texel to destination texture
|
|
119
|
+
* @param scope - The shader scope
|
|
120
|
+
* @param type - The blit type
|
|
121
|
+
* @param uv - The texture coordinate to where the texel will be written
|
|
122
|
+
* @param texel - The texel to be written
|
|
123
|
+
* @returns The written texel
|
|
124
|
+
*/ writeTexel(scope, type, uv, texel) {
|
|
125
|
+
return texel;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Initialize uniforms of the blit program
|
|
129
|
+
* @param scope - The shader scope
|
|
130
|
+
* @param type - The blit type
|
|
131
|
+
*/ setup(scope, type) {}
|
|
132
|
+
/**
|
|
133
|
+
* Update uniforms of the bind group
|
|
134
|
+
* @param bindGroup - The bind group to be updated
|
|
135
|
+
*/ setUniforms(bindGroup, sourceTex) {}
|
|
136
|
+
/** @internal */ blit2D(source, dest, sampler) {
|
|
137
|
+
const device = Application.instance.device;
|
|
138
|
+
const flip = !dest && device.type === 'webgpu';
|
|
139
|
+
const bilinearFiltering = sampler ? sampler.magFilter === 'linear' || sampler.minFilter === 'linear' || sampler.mipFilter === 'linear' : source.isFilterable();
|
|
140
|
+
const programInfo = getBlitProgram('2d', this, bilinearFiltering, source.isIntegerFormat() ? source.isSignedFormat() ? 'int' : 'uint' : 'float', flip);
|
|
141
|
+
programInfo.bindGroup.setTexture('srcTex', source, sampler);
|
|
142
|
+
if (this._destRect) {
|
|
143
|
+
const destWidth = this._viewport?.[2] ?? dest?.getWidth() ?? device.getBackBufferWidth();
|
|
144
|
+
const destHeight = this._viewport?.[3] ?? dest?.getHeight() ?? device.getBackBufferHeight();
|
|
145
|
+
this._offsetParams.setXYZW(this._destRect[2] / destWidth, this._destRect[3] / destHeight, (this._destRect[2] + 2 * this._destRect[0]) / destWidth - 1, (this._destRect[3] + 2 * this._destRect[1]) / destHeight - 1);
|
|
146
|
+
programInfo.bindGroup.setValue('scaleBias', this._offsetParams);
|
|
147
|
+
}
|
|
148
|
+
this.setUniforms(programInfo.bindGroup, source);
|
|
149
|
+
device.setFramebuffer(dest ?? null);
|
|
150
|
+
device.setViewport(this._viewport);
|
|
151
|
+
device.setScissor(this._scissor);
|
|
152
|
+
device.setProgram(programInfo.program);
|
|
153
|
+
device.setBindGroup(0, programInfo.bindGroup);
|
|
154
|
+
device.setRenderStates(this._renderStates ?? getBlitRenderStateSet());
|
|
155
|
+
getBlitPrimitive2D().draw();
|
|
156
|
+
}
|
|
157
|
+
/** @internal */ blit2DArray(source, dest, layer, sampler) {
|
|
158
|
+
const device = Application.instance.device;
|
|
159
|
+
const flip = !dest && device.type === 'webgpu';
|
|
160
|
+
const bilinearFiltering = sampler ? sampler.magFilter === 'linear' || sampler.minFilter === 'linear' || sampler.mipFilter === 'linear' : source.isFilterable();
|
|
161
|
+
const programInfo = getBlitProgram('2d-array', this, bilinearFiltering, source.isIntegerFormat() ? source.isSignedFormat() ? 'int' : 'uint' : 'float', flip);
|
|
162
|
+
programInfo.bindGroup.setTexture('srcTex', source, sampler);
|
|
163
|
+
programInfo.bindGroup.setValue('srcLayer', layer);
|
|
164
|
+
this.setUniforms(programInfo.bindGroup, source);
|
|
165
|
+
device.setFramebuffer(dest ?? null);
|
|
166
|
+
device.setViewport(this._viewport);
|
|
167
|
+
device.setScissor(this._scissor);
|
|
168
|
+
device.setProgram(programInfo.program);
|
|
169
|
+
device.setBindGroup(0, programInfo.bindGroup);
|
|
170
|
+
device.setRenderStates(this._renderStates ?? getBlitRenderStateSet());
|
|
171
|
+
getBlitPrimitive2D().draw();
|
|
172
|
+
}
|
|
173
|
+
/** @internal */ blitCubeMap(source, dest, face, sampler) {
|
|
174
|
+
const device = Application.instance.device;
|
|
175
|
+
const flip = !dest && device.type === 'webgpu';
|
|
176
|
+
const bilinearFiltering = sampler ? sampler.magFilter === 'linear' || sampler.minFilter === 'linear' || sampler.mipFilter === 'linear' : source.isFilterable();
|
|
177
|
+
const programInfo = getBlitProgram('cube', this, bilinearFiltering, source.isIntegerFormat() ? source.isSignedFormat() ? 'int' : 'uint' : 'float', flip);
|
|
178
|
+
programInfo.bindGroup.setTexture('srcTex', source, sampler);
|
|
179
|
+
programInfo.bindGroup.setValue('texelSize', 1 / source.width);
|
|
180
|
+
programInfo.bindGroup.setValue('cubeFace', face);
|
|
181
|
+
this.setUniforms(programInfo.bindGroup, source);
|
|
182
|
+
device.setFramebuffer(dest ?? null);
|
|
183
|
+
device.setViewport(this._viewport);
|
|
184
|
+
device.setScissor(this._scissor);
|
|
185
|
+
device.setProgram(programInfo.program);
|
|
186
|
+
device.setBindGroup(0, programInfo.bindGroup);
|
|
187
|
+
device.setRenderStates(this._renderStates ?? getBlitRenderStateSet());
|
|
188
|
+
getBlitPrimitive2D().draw();
|
|
189
|
+
}
|
|
190
|
+
blit(source, dest, layer, sampler) {
|
|
191
|
+
const device = Application.instance.device;
|
|
192
|
+
device.pushDeviceStates();
|
|
193
|
+
if (!dest) {
|
|
194
|
+
if (source.isTexture2D()) {
|
|
195
|
+
this.blit2D(source, null, sampler);
|
|
196
|
+
} else if (source.isTexture2DArray()) {
|
|
197
|
+
this.blit2DArray(source, null, layer || 0, sampler);
|
|
198
|
+
} else if (source.isTextureCube()) {
|
|
199
|
+
this.blitCubeMap(source, null, layer || 0, sampler);
|
|
200
|
+
} else {
|
|
201
|
+
throw new Error('Blitter.blit() failed: invalid texture type');
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
const framebuffer = dest.isFramebuffer() ? dest : device.createFrameBuffer([
|
|
205
|
+
dest
|
|
206
|
+
], null);
|
|
207
|
+
const destTexture = dest.isFramebuffer() ? dest.getColorAttachments()?.[0] : dest;
|
|
208
|
+
if (source.isTexture2D()) {
|
|
209
|
+
if (!destTexture?.isTexture2D() && !destTexture?.isTexture2DArray()) {
|
|
210
|
+
throw new Error('Blitter.blit() failed: invalid destination texture type');
|
|
211
|
+
}
|
|
212
|
+
if (destTexture.isTexture2DArray()) {
|
|
213
|
+
framebuffer.setColorAttachmentLayer(0, layer || 0);
|
|
214
|
+
}
|
|
215
|
+
this.blit2D(source, framebuffer, sampler);
|
|
216
|
+
} else if (source.isTexture2DArray()) {
|
|
217
|
+
if (!destTexture?.isTexture2D() && !destTexture.isTexture2DArray()) {
|
|
218
|
+
throw new Error('Blitter.blit() failed: invalid destination texture type');
|
|
219
|
+
}
|
|
220
|
+
if (destTexture.isTexture2D()) {
|
|
221
|
+
this.blit2DArray(source, framebuffer, layer || 0, sampler);
|
|
222
|
+
} else {
|
|
223
|
+
if (destTexture.depth !== source.depth) {
|
|
224
|
+
throw new Error('Blitter.blit() failed: can not blit between texture 2d arrays with different array size');
|
|
225
|
+
} else {
|
|
226
|
+
for(let i = 0; i < source.depth; i++){
|
|
227
|
+
framebuffer.setColorAttachmentLayer(0, i);
|
|
228
|
+
this.blit2DArray(source, framebuffer, i, layer);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
} else if (source.isTextureCube()) {
|
|
233
|
+
if (!destTexture.isTextureCube() && !destTexture.isTexture2D()) {
|
|
234
|
+
throw new Error('Blitter.blit() failed: invalid destination texture type');
|
|
235
|
+
}
|
|
236
|
+
if (destTexture.isTextureCube()) {
|
|
237
|
+
for(let i = 0; i < 6; i++){
|
|
238
|
+
framebuffer.setColorAttachmentCubeFace(0, i);
|
|
239
|
+
this.blitCubeMap(source, framebuffer, i, layer);
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
this.blitCubeMap(source, framebuffer, layer || 0, sampler);
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
throw new Error('Blitter.blit() failed: invalid texture type');
|
|
246
|
+
}
|
|
247
|
+
if (framebuffer && framebuffer !== dest) {
|
|
248
|
+
framebuffer.dispose();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
device.popDeviceStates();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const blitProgramCache = {};
|
|
255
|
+
let blitPrimitive2D = null;
|
|
256
|
+
let blitRenderStates = null;
|
|
257
|
+
function getBlitPrimitive2D() {
|
|
258
|
+
if (!blitPrimitive2D) {
|
|
259
|
+
blitPrimitive2D = new Primitive();
|
|
260
|
+
const vb = Application.instance.device.createVertexBuffer('position_f32x2', new Float32Array([
|
|
261
|
+
-1,
|
|
262
|
+
-1,
|
|
263
|
+
1,
|
|
264
|
+
-1,
|
|
265
|
+
-1,
|
|
266
|
+
1,
|
|
267
|
+
1,
|
|
268
|
+
1
|
|
269
|
+
]));
|
|
270
|
+
blitPrimitive2D.setVertexBuffer(vb);
|
|
271
|
+
blitPrimitive2D.indexCount = 4;
|
|
272
|
+
blitPrimitive2D.indexStart = 0;
|
|
273
|
+
blitPrimitive2D.primitiveType = 'triangle-strip';
|
|
274
|
+
}
|
|
275
|
+
return blitPrimitive2D;
|
|
276
|
+
}
|
|
277
|
+
function getBlitRenderStateSet() {
|
|
278
|
+
if (!blitRenderStates) {
|
|
279
|
+
blitRenderStates = Application.instance.device.createRenderStateSet();
|
|
280
|
+
blitRenderStates.useDepthState().enableTest(false).enableWrite(false);
|
|
281
|
+
blitRenderStates.useRasterizerState().setCullMode('none');
|
|
282
|
+
}
|
|
283
|
+
return blitRenderStates;
|
|
284
|
+
}
|
|
285
|
+
function getBlitProgram(type, filter, bilinearFiltering, sampleType, flip) {
|
|
286
|
+
const hash = `${type}:${filter.hash}:${bilinearFiltering}:${sampleType}:${flip ? 1 : 0}`;
|
|
287
|
+
let programInfo = blitProgramCache[hash];
|
|
288
|
+
if (programInfo === undefined) {
|
|
289
|
+
programInfo = createBlitProgram(type, filter, bilinearFiltering, sampleType, flip, !!filter.destRect) || null;
|
|
290
|
+
blitProgramCache[hash] = programInfo;
|
|
291
|
+
}
|
|
292
|
+
return programInfo;
|
|
293
|
+
}
|
|
294
|
+
function createBlitProgram(type, filter, bilinearFiltering, st, flip, scaleBias) {
|
|
295
|
+
const program = Application.instance.device.buildRenderProgram({
|
|
296
|
+
vertex (pb) {
|
|
297
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
298
|
+
this.$outputs.uv = pb.vec2();
|
|
299
|
+
if (scaleBias) {
|
|
300
|
+
this.scaleBias = pb.vec4().uniform(0);
|
|
301
|
+
}
|
|
302
|
+
filter.setup(this, type);
|
|
303
|
+
pb.main(function() {
|
|
304
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
|
|
305
|
+
this.$outputs.uv = type === 'cube' ? pb.mul(pb.vec2(1, -1), this.$inputs.pos.xy) : pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
306
|
+
if (Application.instance.device.type === 'webgpu') {
|
|
307
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
308
|
+
}
|
|
309
|
+
if (scaleBias) {
|
|
310
|
+
this.$l.xy = pb.add(pb.mul(this.$builtins.position.xy, this.scaleBias.xy), this.scaleBias.zw);
|
|
311
|
+
this.$builtins.position = pb.vec4(this.xy, 1, 1);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
fragment (pb) {
|
|
316
|
+
switch(type){
|
|
317
|
+
case '2d':
|
|
318
|
+
if (st === 'int') {
|
|
319
|
+
this.srcTex = pb.itex2D().sampleType('sint').uniform(0);
|
|
320
|
+
} else if (st === 'uint') {
|
|
321
|
+
this.srcTex = pb.utex2D().sampleType('uint').uniform(0);
|
|
322
|
+
} else {
|
|
323
|
+
this.srcTex = pb.tex2D().sampleType(bilinearFiltering ? 'float' : 'unfilterable-float').uniform(0);
|
|
324
|
+
}
|
|
325
|
+
break;
|
|
326
|
+
case '2d-array':
|
|
327
|
+
if (st === 'int') {
|
|
328
|
+
this.srcTex = pb.itex2DArray().sampleType('sint').uniform(0);
|
|
329
|
+
} else if (st === 'uint') {
|
|
330
|
+
this.srcTex = pb.utex2DArray().sampleType('uint').uniform(0);
|
|
331
|
+
} else {
|
|
332
|
+
this.srcTex = pb.tex2DArray().sampleType(bilinearFiltering ? 'float' : 'unfilterable-float').uniform(0);
|
|
333
|
+
}
|
|
334
|
+
this.srcLayer = pb.int().uniform(0);
|
|
335
|
+
break;
|
|
336
|
+
case 'cube':
|
|
337
|
+
if (st === 'int') {
|
|
338
|
+
this.srcTex = pb.itexCube().sampleType('sint').uniform(0);
|
|
339
|
+
} else if (st === 'uint') {
|
|
340
|
+
this.srcTex = pb.utexCube().sampleType('uint').uniform(0);
|
|
341
|
+
} else {
|
|
342
|
+
this.srcTex = pb.texCube().sampleType(bilinearFiltering ? 'float' : 'unfilterable-float').uniform(0);
|
|
343
|
+
}
|
|
344
|
+
this.texelSize = pb.float().uniform(0);
|
|
345
|
+
this.cubeFace = pb.int().uniform(0);
|
|
346
|
+
break;
|
|
347
|
+
default:
|
|
348
|
+
throw new Error(`invalid blit type: ${type}`);
|
|
349
|
+
}
|
|
350
|
+
this.$outputs.outColor = pb.vec4();
|
|
351
|
+
filter.setup(this, type);
|
|
352
|
+
pb.main(function() {
|
|
353
|
+
if (type === 'cube') {
|
|
354
|
+
this.uv = pb.vec3();
|
|
355
|
+
this.$if(pb.equal(this.cubeFace, 0), function() {
|
|
356
|
+
this.uv = pb.vec3(1, this.$inputs.uv.y, pb.neg(this.$inputs.uv.x));
|
|
357
|
+
}).$elseif(pb.equal(this.cubeFace, 1), function() {
|
|
358
|
+
this.uv = pb.vec3(-1, this.$inputs.uv.y, this.$inputs.uv.x);
|
|
359
|
+
}).$elseif(pb.equal(this.cubeFace, 2), function() {
|
|
360
|
+
this.uv = pb.vec3(this.$inputs.uv.x, 1, pb.neg(this.$inputs.uv.y));
|
|
361
|
+
}).$elseif(pb.equal(this.cubeFace, 3), function() {
|
|
362
|
+
this.uv = pb.vec3(this.$inputs.uv.x, -1, this.$inputs.uv.y);
|
|
363
|
+
}).$elseif(pb.equal(this.cubeFace, 4), function() {
|
|
364
|
+
this.uv = pb.vec3(this.$inputs.uv.x, this.$inputs.uv.y, 1);
|
|
365
|
+
}).$else(function() {
|
|
366
|
+
this.uv = pb.vec3(pb.neg(this.$inputs.uv.x), this.$inputs.uv.y, -1);
|
|
367
|
+
});
|
|
368
|
+
} else {
|
|
369
|
+
this.uv = this.$inputs.uv;
|
|
370
|
+
}
|
|
371
|
+
if (flip) {
|
|
372
|
+
this.uv.y = pb.sub(1, this.uv.y);
|
|
373
|
+
}
|
|
374
|
+
this.$l.outTexel = filter.filter(this, type, this.srcTex, this.uv, type === '2d' ? null : this.srcLayer, st);
|
|
375
|
+
this.$outputs.outColor = filter.writeTexel(this, type, this.$inputs.uv, this.outTexel);
|
|
376
|
+
if (filter.srgbOut) {
|
|
377
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.$outputs.outColor.rgb), this.$outputs.outColor.a);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
return program ? {
|
|
383
|
+
program,
|
|
384
|
+
bindGroup: Application.instance.device.createBindGroup(program.bindGroupLayouts[0])
|
|
385
|
+
} : null;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export { Blitter };
|
|
389
|
+
//# sourceMappingURL=blitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blitter.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Blitter } from './blitter.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Box-filter blitter
|
|
5
|
+
* @public
|
|
6
|
+
*/ class BoxFilterBlitter extends Blitter {
|
|
7
|
+
/** @internal */ _phase;
|
|
8
|
+
/** @internal */ _kernelSize;
|
|
9
|
+
/** @internal */ _sigma;
|
|
10
|
+
/** @internal */ _blurSize;
|
|
11
|
+
/** @internal */ _logSpace;
|
|
12
|
+
/** @internal */ _logSpaceMultiplier;
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of BoxFilterBlitter
|
|
15
|
+
* @param phase - phase of the blit operation
|
|
16
|
+
* @param kernelSize - kernel size
|
|
17
|
+
* @param blurSize - blur size
|
|
18
|
+
*/ constructor(phase, kernelSize, blurSize){
|
|
19
|
+
super();
|
|
20
|
+
this._phase = phase;
|
|
21
|
+
this._kernelSize = kernelSize;
|
|
22
|
+
this._blurSize = blurSize;
|
|
23
|
+
this._logSpace = false;
|
|
24
|
+
this._logSpaceMultiplier = 1;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* true if the box filter will be applied in logarithmic space
|
|
28
|
+
*/ get logSpace() {
|
|
29
|
+
return this._logSpace;
|
|
30
|
+
}
|
|
31
|
+
set logSpace(val) {
|
|
32
|
+
this._logSpace = !!val;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Multiplier for logarithmic space blur
|
|
36
|
+
*/ get logSpaceMultiplier() {
|
|
37
|
+
return this._logSpaceMultiplier;
|
|
38
|
+
}
|
|
39
|
+
set logSpaceMultiplier(val) {
|
|
40
|
+
this._logSpaceMultiplier = val;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* {@inheritDoc Blitter.setup}
|
|
44
|
+
* @override
|
|
45
|
+
*/ setup(scope, type) {
|
|
46
|
+
const pb = scope.$builder;
|
|
47
|
+
if (pb.shaderKind === 'fragment') {
|
|
48
|
+
scope.blurSize = pb.float().uniform(0);
|
|
49
|
+
if (this._logSpace && this._phase === 'horizonal') {
|
|
50
|
+
scope.multiplier = pb.float().uniform(0);
|
|
51
|
+
}
|
|
52
|
+
if (this._phase !== 'horizonal' && this._phase !== 'vertical') {
|
|
53
|
+
throw new Error(`GaussianBlurFilter.setupFilter() failed: invalid phase: ${this._phase}`);
|
|
54
|
+
}
|
|
55
|
+
if (!Number.isInteger(this._kernelSize) || this._kernelSize < 0 || (this._kernelSize & 1) === 0) {
|
|
56
|
+
throw new Error(`GaussianBlurFilter.setupFilter() failed: invalid kernel size: ${this._kernelSize}`);
|
|
57
|
+
}
|
|
58
|
+
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);
|
|
59
|
+
scope.numBlurPixelsPerSide = pb.float((this._kernelSize + 1) / 2);
|
|
60
|
+
scope.weight = pb.float(1 / this._kernelSize);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* {@inheritDoc Blitter.setUniforms}
|
|
65
|
+
* @override
|
|
66
|
+
*/ setUniforms(bindGroup) {
|
|
67
|
+
bindGroup.setValue('blurSize', this._blurSize);
|
|
68
|
+
if (this._logSpace && this._phase === 'horizonal') {
|
|
69
|
+
bindGroup.setValue('multiplier', this._logSpaceMultiplier);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* {@inheritDoc Blitter.filter}
|
|
74
|
+
* @override
|
|
75
|
+
*/ filter(scope, type, srcTex, srcUV, srcLayer, sampleType) {
|
|
76
|
+
const that = this;
|
|
77
|
+
const pb = scope.$builder;
|
|
78
|
+
scope.d0 = that.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);
|
|
79
|
+
if (that._logSpace) {
|
|
80
|
+
scope.avgValue = pb.vec4(scope.weight);
|
|
81
|
+
} else {
|
|
82
|
+
scope.avgValue = pb.mul(that.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType), scope.weight);
|
|
83
|
+
}
|
|
84
|
+
scope.$for(pb.float('i'), 1, scope.numBlurPixelsPerSide, function() {
|
|
85
|
+
this.d1 = that.readTexel(this, type, srcTex, pb.sub(srcUV, pb.mul(this.blurMultiplyVec, this.blurSize, this.i)), srcLayer, sampleType);
|
|
86
|
+
this.d2 = that.readTexel(this, type, srcTex, pb.add(srcUV, pb.mul(this.blurMultiplyVec, this.blurSize, this.i)), srcLayer, sampleType);
|
|
87
|
+
if (that._logSpace) {
|
|
88
|
+
if (that._phase === 'horizonal') {
|
|
89
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(pb.exp(pb.mul(pb.sub(this.d1, this.d0), this.multiplier)), this.weight));
|
|
90
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(pb.exp(pb.mul(pb.sub(this.d2, this.d0), this.multiplier)), this.weight));
|
|
91
|
+
} else {
|
|
92
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(pb.exp(pb.sub(this.d1, this.d0)), this.weight));
|
|
93
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(pb.exp(pb.sub(this.d2, this.d0)), this.weight));
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(this.d1, this.weight));
|
|
97
|
+
this.avgValue = pb.add(this.avgValue, pb.mul(this.d2, this.weight));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (that._logSpace) {
|
|
101
|
+
if (that._phase === 'horizonal') {
|
|
102
|
+
scope.avgValue = pb.add(pb.mul(scope.multiplier, scope.d0), pb.log(scope.avgValue));
|
|
103
|
+
} else {
|
|
104
|
+
scope.avgValue = pb.add(scope.d0, pb.log(scope.avgValue));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return scope.avgValue;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* {@inheritDoc Blitter.calcHash}
|
|
111
|
+
* @override
|
|
112
|
+
*/ calcHash() {
|
|
113
|
+
return `${this._phase}-${this._kernelSize}-${Number(!!this._logSpace)}`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { BoxFilterBlitter };
|
|
118
|
+
//# sourceMappingURL=box.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Blitter } from './blitter.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copy blitter
|
|
5
|
+
* @public
|
|
6
|
+
*/ class CopyBlitter extends Blitter {
|
|
7
|
+
/**
|
|
8
|
+
* {@inheritDoc Blitter.filter}
|
|
9
|
+
* @override
|
|
10
|
+
*/ filter(scope, type, srcTex, srcUV, srcLayer, sampleType) {
|
|
11
|
+
return this.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* {@inheritDoc Blitter.calcHash}
|
|
15
|
+
* @override
|
|
16
|
+
*/ calcHash() {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { CopyBlitter };
|
|
22
|
+
//# sourceMappingURL=copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
|