Skip to content

Commit

Permalink
Fix Add Color Uniform of CustomMaterial & PBRCustomMaterial (#14558)
Browse files Browse the repository at this point in the history
  • Loading branch information
Starryi committed Nov 29, 2023
1 parent 2a5c63f commit b2e91ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/dev/materials/src/custom/customMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { StandardMaterial } from "core/Materials/standardMaterial";
import type { Mesh } from "core/Meshes/mesh";
import type { Scene } from "core/scene";
import { RegisterClass } from "core/Misc/typeStore";
import { Color3, Color4 } from "core/Maths/math.color";

export class CustomShaderStructure {
public FragmentStore: string;
Expand Down Expand Up @@ -71,8 +72,17 @@ export class CustomMaterial extends StandardMaterial {
if (ea[0] == "vec2") {
effect.setVector2(ea[1], this._newUniformInstances[el]);
} else if (ea[0] == "vec3") {
effect.setVector3(ea[1], this._newUniformInstances[el]);
if (this._newUniformInstances[el] instanceof Color3) {
effect.setColor3(ea[1], this._newUniformInstances[el]);
} else {
effect.setVector3(ea[1], this._newUniformInstances[el]);
}
} else if (ea[0] == "vec4") {
if (this._newUniformInstances[el] instanceof Color4) {
effect.setDirectColor4(ea[1], this._newUniformInstances[el]);
} else {
effect.setVector4(ea[1], this._newUniformInstances[el]);
}
effect.setVector4(ea[1], this._newUniformInstances[el]);
} else if (ea[0] == "mat4") {
effect.setMatrix(ea[1], this._newUniformInstances[el]);
Expand Down
12 changes: 11 additions & 1 deletion packages/dev/materials/src/custom/pbrCustomMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Scene } from "core/scene";
import { RegisterClass } from "core/Misc/typeStore";
import { ShaderCodeInliner } from "core/Engines/Processors/shaderCodeInliner";
import type { ICustomShaderNameResolveOptions } from "core/Materials/material";
import { Color3, Color4 } from "core/Maths/math.color";

export class ShaderAlbedoParts {
constructor() {}
Expand Down Expand Up @@ -77,8 +78,17 @@ export class PBRCustomMaterial extends PBRMaterial {
if (ea[0] == "vec2") {
effect.setVector2(ea[1], this._newUniformInstances[el]);
} else if (ea[0] == "vec3") {
effect.setVector3(ea[1], this._newUniformInstances[el]);
if (this._newUniformInstances[el] instanceof Color3) {
effect.setColor3(ea[1], this._newUniformInstances[el]);
} else {
effect.setVector3(ea[1], this._newUniformInstances[el]);
}
} else if (ea[0] == "vec4") {
if (this._newUniformInstances[el] instanceof Color4) {
effect.setDirectColor4(ea[1], this._newUniformInstances[el]);
} else {
effect.setVector4(ea[1], this._newUniformInstances[el]);
}
effect.setVector4(ea[1], this._newUniformInstances[el]);
} else if (ea[0] == "mat4") {
effect.setMatrix(ea[1], this._newUniformInstances[el]);
Expand Down

0 comments on commit b2e91ba

Please sign in to comment.