Sign in to follow this  

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 :

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 :

Share this post

Link to post
Share on other sites

I will add the doc in the FacetData section and also in this doc :

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 :

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.