Jump to content

Z sorting issue with createInstance


0l4f
 Share

Recommended Posts

Hello forum!

First post here, and I'm starting off with -probably- a newbie question:

I'm trying to optimize an experiment that uses a lot of textured planes, cloned with createInstance, but I'm getting weird z-sorting issues - as you can see here:

http://rocketclowns.com/canvas/babylon2/

 

The leaves are created with createInstance, like this:

var leavesMaterial = new BABYLON.StandardMaterial("leavesTexture", scene);
leavesMaterial.diffuseTexture = new BABYLON.Texture("textures/viny_leaves.png", scene);
leavesMaterial.diffuseTexture.hasAlpha = true;
leavesMaterial.useAlphaFromDiffuseTexture = true;

var leaves = BABYLON.Mesh.CreatePlane("plane", 75.0, scene);
leaves.scaling.y = 0.71;
leaves.material = leavesMaterial;

for (var l = 0; l < 128; l++) {			

    var newLeavesInstance = leaves.createInstance("iLeaves" + l);

    newLeavesInstance.position.x = 32 + Math.random() * 96;
    newLeavesInstance.position.z = Math.random() * 256;
}

 

Am I overlooking something that causes the weird z-sorting behaviour?

 

Many thanks in advance :)

Link to comment
Share on other sites

Narrowed it down: z-sorting issue only occurs with 

useAlphaFromDiffuseTexture = true

in combination with

createInstance

 

I've attached an image showing the behaviour.

 

Is this a bug?

Is there a workaround for this scenario?

 

Thanks again!

instancesBug.jpg

Link to comment
Share on other sites

Hey jerome and adam, thanks for the info!

The link jerome posted clears up a lot, especially this part:

  • Avoid having heavily-stretched alpha blended meshes (i.e. large planes); since the center of its bounding sphere is used for depth sorting, doing this may result in a mesh being sorted as far away from the camera but actually closer to many other meshes.

I think that's what we're seeing here?

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...