I have used the following curved world shader in the game.
https://playcanvas.com/editor/scene/1353984
Problem : Curve shader works with static batching but does not work with dynamic batching.
Here is the test project for the issue.
https://playcanvas.com/editor/scene/1837572
Hi @yash_mehrotra ,
That’s correct, when enabling dynamic batching the engine overrides the curved world transform chunk removing the effect. Sadly currently there isn’t any elegant way around that. There is a feature request on this:
opened 09:45AM - 05 Jun 18 UTC
area: graphics
The current batching.js has rather unnecessary `this` references to global pc.s… haderChunks defaults.
this.transformVS = boneLimit + "#define DYNAMICBATCH\n" + pc.shaderChunks.transformVS;
this.skinTexVS = pc.shaderChunks.skinBatchTexVS;
this.skinConstVS = pc.shaderChunks.skinBatchConstVS;
It prevents custom vertex shader chunks to work with dynamic batching....since it re-overwrites them back to defaults!
if (dynamic) {
// Patch the material
material = material.clone();
material.chunks.transformVS = this.transformVS;
material.chunks.skinTexVS = this.skinTexVS;
material.chunks.skinConstVS = this.skinConstVS;
material.update();
}
why not: save the device boneLimit if needed....and then...
if (dynamic) {
// Patch the material
material = material.clone();
material.chunks.transformVS = boneLimit + "#define DYNAMICBATCH\n" + (material.chunks.transformVS ? material.chunks.transformVS : pc.shaderChunks.transformVS);// this.transformVS;
material.chunks.skinTexVS = (material.chunks.skinBatchTexVS ? material.chunks.skinBatchTexVS : pc.shaderChunks.skinBatchTexVS);
material.chunks.skinConstVS = (material.chunks.skinBatchConstVS ? material.chunks.skinBatchConstVS : pc.shaderChunks.skinBatchConstVS);
material.update();
}
That way, you check if there's any available custom implementations of those chunks before the batching occurs.
The tricky thing is he might assign Batch group within editor, and then sets material custom chunk later during a script.initialize() ...but he will need some way of informing the batch group to re-update, which can be tricky... Anyway of syncronising these aspects between custom vertex shader chunk settings and batching intialization? I see no way short of manually triggering the batching except by code or manual intiialization of batches by having batched entities within scene remain disabled first. Set custom vertex shader chunks first, then call batching manager to re-update. #
1 Like