Sign in to follow this  
jerome

Mesh Facet Depth Sort

Recommended Posts

Hi ladies and Gentlemen,

Here comes a new feature in the FacetData pack.

As you may know, for performance reasons, the facets of a given mesh are always drawn in the same order. This comes to visual issues when the mesh is transparent and is no longer oriented in the right place from the camera :

http://playground.babylonjs.com/#FWKUY0

This new feature solves the self transparency issue by sorting the mesh facets from some location (the camera position by default) just before drawing them.  
The mesh is required to be updatable.  
The depth sort is done on each call to updateFacetData(). It can be disabled at any time to save CPU cycles if the mesh and the camera don't move any more.  
Usage :

    // the mesh must be updatable
    var mesh = BABYLON.MeshBuilder.CreateTorusKnot("mesh", {updatable: true}, scene);
    mesh.material = mat;                         // transparent material
    mesh.mustDepthSortFacets = true;             // enable the depth sort, can be disabled at any time
    
    scene.registerBeforeRender(function() {
        mesh.updateFacetData();     // sort the facets each frame
    });

Note that this feature uses more memory and more CPU than an usual standard mesh.

 

Please wait for the code review and the PR to be merged and to be pushed in the PG.  Demo : http://jerome.bousquie.fr/BJS/test/facetDepthSort.html

Share this post


Link to post
Share on other sites

I will add the doc in the FacetData section and also in this doc : http://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered#concave-meshes-and-transparency

As I can see, the CPU depth sort seems a bit better (but probably slower) than the GPU DepthPrePass because the transparent mesh keeps  then visible through itself, what is not got with DepthPrePass (try to see the torus through itself).

DepthPrePass : https://www.babylonjs-playground.com/#1PLV5Z#19

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.