@zephyr3d/scene 0.1.0 → 0.1.1
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/README.md +46 -0
- package/dist/animation/animation.js +28 -28
- package/dist/animation/skeleton.js +14 -14
- package/dist/animation/usertrack.js +9 -9
- package/dist/app.js +31 -31
- package/dist/asset/assetmanager.js +50 -50
- package/dist/asset/builtin.js +157 -157
- package/dist/asset/loaders/dds/dds_loader.js +11 -11
- package/dist/asset/loaders/gltf/gltf_loader.js +10 -10
- package/dist/asset/loaders/hdr/hdr.js +5 -5
- package/dist/asset/loaders/image/tga_Loader.js +3 -3
- package/dist/asset/loaders/image/webimage_loader.js +3 -3
- package/dist/asset/loaders/loader.js +19 -19
- package/dist/asset/model.js +57 -57
- package/dist/blitter/blitter.js +35 -35
- package/dist/blitter/box.js +24 -24
- package/dist/blitter/depthlimitedgaussion.js +3 -3
- package/dist/blitter/gaussianblur.js +21 -21
- package/dist/camera/camera.js +68 -68
- package/dist/index.d.ts +2 -0
- package/dist/material/grassmaterial.js +17 -17
- package/dist/material/lambert.js +3 -3
- package/dist/material/lightmodel.js +362 -362
- package/dist/material/material.js +50 -50
- package/dist/material/meshmaterial.js +48 -48
- package/dist/material/unlit.js +3 -3
- package/dist/posteffect/bloom.js +5 -5
- package/dist/posteffect/compositor.js +16 -16
- package/dist/posteffect/fxaa.js +5 -5
- package/dist/posteffect/grayscale.js +5 -5
- package/dist/posteffect/posteffect.js +42 -42
- package/dist/posteffect/sao.js +5 -5
- package/dist/posteffect/tonemap.js +5 -5
- package/dist/posteffect/water.js +6 -6
- package/dist/render/cull_visitor.js +12 -12
- package/dist/render/depth_pass.js +8 -8
- package/dist/render/envlight.js +104 -104
- package/dist/render/render_queue.js +33 -33
- package/dist/render/renderpass.js +18 -18
- package/dist/render/renderscheme.js +14 -14
- package/dist/render/scatteringlut.js +3 -3
- package/dist/render/sky.js +38 -38
- package/dist/render/temporalcache.js +4 -4
- package/dist/render/watermesh.js +5 -5
- package/dist/scene/graph_node.js +25 -25
- package/dist/scene/octree.js +191 -191
- package/dist/scene/scene.js +37 -37
- package/dist/scene/terrain/grass.js +27 -27
- package/dist/scene/terrain/quadtree.js +45 -45
- package/dist/shaders/framework.js +161 -161
- package/dist/shaders/lighting.js +7 -7
- package/dist/shaders/noise.js +43 -43
- package/dist/shadow/shadowmapper.js +76 -76
- package/dist/shadow/ssm.js +34 -34
- package/dist/utility/bounding_volume.js +30 -27
- package/dist/utility/bounding_volume.js.map +1 -1
- package/dist/utility/shprojection.js +14 -14
- package/package.json +70 -70
- package/dist/material/mixins/texture.js +0 -110
- package/dist/material/mixins/texture.js.map +0 -1
|
@@ -45,9 +45,9 @@ class InstanceBindGroupPool {
|
|
|
45
45
|
return offset;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Base class for any kind of materials
|
|
50
|
-
* @public
|
|
48
|
+
/**
|
|
49
|
+
* Base class for any kind of materials
|
|
50
|
+
* @public
|
|
51
51
|
*/ class Material {
|
|
52
52
|
/** @internal */ static _debugChannel = '';
|
|
53
53
|
/** @internal */ static _nextId = 0;
|
|
@@ -73,8 +73,8 @@ class InstanceBindGroupPool {
|
|
|
73
73
|
/** @internal */ _optionTag;
|
|
74
74
|
/** @internal */ _materialBindGroup;
|
|
75
75
|
/** @internal */ _id;
|
|
76
|
-
/**
|
|
77
|
-
* Creates an instance of material
|
|
76
|
+
/**
|
|
77
|
+
* Creates an instance of material
|
|
78
78
|
*/ constructor(){
|
|
79
79
|
this._id = ++Material._nextId;
|
|
80
80
|
this._hash = [];
|
|
@@ -113,10 +113,10 @@ class InstanceBindGroupPool {
|
|
|
113
113
|
/** Returns true if shading of the material will be affected by lights */ supportLighting() {
|
|
114
114
|
return true;
|
|
115
115
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Draws a primitive using this material
|
|
118
|
-
* @param primitive - The prmitive to be drawn
|
|
119
|
-
* @param ctx - The context of current drawing task
|
|
116
|
+
/**
|
|
117
|
+
* Draws a primitive using this material
|
|
118
|
+
* @param primitive - The prmitive to be drawn
|
|
119
|
+
* @param ctx - The context of current drawing task
|
|
120
120
|
*/ draw(primitive, ctx) {
|
|
121
121
|
if (this.beginDraw(ctx)) {
|
|
122
122
|
if (ctx.instanceData?.worldMatrices.length > 1) {
|
|
@@ -127,10 +127,10 @@ class InstanceBindGroupPool {
|
|
|
127
127
|
this.endDraw();
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Prepares for drawing
|
|
132
|
-
* @param ctx - The context of current drawing task
|
|
133
|
-
* @returns true if succeeded, otherwise false
|
|
130
|
+
/**
|
|
131
|
+
* Prepares for drawing
|
|
132
|
+
* @param ctx - The context of current drawing task
|
|
133
|
+
* @returns true if succeeded, otherwise false
|
|
134
134
|
*/ beginDraw(ctx) {
|
|
135
135
|
const numInstances = ctx.instanceData?.worldMatrices?.length || 1;
|
|
136
136
|
const device = Application.instance.device;
|
|
@@ -156,31 +156,31 @@ class InstanceBindGroupPool {
|
|
|
156
156
|
}
|
|
157
157
|
return false;
|
|
158
158
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Ends drawing a primitive
|
|
159
|
+
/**
|
|
160
|
+
* Ends drawing a primitive
|
|
161
161
|
*/ endDraw() {
|
|
162
162
|
this._materialBindGroup = null;
|
|
163
163
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Gets the bind group of this material
|
|
166
|
-
* @returns The bind group of this material
|
|
164
|
+
/**
|
|
165
|
+
* Gets the bind group of this material
|
|
166
|
+
* @returns The bind group of this material
|
|
167
167
|
*/ getMaterialBindGroup() {
|
|
168
168
|
return this._materialBindGroup;
|
|
169
169
|
}
|
|
170
|
-
/**
|
|
171
|
-
* Sets all uniform values to the bind group of the material if needed
|
|
172
|
-
* @param bindGroup - The bind group of the material
|
|
173
|
-
* @param ctx - The context of current drawing task
|
|
174
|
-
* @param needUpdate - true if the uniform values needs to update
|
|
170
|
+
/**
|
|
171
|
+
* Sets all uniform values to the bind group of the material if needed
|
|
172
|
+
* @param bindGroup - The bind group of the material
|
|
173
|
+
* @param ctx - The context of current drawing task
|
|
174
|
+
* @param needUpdate - true if the uniform values needs to update
|
|
175
175
|
*/ applyUniforms(bindGroup, ctx, needUpdate) {
|
|
176
176
|
if (needUpdate) {
|
|
177
177
|
this._applyUniforms(bindGroup, ctx);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
/**
|
|
181
|
-
* Fetch the gpu program of the material for drawing
|
|
182
|
-
* @param ctx - The context for current drawing task
|
|
183
|
-
* @returns Information of the gpu program
|
|
180
|
+
/**
|
|
181
|
+
* Fetch the gpu program of the material for drawing
|
|
182
|
+
* @param ctx - The context for current drawing task
|
|
183
|
+
* @returns Information of the gpu program
|
|
184
184
|
*/ getOrCreateProgram(ctx) {
|
|
185
185
|
const programMap = Material._programMap;
|
|
186
186
|
const renderPassType = ctx.renderPass.type;
|
|
@@ -208,22 +208,22 @@ class InstanceBindGroupPool {
|
|
|
208
208
|
dispose() {
|
|
209
209
|
this.clearBindGroupCache();
|
|
210
210
|
}
|
|
211
|
-
/**
|
|
212
|
-
* Sets the options of garbage collection
|
|
213
|
-
* @param opt - The options to set
|
|
211
|
+
/**
|
|
212
|
+
* Sets the options of garbage collection
|
|
213
|
+
* @param opt - The options to set
|
|
214
214
|
*/ static setGCOptions(opt) {
|
|
215
215
|
this._gcOptions = Object.assign({}, this._gcOptions, opt || {});
|
|
216
216
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Gets the options of garbage collection
|
|
219
|
-
* @returns The options of garbage collection
|
|
217
|
+
/**
|
|
218
|
+
* Gets the options of garbage collection
|
|
219
|
+
* @returns The options of garbage collection
|
|
220
220
|
*/ static getGCOptions() {
|
|
221
221
|
return this._gcOptions;
|
|
222
222
|
}
|
|
223
|
-
/**
|
|
224
|
-
* Performs a garbage collection for this material
|
|
225
|
-
* @param ts - Current time stamp
|
|
226
|
-
* @returns How many bind groups have been garbage collected
|
|
223
|
+
/**
|
|
224
|
+
* Performs a garbage collection for this material
|
|
225
|
+
* @param ts - Current time stamp
|
|
226
|
+
* @returns How many bind groups have been garbage collected
|
|
227
227
|
*/ static garbageCollect(ts) {
|
|
228
228
|
let n = 0;
|
|
229
229
|
ts -= this._gcOptions.inactiveTimeDuration;
|
|
@@ -432,23 +432,23 @@ class InstanceBindGroupPool {
|
|
|
432
432
|
/** @internal */ createRenderStateSet() {
|
|
433
433
|
return Application.instance.device.createRenderStateSet();
|
|
434
434
|
}
|
|
435
|
-
/**
|
|
436
|
-
* Creates the shader program
|
|
437
|
-
* @param pb - The program builder
|
|
438
|
-
* @param ctx - The drawing context
|
|
439
|
-
* @param func - The material func
|
|
440
|
-
* @returns The created shader program
|
|
435
|
+
/**
|
|
436
|
+
* Creates the shader program
|
|
437
|
+
* @param pb - The program builder
|
|
438
|
+
* @param ctx - The drawing context
|
|
439
|
+
* @param func - The material func
|
|
440
|
+
* @returns The created shader program
|
|
441
441
|
*/ _createProgram(pb, ctx) {
|
|
442
442
|
return null;
|
|
443
443
|
}
|
|
444
|
-
/**
|
|
445
|
-
* Applies uniform values
|
|
446
|
-
* @param bindGroup - The bind group
|
|
447
|
-
* @param ctx - The drawing context
|
|
444
|
+
/**
|
|
445
|
+
* Applies uniform values
|
|
446
|
+
* @param bindGroup - The bind group
|
|
447
|
+
* @param ctx - The drawing context
|
|
448
448
|
*/ _applyUniforms(bindGroup, ctx) {}
|
|
449
|
-
/**
|
|
450
|
-
* Calculates the hash code of the shader program
|
|
451
|
-
* @returns The hash code
|
|
449
|
+
/**
|
|
450
|
+
* Calculates the hash code of the shader program
|
|
451
|
+
* @returns The hash code
|
|
452
452
|
*/ _createHash(renderPassType) {
|
|
453
453
|
return '';
|
|
454
454
|
}
|
|
@@ -128,21 +128,21 @@ class MeshMaterial extends Material {
|
|
|
128
128
|
}
|
|
129
129
|
return this._createProgram(pb, ctx);
|
|
130
130
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Check if a feature is in use for given render pass type.
|
|
133
|
-
*
|
|
134
|
-
* @param feature - The feature name
|
|
135
|
-
* @param renderPassType - Render pass type
|
|
136
|
-
* @returns true if the feature is in use, otherwise false.
|
|
131
|
+
/**
|
|
132
|
+
* Check if a feature is in use for given render pass type.
|
|
133
|
+
*
|
|
134
|
+
* @param feature - The feature name
|
|
135
|
+
* @param renderPassType - Render pass type
|
|
136
|
+
* @returns true if the feature is in use, otherwise false.
|
|
137
137
|
*/ featureUsed(feature, renderPassType) {
|
|
138
138
|
const index = this._features.get(feature);
|
|
139
139
|
return this._featureStates[renderPassType][index];
|
|
140
140
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Use or unuse a feature of the material, this will cause the shader to be rebuild.
|
|
143
|
-
*
|
|
144
|
-
* @param feature - Which feature will be used or unused
|
|
145
|
-
* @param use - true if use the feature, otherwise false
|
|
141
|
+
/**
|
|
142
|
+
* Use or unuse a feature of the material, this will cause the shader to be rebuild.
|
|
143
|
+
*
|
|
144
|
+
* @param feature - Which feature will be used or unused
|
|
145
|
+
* @param use - true if use the feature, otherwise false
|
|
146
146
|
*/ useFeature(feature, use, renderPassType) {
|
|
147
147
|
renderPassType = renderPassType ?? allRenderPassTypes;
|
|
148
148
|
if (typeof renderPassType === 'number') {
|
|
@@ -169,40 +169,40 @@ class MeshMaterial extends Material {
|
|
|
169
169
|
this.optionChanged(true);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
/**
|
|
173
|
-
* {@inheritDoc Material._createHash}
|
|
174
|
-
* @override
|
|
172
|
+
/**
|
|
173
|
+
* {@inheritDoc Material._createHash}
|
|
174
|
+
* @override
|
|
175
175
|
*/ _createHash(renderPassType) {
|
|
176
176
|
return this._featureStates[renderPassType].join('');
|
|
177
177
|
}
|
|
178
|
-
/**
|
|
179
|
-
* {@inheritDoc Material._applyUniforms}
|
|
180
|
-
* @override
|
|
178
|
+
/**
|
|
179
|
+
* {@inheritDoc Material._applyUniforms}
|
|
180
|
+
* @override
|
|
181
181
|
*/ _applyUniforms(bindGroup, ctx) {
|
|
182
182
|
this.applyUniformValues(bindGroup, ctx);
|
|
183
183
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Check if the color should be computed in fragment shader, this is required for forward render pass or alpha test is in use or alpha to coverage is in use.
|
|
186
|
-
*
|
|
187
|
-
* @param ctx - The drawing context
|
|
188
|
-
* @returns - true if the color should be computed in fragment shader, otherwise false.
|
|
184
|
+
/**
|
|
185
|
+
* Check if the color should be computed in fragment shader, this is required for forward render pass or alpha test is in use or alpha to coverage is in use.
|
|
186
|
+
*
|
|
187
|
+
* @param ctx - The drawing context
|
|
188
|
+
* @returns - true if the color should be computed in fragment shader, otherwise false.
|
|
189
189
|
*/ needFragmentColor(ctx) {
|
|
190
190
|
return ctx.renderPass.type === RENDER_PASS_TYPE_FORWARD || this._alphaCutoff > 0 || this.alphaToCoverage;
|
|
191
191
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Transform vertex position to the clip space and calcuate the world position, world normal and tangent frame if needed
|
|
194
|
-
*
|
|
195
|
-
* @remarks
|
|
196
|
-
* This function handles skin animation and geometry instancing if needed
|
|
197
|
-
*
|
|
198
|
-
* @param scope - Current shader scope
|
|
192
|
+
/**
|
|
193
|
+
* Transform vertex position to the clip space and calcuate the world position, world normal and tangent frame if needed
|
|
194
|
+
*
|
|
195
|
+
* @remarks
|
|
196
|
+
* This function handles skin animation and geometry instancing if needed
|
|
197
|
+
*
|
|
198
|
+
* @param scope - Current shader scope
|
|
199
199
|
*/ transformVertexAndNormal(scope) {
|
|
200
200
|
ShaderFramework.ftransform(scope);
|
|
201
201
|
}
|
|
202
|
-
/**
|
|
203
|
-
* Vertex shader implementation of this material
|
|
204
|
-
* @param scope - Shader scope
|
|
205
|
-
* @param ctx - The drawing context
|
|
202
|
+
/**
|
|
203
|
+
* Vertex shader implementation of this material
|
|
204
|
+
* @param scope - Shader scope
|
|
205
|
+
* @param ctx - The drawing context
|
|
206
206
|
*/ vertexShader(scope, ctx) {
|
|
207
207
|
const pb = scope.$builder;
|
|
208
208
|
ShaderFramework.prepareVertexShader(pb, ctx);
|
|
@@ -211,10 +211,10 @@ class MeshMaterial extends Material {
|
|
|
211
211
|
scope.$inputs.kkBlendWeights = pb.vec4().attrib('blendWeights');
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
|
-
/**
|
|
215
|
-
* Fragment shader implementation of this material
|
|
216
|
-
* @param scope - Shader scope
|
|
217
|
-
* @param ctx - The drawing context
|
|
214
|
+
/**
|
|
215
|
+
* Fragment shader implementation of this material
|
|
216
|
+
* @param scope - Shader scope
|
|
217
|
+
* @param ctx - The drawing context
|
|
218
218
|
*/ fragmentShader(scope, ctx) {
|
|
219
219
|
const pb = scope.$builder;
|
|
220
220
|
ShaderFramework.prepareFragmentShader(pb, ctx);
|
|
@@ -227,9 +227,9 @@ class MeshMaterial extends Material {
|
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
/**
|
|
231
|
-
* {@inheritDoc Material._createProgram}
|
|
232
|
-
* @override
|
|
230
|
+
/**
|
|
231
|
+
* {@inheritDoc Material._createProgram}
|
|
232
|
+
* @override
|
|
233
233
|
*/ _createProgram(pb, ctx) {
|
|
234
234
|
const that = this;
|
|
235
235
|
const program = pb.buildRenderProgram({
|
|
@@ -247,14 +247,14 @@ class MeshMaterial extends Material {
|
|
|
247
247
|
});
|
|
248
248
|
return program;
|
|
249
249
|
}
|
|
250
|
-
/**
|
|
251
|
-
* Calculate final fragment color for output.
|
|
252
|
-
*
|
|
253
|
-
* @param scope - Shader scope
|
|
254
|
-
* @param color - Lit fragment color
|
|
255
|
-
* @param ctx - The drawing context
|
|
256
|
-
*
|
|
257
|
-
* @returns The final fragment color
|
|
250
|
+
/**
|
|
251
|
+
* Calculate final fragment color for output.
|
|
252
|
+
*
|
|
253
|
+
* @param scope - Shader scope
|
|
254
|
+
* @param color - Lit fragment color
|
|
255
|
+
* @param ctx - The drawing context
|
|
256
|
+
*
|
|
257
|
+
* @returns The final fragment color
|
|
258
258
|
*/ outputFragmentColor(scope, color, ctx) {
|
|
259
259
|
const pb = scope.$builder;
|
|
260
260
|
const that = this;
|
package/dist/material/unlit.js
CHANGED
|
@@ -2,9 +2,9 @@ import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
|
|
|
2
2
|
import { mixinAlbedoColor } from './mixins/albedocolor.js';
|
|
3
3
|
import { mixinVertexColor } from './mixins/vertexcolor.js';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Unlit material
|
|
7
|
-
* @public
|
|
5
|
+
/**
|
|
6
|
+
* Unlit material
|
|
7
|
+
* @public
|
|
8
8
|
*/ class UnlitMaterial extends applyMaterialMixins(MeshMaterial, mixinVertexColor, mixinAlbedoColor) {
|
|
9
9
|
static FEATURE_VERTEX_COLOR = 'um_vertexcolor';
|
|
10
10
|
constructor(){
|
package/dist/posteffect/bloom.js
CHANGED
|
@@ -16,9 +16,9 @@ import '../render/clipmap.js';
|
|
|
16
16
|
import { TemporalCache } from '../render/temporalcache.js';
|
|
17
17
|
import '../render/watermesh.js';
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* The bloom post effect
|
|
21
|
-
* @public
|
|
19
|
+
/**
|
|
20
|
+
* The bloom post effect
|
|
21
|
+
* @public
|
|
22
22
|
*/ class Bloom extends AbstractPostEffect {
|
|
23
23
|
static _nearestSampler = null;
|
|
24
24
|
static _programDownsampleH = null;
|
|
@@ -39,8 +39,8 @@ import '../render/watermesh.js';
|
|
|
39
39
|
_threshold;
|
|
40
40
|
_thresholdKnee;
|
|
41
41
|
_intensity;
|
|
42
|
-
/**
|
|
43
|
-
* Creates an instance of tonemap post effect
|
|
42
|
+
/**
|
|
43
|
+
* Creates an instance of tonemap post effect
|
|
44
44
|
*/ constructor(){
|
|
45
45
|
super();
|
|
46
46
|
this._bindgroupDownsampleH = null;
|
|
@@ -16,9 +16,9 @@ import '../render/clipmap.js';
|
|
|
16
16
|
import { TemporalCache } from '../render/temporalcache.js';
|
|
17
17
|
import '../render/watermesh.js';
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Post processing compositor
|
|
21
|
-
* @public
|
|
19
|
+
/**
|
|
20
|
+
* Post processing compositor
|
|
21
|
+
* @public
|
|
22
22
|
*/ class Compositor {
|
|
23
23
|
/** @internal */ _postEffectsOpaque;
|
|
24
24
|
/** @internal */ _postEffectsTransparency;
|
|
@@ -27,8 +27,8 @@ import '../render/watermesh.js';
|
|
|
27
27
|
/** @internal */ static _blitBindgroup = null;
|
|
28
28
|
/** @internal */ static _blitRenderStates = null;
|
|
29
29
|
/** @internal */ static _blitVertexLayout = null;
|
|
30
|
-
/**
|
|
31
|
-
* Creates an instance of Compositor
|
|
30
|
+
/**
|
|
31
|
+
* Creates an instance of Compositor
|
|
32
32
|
*/ constructor(){
|
|
33
33
|
this._postEffectsOpaque = [];
|
|
34
34
|
this._postEffectsTransparency = [];
|
|
@@ -46,11 +46,11 @@ import '../render/watermesh.js';
|
|
|
46
46
|
}
|
|
47
47
|
return false;
|
|
48
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
|
|
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
54
|
*/ appendPostEffect(postEffect) {
|
|
55
55
|
if (postEffect) {
|
|
56
56
|
if (this._postEffectsOpaque.indexOf(postEffect) >= 0 || this._postEffectsTransparency.indexOf(postEffect) >= 0) {
|
|
@@ -61,10 +61,10 @@ import '../render/watermesh.js';
|
|
|
61
61
|
postEffects.push(postEffect);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Removes a posteffect that was previously added
|
|
66
|
-
*
|
|
67
|
-
* @param postEffect - The posteffect to be remove.
|
|
64
|
+
/**
|
|
65
|
+
* Removes a posteffect that was previously added
|
|
66
|
+
*
|
|
67
|
+
* @param postEffect - The posteffect to be remove.
|
|
68
68
|
*/ removePostEffect(postEffect) {
|
|
69
69
|
for (const list of [
|
|
70
70
|
this._postEffectsOpaque,
|
|
@@ -77,8 +77,8 @@ import '../render/watermesh.js';
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Gets all post effects
|
|
80
|
+
/**
|
|
81
|
+
* Gets all post effects
|
|
82
82
|
*/ getPostEffects() {
|
|
83
83
|
return [
|
|
84
84
|
...this._postEffectsOpaque,
|
package/dist/posteffect/fxaa.js
CHANGED
|
@@ -3,16 +3,16 @@ import { Application } from '../app.js';
|
|
|
3
3
|
import { AbstractPostEffect } from './posteffect.js';
|
|
4
4
|
import { linearToGamma } from '../shaders/misc.js';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* FXAA post effect
|
|
8
|
-
* @public
|
|
6
|
+
/**
|
|
7
|
+
* FXAA post effect
|
|
8
|
+
* @public
|
|
9
9
|
*/ class FXAA extends AbstractPostEffect {
|
|
10
10
|
static _program = null;
|
|
11
11
|
static _sampler = null;
|
|
12
12
|
_bindgroup;
|
|
13
13
|
_invTexSize;
|
|
14
|
-
/**
|
|
15
|
-
* Creates an instance of grayscale post effect
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of grayscale post effect
|
|
16
16
|
*/ constructor(){
|
|
17
17
|
super();
|
|
18
18
|
this._opaque = false;
|
|
@@ -2,15 +2,15 @@ import { Application } from '../app.js';
|
|
|
2
2
|
import { AbstractPostEffect } from './posteffect.js';
|
|
3
3
|
import { linearToGamma } from '../shaders/misc.js';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Grayscale post effect
|
|
7
|
-
* @public
|
|
5
|
+
/**
|
|
6
|
+
* Grayscale post effect
|
|
7
|
+
* @public
|
|
8
8
|
*/ class Grayscale extends AbstractPostEffect {
|
|
9
9
|
static _program = null;
|
|
10
10
|
static _sampler = null;
|
|
11
11
|
_bindgroup;
|
|
12
|
-
/**
|
|
13
|
-
* Creates an instance of grayscale post effect
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of grayscale post effect
|
|
14
14
|
*/ constructor(){
|
|
15
15
|
super();
|
|
16
16
|
this._opaque = false;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Application } from '../app.js';
|
|
2
2
|
import { drawFullscreenQuad } from '../render/helper.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Base class for any type of post effect
|
|
6
|
-
* @public
|
|
4
|
+
/**
|
|
5
|
+
* Base class for any type of post effect
|
|
6
|
+
* @public
|
|
7
7
|
*/ class AbstractPostEffect {
|
|
8
8
|
_outputTexture;
|
|
9
9
|
_quadVertexLayout;
|
|
@@ -11,9 +11,9 @@ import { drawFullscreenQuad } from '../render/helper.js';
|
|
|
11
11
|
_enabled;
|
|
12
12
|
_opaque;
|
|
13
13
|
_intermediateFramebuffers;
|
|
14
|
-
/**
|
|
15
|
-
* Creates an instance of a post effect
|
|
16
|
-
* @param name - Name of the post effect
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of a post effect
|
|
16
|
+
* @param name - Name of the post effect
|
|
17
17
|
*/ constructor(){
|
|
18
18
|
this._outputTexture = null;
|
|
19
19
|
this._quadVertexLayout = null;
|
|
@@ -31,18 +31,18 @@ import { drawFullscreenQuad } from '../render/helper.js';
|
|
|
31
31
|
/** Whether this post effect will be rendered at opaque phase */ get opaque() {
|
|
32
32
|
return this._opaque;
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Check if the post effect should be rendered upside down.
|
|
36
|
-
* @param device - The device object
|
|
37
|
-
* @returns true if the post effect should be rendered upside down
|
|
34
|
+
/**
|
|
35
|
+
* Check if the post effect should be rendered upside down.
|
|
36
|
+
* @param device - The device object
|
|
37
|
+
* @returns true if the post effect should be rendered upside down
|
|
38
38
|
*/ needFlip(device) {
|
|
39
39
|
return device.type === 'webgpu' && !!device.getFramebuffer();
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Adds an intermediate frame buffer
|
|
43
|
-
* @param name - Name of the frame buffer
|
|
44
|
-
* @param format - Render target texture format
|
|
45
|
-
* @param useDepth - Whether the scene depth buffer should be attached to the frame buffer
|
|
41
|
+
/**
|
|
42
|
+
* Adds an intermediate frame buffer
|
|
43
|
+
* @param name - Name of the frame buffer
|
|
44
|
+
* @param format - Render target texture format
|
|
45
|
+
* @param useDepth - Whether the scene depth buffer should be attached to the frame buffer
|
|
46
46
|
*/ addIntermediateFramebuffer(name, depth) {
|
|
47
47
|
if (this._intermediateFramebuffers[name]) {
|
|
48
48
|
throw new Error(`Intermediate framebuffer already exists: ${name}`);
|
|
@@ -52,15 +52,15 @@ import { drawFullscreenQuad } from '../render/helper.js';
|
|
|
52
52
|
framebuffer: null
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Gets the intermediate frame buffer by name
|
|
57
|
-
* @param name - Name of the intermediate frame buffer
|
|
58
|
-
* @param width - Width of the frame buffer
|
|
59
|
-
* @param height - Height of the frame buffer
|
|
60
|
-
* @returns The intermediate frame buffer or null if not exists
|
|
61
|
-
*
|
|
62
|
-
* @remarks
|
|
63
|
-
* The intemediate buffer will be resized to fit the given size if needed
|
|
55
|
+
/**
|
|
56
|
+
* Gets the intermediate frame buffer by name
|
|
57
|
+
* @param name - Name of the intermediate frame buffer
|
|
58
|
+
* @param width - Width of the frame buffer
|
|
59
|
+
* @param height - Height of the frame buffer
|
|
60
|
+
* @returns The intermediate frame buffer or null if not exists
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* The intemediate buffer will be resized to fit the given size if needed
|
|
64
64
|
*/ getIntermediateFramebuffer(name, format, width, height) {
|
|
65
65
|
const fb = this._intermediateFramebuffers[name];
|
|
66
66
|
if (!fb) {
|
|
@@ -100,8 +100,8 @@ import { drawFullscreenQuad } from '../render/helper.js';
|
|
|
100
100
|
}
|
|
101
101
|
return fb.framebuffer;
|
|
102
102
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Disposes the post effect.
|
|
103
|
+
/**
|
|
104
|
+
* Disposes the post effect.
|
|
105
105
|
*/ dispose() {
|
|
106
106
|
this._quadVertexLayout?.dispose();
|
|
107
107
|
this._quadVertexLayout = null;
|
|
@@ -116,24 +116,24 @@ import { drawFullscreenQuad } from '../render/helper.js';
|
|
|
116
116
|
}
|
|
117
117
|
this._intermediateFramebuffers = {};
|
|
118
118
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Draws a fullscreen quad
|
|
121
|
-
* @param renderStateSet - Render states that will be used when drawing the fullscreen quad.
|
|
119
|
+
/**
|
|
120
|
+
* Draws a fullscreen quad
|
|
121
|
+
* @param renderStateSet - Render states that will be used when drawing the fullscreen quad.
|
|
122
122
|
*/ drawFullscreenQuad(renderStateSet) {
|
|
123
123
|
drawFullscreenQuad(renderStateSet);
|
|
124
|
-
/*
|
|
125
|
-
const device = Application.instance.device;
|
|
126
|
-
if (!this._quadVertexLayout) {
|
|
127
|
-
this._quadVertexLayout = this.createVertexLayout(device);
|
|
128
|
-
}
|
|
129
|
-
if (!this._quadRenderStateSet) {
|
|
130
|
-
this._quadRenderStateSet = this.createRenderStates(device);
|
|
131
|
-
}
|
|
132
|
-
const lastRenderState = device.getRenderStates();
|
|
133
|
-
device.setVertexLayout(this._quadVertexLayout);
|
|
134
|
-
device.setRenderStates(renderStateSet ?? this._quadRenderStateSet);
|
|
135
|
-
device.draw('triangle-strip', 0, 4);
|
|
136
|
-
device.setRenderStates(lastRenderState);
|
|
124
|
+
/*
|
|
125
|
+
const device = Application.instance.device;
|
|
126
|
+
if (!this._quadVertexLayout) {
|
|
127
|
+
this._quadVertexLayout = this.createVertexLayout(device);
|
|
128
|
+
}
|
|
129
|
+
if (!this._quadRenderStateSet) {
|
|
130
|
+
this._quadRenderStateSet = this.createRenderStates(device);
|
|
131
|
+
}
|
|
132
|
+
const lastRenderState = device.getRenderStates();
|
|
133
|
+
device.setVertexLayout(this._quadVertexLayout);
|
|
134
|
+
device.setRenderStates(renderStateSet ?? this._quadRenderStateSet);
|
|
135
|
+
device.draw('triangle-strip', 0, 4);
|
|
136
|
+
device.setRenderStates(lastRenderState);
|
|
137
137
|
*/ }
|
|
138
138
|
/** @internal */ createVertexLayout(device) {
|
|
139
139
|
return device.createVertexLayout({
|
package/dist/posteffect/sao.js
CHANGED
|
@@ -21,9 +21,9 @@ import '../render/watermesh.js';
|
|
|
21
21
|
|
|
22
22
|
const NUM_SAMPLES = 7;
|
|
23
23
|
const NUM_RINGS = 4;
|
|
24
|
-
/**
|
|
25
|
-
* The Scalable Ambient Obscurance (SAO) post effect
|
|
26
|
-
* @public
|
|
24
|
+
/**
|
|
25
|
+
* The Scalable Ambient Obscurance (SAO) post effect
|
|
26
|
+
* @public
|
|
27
27
|
*/ class SAO extends AbstractPostEffect {
|
|
28
28
|
static _nearestSampler = null;
|
|
29
29
|
static _program = null;
|
|
@@ -43,8 +43,8 @@ const NUM_RINGS = 4;
|
|
|
43
43
|
_blitterV;
|
|
44
44
|
_copyBlitter;
|
|
45
45
|
_supported;
|
|
46
|
-
/**
|
|
47
|
-
* Creates an instance of SAO post effect
|
|
46
|
+
/**
|
|
47
|
+
* Creates an instance of SAO post effect
|
|
48
48
|
*/ constructor(){
|
|
49
49
|
super();
|
|
50
50
|
this._bindgroup = null;
|
|
@@ -2,16 +2,16 @@ import { Application } from '../app.js';
|
|
|
2
2
|
import { AbstractPostEffect } from './posteffect.js';
|
|
3
3
|
import { linearToGamma } from '../shaders/misc.js';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* The tonemap post effect
|
|
7
|
-
* @public
|
|
5
|
+
/**
|
|
6
|
+
* The tonemap post effect
|
|
7
|
+
* @public
|
|
8
8
|
*/ class Tonemap extends AbstractPostEffect {
|
|
9
9
|
static _nearestSampler = null;
|
|
10
10
|
static _programTonemap = null;
|
|
11
11
|
_bindgroupTonemap;
|
|
12
12
|
_exposure;
|
|
13
|
-
/**
|
|
14
|
-
* Creates an instance of tonemap post effect
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of tonemap post effect
|
|
15
15
|
*/ constructor(){
|
|
16
16
|
super();
|
|
17
17
|
this._bindgroupTonemap = null;
|
package/dist/posteffect/water.js
CHANGED
|
@@ -20,9 +20,9 @@ import { Camera } from '../camera/camera.js';
|
|
|
20
20
|
import { CopyBlitter } from '../blitter/copy.js';
|
|
21
21
|
import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
* The post water effect
|
|
25
|
-
* @public
|
|
23
|
+
/**
|
|
24
|
+
* The post water effect
|
|
25
|
+
* @public
|
|
26
26
|
*/ class PostWater extends AbstractPostEffect {
|
|
27
27
|
_elevation;
|
|
28
28
|
_region;
|
|
@@ -53,9 +53,9 @@ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
|
53
53
|
_waveCroppiness2;
|
|
54
54
|
_currentWaterMesh;
|
|
55
55
|
_waterMeshes;
|
|
56
|
-
/**
|
|
57
|
-
* Creates an instance of PostWater.
|
|
58
|
-
* @param elevation - Elevation of the water
|
|
56
|
+
/**
|
|
57
|
+
* Creates an instance of PostWater.
|
|
58
|
+
* @param elevation - Elevation of the water
|
|
59
59
|
*/ constructor(elevation){
|
|
60
60
|
super();
|
|
61
61
|
this._elevation = elevation ?? 0;
|