Jump to content

Opacity textures make meshes disapear


Dai
 Share

Recommended Posts

Hello guys,

This is my first message on this forum and I am a pure noob regarding to Babylon so please, don't kill me if the answer to my question is obvious :D

Here's my problem: if I set material.hasAlpha to true and set the same texture as opacity texture and diffuse texture*, some meshes disapear according to the camera position. Like if they were considered as out of the frustrum or something.

I attached a webm showing what's going on. Do you have any idea how to fix it ?

I am using Babylon 2.4.0 beta.

Thanks !

 

* I said diffuse, but I lied. I'm actually using emissive because I want no shading, so there's no lights in my scene. Is this the right way ?

PS: I have another question: is it possible to load a mesh without appending it to the scene ? So far all solutions I saw (ImportMesh, AssetManager) instantiate the mesh on the fly. I took a look to the ImportMesh function to see if I could extract any code that's just preloading the object, but it seems the append-the-mesh stuff goes pretty deep.

Animation.webm

Link to comment
Share on other sites

Hello I have no tool to display .webm (and even chrome does not want to display it Oo).

The best way to help you is to provide a repro case on the Playground :)

For your second question, you can import a mesh and immediately flag it as disabled with mesh.setEnabled(false). This way, the scene won't consider it anymore

Link to comment
Share on other sites

@Dai

Hi & welcome to BabylonJs!

On one hand, It looks like it could be a camera issue, 

try setting minZ & maxZ with the values below  and de/increase if needed.

camera.minZ = 0.5; //Minimum distance of view. (decrease if there's still issues)

camera.maxZ = 100; //Maximum distance of view. (increase if there's still issues)

 

Hopefully that solves it.. 

But on the other hand, your plane/ground doesn't seem to be affected, so if it doesn't work, could you please share some of your code with us? it might help a great deal :) 

 

 

As for your other question, you can simply set yourMesh.isVisible = false; when loading, and set it true when you need to display it, anything you want to edit can be done "on the go" so to speak, really no need to "pre-load" and not add it to the scene :)

Link to comment
Share on other sites

  • 2 weeks later...

Hi, thank you for your help. And sorry for the late answer, I had a holiday week.

I tried your solutions, but it didn't work. I investigated on the problem and it turned out the meshes don't disapear: they are rendered behind the ground (cf. the attached gif).

I've re-created the scene on the playground. It is an horizontal square (the ground) with vertical squares (cf. the other attached file).

If you drag the camera in order to move the meshes to the top right corner, the bug will occur (it depends on your resolution, mine's 1920x1080).

The textures don't load, but it "works" the same. The bug also occurs when I'm using jpeg textures without alpha.

 

Thanks !

Animation.gif

Untitled-1.jpg

Link to comment
Share on other sites

Croeso Dai :).

I have seen this effect before - but have no idea why it happens.  However, I added a few lines to your playground (marked them "added line") that set the rendering order. That seems to stop the effect you are observing.

Playground

cheers, gryff :)

Link to comment
Share on other sites

The problem is that you also assigned the opacityTexture to the ground. If you don't use a opacityTexture for the ground it should work.
If you use a opacityTexture it means the object will be handled as an transparent object. Transparent objects are rendered after opaque objects.
In your case all your objects are transparent.
I'm not so sure but i think BJS tries to render transparent objects from back to front (using the bounding box to determine the position) but in some cases the ordering will not give the correct result. Especially if you have big transparent objects which overlap some smaller ones (like your ground).

Link to comment
Share on other sites

You're right, it's an alpha blend problem.

I don't know what I'll use yet (alpha test instead of alpha blend or alphaIndex (better than render groups I guess)) but now I know what the problem is and what solutions I have.
I think we can tag this thread as solved !

Thank you all, you're great <3

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