Thank you for the quick reply, I’ve just tried what you said and its not throwing any errors, but it doesn’t show my texture on the ball, just the standard white physical shader.
uniform sampler2D faceImage;
uniform sampler2D mask;
uniform float linecolour_r;
uniform float linecolour_g;
uniform float linecolour_b;
uniform float ballcolour_r;
uniform float ballcolour_g;
uniform float ballcolour_b;
void getAlbedo(inout psInternalData data)
{
vec4 maskTex = texture2D(mask, $UV);
vec4 faceImageTex = texture2D(faceImage, $UV);
vec4 ballColor = vec4(ballcolour_r, ballcolour_g, ballcolour_b, 1);
vec4 lineColor = vec4(linecolour_r, linecolour_g, linecolour_b, 1);
data.albedo = (mix( mix( mix( ballColor, faceImageTex, maskTex.r), lineColor, maskTex.g), lineColor, maskTex.b)).rgb;
}
and in my script, I configure it like so:
pc.script.attribute("fs", "asset", null, {displayName: "Mask Shader", type: "shader", max:1});
pc.script.attribute("mask", "asset", null, {displayName: 'Mask', type: 'texture', max: 1});
pc.script.attribute("face", "asset", null, {displayName: 'Face', type: 'texture', max: 1});
pc.script.attribute("linecolor", "rgba", null, {displayName: 'Line Colour', type: 'rgba', max: 1});
pc.script.attribute("ballcolor", "rgba", null, {displayName: 'Ball Colour', type: 'rgba', max: 1});
...
initialize: function () {
var model = this.entity.model.model;
var maskTexture = app.assets.get(this.mask).resource;
var faceTexture = app.assets.get(this.face).resource;
var fragmentShader = app.assets.get(this.fs).resource;
model.meshInstances[0].material.chunks.diffuseTexPS = fragmentShader
model.meshInstances[0].material.setParameter("mask", maskTexture);
model.meshInstances[0].material.setParameter("faceImage", faceTexture);
model.meshInstances[0].material.setParameter("ballcolour_r", this.ballcolor.r);
model.meshInstances[0].material.setParameter("ballcolour_g", this.ballcolor.g);
model.meshInstances[0].material.setParameter("ballcolour_b", this.ballcolor.b);
model.meshInstances[0].material.setParameter("linecolour_r", this.linecolor.r);
model.meshInstances[0].material.setParameter("linecolour_g", this.linecolor.g);
model.meshInstances[0].material.setParameter("linecolour_b", this.linecolor.b);
model.meshInstances[0].material.update();
}