hey team,
I have setup almost 50 identical custom materials, for example one material is like this:
var mat1= new BABYLON.CustomMaterial("mat1", scene);
mat1.diffuseTexture = new BABYLON.Texture("/assets/mat1.png" scene);
mat1.AddAttribute("tileOffset");
mat1.Vertex_Definitions(`
attribute vec4 tileOffset;
varying vec4 vtileOffset;
`);
mat1.Vertex_MainEnd(`
vtileOffset = tileOffset;
`);
mat1.Fragment_Definitions(`
varying vec4 vtileOffset;
`);
mat1.Fragment_Custom_Diffuse(`
float fx = clamp(fract(vDiffuseUV.x), 0., 1.), fy = clamp(fract(vDiffuseUV.y), 0., 1.);
vec2 uvCoord = vec2(vtileOffset.x + fx * vtileOffset.z, vtileOffset.y + fy * vtileOffset.w);
baseColor = texture2D(diffuseSampler, uvCoord);
`);
All of my 50 materials are using same above snippet (for atlas, each diffuseTexture is 1024X1024 and has 64X64 atlas image) except diffuseTexture is different, ie:
mat2.diffuseTexture = new BABYLON.Texture("/assets/mat2.png" scene);
mat3.diffuseTexture = new BABYLON.Texture("/assets/mat3.png" scene);
is there a way I could optimise this? like just same material but with different diffuseTexture?
@Evgeni_Popov any idea for this?
Thanks