|
@@ -614,27 +614,29 @@ export class ShaderMaterial extends Material {
|
|
/**
|
|
/**
|
|
* Binds the world matrix to the material
|
|
* Binds the world matrix to the material
|
|
* @param world defines the world transformation matrix
|
|
* @param world defines the world transformation matrix
|
|
|
|
+ * @param effectOverride - If provided, use this effect instead of internal effect
|
|
*/
|
|
*/
|
|
- public bindOnlyWorldMatrix(world: Matrix): void {
|
|
|
|
|
|
+ public bindOnlyWorldMatrix(world: Matrix, effectOverride?: Nullable<Effect>): void {
|
|
var scene = this.getScene();
|
|
var scene = this.getScene();
|
|
|
|
|
|
- if (!this._effect) {
|
|
|
|
|
|
+ const effect = effectOverride ?? this._effect;
|
|
|
|
+
|
|
|
|
+ if (!effect) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
if (this._options.uniforms.indexOf("world") !== -1) {
|
|
if (this._options.uniforms.indexOf("world") !== -1) {
|
|
- this._effect.setMatrix("world", world);
|
|
|
|
|
|
+ effect.setMatrix("world", world);
|
|
}
|
|
}
|
|
|
|
|
|
if (this._options.uniforms.indexOf("worldView") !== -1) {
|
|
if (this._options.uniforms.indexOf("worldView") !== -1) {
|
|
world.multiplyToRef(scene.getViewMatrix(), this._cachedWorldViewMatrix);
|
|
world.multiplyToRef(scene.getViewMatrix(), this._cachedWorldViewMatrix);
|
|
- this._effect.setMatrix("worldView", this._cachedWorldViewMatrix);
|
|
|
|
|
|
+ effect.setMatrix("worldView", this._cachedWorldViewMatrix);
|
|
}
|
|
}
|
|
|
|
|
|
if (this._options.uniforms.indexOf("worldViewProjection") !== -1) {
|
|
if (this._options.uniforms.indexOf("worldViewProjection") !== -1) {
|
|
world.multiplyToRef(scene.getTransformMatrix(), this._cachedWorldViewProjectionMatrix);
|
|
world.multiplyToRef(scene.getTransformMatrix(), this._cachedWorldViewProjectionMatrix);
|
|
- this._effect.setMatrix("worldViewProjection", this._cachedWorldViewProjectionMatrix);
|
|
|
|
-
|
|
|
|
|
|
+ effect.setMatrix("worldViewProjection", this._cachedWorldViewProjectionMatrix);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -643,138 +645,142 @@ export class ShaderMaterial extends Material {
|
|
* @param world defines the world transformation matrix
|
|
* @param world defines the world transformation matrix
|
|
* @param mesh defines the mesh containing the submesh
|
|
* @param mesh defines the mesh containing the submesh
|
|
* @param subMesh defines the submesh to bind the material to
|
|
* @param subMesh defines the submesh to bind the material to
|
|
|
|
+ * @param effectOverride - If provided, use this effect instead of internal effect
|
|
*/
|
|
*/
|
|
- public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {
|
|
|
|
- this.bind(world, mesh);
|
|
|
|
|
|
+ public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh, effectOverride?: Nullable<Effect>): void {
|
|
|
|
+ this.bind(world, mesh, effectOverride);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Binds the material to the mesh
|
|
* Binds the material to the mesh
|
|
* @param world defines the world transformation matrix
|
|
* @param world defines the world transformation matrix
|
|
* @param mesh defines the mesh to bind the material to
|
|
* @param mesh defines the mesh to bind the material to
|
|
|
|
+ * @param effectOverride - If provided, use this effect instead of internal effect
|
|
*/
|
|
*/
|
|
- public bind(world: Matrix, mesh?: Mesh): void {
|
|
|
|
|
|
+ public bind(world: Matrix, mesh?: Mesh, effectOverride?: Nullable<Effect>): void {
|
|
// Std values
|
|
// Std values
|
|
- this.bindOnlyWorldMatrix(world);
|
|
|
|
|
|
+ this.bindOnlyWorldMatrix(world, effectOverride);
|
|
|
|
+
|
|
|
|
+ const effect = effectOverride ?? this._effect;
|
|
|
|
|
|
- if (this._effect && this.getScene().getCachedMaterial() !== this) {
|
|
|
|
|
|
+ if (effect && this.getScene().getCachedMaterial() !== this) {
|
|
if (this._options.uniforms.indexOf("view") !== -1) {
|
|
if (this._options.uniforms.indexOf("view") !== -1) {
|
|
- this._effect.setMatrix("view", this.getScene().getViewMatrix());
|
|
|
|
|
|
+ effect.setMatrix("view", this.getScene().getViewMatrix());
|
|
}
|
|
}
|
|
|
|
|
|
if (this._options.uniforms.indexOf("projection") !== -1) {
|
|
if (this._options.uniforms.indexOf("projection") !== -1) {
|
|
- this._effect.setMatrix("projection", this.getScene().getProjectionMatrix());
|
|
|
|
|
|
+ effect.setMatrix("projection", this.getScene().getProjectionMatrix());
|
|
}
|
|
}
|
|
|
|
|
|
if (this._options.uniforms.indexOf("viewProjection") !== -1) {
|
|
if (this._options.uniforms.indexOf("viewProjection") !== -1) {
|
|
- this._effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
|
|
|
|
|
|
+ effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
|
|
if (this._multiview) {
|
|
if (this._multiview) {
|
|
- this._effect.setMatrix("viewProjectionR", this.getScene()._transformMatrixR);
|
|
|
|
|
|
+ effect.setMatrix("viewProjectionR", this.getScene()._transformMatrixR);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (this.getScene().activeCamera && this._options.uniforms.indexOf("cameraPosition") !== -1) {
|
|
if (this.getScene().activeCamera && this._options.uniforms.indexOf("cameraPosition") !== -1) {
|
|
- this._effect.setVector3("cameraPosition", this.getScene().activeCamera!.globalPosition);
|
|
|
|
|
|
+ effect.setVector3("cameraPosition", this.getScene().activeCamera!.globalPosition);
|
|
}
|
|
}
|
|
|
|
|
|
// Bones
|
|
// Bones
|
|
- MaterialHelper.BindBonesParameters(mesh, this._effect);
|
|
|
|
|
|
+ MaterialHelper.BindBonesParameters(mesh, effect);
|
|
|
|
|
|
var name: string;
|
|
var name: string;
|
|
// Texture
|
|
// Texture
|
|
for (name in this._textures) {
|
|
for (name in this._textures) {
|
|
- this._effect.setTexture(name, this._textures[name]);
|
|
|
|
|
|
+ effect.setTexture(name, this._textures[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Texture arrays
|
|
// Texture arrays
|
|
for (name in this._textureArrays) {
|
|
for (name in this._textureArrays) {
|
|
- this._effect.setTextureArray(name, this._textureArrays[name]);
|
|
|
|
|
|
+ effect.setTextureArray(name, this._textureArrays[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Int
|
|
// Int
|
|
for (name in this._ints) {
|
|
for (name in this._ints) {
|
|
- this._effect.setInt(name, this._ints[name]);
|
|
|
|
|
|
+ effect.setInt(name, this._ints[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Float
|
|
// Float
|
|
for (name in this._floats) {
|
|
for (name in this._floats) {
|
|
- this._effect.setFloat(name, this._floats[name]);
|
|
|
|
|
|
+ effect.setFloat(name, this._floats[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Floats
|
|
// Floats
|
|
for (name in this._floatsArrays) {
|
|
for (name in this._floatsArrays) {
|
|
- this._effect.setArray(name, this._floatsArrays[name]);
|
|
|
|
|
|
+ effect.setArray(name, this._floatsArrays[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Color3
|
|
// Color3
|
|
for (name in this._colors3) {
|
|
for (name in this._colors3) {
|
|
- this._effect.setColor3(name, this._colors3[name]);
|
|
|
|
|
|
+ effect.setColor3(name, this._colors3[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Color3Array
|
|
// Color3Array
|
|
for (name in this._colors3Arrays) {
|
|
for (name in this._colors3Arrays) {
|
|
- this._effect.setArray3(name, this._colors3Arrays[name]);
|
|
|
|
|
|
+ effect.setArray3(name, this._colors3Arrays[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Color4
|
|
// Color4
|
|
for (name in this._colors4) {
|
|
for (name in this._colors4) {
|
|
var color = this._colors4[name];
|
|
var color = this._colors4[name];
|
|
- this._effect.setFloat4(name, color.r, color.g, color.b, color.a);
|
|
|
|
|
|
+ effect.setFloat4(name, color.r, color.g, color.b, color.a);
|
|
}
|
|
}
|
|
|
|
|
|
// Color4Array
|
|
// Color4Array
|
|
for (name in this._colors4Arrays) {
|
|
for (name in this._colors4Arrays) {
|
|
- this._effect.setArray4(name, this._colors4Arrays[name]);
|
|
|
|
|
|
+ effect.setArray4(name, this._colors4Arrays[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Vector2
|
|
// Vector2
|
|
for (name in this._vectors2) {
|
|
for (name in this._vectors2) {
|
|
- this._effect.setVector2(name, this._vectors2[name]);
|
|
|
|
|
|
+ effect.setVector2(name, this._vectors2[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Vector3
|
|
// Vector3
|
|
for (name in this._vectors3) {
|
|
for (name in this._vectors3) {
|
|
- this._effect.setVector3(name, this._vectors3[name]);
|
|
|
|
|
|
+ effect.setVector3(name, this._vectors3[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Vector4
|
|
// Vector4
|
|
for (name in this._vectors4) {
|
|
for (name in this._vectors4) {
|
|
- this._effect.setVector4(name, this._vectors4[name]);
|
|
|
|
|
|
+ effect.setVector4(name, this._vectors4[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Matrix
|
|
// Matrix
|
|
for (name in this._matrices) {
|
|
for (name in this._matrices) {
|
|
- this._effect.setMatrix(name, this._matrices[name]);
|
|
|
|
|
|
+ effect.setMatrix(name, this._matrices[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// MatrixArray
|
|
// MatrixArray
|
|
for (name in this._matrixArrays) {
|
|
for (name in this._matrixArrays) {
|
|
- this._effect.setMatrices(name, this._matrixArrays[name]);
|
|
|
|
|
|
+ effect.setMatrices(name, this._matrixArrays[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Matrix 3x3
|
|
// Matrix 3x3
|
|
for (name in this._matrices3x3) {
|
|
for (name in this._matrices3x3) {
|
|
- this._effect.setMatrix3x3(name, this._matrices3x3[name]);
|
|
|
|
|
|
+ effect.setMatrix3x3(name, this._matrices3x3[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Matrix 2x2
|
|
// Matrix 2x2
|
|
for (name in this._matrices2x2) {
|
|
for (name in this._matrices2x2) {
|
|
- this._effect.setMatrix2x2(name, this._matrices2x2[name]);
|
|
|
|
|
|
+ effect.setMatrix2x2(name, this._matrices2x2[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Vector2Array
|
|
// Vector2Array
|
|
for (name in this._vectors2Arrays) {
|
|
for (name in this._vectors2Arrays) {
|
|
- this._effect.setArray2(name, this._vectors2Arrays[name]);
|
|
|
|
|
|
+ effect.setArray2(name, this._vectors2Arrays[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Vector3Array
|
|
// Vector3Array
|
|
for (name in this._vectors3Arrays) {
|
|
for (name in this._vectors3Arrays) {
|
|
- this._effect.setArray3(name, this._vectors3Arrays[name]);
|
|
|
|
|
|
+ effect.setArray3(name, this._vectors3Arrays[name]);
|
|
}
|
|
}
|
|
|
|
|
|
// Vector4Array
|
|
// Vector4Array
|
|
for (name in this._vectors4Arrays) {
|
|
for (name in this._vectors4Arrays) {
|
|
- this._effect.setArray4(name, this._vectors4Arrays[name]);
|
|
|
|
|
|
+ effect.setArray4(name, this._vectors4Arrays[name]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|