BlackMojito Posted February 6, 2018 Share Posted February 6, 2018 Hi Folks, Just by curiosity, how do we avoid expensive glUseProgram calls internally in Babylonjs? Do we sort meshes by shader so that we can minimize shader changes? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 6, 2018 Share Posted February 6, 2018 Yes, in BJS terminology, having scene.meshes in order by mesh.material has been mentioned before as desireable. I am not sure how much this helps though. To be honest, I think you can get all of this plus the JS overheard for each mesh calling BABYLON.Mesh.Merge() for meshes of the same material. You also avoid the draw calls too! This works as long as the individual meshes do not move rotate independently. Quote Link to comment Share on other sites More sharing options...
Guest Posted February 6, 2018 Share Posted February 6, 2018 You can provide your own sorting function for opaque meshes if you want: http://doc.babylonjs.com/classes/3.1/scene#setrenderingorder-renderinggroupid-opaquesortcomparefn-alphatestsortcomparefn-transparentsortcomparefn-rarr-void This is not done by default as most of the time JS code is FAR slower than internal glUseProgram call Quote Link to comment Share on other sites More sharing options...
BlackMojito Posted February 7, 2018 Author Share Posted February 7, 2018 6 hours ago, Deltakosh said: You can provide your own sorting function for opaque meshes if you want: http://doc.babylonjs.com/classes/3.1/scene#setrenderingorder-renderinggroupid-opaquesortcomparefn-alphatestsortcomparefn-transparentsortcomparefn-rarr-void This is not done by default as most of the time JS code is FAR slower than internal glUseProgram call Is the sorting done only once then the new order will always be used from that moment, or we need to execute sorting every frame ? As my meshes are mostly static. Is the sorting is done only once, it will be so cool for me Quote Link to comment Share on other sites More sharing options...
BlackMojito Posted February 7, 2018 Author Share Posted February 7, 2018 7 hours ago, JCPalmer said: Yes, in BJS terminology, having scene.meshes in order by mesh.material has been mentioned before as desireable. I am not sure how much this helps though. To be honest, I think you can get all of this plus the JS overheard for each mesh calling BABYLON.Mesh.Merge() for meshes of the same material. You also avoid the draw calls too! This works as long as the individual meshes do not move rotate independently. Yes sir but I need to handle highlighting and selection too. This meas I need to maintain two scene graphs ? For big models I am not sure if the limited browser memory can allow it Quote Link to comment Share on other sites More sharing options...
Guest Posted February 7, 2018 Share Posted February 7, 2018 You can then directly sort the scene.meshes array manually Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.