My goal is to alter diffuse color of pixels according to position of the pixel in the model.
My current solution is as follows:
I’ve replaced “transformVS” chunk with my own code. My code is almost the same as the original one (transform.vert). The only difference is I’ve added varying vPosition and stored vertex_position in it.
I’ve replaced “diffuseTexPS” chunk with my own code which calculates dAlbedo according to value of vPosition.
This works fine with non batched models but it doesn’t work with batched ones.
It looks like batched models completely ignore my custom vertex shader code (“transformVS” chunk) and they use the original code. Also it looks like I can’t use any custom uniforms in my fragment shader code in “diffuseTexPS” chunk - my code in “diffuseTexPS” chunk still runs but my uniforms doesn’t have correct values.
You can definitely use custom shaders or override shder chunks on batched models. The batcher will group the mesh instances based on their material/shader and same uniform values.
I am not sure why your shader changes aren’t respected after the batcher runs, most likely a race condition or something. You can easily get a reference to the material used by any batch group and further override its shader after the batcher ran. That will be automatically applied to all of the mesh instances included in that batch group.
var batches = this.app.batcher._batchList;
var material = batch.meshInstance.material;
// this is the material used by this batch instance