Jump to content

Strange happenings with hasVertexAlpha and DOUBLESIDE


JohnK
 Share

Recommended Posts

In trying to create a PG to solve another topic I came across the strange phenomenon (well it might not be strange just not what I expected) 

Having used MeshBuilder to create some small boxes and  big box to fit them in I decided to make the box lidless by making the top transparent.

Did this by setting a faceColor for the top face as

faceColors[4] = new BABYLON.Color4(0,0,0,0);

and realised that I then needed to set hasVertexAlpha to be true for the bigbox. http://www.babylonjs-playground.com/#1KH9RY#6

but the the rear and side faces disappear depending on camera angle.

 

Ahah a moment of inspiration, I needed to make the sideOrientation DOUBLESIDE but then the front side disappeared. To check what was happening I made the rear face red

faceColors[0] = new BABYLON.Color4(1,0,0,1); 

As you rotate the box so that you can view towards the rear red face, the red face disappears but the redness is applied to the inner small boxes (or so it appears) STRANGE:wacko:

http://www.babylonjs-playground.com/#1KH9RY#4

Any explanations, corrections, advice very welcome perhaps one for @jerome

Link to comment
Share on other sites

Well, when a mesh is declared as having VertexAlpha, it is fully considered as a transparent mesh, even if its alpha value is 1.

The alpha blending is computed for an entire mesh and is compared to the other ones. It's not computed, for performance reasons, per mesh face. I guess that's why you have these unexpected behavior : the transparent faces (even with alpha = 1) aren't sorted the way you would expect.

AFAIK, this is a usual compromise accepted in the 3D engines. 

Maybe a workaround would be then to have 2 boxes, one embedded in the other, so 2 different meshes... and a better alpha blending

This documentation is worth it : http://doc.babylonjs.com/tutorials/Transparency_and_How_Meshes_Are_Rendered

or try the trick from the last part of this doc ;)

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