wnr Posted August 20, 2021 Share Posted August 20, 2021 Hello, I'm working on a 2D infinite world built by destructible quads. The quads are rendered procedurally by using a noise shader + color mapping. This because I want to learn shaders, and have no seams or repeating as the camera moves around. I've managed to implement this and all is well, except for the horrible performance of my naive implementation. I've made an example that captures the gist of my naive implementation, by using n meshes and shaders: https://www.pixiplayground.com/#/edit/kuHFKOZiQsydVdzrP1PrT When I monitored the scene by using Spector.js, I understood that the problem is the meshes not being batched so that each mesh results in a WebGL drawCall. So having n meshes means n drawCalls. I went further to test having n sprites/geometries without shaders, which indeed performs much faster by being batched into a single drawCall. I tried mesh instancing, which did result in only 1 drawCall, but the performance was still really bad. I don't know why, the only difference I noticed is that the function drawElementsInstanced was being used instead of drawElements... After reading many many posts on this forum about batching, I came to the conclusion that I needed to implement my own batching plugin. So I've tried, and here is the result: https://www.pixiplayground.com/#/edit/kTcHxuSMF7wvehlHvpQPY The performance is great, as all meshes are batched into 1 drawCall. However, I get the feeling that this is the wrong approach. Hacking the AbstractBatchRenderer the way I do seems awful, and I'm having a hard time understanding how to handle the uniforms. More specifically, I cannot manage to set my colormap texture uniform correctly, it keeps uploading a white 16x16 texture to WebGL. Also, I don't understand how to send mesh-instance specific uniforms to my plugin shader, like "uWorldPosition" in my example. I would really appreciate some help, as I've banged my head against this for a week now ? Cheers Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.