Jump to content

Optimizing mirrors performance


dsman
 Share

Recommended Posts

So I have a scene which is genered from imported .babylon model.  Total vertices :58590

 

There's a mesh which I want to apply mirror material. Now initially, the mesh only has 214 vertices heavy. (This mean when imported from model it had only this many vertices. )

 

But If I apply mirror material, the mesh adds up ~58000 vertices (yes 58k).  (I am checking the difference in number Active Vertices in stats by hiding the mesh on which I applied mirror and show it)

 

What's reason in sudden increase of vertices count? And we are applying texture not modifying the mesh vertices data. So why does vertices count goes this high?

 

It is reducing fps by 4th.  What are other things we can do to improve mirror performance ?

 

Link to comment
Share on other sites

I can give you zip file.  But I think it is happening because I am passing entire scene.meshes array  to mirrorMaterial.reflectionTexture.renderList . And that could be reason it is increasing active vertices count to same amount as total vertices in original scene. 

 

But shouldn't  "Active Vertices count "  =  the total vertices in camera view port  + total vertices in mirror view port ? 

Instead of   - " Active vertices count " = the total vertices in the camera view port + total vertices in the scene ?

Link to comment
Share on other sites

So I confirm above is true. (That whatever number of vertices are there in total for all meshes you are adding in renderList property of reflectionTexture , will be added to the Active Vertice count  , no matter how many meshes are being displayed actually inside the mirror for current camera port ) 

 

So this is wrong in my opinion and can be improved. 

 

Now I tried adding only meshes whose vertice count is less than 1000  in the renderList. And the increase in Active Vertice Count is 1000 regardless of what is being shown in the mirror. In one camera view, I see only a plane mesh in the mirror having 10-20 vertices. But still the Active Vertices Count is 1000 more than when I hide mirror mesh. 

 

One more performance problem I encountered: 

 

I have total 39 meshes in scene. Out of which I have 10-15 meshes set as renderList in a mesh's mirror material. Now I generated 400 dynamic Plane meshes by code, each having four vertices (or Six?). And I set all those meshes in the mirror's renderList. The potential  FPS dropped from 200-300 to 40-60.  

 

Here I understand I increased count of meshes in renderList from 10-15 to  410-415 . But the total number of vertices from all newly added dynamic meshes is very small. Like around 2k. So why such sudden drop in potential FPS. 

Link to comment
Share on other sites

Active vertices are the number of vertices sent to the GPU. The viewport is not computed on the CPU so there is no way to know the PRECISE number of vertices drawn.

 

For your second question: a big number of small meshes is counter-efficient because it breaks the GPU pipeline (GPU prefer a big bunch of vertices instead of a big number of draw calls)

Link to comment
Share on other sites

@Deltakosh

I understood little of what you said about CPU/GPU. But I am intrigued at how mirror adds up all vertices in all meshes given in RenderList   " Active Vertices Count"  regardless of how many meshes are currently being displayed in the mirror. 

 

Suppose I have set 15 meshes (with 1000 vertices each) in the RenderList of mirror material. Now my camera is positioned such that mirror only shows reflection of 1 mesh out of 15 in its RenderList. So in this case only 1000 vertices should be added to the " Active Vertices Count"  Right ? or No ? Currently in such case, it adds all 15 * 1000 = 15000 vertices to " Active Vertices Count" , regardless of the fact that mirror only shows 1 mesh  out of 15 and not all 15. 

 

So same logic that applies for camera view isn't applied to mirror basically. In case of camera view, " Active Vertices Count"  considers only # of vertices in the meshes which are viewable in current camera viewport. 

 

.............

About my second question, What are my option to reduce number of draw call in such case ?  I am generating separate dynamic mesh by code, because I need to place them at certain position and apply separate texture to each.  Can this be done with any alternate method with better performance ?

Link to comment
Share on other sites

Suppose I have set 15 meshes (with 1000 vertices each) in the RenderList of mirror material. Now my camera is positioned such that mirror only shows reflection of 1 mesh out of 15 in its RenderList

 

In this case ALL meshes will be sent to the GPU as there is no frustum clipping / occlusion testing done on the CPU. So 1000*15 vertices will be added.

 

For your second question, you should think about merging your meshes into a bigger one

Link to comment
Share on other sites

Can someone point to specific thing I should be looking for here ? 

 

I saw "Merging Meshes"  article (Link below) . But it will make one mesh out of multiple mesh I guess. And I will have no way to separately apply transform  later on. 

http://doc.babylonjs.com/page.php?p=22451

 

I saw " Creating Instances" article  (Link below). But in that case I can't have meshes of different type having different texture instantiated from a mesh. 

http://doc.babylonjs.com/page.php?p=22571

 

Is mesh grouping entirely different thing ? Any pointer ?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...