@spiffcommerce/preview 3.6.2-rc.8 → 4.0.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/index.esm.js +1576 -38
- package/dist/index.umd.js +1 -0
- package/package.json +4 -6
- package/dist/_tslib.esm.js +0 -33
- package/dist/animation.esm.js +0 -1364
- package/dist/assetCache.esm.js +0 -6
- package/dist/assetCache.esm2.js +0 -825
- package/dist/blurPostProcess.esm.js +0 -327
- package/dist/bumpVertex.esm.js +0 -497
- package/dist/compatibilityOptions.esm.js +0 -68
- package/dist/configuration.esm.js +0 -121
- package/dist/core.esm.js +0 -8135
- package/dist/dynamicTexture.esm.js +0 -105
- package/dist/dynamicTexture.esm2.js +0 -238
- package/dist/easing.esm.js +0 -130
- package/dist/effectFallbacks.esm.js +0 -378
- package/dist/engine.esm.js +0 -25504
- package/dist/glbLoaderExtensions.esm.js +0 -690
- package/dist/glowLayer.esm.js +0 -1621
- package/dist/glowLayerManager.esm.js +0 -50
- package/dist/guid.esm.js +0 -21
- package/dist/hdrFilteringFunctions.esm.js +0 -816
- package/dist/helperFunctions.esm.js +0 -5145
- package/dist/material.esm.js +0 -115
- package/dist/material.esm2.js +0 -5245
- package/dist/math.axis.esm.js +0 -35
- package/dist/math.color.esm.js +0 -1661
- package/dist/math.path.esm.js +0 -15
- package/dist/math.size.esm.js +0 -137
- package/dist/mesh.esm.js +0 -11170
- package/dist/modelContainer.esm.js +0 -1895
- package/dist/node.esm.js +0 -795
- package/dist/pbrBRDFFunctions.esm.js +0 -124
- package/dist/pbrMaterial.esm.js +8 -8739
- package/dist/productAnimations.esm.js +0 -182
- package/dist/productCamera.esm.js +0 -14
- package/dist/productCamera.esm2.js +0 -3870
- package/dist/renderConstants.esm.js +0 -116
- package/dist/renderingPipeline.esm.js +0 -18
- package/dist/renderingPipeline.esm2.js +1 -3594
- package/dist/sceneLoaderFlags.esm.js +0 -51
- package/dist/types.esm.js +0 -30
- package/dist/variants.esm.js +0 -16
- package/dist/variants.esm2.js +0 -3097
- package/dist/webRequest.esm.js +0 -7777
package/dist/glowLayer.esm.js
DELETED
|
@@ -1,1621 +0,0 @@
|
|
|
1
|
-
import { _ as __decorate, O as Observable, E as EngineStore, a as _WarnImport, s as serialize, f as serializeAsColor4, g as serializeAsCameraReference, b as Vector2, S as SerializationHelper } from './webRequest.esm.js';
|
|
2
|
-
import { e as ShaderStore, V as VertexBuffer, E as Engine, g as DrawWrapper, c as Tools, A as AbstractScene, h as SceneComponentConstants } from './engine.esm.js';
|
|
3
|
-
import { R as RenderTargetTexture, T as Texture } from './helperFunctions.esm.js';
|
|
4
|
-
import { M as Material, a as MaterialHelper, p as prepareStringDefinesForClipPlanes, b as addClipPlaneUniforms, c as bindClipPlane, C as Camera } from './material.esm2.js';
|
|
5
|
-
import { B as BlurPostProcess } from './blurPostProcess.esm.js';
|
|
6
|
-
import { C as Color4, R as RegisterClass } from './math.color.esm.js';
|
|
7
|
-
import { E as EffectFallbacks } from './effectFallbacks.esm.js';
|
|
8
|
-
|
|
9
|
-
// Do not edit.
|
|
10
|
-
const name$3 = "glowMapGenerationPixelShader";
|
|
11
|
-
const shader$3 = `#if defined(DIFFUSE_ISLINEAR) || defined(EMISSIVE_ISLINEAR)
|
|
12
|
-
#include<helperFunctions>
|
|
13
|
-
#endif
|
|
14
|
-
#ifdef DIFFUSE
|
|
15
|
-
varying vec2 vUVDiffuse;
|
|
16
|
-
#ifdef OPACITY
|
|
17
|
-
varying vec2 vUVOpacity;
|
|
18
|
-
#ifdef EMISSIVE
|
|
19
|
-
varying vec2 vUVEmissive;
|
|
20
|
-
#ifdef VERTEXALPHA
|
|
21
|
-
varying vec4 vColor;
|
|
22
|
-
uniform vec4 glowColor;
|
|
23
|
-
#define CUSTOM_FRAGMENT_DEFINITIONS
|
|
24
|
-
void main(void)
|
|
25
|
-
vec4 finalColor=glowColor;
|
|
26
|
-
vec4 albedoTexture=texture2D(diffuseSampler,vUVDiffuse);
|
|
27
|
-
albedoTexture=toGammaSpace(albedoTexture);
|
|
28
|
-
#ifdef GLOW
|
|
29
|
-
finalColor.a*=albedoTexture.a;
|
|
30
|
-
#ifdef HIGHLIGHT
|
|
31
|
-
finalColor.a=albedoTexture.a;
|
|
32
|
-
#endif
|
|
33
|
-
#ifdef OPACITY
|
|
34
|
-
vec4 opacityMap=texture2D(opacitySampler,vUVOpacity);
|
|
35
|
-
finalColor.a*=getLuminance(opacityMap.rgb);
|
|
36
|
-
finalColor.a*=opacityMap.a;
|
|
37
|
-
finalColor.a*=opacityIntensity;
|
|
38
|
-
#ifdef VERTEXALPHA
|
|
39
|
-
finalColor.a*=vColor.a;
|
|
40
|
-
#ifdef ALPHATEST
|
|
41
|
-
if (finalColor.a<ALPHATESTVALUE)
|
|
42
|
-
#ifdef EMISSIVE
|
|
43
|
-
vec4 emissive=texture2D(emissiveSampler,vUVEmissive);
|
|
44
|
-
emissive=toGammaSpace(emissive);
|
|
45
|
-
gl_FragColor=emissive*finalColor*glowIntensity;
|
|
46
|
-
gl_FragColor=finalColor*glowIntensity;
|
|
47
|
-
#ifdef HIGHLIGHT
|
|
48
|
-
gl_FragColor.a=glowColor.a;
|
|
49
|
-
}`;
|
|
50
|
-
// Sideeffect
|
|
51
|
-
ShaderStore.ShadersStore[name$3] = shader$3;
|
|
52
|
-
|
|
53
|
-
// Do not edit.
|
|
54
|
-
const name$2 = "glowMapGenerationVertexShader";
|
|
55
|
-
const shader$2 = `attribute vec3 position;
|
|
56
|
-
#include<bakedVertexAnimationDeclaration>
|
|
57
|
-
#include<morphTargetsVertexGlobalDeclaration>
|
|
58
|
-
#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]
|
|
59
|
-
#include<clipPlaneVertexDeclaration>
|
|
60
|
-
#include<instancesDeclaration>
|
|
61
|
-
uniform mat4 viewProjection;
|
|
62
|
-
attribute vec2 uv;
|
|
63
|
-
#ifdef UV2
|
|
64
|
-
attribute vec2 uv2;
|
|
65
|
-
#ifdef DIFFUSE
|
|
66
|
-
varying vec2 vUVDiffuse;
|
|
67
|
-
#ifdef OPACITY
|
|
68
|
-
varying vec2 vUVOpacity;
|
|
69
|
-
#ifdef EMISSIVE
|
|
70
|
-
varying vec2 vUVEmissive;
|
|
71
|
-
#ifdef VERTEXALPHA
|
|
72
|
-
attribute vec4 color;
|
|
73
|
-
#define CUSTOM_VERTEX_DEFINITIONS
|
|
74
|
-
void main(void)
|
|
75
|
-
vec2 uvUpdated=uv;
|
|
76
|
-
#include<morphTargetsVertexGlobal>
|
|
77
|
-
#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
|
|
78
|
-
#include<instancesVertex>
|
|
79
|
-
#include<bonesVertex>
|
|
80
|
-
#include<bakedVertexAnimation>
|
|
81
|
-
vec4 worldPos=finalWorld*vec4(positionUpdated,1.0);
|
|
82
|
-
vPosition=worldPos;
|
|
83
|
-
vPosition=viewProjection*worldPos;
|
|
84
|
-
#ifdef DIFFUSE
|
|
85
|
-
#ifdef DIFFUSEUV1
|
|
86
|
-
vUVDiffuse=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));
|
|
87
|
-
#ifdef DIFFUSEUV2
|
|
88
|
-
vUVDiffuse=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));
|
|
89
|
-
#endif
|
|
90
|
-
#ifdef OPACITY
|
|
91
|
-
#ifdef OPACITYUV1
|
|
92
|
-
vUVOpacity=vec2(opacityMatrix*vec4(uvUpdated,1.0,0.0));
|
|
93
|
-
#ifdef OPACITYUV2
|
|
94
|
-
vUVOpacity=vec2(opacityMatrix*vec4(uv2,1.0,0.0));
|
|
95
|
-
#endif
|
|
96
|
-
#ifdef EMISSIVE
|
|
97
|
-
#ifdef EMISSIVEUV1
|
|
98
|
-
vUVEmissive=vec2(emissiveMatrix*vec4(uvUpdated,1.0,0.0));
|
|
99
|
-
#ifdef EMISSIVEUV2
|
|
100
|
-
vUVEmissive=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));
|
|
101
|
-
#endif
|
|
102
|
-
#ifdef VERTEXALPHA
|
|
103
|
-
vColor=color;
|
|
104
|
-
#include<clipPlaneVertex>
|
|
105
|
-
}`;
|
|
106
|
-
// Sideeffect
|
|
107
|
-
ShaderStore.ShadersStore[name$2] = shader$2;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* The effect layer Helps adding post process effect blended with the main pass.
|
|
111
|
-
*
|
|
112
|
-
* This can be for instance use to generate glow or highlight effects on the scene.
|
|
113
|
-
*
|
|
114
|
-
* The effect layer class can not be used directly and is intented to inherited from to be
|
|
115
|
-
* customized per effects.
|
|
116
|
-
*/
|
|
117
|
-
class EffectLayer {
|
|
118
|
-
/**
|
|
119
|
-
* Gets the camera attached to the layer.
|
|
120
|
-
*/
|
|
121
|
-
get camera() {
|
|
122
|
-
return this._effectLayerOptions.camera;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Gets the rendering group id the layer should render in.
|
|
126
|
-
*/
|
|
127
|
-
get renderingGroupId() {
|
|
128
|
-
return this._effectLayerOptions.renderingGroupId;
|
|
129
|
-
}
|
|
130
|
-
set renderingGroupId(renderingGroupId) {
|
|
131
|
-
this._effectLayerOptions.renderingGroupId = renderingGroupId;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Gets the main texture where the effect is rendered
|
|
135
|
-
*/
|
|
136
|
-
get mainTexture() {
|
|
137
|
-
return this._mainTexture;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Sets a specific material to be used to render a mesh/a list of meshes in the layer
|
|
141
|
-
* @param mesh mesh or array of meshes
|
|
142
|
-
* @param material material to use by the layer when rendering the mesh(es). If undefined is passed, the specific material created by the layer will be used.
|
|
143
|
-
*/
|
|
144
|
-
setMaterialForRendering(mesh, material) {
|
|
145
|
-
this._mainTexture.setMaterialForRendering(mesh, material);
|
|
146
|
-
if (Array.isArray(mesh)) {
|
|
147
|
-
for (let i = 0; i < mesh.length; ++i) {
|
|
148
|
-
const currentMesh = mesh[i];
|
|
149
|
-
if (!material) {
|
|
150
|
-
delete this._materialForRendering[currentMesh.uniqueId];
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
this._materialForRendering[currentMesh.uniqueId] = [currentMesh, material];
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
if (!material) {
|
|
159
|
-
delete this._materialForRendering[mesh.uniqueId];
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
this._materialForRendering[mesh.uniqueId] = [mesh, material];
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Gets the intensity of the effect for a specific mesh.
|
|
168
|
-
* @param mesh The mesh to get the effect intensity for
|
|
169
|
-
* @returns The intensity of the effect for the mesh
|
|
170
|
-
*/
|
|
171
|
-
getEffectIntensity(mesh) {
|
|
172
|
-
var _a;
|
|
173
|
-
return (_a = this._effectIntensity[mesh.uniqueId]) !== null && _a !== void 0 ? _a : 1;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Sets the intensity of the effect for a specific mesh.
|
|
177
|
-
* @param mesh The mesh to set the effect intensity for
|
|
178
|
-
* @param intensity The intensity of the effect for the mesh
|
|
179
|
-
*/
|
|
180
|
-
setEffectIntensity(mesh, intensity) {
|
|
181
|
-
this._effectIntensity[mesh.uniqueId] = intensity;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Instantiates a new effect Layer and references it in the scene.
|
|
185
|
-
* @param name The name of the layer
|
|
186
|
-
* @param scene The scene to use the layer in
|
|
187
|
-
*/
|
|
188
|
-
constructor(
|
|
189
|
-
/** The Friendly of the effect in the scene */
|
|
190
|
-
name, scene) {
|
|
191
|
-
this._vertexBuffers = {};
|
|
192
|
-
this._maxSize = 0;
|
|
193
|
-
this._mainTextureDesiredSize = { width: 0, height: 0 };
|
|
194
|
-
this._shouldRender = true;
|
|
195
|
-
this._postProcesses = [];
|
|
196
|
-
this._textures = [];
|
|
197
|
-
this._emissiveTextureAndColor = { texture: null, color: new Color4() };
|
|
198
|
-
this._effectIntensity = {};
|
|
199
|
-
/**
|
|
200
|
-
* The clear color of the texture used to generate the glow map.
|
|
201
|
-
*/
|
|
202
|
-
this.neutralColor = new Color4();
|
|
203
|
-
/**
|
|
204
|
-
* Specifies whether the highlight layer is enabled or not.
|
|
205
|
-
*/
|
|
206
|
-
this.isEnabled = true;
|
|
207
|
-
/**
|
|
208
|
-
* Specifies if the bounding boxes should be rendered normally or if they should undergo the effect of the layer
|
|
209
|
-
*/
|
|
210
|
-
this.disableBoundingBoxesFromEffectLayer = false;
|
|
211
|
-
/**
|
|
212
|
-
* An event triggered when the effect layer has been disposed.
|
|
213
|
-
*/
|
|
214
|
-
this.onDisposeObservable = new Observable();
|
|
215
|
-
/**
|
|
216
|
-
* An event triggered when the effect layer is about rendering the main texture with the glowy parts.
|
|
217
|
-
*/
|
|
218
|
-
this.onBeforeRenderMainTextureObservable = new Observable();
|
|
219
|
-
/**
|
|
220
|
-
* An event triggered when the generated texture is being merged in the scene.
|
|
221
|
-
*/
|
|
222
|
-
this.onBeforeComposeObservable = new Observable();
|
|
223
|
-
/**
|
|
224
|
-
* An event triggered when the mesh is rendered into the effect render target.
|
|
225
|
-
*/
|
|
226
|
-
this.onBeforeRenderMeshToEffect = new Observable();
|
|
227
|
-
/**
|
|
228
|
-
* An event triggered after the mesh has been rendered into the effect render target.
|
|
229
|
-
*/
|
|
230
|
-
this.onAfterRenderMeshToEffect = new Observable();
|
|
231
|
-
/**
|
|
232
|
-
* An event triggered when the generated texture has been merged in the scene.
|
|
233
|
-
*/
|
|
234
|
-
this.onAfterComposeObservable = new Observable();
|
|
235
|
-
/**
|
|
236
|
-
* An event triggered when the effect layer changes its size.
|
|
237
|
-
*/
|
|
238
|
-
this.onSizeChangedObservable = new Observable();
|
|
239
|
-
this._materialForRendering = {};
|
|
240
|
-
this.name = name;
|
|
241
|
-
this._scene = scene || EngineStore.LastCreatedScene;
|
|
242
|
-
EffectLayer._SceneComponentInitialization(this._scene);
|
|
243
|
-
this._engine = this._scene.getEngine();
|
|
244
|
-
this._maxSize = this._engine.getCaps().maxTextureSize;
|
|
245
|
-
this._scene.effectLayers.push(this);
|
|
246
|
-
this._mergeDrawWrapper = [];
|
|
247
|
-
// Generate Buffers
|
|
248
|
-
this._generateIndexBuffer();
|
|
249
|
-
this._generateVertexBuffer();
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Number of times _internalRender will be called. Some effect layers need to render the mesh several times, so they should override this method with the number of times the mesh should be rendered
|
|
253
|
-
* @returns Number of times a mesh must be rendered in the layer
|
|
254
|
-
*/
|
|
255
|
-
_numInternalDraws() {
|
|
256
|
-
return 1;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Initializes the effect layer with the required options.
|
|
260
|
-
* @param options Sets of none mandatory options to use with the layer (see IEffectLayerOptions for more information)
|
|
261
|
-
*/
|
|
262
|
-
_init(options) {
|
|
263
|
-
// Adapt options
|
|
264
|
-
this._effectLayerOptions = Object.assign({ mainTextureRatio: 0.5, alphaBlendingMode: 2, camera: null, renderingGroupId: -1, mainTextureType: 0, generateStencilBuffer: false }, options);
|
|
265
|
-
this._setMainTextureSize();
|
|
266
|
-
this._createMainTexture();
|
|
267
|
-
this._createTextureAndPostProcesses();
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Generates the index buffer of the full screen quad blending to the main canvas.
|
|
271
|
-
*/
|
|
272
|
-
_generateIndexBuffer() {
|
|
273
|
-
// Indices
|
|
274
|
-
const indices = [];
|
|
275
|
-
indices.push(0);
|
|
276
|
-
indices.push(1);
|
|
277
|
-
indices.push(2);
|
|
278
|
-
indices.push(0);
|
|
279
|
-
indices.push(2);
|
|
280
|
-
indices.push(3);
|
|
281
|
-
this._indexBuffer = this._engine.createIndexBuffer(indices);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Generates the vertex buffer of the full screen quad blending to the main canvas.
|
|
285
|
-
*/
|
|
286
|
-
_generateVertexBuffer() {
|
|
287
|
-
// VBO
|
|
288
|
-
const vertices = [];
|
|
289
|
-
vertices.push(1, 1);
|
|
290
|
-
vertices.push(-1, 1);
|
|
291
|
-
vertices.push(-1, -1);
|
|
292
|
-
vertices.push(1, -1);
|
|
293
|
-
const vertexBuffer = new VertexBuffer(this._engine, vertices, VertexBuffer.PositionKind, false, false, 2);
|
|
294
|
-
this._vertexBuffers[VertexBuffer.PositionKind] = vertexBuffer;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Sets the main texture desired size which is the closest power of two
|
|
298
|
-
* of the engine canvas size.
|
|
299
|
-
*/
|
|
300
|
-
_setMainTextureSize() {
|
|
301
|
-
if (this._effectLayerOptions.mainTextureFixedSize) {
|
|
302
|
-
this._mainTextureDesiredSize.width = this._effectLayerOptions.mainTextureFixedSize;
|
|
303
|
-
this._mainTextureDesiredSize.height = this._effectLayerOptions.mainTextureFixedSize;
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
this._mainTextureDesiredSize.width = this._engine.getRenderWidth() * this._effectLayerOptions.mainTextureRatio;
|
|
307
|
-
this._mainTextureDesiredSize.height = this._engine.getRenderHeight() * this._effectLayerOptions.mainTextureRatio;
|
|
308
|
-
this._mainTextureDesiredSize.width = this._engine.needPOTTextures
|
|
309
|
-
? Engine.GetExponentOfTwo(this._mainTextureDesiredSize.width, this._maxSize)
|
|
310
|
-
: this._mainTextureDesiredSize.width;
|
|
311
|
-
this._mainTextureDesiredSize.height = this._engine.needPOTTextures
|
|
312
|
-
? Engine.GetExponentOfTwo(this._mainTextureDesiredSize.height, this._maxSize)
|
|
313
|
-
: this._mainTextureDesiredSize.height;
|
|
314
|
-
}
|
|
315
|
-
this._mainTextureDesiredSize.width = Math.floor(this._mainTextureDesiredSize.width);
|
|
316
|
-
this._mainTextureDesiredSize.height = Math.floor(this._mainTextureDesiredSize.height);
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Creates the main texture for the effect layer.
|
|
320
|
-
*/
|
|
321
|
-
_createMainTexture() {
|
|
322
|
-
this._mainTexture = new RenderTargetTexture("EffectLayerMainRTT", {
|
|
323
|
-
width: this._mainTextureDesiredSize.width,
|
|
324
|
-
height: this._mainTextureDesiredSize.height,
|
|
325
|
-
}, this._scene, false, true, this._effectLayerOptions.mainTextureType, false, Texture.TRILINEAR_SAMPLINGMODE, true, this._effectLayerOptions.generateStencilBuffer);
|
|
326
|
-
this._mainTexture.activeCamera = this._effectLayerOptions.camera;
|
|
327
|
-
this._mainTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
|
|
328
|
-
this._mainTexture.wrapV = Texture.CLAMP_ADDRESSMODE;
|
|
329
|
-
this._mainTexture.anisotropicFilteringLevel = 1;
|
|
330
|
-
this._mainTexture.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);
|
|
331
|
-
this._mainTexture.renderParticles = false;
|
|
332
|
-
this._mainTexture.renderList = null;
|
|
333
|
-
this._mainTexture.ignoreCameraViewport = true;
|
|
334
|
-
for (const id in this._materialForRendering) {
|
|
335
|
-
const [mesh, material] = this._materialForRendering[id];
|
|
336
|
-
this._mainTexture.setMaterialForRendering(mesh, material);
|
|
337
|
-
}
|
|
338
|
-
this._mainTexture.customIsReadyFunction = (mesh, refreshRate, preWarm) => {
|
|
339
|
-
if ((preWarm || refreshRate === 0) && mesh.subMeshes) {
|
|
340
|
-
for (let i = 0; i < mesh.subMeshes.length; ++i) {
|
|
341
|
-
const subMesh = mesh.subMeshes[i];
|
|
342
|
-
const material = subMesh.getMaterial();
|
|
343
|
-
const renderingMesh = subMesh.getRenderingMesh();
|
|
344
|
-
if (!material) {
|
|
345
|
-
continue;
|
|
346
|
-
}
|
|
347
|
-
const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!subMesh.getReplacementMesh());
|
|
348
|
-
const hardwareInstancedRendering = batch.hardwareInstancedRendering[subMesh._id] || renderingMesh.hasThinInstances;
|
|
349
|
-
this._setEmissiveTextureAndColor(renderingMesh, subMesh, material);
|
|
350
|
-
if (!this._isReady(subMesh, hardwareInstancedRendering, this._emissiveTextureAndColor.texture)) {
|
|
351
|
-
return false;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return true;
|
|
356
|
-
};
|
|
357
|
-
// Custom render function
|
|
358
|
-
this._mainTexture.customRenderFunction = (opaqueSubMeshes, alphaTestSubMeshes, transparentSubMeshes, depthOnlySubMeshes) => {
|
|
359
|
-
this.onBeforeRenderMainTextureObservable.notifyObservers(this);
|
|
360
|
-
let index;
|
|
361
|
-
const engine = this._scene.getEngine();
|
|
362
|
-
if (depthOnlySubMeshes.length) {
|
|
363
|
-
engine.setColorWrite(false);
|
|
364
|
-
for (index = 0; index < depthOnlySubMeshes.length; index++) {
|
|
365
|
-
this._renderSubMesh(depthOnlySubMeshes.data[index]);
|
|
366
|
-
}
|
|
367
|
-
engine.setColorWrite(true);
|
|
368
|
-
}
|
|
369
|
-
for (index = 0; index < opaqueSubMeshes.length; index++) {
|
|
370
|
-
this._renderSubMesh(opaqueSubMeshes.data[index]);
|
|
371
|
-
}
|
|
372
|
-
for (index = 0; index < alphaTestSubMeshes.length; index++) {
|
|
373
|
-
this._renderSubMesh(alphaTestSubMeshes.data[index]);
|
|
374
|
-
}
|
|
375
|
-
const previousAlphaMode = engine.getAlphaMode();
|
|
376
|
-
for (index = 0; index < transparentSubMeshes.length; index++) {
|
|
377
|
-
this._renderSubMesh(transparentSubMeshes.data[index], true);
|
|
378
|
-
}
|
|
379
|
-
engine.setAlphaMode(previousAlphaMode);
|
|
380
|
-
};
|
|
381
|
-
this._mainTexture.onClearObservable.add((engine) => {
|
|
382
|
-
engine.clear(this.neutralColor, true, true, true);
|
|
383
|
-
});
|
|
384
|
-
// Prevent package size in es6 (getBoundingBoxRenderer might not be present)
|
|
385
|
-
if (this._scene.getBoundingBoxRenderer) {
|
|
386
|
-
const boundingBoxRendererEnabled = this._scene.getBoundingBoxRenderer().enabled;
|
|
387
|
-
this._mainTexture.onBeforeBindObservable.add(() => {
|
|
388
|
-
this._scene.getBoundingBoxRenderer().enabled = !this.disableBoundingBoxesFromEffectLayer && boundingBoxRendererEnabled;
|
|
389
|
-
});
|
|
390
|
-
this._mainTexture.onAfterUnbindObservable.add(() => {
|
|
391
|
-
this._scene.getBoundingBoxRenderer().enabled = boundingBoxRendererEnabled;
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Adds specific effects defines.
|
|
397
|
-
* @param defines The defines to add specifics to.
|
|
398
|
-
*/
|
|
399
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
400
|
-
_addCustomEffectDefines(defines) {
|
|
401
|
-
// Nothing to add by default.
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Checks for the readiness of the element composing the layer.
|
|
405
|
-
* @param subMesh the mesh to check for
|
|
406
|
-
* @param useInstances specify whether or not to use instances to render the mesh
|
|
407
|
-
* @param emissiveTexture the associated emissive texture used to generate the glow
|
|
408
|
-
* @returns true if ready otherwise, false
|
|
409
|
-
*/
|
|
410
|
-
_isReady(subMesh, useInstances, emissiveTexture) {
|
|
411
|
-
var _a;
|
|
412
|
-
const engine = this._scene.getEngine();
|
|
413
|
-
const mesh = subMesh.getMesh();
|
|
414
|
-
const renderingMaterial = (_a = mesh._internalAbstractMeshDataInfo._materialForRenderPass) === null || _a === void 0 ? void 0 : _a[engine.currentRenderPassId];
|
|
415
|
-
if (renderingMaterial) {
|
|
416
|
-
return renderingMaterial.isReadyForSubMesh(mesh, subMesh, useInstances);
|
|
417
|
-
}
|
|
418
|
-
const material = subMesh.getMaterial();
|
|
419
|
-
if (!material) {
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
422
|
-
if (this._useMeshMaterial(subMesh.getRenderingMesh())) {
|
|
423
|
-
return material.isReadyForSubMesh(subMesh.getMesh(), subMesh, useInstances);
|
|
424
|
-
}
|
|
425
|
-
const defines = [];
|
|
426
|
-
const attribs = [VertexBuffer.PositionKind];
|
|
427
|
-
let uv1 = false;
|
|
428
|
-
let uv2 = false;
|
|
429
|
-
// Diffuse
|
|
430
|
-
if (material) {
|
|
431
|
-
const needAlphaTest = material.needAlphaTesting();
|
|
432
|
-
const diffuseTexture = material.getAlphaTestTexture();
|
|
433
|
-
const needAlphaBlendFromDiffuse = diffuseTexture && diffuseTexture.hasAlpha && (material.useAlphaFromDiffuseTexture || material._useAlphaFromAlbedoTexture);
|
|
434
|
-
if (diffuseTexture && (needAlphaTest || needAlphaBlendFromDiffuse)) {
|
|
435
|
-
defines.push("#define DIFFUSE");
|
|
436
|
-
if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) && diffuseTexture.coordinatesIndex === 1) {
|
|
437
|
-
defines.push("#define DIFFUSEUV2");
|
|
438
|
-
uv2 = true;
|
|
439
|
-
}
|
|
440
|
-
else if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
|
|
441
|
-
defines.push("#define DIFFUSEUV1");
|
|
442
|
-
uv1 = true;
|
|
443
|
-
}
|
|
444
|
-
if (needAlphaTest) {
|
|
445
|
-
defines.push("#define ALPHATEST");
|
|
446
|
-
defines.push("#define ALPHATESTVALUE 0.4");
|
|
447
|
-
}
|
|
448
|
-
if (!diffuseTexture.gammaSpace) {
|
|
449
|
-
defines.push("#define DIFFUSE_ISLINEAR");
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
const opacityTexture = material.opacityTexture;
|
|
453
|
-
if (opacityTexture) {
|
|
454
|
-
defines.push("#define OPACITY");
|
|
455
|
-
if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) && opacityTexture.coordinatesIndex === 1) {
|
|
456
|
-
defines.push("#define OPACITYUV2");
|
|
457
|
-
uv2 = true;
|
|
458
|
-
}
|
|
459
|
-
else if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
|
|
460
|
-
defines.push("#define OPACITYUV1");
|
|
461
|
-
uv1 = true;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
// Emissive
|
|
466
|
-
if (emissiveTexture) {
|
|
467
|
-
defines.push("#define EMISSIVE");
|
|
468
|
-
if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind) && emissiveTexture.coordinatesIndex === 1) {
|
|
469
|
-
defines.push("#define EMISSIVEUV2");
|
|
470
|
-
uv2 = true;
|
|
471
|
-
}
|
|
472
|
-
else if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
|
|
473
|
-
defines.push("#define EMISSIVEUV1");
|
|
474
|
-
uv1 = true;
|
|
475
|
-
}
|
|
476
|
-
if (!emissiveTexture.gammaSpace) {
|
|
477
|
-
defines.push("#define EMISSIVE_ISLINEAR");
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
// Vertex
|
|
481
|
-
if (mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind) && mesh.hasVertexAlpha && material.transparencyMode !== Material.MATERIAL_OPAQUE) {
|
|
482
|
-
attribs.push(VertexBuffer.ColorKind);
|
|
483
|
-
defines.push("#define VERTEXALPHA");
|
|
484
|
-
}
|
|
485
|
-
if (uv1) {
|
|
486
|
-
attribs.push(VertexBuffer.UVKind);
|
|
487
|
-
defines.push("#define UV1");
|
|
488
|
-
}
|
|
489
|
-
if (uv2) {
|
|
490
|
-
attribs.push(VertexBuffer.UV2Kind);
|
|
491
|
-
defines.push("#define UV2");
|
|
492
|
-
}
|
|
493
|
-
// Bones
|
|
494
|
-
const fallbacks = new EffectFallbacks();
|
|
495
|
-
if (mesh.useBones && mesh.computeBonesUsingShaders) {
|
|
496
|
-
attribs.push(VertexBuffer.MatricesIndicesKind);
|
|
497
|
-
attribs.push(VertexBuffer.MatricesWeightsKind);
|
|
498
|
-
if (mesh.numBoneInfluencers > 4) {
|
|
499
|
-
attribs.push(VertexBuffer.MatricesIndicesExtraKind);
|
|
500
|
-
attribs.push(VertexBuffer.MatricesWeightsExtraKind);
|
|
501
|
-
}
|
|
502
|
-
defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
|
|
503
|
-
const skeleton = mesh.skeleton;
|
|
504
|
-
if (skeleton && skeleton.isUsingTextureForMatrices) {
|
|
505
|
-
defines.push("#define BONETEXTURE");
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
defines.push("#define BonesPerMesh " + (skeleton ? skeleton.bones.length + 1 : 0));
|
|
509
|
-
}
|
|
510
|
-
if (mesh.numBoneInfluencers > 0) {
|
|
511
|
-
fallbacks.addCPUSkinningFallback(0, mesh);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
else {
|
|
515
|
-
defines.push("#define NUM_BONE_INFLUENCERS 0");
|
|
516
|
-
}
|
|
517
|
-
// Morph targets
|
|
518
|
-
const manager = mesh.morphTargetManager;
|
|
519
|
-
let morphInfluencers = 0;
|
|
520
|
-
if (manager) {
|
|
521
|
-
if (manager.numInfluencers > 0) {
|
|
522
|
-
defines.push("#define MORPHTARGETS");
|
|
523
|
-
morphInfluencers = manager.numInfluencers;
|
|
524
|
-
defines.push("#define NUM_MORPH_INFLUENCERS " + morphInfluencers);
|
|
525
|
-
if (manager.isUsingTextureForTargets) {
|
|
526
|
-
defines.push("#define MORPHTARGETS_TEXTURE");
|
|
527
|
-
}
|
|
528
|
-
MaterialHelper.PrepareAttributesForMorphTargetsInfluencers(attribs, mesh, morphInfluencers);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
// Instances
|
|
532
|
-
if (useInstances) {
|
|
533
|
-
defines.push("#define INSTANCES");
|
|
534
|
-
MaterialHelper.PushAttributesForInstances(attribs);
|
|
535
|
-
if (subMesh.getRenderingMesh().hasThinInstances) {
|
|
536
|
-
defines.push("#define THIN_INSTANCES");
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
// ClipPlanes
|
|
540
|
-
prepareStringDefinesForClipPlanes(material, this._scene, defines);
|
|
541
|
-
this._addCustomEffectDefines(defines);
|
|
542
|
-
// Get correct effect
|
|
543
|
-
const drawWrapper = subMesh._getDrawWrapper(undefined, true);
|
|
544
|
-
const cachedDefines = drawWrapper.defines;
|
|
545
|
-
const join = defines.join("\n");
|
|
546
|
-
if (cachedDefines !== join) {
|
|
547
|
-
const uniforms = [
|
|
548
|
-
"world",
|
|
549
|
-
"mBones",
|
|
550
|
-
"viewProjection",
|
|
551
|
-
"glowColor",
|
|
552
|
-
"morphTargetInfluences",
|
|
553
|
-
"boneTextureWidth",
|
|
554
|
-
"diffuseMatrix",
|
|
555
|
-
"emissiveMatrix",
|
|
556
|
-
"opacityMatrix",
|
|
557
|
-
"opacityIntensity",
|
|
558
|
-
"morphTargetTextureInfo",
|
|
559
|
-
"morphTargetTextureIndices",
|
|
560
|
-
"glowIntensity",
|
|
561
|
-
];
|
|
562
|
-
addClipPlaneUniforms(uniforms);
|
|
563
|
-
drawWrapper.setEffect(this._engine.createEffect("glowMapGeneration", attribs, uniforms, ["diffuseSampler", "emissiveSampler", "opacitySampler", "boneSampler", "morphTargets"], join, fallbacks, undefined, undefined, { maxSimultaneousMorphTargets: morphInfluencers }), join);
|
|
564
|
-
}
|
|
565
|
-
return drawWrapper.effect.isReady();
|
|
566
|
-
}
|
|
567
|
-
/**
|
|
568
|
-
* Renders the glowing part of the scene by blending the blurred glowing meshes on top of the rendered scene.
|
|
569
|
-
*/
|
|
570
|
-
render() {
|
|
571
|
-
for (let i = 0; i < this._postProcesses.length; i++) {
|
|
572
|
-
if (!this._postProcesses[i].isReady()) {
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
const engine = this._scene.getEngine();
|
|
577
|
-
const numDraws = this._numInternalDraws();
|
|
578
|
-
// Check
|
|
579
|
-
let isReady = true;
|
|
580
|
-
for (let i = 0; i < numDraws; ++i) {
|
|
581
|
-
let currentEffect = this._mergeDrawWrapper[i];
|
|
582
|
-
if (!currentEffect) {
|
|
583
|
-
currentEffect = this._mergeDrawWrapper[i] = new DrawWrapper(this._engine);
|
|
584
|
-
currentEffect.setEffect(this._createMergeEffect());
|
|
585
|
-
}
|
|
586
|
-
isReady = isReady && currentEffect.effect.isReady();
|
|
587
|
-
}
|
|
588
|
-
if (!isReady) {
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
this.onBeforeComposeObservable.notifyObservers(this);
|
|
592
|
-
const previousAlphaMode = engine.getAlphaMode();
|
|
593
|
-
for (let i = 0; i < numDraws; ++i) {
|
|
594
|
-
const currentEffect = this._mergeDrawWrapper[i];
|
|
595
|
-
// Render
|
|
596
|
-
engine.enableEffect(currentEffect);
|
|
597
|
-
engine.setState(false);
|
|
598
|
-
// VBOs
|
|
599
|
-
engine.bindBuffers(this._vertexBuffers, this._indexBuffer, currentEffect.effect);
|
|
600
|
-
// Go Blend.
|
|
601
|
-
engine.setAlphaMode(this._effectLayerOptions.alphaBlendingMode);
|
|
602
|
-
// Blends the map on the main canvas.
|
|
603
|
-
this._internalRender(currentEffect.effect, i);
|
|
604
|
-
}
|
|
605
|
-
// Restore Alpha
|
|
606
|
-
engine.setAlphaMode(previousAlphaMode);
|
|
607
|
-
this.onAfterComposeObservable.notifyObservers(this);
|
|
608
|
-
// Handle size changes.
|
|
609
|
-
const size = this._mainTexture.getSize();
|
|
610
|
-
this._setMainTextureSize();
|
|
611
|
-
if ((size.width !== this._mainTextureDesiredSize.width || size.height !== this._mainTextureDesiredSize.height) &&
|
|
612
|
-
this._mainTextureDesiredSize.width !== 0 &&
|
|
613
|
-
this._mainTextureDesiredSize.height !== 0) {
|
|
614
|
-
// Recreate RTT and post processes on size change.
|
|
615
|
-
this.onSizeChangedObservable.notifyObservers(this);
|
|
616
|
-
this._disposeTextureAndPostProcesses();
|
|
617
|
-
this._createMainTexture();
|
|
618
|
-
this._createTextureAndPostProcesses();
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Determine if a given mesh will be used in the current effect.
|
|
623
|
-
* @param mesh mesh to test
|
|
624
|
-
* @returns true if the mesh will be used
|
|
625
|
-
*/
|
|
626
|
-
hasMesh(mesh) {
|
|
627
|
-
if (this.renderingGroupId === -1 || mesh.renderingGroupId === this.renderingGroupId) {
|
|
628
|
-
return true;
|
|
629
|
-
}
|
|
630
|
-
return false;
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* Returns true if the layer contains information to display, otherwise false.
|
|
634
|
-
* @returns true if the glow layer should be rendered
|
|
635
|
-
*/
|
|
636
|
-
shouldRender() {
|
|
637
|
-
return this.isEnabled && this._shouldRender;
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Returns true if the mesh should render, otherwise false.
|
|
641
|
-
* @param mesh The mesh to render
|
|
642
|
-
* @returns true if it should render otherwise false
|
|
643
|
-
*/
|
|
644
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
645
|
-
_shouldRenderMesh(mesh) {
|
|
646
|
-
return true;
|
|
647
|
-
}
|
|
648
|
-
/**
|
|
649
|
-
* Returns true if the mesh can be rendered, otherwise false.
|
|
650
|
-
* @param mesh The mesh to render
|
|
651
|
-
* @param material The material used on the mesh
|
|
652
|
-
* @returns true if it can be rendered otherwise false
|
|
653
|
-
*/
|
|
654
|
-
_canRenderMesh(mesh, material) {
|
|
655
|
-
return !material.needAlphaBlendingForMesh(mesh);
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* Returns true if the mesh should render, otherwise false.
|
|
659
|
-
* @returns true if it should render otherwise false
|
|
660
|
-
*/
|
|
661
|
-
_shouldRenderEmissiveTextureForMesh() {
|
|
662
|
-
return true;
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* Renders the submesh passed in parameter to the generation map.
|
|
666
|
-
* @param subMesh
|
|
667
|
-
* @param enableAlphaMode
|
|
668
|
-
*/
|
|
669
|
-
_renderSubMesh(subMesh, enableAlphaMode = false) {
|
|
670
|
-
var _a, _b;
|
|
671
|
-
if (!this.shouldRender()) {
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
const material = subMesh.getMaterial();
|
|
675
|
-
const ownerMesh = subMesh.getMesh();
|
|
676
|
-
const replacementMesh = subMesh.getReplacementMesh();
|
|
677
|
-
const renderingMesh = subMesh.getRenderingMesh();
|
|
678
|
-
const effectiveMesh = subMesh.getEffectiveMesh();
|
|
679
|
-
const scene = this._scene;
|
|
680
|
-
const engine = scene.getEngine();
|
|
681
|
-
effectiveMesh._internalAbstractMeshDataInfo._isActiveIntermediate = false;
|
|
682
|
-
if (!material) {
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
// Do not block in blend mode.
|
|
686
|
-
if (!this._canRenderMesh(renderingMesh, material)) {
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
// Culling
|
|
690
|
-
let sideOrientation = (_a = renderingMesh.overrideMaterialSideOrientation) !== null && _a !== void 0 ? _a : material.sideOrientation;
|
|
691
|
-
const mainDeterminant = effectiveMesh._getWorldMatrixDeterminant();
|
|
692
|
-
if (mainDeterminant < 0) {
|
|
693
|
-
sideOrientation = sideOrientation === Material.ClockWiseSideOrientation ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
|
|
694
|
-
}
|
|
695
|
-
const reverse = sideOrientation === Material.ClockWiseSideOrientation;
|
|
696
|
-
engine.setState(material.backFaceCulling, material.zOffset, undefined, reverse, material.cullBackFaces, undefined, material.zOffsetUnits);
|
|
697
|
-
// Managing instances
|
|
698
|
-
const batch = renderingMesh._getInstancesRenderList(subMesh._id, !!replacementMesh);
|
|
699
|
-
if (batch.mustReturn) {
|
|
700
|
-
return;
|
|
701
|
-
}
|
|
702
|
-
// Early Exit per mesh
|
|
703
|
-
if (!this._shouldRenderMesh(renderingMesh)) {
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
const hardwareInstancedRendering = batch.hardwareInstancedRendering[subMesh._id] || renderingMesh.hasThinInstances;
|
|
707
|
-
this._setEmissiveTextureAndColor(renderingMesh, subMesh, material);
|
|
708
|
-
this.onBeforeRenderMeshToEffect.notifyObservers(ownerMesh);
|
|
709
|
-
if (this._useMeshMaterial(renderingMesh)) {
|
|
710
|
-
renderingMesh.render(subMesh, enableAlphaMode, replacementMesh || undefined);
|
|
711
|
-
}
|
|
712
|
-
else if (this._isReady(subMesh, hardwareInstancedRendering, this._emissiveTextureAndColor.texture)) {
|
|
713
|
-
const renderingMaterial = (_b = effectiveMesh._internalAbstractMeshDataInfo._materialForRenderPass) === null || _b === void 0 ? void 0 : _b[engine.currentRenderPassId];
|
|
714
|
-
let drawWrapper = subMesh._getDrawWrapper();
|
|
715
|
-
if (!drawWrapper && renderingMaterial) {
|
|
716
|
-
drawWrapper = renderingMaterial._getDrawWrapper();
|
|
717
|
-
}
|
|
718
|
-
if (!drawWrapper) {
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
const effect = drawWrapper.effect;
|
|
722
|
-
engine.enableEffect(drawWrapper);
|
|
723
|
-
if (!hardwareInstancedRendering) {
|
|
724
|
-
renderingMesh._bind(subMesh, effect, material.fillMode);
|
|
725
|
-
}
|
|
726
|
-
if (!renderingMaterial) {
|
|
727
|
-
effect.setMatrix("viewProjection", scene.getTransformMatrix());
|
|
728
|
-
effect.setMatrix("world", effectiveMesh.getWorldMatrix());
|
|
729
|
-
effect.setFloat4("glowColor", this._emissiveTextureAndColor.color.r, this._emissiveTextureAndColor.color.g, this._emissiveTextureAndColor.color.b, this._emissiveTextureAndColor.color.a);
|
|
730
|
-
}
|
|
731
|
-
else {
|
|
732
|
-
renderingMaterial.bindForSubMesh(effectiveMesh.getWorldMatrix(), effectiveMesh, subMesh);
|
|
733
|
-
}
|
|
734
|
-
if (!renderingMaterial) {
|
|
735
|
-
const needAlphaTest = material.needAlphaTesting();
|
|
736
|
-
const diffuseTexture = material.getAlphaTestTexture();
|
|
737
|
-
const needAlphaBlendFromDiffuse = diffuseTexture && diffuseTexture.hasAlpha && (material.useAlphaFromDiffuseTexture || material._useAlphaFromAlbedoTexture);
|
|
738
|
-
if (diffuseTexture && (needAlphaTest || needAlphaBlendFromDiffuse)) {
|
|
739
|
-
effect.setTexture("diffuseSampler", diffuseTexture);
|
|
740
|
-
const textureMatrix = diffuseTexture.getTextureMatrix();
|
|
741
|
-
if (textureMatrix) {
|
|
742
|
-
effect.setMatrix("diffuseMatrix", textureMatrix);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
const opacityTexture = material.opacityTexture;
|
|
746
|
-
if (opacityTexture) {
|
|
747
|
-
effect.setTexture("opacitySampler", opacityTexture);
|
|
748
|
-
effect.setFloat("opacityIntensity", opacityTexture.level);
|
|
749
|
-
const textureMatrix = opacityTexture.getTextureMatrix();
|
|
750
|
-
if (textureMatrix) {
|
|
751
|
-
effect.setMatrix("opacityMatrix", textureMatrix);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
// Glow emissive only
|
|
755
|
-
if (this._emissiveTextureAndColor.texture) {
|
|
756
|
-
effect.setTexture("emissiveSampler", this._emissiveTextureAndColor.texture);
|
|
757
|
-
effect.setMatrix("emissiveMatrix", this._emissiveTextureAndColor.texture.getTextureMatrix());
|
|
758
|
-
}
|
|
759
|
-
// Bones
|
|
760
|
-
if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {
|
|
761
|
-
const skeleton = renderingMesh.skeleton;
|
|
762
|
-
if (skeleton.isUsingTextureForMatrices) {
|
|
763
|
-
const boneTexture = skeleton.getTransformMatrixTexture(renderingMesh);
|
|
764
|
-
if (!boneTexture) {
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
767
|
-
effect.setTexture("boneSampler", boneTexture);
|
|
768
|
-
effect.setFloat("boneTextureWidth", 4.0 * (skeleton.bones.length + 1));
|
|
769
|
-
}
|
|
770
|
-
else {
|
|
771
|
-
effect.setMatrices("mBones", skeleton.getTransformMatrices(renderingMesh));
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
// Morph targets
|
|
775
|
-
MaterialHelper.BindMorphTargetParameters(renderingMesh, effect);
|
|
776
|
-
if (renderingMesh.morphTargetManager && renderingMesh.morphTargetManager.isUsingTextureForTargets) {
|
|
777
|
-
renderingMesh.morphTargetManager._bind(effect);
|
|
778
|
-
}
|
|
779
|
-
// Alpha mode
|
|
780
|
-
if (enableAlphaMode) {
|
|
781
|
-
engine.setAlphaMode(material.alphaMode);
|
|
782
|
-
}
|
|
783
|
-
// Intensity of effect
|
|
784
|
-
effect.setFloat("glowIntensity", this.getEffectIntensity(renderingMesh));
|
|
785
|
-
// Clip planes
|
|
786
|
-
bindClipPlane(effect, material, scene);
|
|
787
|
-
}
|
|
788
|
-
// Draw
|
|
789
|
-
renderingMesh._processRendering(effectiveMesh, subMesh, effect, material.fillMode, batch, hardwareInstancedRendering, (isInstance, world) => effect.setMatrix("world", world));
|
|
790
|
-
}
|
|
791
|
-
else {
|
|
792
|
-
// Need to reset refresh rate of the main map
|
|
793
|
-
this._mainTexture.resetRefreshCounter();
|
|
794
|
-
}
|
|
795
|
-
this.onAfterRenderMeshToEffect.notifyObservers(ownerMesh);
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
* Defines whether the current material of the mesh should be use to render the effect.
|
|
799
|
-
* @param mesh defines the current mesh to render
|
|
800
|
-
*/
|
|
801
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
802
|
-
_useMeshMaterial(mesh) {
|
|
803
|
-
return false;
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Rebuild the required buffers.
|
|
807
|
-
* @internal Internal use only.
|
|
808
|
-
*/
|
|
809
|
-
_rebuild() {
|
|
810
|
-
const vb = this._vertexBuffers[VertexBuffer.PositionKind];
|
|
811
|
-
if (vb) {
|
|
812
|
-
vb._rebuild();
|
|
813
|
-
}
|
|
814
|
-
this._generateIndexBuffer();
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Dispose only the render target textures and post process.
|
|
818
|
-
*/
|
|
819
|
-
_disposeTextureAndPostProcesses() {
|
|
820
|
-
this._mainTexture.dispose();
|
|
821
|
-
for (let i = 0; i < this._postProcesses.length; i++) {
|
|
822
|
-
if (this._postProcesses[i]) {
|
|
823
|
-
this._postProcesses[i].dispose();
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
this._postProcesses = [];
|
|
827
|
-
for (let i = 0; i < this._textures.length; i++) {
|
|
828
|
-
if (this._textures[i]) {
|
|
829
|
-
this._textures[i].dispose();
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
this._textures = [];
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Dispose the highlight layer and free resources.
|
|
836
|
-
*/
|
|
837
|
-
dispose() {
|
|
838
|
-
const vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];
|
|
839
|
-
if (vertexBuffer) {
|
|
840
|
-
vertexBuffer.dispose();
|
|
841
|
-
this._vertexBuffers[VertexBuffer.PositionKind] = null;
|
|
842
|
-
}
|
|
843
|
-
if (this._indexBuffer) {
|
|
844
|
-
this._scene.getEngine()._releaseBuffer(this._indexBuffer);
|
|
845
|
-
this._indexBuffer = null;
|
|
846
|
-
}
|
|
847
|
-
for (const drawWrapper of this._mergeDrawWrapper) {
|
|
848
|
-
drawWrapper.dispose();
|
|
849
|
-
}
|
|
850
|
-
this._mergeDrawWrapper = [];
|
|
851
|
-
// Clean textures and post processes
|
|
852
|
-
this._disposeTextureAndPostProcesses();
|
|
853
|
-
// Remove from scene
|
|
854
|
-
const index = this._scene.effectLayers.indexOf(this, 0);
|
|
855
|
-
if (index > -1) {
|
|
856
|
-
this._scene.effectLayers.splice(index, 1);
|
|
857
|
-
}
|
|
858
|
-
// Callback
|
|
859
|
-
this.onDisposeObservable.notifyObservers(this);
|
|
860
|
-
this.onDisposeObservable.clear();
|
|
861
|
-
this.onBeforeRenderMainTextureObservable.clear();
|
|
862
|
-
this.onBeforeComposeObservable.clear();
|
|
863
|
-
this.onBeforeRenderMeshToEffect.clear();
|
|
864
|
-
this.onAfterRenderMeshToEffect.clear();
|
|
865
|
-
this.onAfterComposeObservable.clear();
|
|
866
|
-
this.onSizeChangedObservable.clear();
|
|
867
|
-
}
|
|
868
|
-
/**
|
|
869
|
-
* Gets the class name of the effect layer
|
|
870
|
-
* @returns the string with the class name of the effect layer
|
|
871
|
-
*/
|
|
872
|
-
getClassName() {
|
|
873
|
-
return "EffectLayer";
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* Creates an effect layer from parsed effect layer data
|
|
877
|
-
* @param parsedEffectLayer defines effect layer data
|
|
878
|
-
* @param scene defines the current scene
|
|
879
|
-
* @param rootUrl defines the root URL containing the effect layer information
|
|
880
|
-
* @returns a parsed effect Layer
|
|
881
|
-
*/
|
|
882
|
-
static Parse(parsedEffectLayer, scene, rootUrl) {
|
|
883
|
-
const effectLayerType = Tools.Instantiate(parsedEffectLayer.customType);
|
|
884
|
-
return effectLayerType.Parse(parsedEffectLayer, scene, rootUrl);
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
/**
|
|
888
|
-
* @internal
|
|
889
|
-
*/
|
|
890
|
-
EffectLayer._SceneComponentInitialization = (_) => {
|
|
891
|
-
throw _WarnImport("EffectLayerSceneComponent");
|
|
892
|
-
};
|
|
893
|
-
__decorate([
|
|
894
|
-
serialize()
|
|
895
|
-
], EffectLayer.prototype, "name", void 0);
|
|
896
|
-
__decorate([
|
|
897
|
-
serializeAsColor4()
|
|
898
|
-
], EffectLayer.prototype, "neutralColor", void 0);
|
|
899
|
-
__decorate([
|
|
900
|
-
serialize()
|
|
901
|
-
], EffectLayer.prototype, "isEnabled", void 0);
|
|
902
|
-
__decorate([
|
|
903
|
-
serializeAsCameraReference()
|
|
904
|
-
], EffectLayer.prototype, "camera", null);
|
|
905
|
-
__decorate([
|
|
906
|
-
serialize()
|
|
907
|
-
], EffectLayer.prototype, "renderingGroupId", null);
|
|
908
|
-
__decorate([
|
|
909
|
-
serialize()
|
|
910
|
-
], EffectLayer.prototype, "disableBoundingBoxesFromEffectLayer", void 0);
|
|
911
|
-
|
|
912
|
-
// Do not edit.
|
|
913
|
-
const name$1 = "glowMapMergePixelShader";
|
|
914
|
-
const shader$1 = `varying vec2 vUV;
|
|
915
|
-
uniform sampler2D textureSampler2;
|
|
916
|
-
uniform float offset;
|
|
917
|
-
void main(void) {
|
|
918
|
-
vec4 baseColor=texture2D(textureSampler,vUV);
|
|
919
|
-
baseColor+=texture2D(textureSampler2,vUV);
|
|
920
|
-
baseColor.a=abs(offset-baseColor.a);
|
|
921
|
-
float alpha=smoothstep(.0,.1,baseColor.a);
|
|
922
|
-
#endif
|
|
923
|
-
#if LDR
|
|
924
|
-
baseColor=clamp(baseColor,0.,1.0);
|
|
925
|
-
gl_FragColor=baseColor;
|
|
926
|
-
}`;
|
|
927
|
-
// Sideeffect
|
|
928
|
-
ShaderStore.ShadersStore[name$1] = shader$1;
|
|
929
|
-
|
|
930
|
-
// Do not edit.
|
|
931
|
-
const name = "glowMapMergeVertexShader";
|
|
932
|
-
const shader = `attribute vec2 position;
|
|
933
|
-
void main(void) {
|
|
934
|
-
vUV=position*madd+madd;
|
|
935
|
-
}`;
|
|
936
|
-
// Sideeffect
|
|
937
|
-
ShaderStore.ShadersStore[name] = shader;
|
|
938
|
-
|
|
939
|
-
// Adds the parser to the scene parsers.
|
|
940
|
-
AbstractScene.AddParser(SceneComponentConstants.NAME_EFFECTLAYER, (parsedData, scene, container, rootUrl) => {
|
|
941
|
-
if (parsedData.effectLayers) {
|
|
942
|
-
if (!container.effectLayers) {
|
|
943
|
-
container.effectLayers = new Array();
|
|
944
|
-
}
|
|
945
|
-
for (let index = 0; index < parsedData.effectLayers.length; index++) {
|
|
946
|
-
const effectLayer = EffectLayer.Parse(parsedData.effectLayers[index], scene, rootUrl);
|
|
947
|
-
container.effectLayers.push(effectLayer);
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
});
|
|
951
|
-
AbstractScene.prototype.removeEffectLayer = function (toRemove) {
|
|
952
|
-
const index = this.effectLayers.indexOf(toRemove);
|
|
953
|
-
if (index !== -1) {
|
|
954
|
-
this.effectLayers.splice(index, 1);
|
|
955
|
-
}
|
|
956
|
-
return index;
|
|
957
|
-
};
|
|
958
|
-
AbstractScene.prototype.addEffectLayer = function (newEffectLayer) {
|
|
959
|
-
this.effectLayers.push(newEffectLayer);
|
|
960
|
-
};
|
|
961
|
-
/**
|
|
962
|
-
* Defines the layer scene component responsible to manage any effect layers
|
|
963
|
-
* in a given scene.
|
|
964
|
-
*/
|
|
965
|
-
class EffectLayerSceneComponent {
|
|
966
|
-
/**
|
|
967
|
-
* Creates a new instance of the component for the given scene
|
|
968
|
-
* @param scene Defines the scene to register the component in
|
|
969
|
-
*/
|
|
970
|
-
constructor(scene) {
|
|
971
|
-
/**
|
|
972
|
-
* The component name helpful to identify the component in the list of scene components.
|
|
973
|
-
*/
|
|
974
|
-
this.name = SceneComponentConstants.NAME_EFFECTLAYER;
|
|
975
|
-
this._renderEffects = false;
|
|
976
|
-
this._needStencil = false;
|
|
977
|
-
this._previousStencilState = false;
|
|
978
|
-
this.scene = scene || EngineStore.LastCreatedScene;
|
|
979
|
-
if (!this.scene) {
|
|
980
|
-
return;
|
|
981
|
-
}
|
|
982
|
-
this._engine = this.scene.getEngine();
|
|
983
|
-
this.scene.effectLayers = new Array();
|
|
984
|
-
}
|
|
985
|
-
/**
|
|
986
|
-
* Registers the component in a given scene
|
|
987
|
-
*/
|
|
988
|
-
register() {
|
|
989
|
-
this.scene._isReadyForMeshStage.registerStep(SceneComponentConstants.STEP_ISREADYFORMESH_EFFECTLAYER, this, this._isReadyForMesh);
|
|
990
|
-
this.scene._cameraDrawRenderTargetStage.registerStep(SceneComponentConstants.STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER, this, this._renderMainTexture);
|
|
991
|
-
this.scene._beforeCameraDrawStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERADRAW_EFFECTLAYER, this, this._setStencil);
|
|
992
|
-
this.scene._afterRenderingGroupDrawStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW, this, this._drawRenderingGroup);
|
|
993
|
-
this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER, this, this._setStencilBack);
|
|
994
|
-
this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW, this, this._drawCamera);
|
|
995
|
-
}
|
|
996
|
-
/**
|
|
997
|
-
* Rebuilds the elements related to this component in case of
|
|
998
|
-
* context lost for instance.
|
|
999
|
-
*/
|
|
1000
|
-
rebuild() {
|
|
1001
|
-
const layers = this.scene.effectLayers;
|
|
1002
|
-
for (const effectLayer of layers) {
|
|
1003
|
-
effectLayer._rebuild();
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
/**
|
|
1007
|
-
* Serializes the component data to the specified json object
|
|
1008
|
-
* @param serializationObject The object to serialize to
|
|
1009
|
-
*/
|
|
1010
|
-
serialize(serializationObject) {
|
|
1011
|
-
// Effect layers
|
|
1012
|
-
serializationObject.effectLayers = [];
|
|
1013
|
-
const layers = this.scene.effectLayers;
|
|
1014
|
-
for (const effectLayer of layers) {
|
|
1015
|
-
if (effectLayer.serialize) {
|
|
1016
|
-
serializationObject.effectLayers.push(effectLayer.serialize());
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
/**
|
|
1021
|
-
* Adds all the elements from the container to the scene
|
|
1022
|
-
* @param container the container holding the elements
|
|
1023
|
-
*/
|
|
1024
|
-
addFromContainer(container) {
|
|
1025
|
-
if (!container.effectLayers) {
|
|
1026
|
-
return;
|
|
1027
|
-
}
|
|
1028
|
-
container.effectLayers.forEach((o) => {
|
|
1029
|
-
this.scene.addEffectLayer(o);
|
|
1030
|
-
});
|
|
1031
|
-
}
|
|
1032
|
-
/**
|
|
1033
|
-
* Removes all the elements in the container from the scene
|
|
1034
|
-
* @param container contains the elements to remove
|
|
1035
|
-
* @param dispose if the removed element should be disposed (default: false)
|
|
1036
|
-
*/
|
|
1037
|
-
removeFromContainer(container, dispose) {
|
|
1038
|
-
if (!container.effectLayers) {
|
|
1039
|
-
return;
|
|
1040
|
-
}
|
|
1041
|
-
container.effectLayers.forEach((o) => {
|
|
1042
|
-
this.scene.removeEffectLayer(o);
|
|
1043
|
-
if (dispose) {
|
|
1044
|
-
o.dispose();
|
|
1045
|
-
}
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Disposes the component and the associated resources.
|
|
1050
|
-
*/
|
|
1051
|
-
dispose() {
|
|
1052
|
-
const layers = this.scene.effectLayers;
|
|
1053
|
-
while (layers.length) {
|
|
1054
|
-
layers[0].dispose();
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
_isReadyForMesh(mesh, hardwareInstancedRendering) {
|
|
1058
|
-
const currentRenderPassId = this._engine.currentRenderPassId;
|
|
1059
|
-
const layers = this.scene.effectLayers;
|
|
1060
|
-
for (const layer of layers) {
|
|
1061
|
-
if (!layer.hasMesh(mesh)) {
|
|
1062
|
-
continue;
|
|
1063
|
-
}
|
|
1064
|
-
const renderTarget = layer._mainTexture;
|
|
1065
|
-
this._engine.currentRenderPassId = renderTarget.renderPassId;
|
|
1066
|
-
for (const subMesh of mesh.subMeshes) {
|
|
1067
|
-
if (!layer.isReady(subMesh, hardwareInstancedRendering)) {
|
|
1068
|
-
this._engine.currentRenderPassId = currentRenderPassId;
|
|
1069
|
-
return false;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
this._engine.currentRenderPassId = currentRenderPassId;
|
|
1074
|
-
return true;
|
|
1075
|
-
}
|
|
1076
|
-
_renderMainTexture(camera) {
|
|
1077
|
-
this._renderEffects = false;
|
|
1078
|
-
this._needStencil = false;
|
|
1079
|
-
let needRebind = false;
|
|
1080
|
-
const layers = this.scene.effectLayers;
|
|
1081
|
-
if (layers && layers.length > 0) {
|
|
1082
|
-
this._previousStencilState = this._engine.getStencilBuffer();
|
|
1083
|
-
for (const effectLayer of layers) {
|
|
1084
|
-
if (effectLayer.shouldRender() &&
|
|
1085
|
-
(!effectLayer.camera ||
|
|
1086
|
-
(effectLayer.camera.cameraRigMode === Camera.RIG_MODE_NONE && camera === effectLayer.camera) ||
|
|
1087
|
-
(effectLayer.camera.cameraRigMode !== Camera.RIG_MODE_NONE && effectLayer.camera._rigCameras.indexOf(camera) > -1))) {
|
|
1088
|
-
this._renderEffects = true;
|
|
1089
|
-
this._needStencil = this._needStencil || effectLayer.needStencil();
|
|
1090
|
-
const renderTarget = effectLayer._mainTexture;
|
|
1091
|
-
if (renderTarget._shouldRender()) {
|
|
1092
|
-
this.scene.incrementRenderId();
|
|
1093
|
-
renderTarget.render(false, false);
|
|
1094
|
-
needRebind = true;
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
this.scene.incrementRenderId();
|
|
1099
|
-
}
|
|
1100
|
-
return needRebind;
|
|
1101
|
-
}
|
|
1102
|
-
_setStencil() {
|
|
1103
|
-
// Activate effect Layer stencil
|
|
1104
|
-
if (this._needStencil) {
|
|
1105
|
-
this._engine.setStencilBuffer(true);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
_setStencilBack() {
|
|
1109
|
-
// Restore effect Layer stencil
|
|
1110
|
-
if (this._needStencil) {
|
|
1111
|
-
this._engine.setStencilBuffer(this._previousStencilState);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
_draw(renderingGroupId) {
|
|
1115
|
-
if (this._renderEffects) {
|
|
1116
|
-
this._engine.setDepthBuffer(false);
|
|
1117
|
-
const layers = this.scene.effectLayers;
|
|
1118
|
-
for (let i = 0; i < layers.length; i++) {
|
|
1119
|
-
const effectLayer = layers[i];
|
|
1120
|
-
if (effectLayer.renderingGroupId === renderingGroupId) {
|
|
1121
|
-
if (effectLayer.shouldRender()) {
|
|
1122
|
-
effectLayer.render();
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
this._engine.setDepthBuffer(true);
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
_drawCamera() {
|
|
1130
|
-
if (this._renderEffects) {
|
|
1131
|
-
this._draw(-1);
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
_drawRenderingGroup(index) {
|
|
1135
|
-
if (!this.scene._isInIntermediateRendering() && this._renderEffects) {
|
|
1136
|
-
this._draw(index);
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
EffectLayer._SceneComponentInitialization = (scene) => {
|
|
1141
|
-
let component = scene._getComponent(SceneComponentConstants.NAME_EFFECTLAYER);
|
|
1142
|
-
if (!component) {
|
|
1143
|
-
component = new EffectLayerSceneComponent(scene);
|
|
1144
|
-
scene._addComponent(component);
|
|
1145
|
-
}
|
|
1146
|
-
};
|
|
1147
|
-
|
|
1148
|
-
AbstractScene.prototype.getGlowLayerByName = function (name) {
|
|
1149
|
-
var _a;
|
|
1150
|
-
for (let index = 0; index < ((_a = this.effectLayers) === null || _a === void 0 ? void 0 : _a.length); index++) {
|
|
1151
|
-
if (this.effectLayers[index].name === name && this.effectLayers[index].getEffectName() === GlowLayer.EffectName) {
|
|
1152
|
-
return this.effectLayers[index];
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
return null;
|
|
1156
|
-
};
|
|
1157
|
-
/**
|
|
1158
|
-
* The glow layer Helps adding a glow effect around the emissive parts of a mesh.
|
|
1159
|
-
*
|
|
1160
|
-
* Once instantiated in a scene, by default, all the emissive meshes will glow.
|
|
1161
|
-
*
|
|
1162
|
-
* Documentation: https://doc.babylonjs.com/features/featuresDeepDive/mesh/glowLayer
|
|
1163
|
-
*/
|
|
1164
|
-
class GlowLayer extends EffectLayer {
|
|
1165
|
-
/**
|
|
1166
|
-
* Sets the kernel size of the blur.
|
|
1167
|
-
*/
|
|
1168
|
-
set blurKernelSize(value) {
|
|
1169
|
-
if (value === this._options.blurKernelSize) {
|
|
1170
|
-
return;
|
|
1171
|
-
}
|
|
1172
|
-
this._options.blurKernelSize = value;
|
|
1173
|
-
const effectiveKernel = this._getEffectiveBlurKernelSize();
|
|
1174
|
-
this._horizontalBlurPostprocess1.kernel = effectiveKernel;
|
|
1175
|
-
this._verticalBlurPostprocess1.kernel = effectiveKernel;
|
|
1176
|
-
this._horizontalBlurPostprocess2.kernel = effectiveKernel;
|
|
1177
|
-
this._verticalBlurPostprocess2.kernel = effectiveKernel;
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
* Gets the kernel size of the blur.
|
|
1181
|
-
*/
|
|
1182
|
-
get blurKernelSize() {
|
|
1183
|
-
return this._options.blurKernelSize;
|
|
1184
|
-
}
|
|
1185
|
-
/**
|
|
1186
|
-
* Sets the glow intensity.
|
|
1187
|
-
*/
|
|
1188
|
-
set intensity(value) {
|
|
1189
|
-
this._intensity = value;
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Gets the glow intensity.
|
|
1193
|
-
*/
|
|
1194
|
-
get intensity() {
|
|
1195
|
-
return this._intensity;
|
|
1196
|
-
}
|
|
1197
|
-
/**
|
|
1198
|
-
* Instantiates a new glow Layer and references it to the scene.
|
|
1199
|
-
* @param name The name of the layer
|
|
1200
|
-
* @param scene The scene to use the layer in
|
|
1201
|
-
* @param options Sets of none mandatory options to use with the layer (see IGlowLayerOptions for more information)
|
|
1202
|
-
*/
|
|
1203
|
-
constructor(name, scene, options) {
|
|
1204
|
-
super(name, scene);
|
|
1205
|
-
this._intensity = 1.0;
|
|
1206
|
-
this._includedOnlyMeshes = [];
|
|
1207
|
-
this._excludedMeshes = [];
|
|
1208
|
-
this._meshesUsingTheirOwnMaterials = [];
|
|
1209
|
-
this.neutralColor = new Color4(0, 0, 0, 1);
|
|
1210
|
-
// Adapt options
|
|
1211
|
-
this._options = Object.assign({ mainTextureRatio: GlowLayer.DefaultTextureRatio, blurKernelSize: 32, mainTextureFixedSize: undefined, camera: null, mainTextureSamples: 1, renderingGroupId: -1, ldrMerge: false, alphaBlendingMode: 1, mainTextureType: 0, generateStencilBuffer: false }, options);
|
|
1212
|
-
// Initialize the layer
|
|
1213
|
-
this._init({
|
|
1214
|
-
alphaBlendingMode: this._options.alphaBlendingMode,
|
|
1215
|
-
camera: this._options.camera,
|
|
1216
|
-
mainTextureFixedSize: this._options.mainTextureFixedSize,
|
|
1217
|
-
mainTextureRatio: this._options.mainTextureRatio,
|
|
1218
|
-
renderingGroupId: this._options.renderingGroupId,
|
|
1219
|
-
mainTextureType: this._options.mainTextureType,
|
|
1220
|
-
generateStencilBuffer: this._options.generateStencilBuffer,
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
/**
|
|
1224
|
-
* Get the effect name of the layer.
|
|
1225
|
-
* @returns The effect name
|
|
1226
|
-
*/
|
|
1227
|
-
getEffectName() {
|
|
1228
|
-
return GlowLayer.EffectName;
|
|
1229
|
-
}
|
|
1230
|
-
/**
|
|
1231
|
-
* Create the merge effect. This is the shader use to blit the information back
|
|
1232
|
-
* to the main canvas at the end of the scene rendering.
|
|
1233
|
-
*/
|
|
1234
|
-
_createMergeEffect() {
|
|
1235
|
-
let defines = "#define EMISSIVE \n";
|
|
1236
|
-
if (this._options.ldrMerge) {
|
|
1237
|
-
defines += "#define LDR \n";
|
|
1238
|
-
}
|
|
1239
|
-
// Effect
|
|
1240
|
-
return this._engine.createEffect("glowMapMerge", [VertexBuffer.PositionKind], ["offset"], ["textureSampler", "textureSampler2"], defines);
|
|
1241
|
-
}
|
|
1242
|
-
/**
|
|
1243
|
-
* Creates the render target textures and post processes used in the glow layer.
|
|
1244
|
-
*/
|
|
1245
|
-
_createTextureAndPostProcesses() {
|
|
1246
|
-
let blurTextureWidth = this._mainTextureDesiredSize.width;
|
|
1247
|
-
let blurTextureHeight = this._mainTextureDesiredSize.height;
|
|
1248
|
-
blurTextureWidth = this._engine.needPOTTextures ? Engine.GetExponentOfTwo(blurTextureWidth, this._maxSize) : blurTextureWidth;
|
|
1249
|
-
blurTextureHeight = this._engine.needPOTTextures ? Engine.GetExponentOfTwo(blurTextureHeight, this._maxSize) : blurTextureHeight;
|
|
1250
|
-
let textureType = 0;
|
|
1251
|
-
if (this._engine.getCaps().textureHalfFloatRender) {
|
|
1252
|
-
textureType = 2;
|
|
1253
|
-
}
|
|
1254
|
-
else {
|
|
1255
|
-
textureType = 0;
|
|
1256
|
-
}
|
|
1257
|
-
this._blurTexture1 = new RenderTargetTexture("GlowLayerBlurRTT", {
|
|
1258
|
-
width: blurTextureWidth,
|
|
1259
|
-
height: blurTextureHeight,
|
|
1260
|
-
}, this._scene, false, true, textureType);
|
|
1261
|
-
this._blurTexture1.wrapU = Texture.CLAMP_ADDRESSMODE;
|
|
1262
|
-
this._blurTexture1.wrapV = Texture.CLAMP_ADDRESSMODE;
|
|
1263
|
-
this._blurTexture1.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);
|
|
1264
|
-
this._blurTexture1.renderParticles = false;
|
|
1265
|
-
this._blurTexture1.ignoreCameraViewport = true;
|
|
1266
|
-
const blurTextureWidth2 = Math.floor(blurTextureWidth / 2);
|
|
1267
|
-
const blurTextureHeight2 = Math.floor(blurTextureHeight / 2);
|
|
1268
|
-
this._blurTexture2 = new RenderTargetTexture("GlowLayerBlurRTT2", {
|
|
1269
|
-
width: blurTextureWidth2,
|
|
1270
|
-
height: blurTextureHeight2,
|
|
1271
|
-
}, this._scene, false, true, textureType);
|
|
1272
|
-
this._blurTexture2.wrapU = Texture.CLAMP_ADDRESSMODE;
|
|
1273
|
-
this._blurTexture2.wrapV = Texture.CLAMP_ADDRESSMODE;
|
|
1274
|
-
this._blurTexture2.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE);
|
|
1275
|
-
this._blurTexture2.renderParticles = false;
|
|
1276
|
-
this._blurTexture2.ignoreCameraViewport = true;
|
|
1277
|
-
this._textures = [this._blurTexture1, this._blurTexture2];
|
|
1278
|
-
const effectiveKernel = this._getEffectiveBlurKernelSize();
|
|
1279
|
-
this._horizontalBlurPostprocess1 = new BlurPostProcess("GlowLayerHBP1", new Vector2(1.0, 0), effectiveKernel, {
|
|
1280
|
-
width: blurTextureWidth,
|
|
1281
|
-
height: blurTextureHeight,
|
|
1282
|
-
}, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, textureType);
|
|
1283
|
-
this._horizontalBlurPostprocess1.width = blurTextureWidth;
|
|
1284
|
-
this._horizontalBlurPostprocess1.height = blurTextureHeight;
|
|
1285
|
-
this._horizontalBlurPostprocess1.externalTextureSamplerBinding = true;
|
|
1286
|
-
this._horizontalBlurPostprocess1.onApplyObservable.add((effect) => {
|
|
1287
|
-
effect.setTexture("textureSampler", this._mainTexture);
|
|
1288
|
-
});
|
|
1289
|
-
this._verticalBlurPostprocess1 = new BlurPostProcess("GlowLayerVBP1", new Vector2(0, 1.0), effectiveKernel, {
|
|
1290
|
-
width: blurTextureWidth,
|
|
1291
|
-
height: blurTextureHeight,
|
|
1292
|
-
}, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, textureType);
|
|
1293
|
-
this._horizontalBlurPostprocess2 = new BlurPostProcess("GlowLayerHBP2", new Vector2(1.0, 0), effectiveKernel, {
|
|
1294
|
-
width: blurTextureWidth2,
|
|
1295
|
-
height: blurTextureHeight2,
|
|
1296
|
-
}, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, textureType);
|
|
1297
|
-
this._horizontalBlurPostprocess2.width = blurTextureWidth2;
|
|
1298
|
-
this._horizontalBlurPostprocess2.height = blurTextureHeight2;
|
|
1299
|
-
this._horizontalBlurPostprocess2.externalTextureSamplerBinding = true;
|
|
1300
|
-
this._horizontalBlurPostprocess2.onApplyObservable.add((effect) => {
|
|
1301
|
-
effect.setTexture("textureSampler", this._blurTexture1);
|
|
1302
|
-
});
|
|
1303
|
-
this._verticalBlurPostprocess2 = new BlurPostProcess("GlowLayerVBP2", new Vector2(0, 1.0), effectiveKernel, {
|
|
1304
|
-
width: blurTextureWidth2,
|
|
1305
|
-
height: blurTextureHeight2,
|
|
1306
|
-
}, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, textureType);
|
|
1307
|
-
this._postProcesses = [this._horizontalBlurPostprocess1, this._verticalBlurPostprocess1, this._horizontalBlurPostprocess2, this._verticalBlurPostprocess2];
|
|
1308
|
-
this._postProcesses1 = [this._horizontalBlurPostprocess1, this._verticalBlurPostprocess1];
|
|
1309
|
-
this._postProcesses2 = [this._horizontalBlurPostprocess2, this._verticalBlurPostprocess2];
|
|
1310
|
-
this._mainTexture.samples = this._options.mainTextureSamples;
|
|
1311
|
-
this._mainTexture.onAfterUnbindObservable.add(() => {
|
|
1312
|
-
const internalTexture = this._blurTexture1.renderTarget;
|
|
1313
|
-
if (internalTexture) {
|
|
1314
|
-
this._scene.postProcessManager.directRender(this._postProcesses1, internalTexture, true);
|
|
1315
|
-
const internalTexture2 = this._blurTexture2.renderTarget;
|
|
1316
|
-
if (internalTexture2) {
|
|
1317
|
-
this._scene.postProcessManager.directRender(this._postProcesses2, internalTexture2, true);
|
|
1318
|
-
}
|
|
1319
|
-
this._engine.unBindFramebuffer(internalTexture2 !== null && internalTexture2 !== void 0 ? internalTexture2 : internalTexture, true);
|
|
1320
|
-
}
|
|
1321
|
-
});
|
|
1322
|
-
// Prevent autoClear.
|
|
1323
|
-
this._postProcesses.map((pp) => {
|
|
1324
|
-
pp.autoClear = false;
|
|
1325
|
-
});
|
|
1326
|
-
}
|
|
1327
|
-
/**
|
|
1328
|
-
* @returns The blur kernel size used by the glow.
|
|
1329
|
-
* Note: The value passed in the options is divided by 2 for back compatibility.
|
|
1330
|
-
*/
|
|
1331
|
-
_getEffectiveBlurKernelSize() {
|
|
1332
|
-
return this._options.blurKernelSize / 2;
|
|
1333
|
-
}
|
|
1334
|
-
/**
|
|
1335
|
-
* Checks for the readiness of the element composing the layer.
|
|
1336
|
-
* @param subMesh the mesh to check for
|
|
1337
|
-
* @param useInstances specify whether or not to use instances to render the mesh
|
|
1338
|
-
* @returns true if ready otherwise, false
|
|
1339
|
-
*/
|
|
1340
|
-
isReady(subMesh, useInstances) {
|
|
1341
|
-
const material = subMesh.getMaterial();
|
|
1342
|
-
const mesh = subMesh.getRenderingMesh();
|
|
1343
|
-
if (!material || !mesh) {
|
|
1344
|
-
return false;
|
|
1345
|
-
}
|
|
1346
|
-
const emissiveTexture = material.emissiveTexture;
|
|
1347
|
-
return super._isReady(subMesh, useInstances, emissiveTexture);
|
|
1348
|
-
}
|
|
1349
|
-
/**
|
|
1350
|
-
* Returns whether or not the layer needs stencil enabled during the mesh rendering.
|
|
1351
|
-
*/
|
|
1352
|
-
needStencil() {
|
|
1353
|
-
return false;
|
|
1354
|
-
}
|
|
1355
|
-
/**
|
|
1356
|
-
* Returns true if the mesh can be rendered, otherwise false.
|
|
1357
|
-
* @param mesh The mesh to render
|
|
1358
|
-
* @param material The material used on the mesh
|
|
1359
|
-
* @returns true if it can be rendered otherwise false
|
|
1360
|
-
*/
|
|
1361
|
-
_canRenderMesh(mesh, material) {
|
|
1362
|
-
return true;
|
|
1363
|
-
}
|
|
1364
|
-
/**
|
|
1365
|
-
* Implementation specific of rendering the generating effect on the main canvas.
|
|
1366
|
-
* @param effect The effect used to render through
|
|
1367
|
-
*/
|
|
1368
|
-
_internalRender(effect) {
|
|
1369
|
-
// Texture
|
|
1370
|
-
effect.setTexture("textureSampler", this._blurTexture1);
|
|
1371
|
-
effect.setTexture("textureSampler2", this._blurTexture2);
|
|
1372
|
-
effect.setFloat("offset", this._intensity);
|
|
1373
|
-
// Cache
|
|
1374
|
-
const engine = this._engine;
|
|
1375
|
-
const previousStencilBuffer = engine.getStencilBuffer();
|
|
1376
|
-
// Draw order
|
|
1377
|
-
engine.setStencilBuffer(false);
|
|
1378
|
-
engine.drawElementsType(Material.TriangleFillMode, 0, 6);
|
|
1379
|
-
// Draw order
|
|
1380
|
-
engine.setStencilBuffer(previousStencilBuffer);
|
|
1381
|
-
}
|
|
1382
|
-
/**
|
|
1383
|
-
* Sets the required values for both the emissive texture and and the main color.
|
|
1384
|
-
* @param mesh
|
|
1385
|
-
* @param subMesh
|
|
1386
|
-
* @param material
|
|
1387
|
-
*/
|
|
1388
|
-
_setEmissiveTextureAndColor(mesh, subMesh, material) {
|
|
1389
|
-
var _a;
|
|
1390
|
-
let textureLevel = 1.0;
|
|
1391
|
-
if (this.customEmissiveTextureSelector) {
|
|
1392
|
-
this._emissiveTextureAndColor.texture = this.customEmissiveTextureSelector(mesh, subMesh, material);
|
|
1393
|
-
}
|
|
1394
|
-
else {
|
|
1395
|
-
if (material) {
|
|
1396
|
-
this._emissiveTextureAndColor.texture = material.emissiveTexture;
|
|
1397
|
-
if (this._emissiveTextureAndColor.texture) {
|
|
1398
|
-
textureLevel = this._emissiveTextureAndColor.texture.level;
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
else {
|
|
1402
|
-
this._emissiveTextureAndColor.texture = null;
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
if (this.customEmissiveColorSelector) {
|
|
1406
|
-
this.customEmissiveColorSelector(mesh, subMesh, material, this._emissiveTextureAndColor.color);
|
|
1407
|
-
}
|
|
1408
|
-
else {
|
|
1409
|
-
if (material.emissiveColor) {
|
|
1410
|
-
const emissiveIntensity = (_a = material.emissiveIntensity) !== null && _a !== void 0 ? _a : 1;
|
|
1411
|
-
textureLevel *= emissiveIntensity;
|
|
1412
|
-
this._emissiveTextureAndColor.color.set(material.emissiveColor.r * textureLevel, material.emissiveColor.g * textureLevel, material.emissiveColor.b * textureLevel, material.alpha);
|
|
1413
|
-
}
|
|
1414
|
-
else {
|
|
1415
|
-
this._emissiveTextureAndColor.color.set(this.neutralColor.r, this.neutralColor.g, this.neutralColor.b, this.neutralColor.a);
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
/**
|
|
1420
|
-
* Returns true if the mesh should render, otherwise false.
|
|
1421
|
-
* @param mesh The mesh to render
|
|
1422
|
-
* @returns true if it should render otherwise false
|
|
1423
|
-
*/
|
|
1424
|
-
_shouldRenderMesh(mesh) {
|
|
1425
|
-
return this.hasMesh(mesh);
|
|
1426
|
-
}
|
|
1427
|
-
/**
|
|
1428
|
-
* Adds specific effects defines.
|
|
1429
|
-
* @param defines The defines to add specifics to.
|
|
1430
|
-
*/
|
|
1431
|
-
_addCustomEffectDefines(defines) {
|
|
1432
|
-
defines.push("#define GLOW");
|
|
1433
|
-
}
|
|
1434
|
-
/**
|
|
1435
|
-
* Add a mesh in the exclusion list to prevent it to impact or being impacted by the glow layer.
|
|
1436
|
-
* @param mesh The mesh to exclude from the glow layer
|
|
1437
|
-
*/
|
|
1438
|
-
addExcludedMesh(mesh) {
|
|
1439
|
-
if (this._excludedMeshes.indexOf(mesh.uniqueId) === -1) {
|
|
1440
|
-
this._excludedMeshes.push(mesh.uniqueId);
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
/**
|
|
1444
|
-
* Remove a mesh from the exclusion list to let it impact or being impacted by the glow layer.
|
|
1445
|
-
* @param mesh The mesh to remove
|
|
1446
|
-
*/
|
|
1447
|
-
removeExcludedMesh(mesh) {
|
|
1448
|
-
const index = this._excludedMeshes.indexOf(mesh.uniqueId);
|
|
1449
|
-
if (index !== -1) {
|
|
1450
|
-
this._excludedMeshes.splice(index, 1);
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Add a mesh in the inclusion list to impact or being impacted by the glow layer.
|
|
1455
|
-
* @param mesh The mesh to include in the glow layer
|
|
1456
|
-
*/
|
|
1457
|
-
addIncludedOnlyMesh(mesh) {
|
|
1458
|
-
if (this._includedOnlyMeshes.indexOf(mesh.uniqueId) === -1) {
|
|
1459
|
-
this._includedOnlyMeshes.push(mesh.uniqueId);
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
/**
|
|
1463
|
-
* Remove a mesh from the Inclusion list to prevent it to impact or being impacted by the glow layer.
|
|
1464
|
-
* @param mesh The mesh to remove
|
|
1465
|
-
*/
|
|
1466
|
-
removeIncludedOnlyMesh(mesh) {
|
|
1467
|
-
const index = this._includedOnlyMeshes.indexOf(mesh.uniqueId);
|
|
1468
|
-
if (index !== -1) {
|
|
1469
|
-
this._includedOnlyMeshes.splice(index, 1);
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
/**
|
|
1473
|
-
* Determine if a given mesh will be used in the glow layer
|
|
1474
|
-
* @param mesh The mesh to test
|
|
1475
|
-
* @returns true if the mesh will be highlighted by the current glow layer
|
|
1476
|
-
*/
|
|
1477
|
-
hasMesh(mesh) {
|
|
1478
|
-
if (!super.hasMesh(mesh)) {
|
|
1479
|
-
return false;
|
|
1480
|
-
}
|
|
1481
|
-
// Included Mesh
|
|
1482
|
-
if (this._includedOnlyMeshes.length) {
|
|
1483
|
-
return this._includedOnlyMeshes.indexOf(mesh.uniqueId) !== -1;
|
|
1484
|
-
}
|
|
1485
|
-
// Excluded Mesh
|
|
1486
|
-
if (this._excludedMeshes.length) {
|
|
1487
|
-
return this._excludedMeshes.indexOf(mesh.uniqueId) === -1;
|
|
1488
|
-
}
|
|
1489
|
-
return true;
|
|
1490
|
-
}
|
|
1491
|
-
/**
|
|
1492
|
-
* Defines whether the current material of the mesh should be use to render the effect.
|
|
1493
|
-
* @param mesh defines the current mesh to render
|
|
1494
|
-
*/
|
|
1495
|
-
_useMeshMaterial(mesh) {
|
|
1496
|
-
if (this._meshesUsingTheirOwnMaterials.length == 0) {
|
|
1497
|
-
return false;
|
|
1498
|
-
}
|
|
1499
|
-
return this._meshesUsingTheirOwnMaterials.indexOf(mesh.uniqueId) > -1;
|
|
1500
|
-
}
|
|
1501
|
-
/**
|
|
1502
|
-
* Add a mesh to be rendered through its own material and not with emissive only.
|
|
1503
|
-
* @param mesh The mesh for which we need to use its material
|
|
1504
|
-
*/
|
|
1505
|
-
referenceMeshToUseItsOwnMaterial(mesh) {
|
|
1506
|
-
mesh.resetDrawCache(this._mainTexture.renderPassId);
|
|
1507
|
-
this._meshesUsingTheirOwnMaterials.push(mesh.uniqueId);
|
|
1508
|
-
mesh.onDisposeObservable.add(() => {
|
|
1509
|
-
this._disposeMesh(mesh);
|
|
1510
|
-
});
|
|
1511
|
-
}
|
|
1512
|
-
/**
|
|
1513
|
-
* Remove a mesh from being rendered through its own material and not with emissive only.
|
|
1514
|
-
* @param mesh The mesh for which we need to not use its material
|
|
1515
|
-
*/
|
|
1516
|
-
unReferenceMeshFromUsingItsOwnMaterial(mesh) {
|
|
1517
|
-
let index = this._meshesUsingTheirOwnMaterials.indexOf(mesh.uniqueId);
|
|
1518
|
-
while (index >= 0) {
|
|
1519
|
-
this._meshesUsingTheirOwnMaterials.splice(index, 1);
|
|
1520
|
-
index = this._meshesUsingTheirOwnMaterials.indexOf(mesh.uniqueId);
|
|
1521
|
-
}
|
|
1522
|
-
mesh.resetDrawCache(this._mainTexture.renderPassId);
|
|
1523
|
-
}
|
|
1524
|
-
/**
|
|
1525
|
-
* Free any resources and references associated to a mesh.
|
|
1526
|
-
* Internal use
|
|
1527
|
-
* @param mesh The mesh to free.
|
|
1528
|
-
* @internal
|
|
1529
|
-
*/
|
|
1530
|
-
_disposeMesh(mesh) {
|
|
1531
|
-
this.removeIncludedOnlyMesh(mesh);
|
|
1532
|
-
this.removeExcludedMesh(mesh);
|
|
1533
|
-
}
|
|
1534
|
-
/**
|
|
1535
|
-
* Gets the class name of the effect layer
|
|
1536
|
-
* @returns the string with the class name of the effect layer
|
|
1537
|
-
*/
|
|
1538
|
-
getClassName() {
|
|
1539
|
-
return "GlowLayer";
|
|
1540
|
-
}
|
|
1541
|
-
/**
|
|
1542
|
-
* Serializes this glow layer
|
|
1543
|
-
* @returns a serialized glow layer object
|
|
1544
|
-
*/
|
|
1545
|
-
serialize() {
|
|
1546
|
-
const serializationObject = SerializationHelper.Serialize(this);
|
|
1547
|
-
serializationObject.customType = "BABYLON.GlowLayer";
|
|
1548
|
-
let index;
|
|
1549
|
-
// Included meshes
|
|
1550
|
-
serializationObject.includedMeshes = [];
|
|
1551
|
-
if (this._includedOnlyMeshes.length) {
|
|
1552
|
-
for (index = 0; index < this._includedOnlyMeshes.length; index++) {
|
|
1553
|
-
const mesh = this._scene.getMeshByUniqueId(this._includedOnlyMeshes[index]);
|
|
1554
|
-
if (mesh) {
|
|
1555
|
-
serializationObject.includedMeshes.push(mesh.id);
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
// Excluded meshes
|
|
1560
|
-
serializationObject.excludedMeshes = [];
|
|
1561
|
-
if (this._excludedMeshes.length) {
|
|
1562
|
-
for (index = 0; index < this._excludedMeshes.length; index++) {
|
|
1563
|
-
const mesh = this._scene.getMeshByUniqueId(this._excludedMeshes[index]);
|
|
1564
|
-
if (mesh) {
|
|
1565
|
-
serializationObject.excludedMeshes.push(mesh.id);
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
return serializationObject;
|
|
1570
|
-
}
|
|
1571
|
-
/**
|
|
1572
|
-
* Creates a Glow Layer from parsed glow layer data
|
|
1573
|
-
* @param parsedGlowLayer defines glow layer data
|
|
1574
|
-
* @param scene defines the current scene
|
|
1575
|
-
* @param rootUrl defines the root URL containing the glow layer information
|
|
1576
|
-
* @returns a parsed Glow Layer
|
|
1577
|
-
*/
|
|
1578
|
-
static Parse(parsedGlowLayer, scene, rootUrl) {
|
|
1579
|
-
const gl = SerializationHelper.Parse(() => new GlowLayer(parsedGlowLayer.name, scene, parsedGlowLayer.options), parsedGlowLayer, scene, rootUrl);
|
|
1580
|
-
let index;
|
|
1581
|
-
// Excluded meshes
|
|
1582
|
-
for (index = 0; index < parsedGlowLayer.excludedMeshes.length; index++) {
|
|
1583
|
-
const mesh = scene.getMeshById(parsedGlowLayer.excludedMeshes[index]);
|
|
1584
|
-
if (mesh) {
|
|
1585
|
-
gl.addExcludedMesh(mesh);
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
// Included meshes
|
|
1589
|
-
for (index = 0; index < parsedGlowLayer.includedMeshes.length; index++) {
|
|
1590
|
-
const mesh = scene.getMeshById(parsedGlowLayer.includedMeshes[index]);
|
|
1591
|
-
if (mesh) {
|
|
1592
|
-
gl.addIncludedOnlyMesh(mesh);
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
return gl;
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
/**
|
|
1599
|
-
* Effect Name of the layer.
|
|
1600
|
-
*/
|
|
1601
|
-
GlowLayer.EffectName = "GlowLayer";
|
|
1602
|
-
/**
|
|
1603
|
-
* The default blur kernel size used for the glow.
|
|
1604
|
-
*/
|
|
1605
|
-
GlowLayer.DefaultBlurKernelSize = 32;
|
|
1606
|
-
/**
|
|
1607
|
-
* The default texture size ratio used for the glow.
|
|
1608
|
-
*/
|
|
1609
|
-
GlowLayer.DefaultTextureRatio = 0.5;
|
|
1610
|
-
__decorate([
|
|
1611
|
-
serialize()
|
|
1612
|
-
], GlowLayer.prototype, "blurKernelSize", null);
|
|
1613
|
-
__decorate([
|
|
1614
|
-
serialize()
|
|
1615
|
-
], GlowLayer.prototype, "intensity", null);
|
|
1616
|
-
__decorate([
|
|
1617
|
-
serialize("options")
|
|
1618
|
-
], GlowLayer.prototype, "_options", void 0);
|
|
1619
|
-
RegisterClass("BABYLON.GlowLayer", GlowLayer);
|
|
1620
|
-
|
|
1621
|
-
export { EffectLayer as E, GlowLayer as G };
|