Looking at your code might be even simpler, if you don’t clone the original material, and just override it, you might not need to find the batched mesh instances and reassign the material.
I’m currently trying to find the Batch. I see that you can get the Batch Group using app.batcher.getGroupByName BUT, that doesn’t reference the Batch in any way, it’s just the Batch Group that you create using the editor.
No idea how to find the actual batch and access its meshInstance.
Yeah, i’ve progressed a tad after that post. But still got nowhere tbh.
I set the console log to delay by 1 second, then I could access the properties. HOWEVER, setting the material shader params like I would set it on the individual mesh Instances material, doesn’t seem to work, it doesn’t do anything.
The material that the batch uses is correct and has the custom shader chunks, but still it doesn’t get the parameter updates.
Actually, the transformVS (vertex shader chunk) isn’t correct, it has been overriden to default.
When I try to set it directly on the batch meshInstance, the mesh disappears from the scene.
When I try to set it to a temporary material and then set the material to the batch meshInstance, the same happens…
So apparently checking “Dynamic” in the Batch Group is only for Skinned Meshes, that’s why it was crashing and disappearing when I placed my grass vertex shader.
I thought “Dynamic” was to be set for all moving objects.
So I still don’t know why my vertex shader crashes when checking as “Dynamic”. I will continue testing and researching today.
Worst case is we can’t use Dynamic batching with custom shader chunks, and have to do all of the orientation stuff on the vertex shader, also have to research how to do that.
Okay this time it’s 100% fixed. Grass is running on Dynamic batching and I’m still doing billboarding with lookAt instead of doing it in the vertex shader.
However I have to figure out how to do billboarding in the vertex shader because the lookAt function is taking a lot of time with thousands and thousands of grass quads.
Before, rendering 500 grass quads would result in very bad framerate. now 5000 is still playable.
Gonna keep improving, let’s see if doing billboarding on the shader lets me up that number even more.
Hey, you’re free to use this “as is”. It was an experiment and it includes:
Procedural mesh generation.
Shader animation.
I don’t think you’ll be able to use it easily because it’s all kinda hacked together in a messy way. But if it can educate you into how to approach grass with this engine, you’re completely free to fork, study the code, and do whatever you please with it
I have plans of eventually releasing a proper grass system plugin when the PlayCanvas Team updates the Asset Store to allow for more stuff to be in etc.