@Deltakosh
I need a hand here, I’ve spent entirely too much time on trying to squeeze the performance out of babylonjs + webgl for a 3d map, that I expect to run on desktop, laptop, tablet, and mobile. I created the dumbest version that I could, works fine on a desktop, but the next step down on a laptop horrid frame rate.
The biggest issue is there are some meshes in the scene that have some animation, like water, and the rest of the meshes unless you move the map it should be identical to the previous frame(think bitmap caching here)… sure I can stop the water but STILL I can’t get 60 frames even with the static non-moving meshes and sprites!
Here comes my idea… I went and modified babylonjs to pass a flag to the scene.render function called RenderPipelineOptions which simply contains an array of boolean dirty flags for each render group index. In the RenderManager, if the rendergroup is not flagged dirty I completely skip rendering everything in the render group, assuming the layer has been previously rendered and is now in a “bitmap cached” state… I’ve turned off autoClear everywhere I could on the depth, stencils, etc on the scene… I’m able to achieve massive performance boosts by only rendering those when needed… however those render groups STILL get cleared… I went and even modified engine._gl.clear functions to not call and clear as well, and they still ended up cleared…
So here’s where I need a hand…
I decided to implement a cache feature into babylonjs which I think will solve my performance issues… but I’m definitely not a pro at WebGL and camera perspectives etc…
This is what I would like to do pseudo… >
if (renderGroup.cache) {
if(renderGroup.cache.isDirty === true || !renderGroup.cache.texture) {
// creates or updates the cache render target texture that is the smallest texture size for the
// render groups canvas area
renderGroup.renderToCache(renderGroup.cache, …);
}
// draws the cached render target texture to the webgl canvas in the specific rectangle area
// with transparency that the renderGroup covers
renderGroup.renderCache(renderGroup.cache, …)
}
else {
// render normally no cache
renderGroup.render(…);
}
I’m able to render a specific mesh to a render target texture and that on a plane however aspect of the rendering is off, and where specifically to position it etc… able to give me a hand here, I basically want to render to a frame buffer it sounds like, then copy that framebuffer onto the canvas but it’s not so simple as that.
I believe we have to
- Determine size of render group
- Generate the render target texture at the power of two(I’m assuming) to contain the render group
- Generate a plane in the render groups position relative to the camera / canvas space
- Use a shader to draw the render target texture
Seems this would be a great improvement on performance of babylon, thoughts? Did I miss something that already does this?!