OK so I have successfully been able to extend materials to use the same image for diffuse/normal/specular maps. My next step was to use the same image also for all diffuse variants.
This is an example image: https://www.titansoftime.com/stitchtextures2/118_2048.jpg
I got this working by cloning the cached base material. The clone method had some draw backs. For one initial scene rendering took forever. Like way too long. So to get around this I used a method that I found in a discussion on github regarding per object uniforms.
This SO post contains a similar question. WestLangley’s solution was to clone the material and not worry about it. This may be ok in small little demo’s but in large applications it’s not ideal on the CPU side although GPU side seems ok.
The second solution from Elias (which I also read about on github here: https://github.com/mrdoob/three.js/issues/9741) is imo the better way to go.
Problem… I cannot seem to get this to work correctly. With only one object being rendered at a time, it works fine. But when two objects sharing a material but with different uniforms set by
onBeforeRender, it breaks down.
Here is a live demonstration (pan the camera to screen left, so that only the left most Mesh is on screen and you will see what I mean).
What am I doing wrong? I’ve tried and tried.