Jump to content
  • Advertisement
Sign in to follow this  
iedoc

Transparent objects always in front of opaque objects

This topic is 2660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I turn on depth testing and turn off blending and draw my opaque objects, then i turn off depth testing and turn on blending and draw my transparent objects, everything works well except for when the opaque object comes between the camera and the transparent object, which make it look like the transparent object is still in front when it really isn't. of course this is because depth testing is turned off when i draw the transparent object, so since the transparent object is drawn after the opaque object, direct3d doesn't know that its actually behind the opaque object. So how am I supposed to get this to work correctly? Thanks for any advice

Share this post


Link to post
Share on other sites
Advertisement
Don't turn off depth testing, and sort your transparent objects from back to front.
If you really have to disable depth for transparent objects for whatever reason, just disable depth writes (set the depth mask to 0), instead of disabling the whole test.

Share this post


Link to post
Share on other sites
Thanks for the fast reply. Your right about the depth testing being disabled. But with it disabled i'm back with the problem i've had before. To test it, i have a cube. I want to see the other side of the object so i turn off back face culling. with just one object, it works fine with depth testing disabled, but with depth testing enabled i have a problem which you would basically think its because i'm drawing the object from front to back, so the front face, being drawn first, appears opaque to the rest of the object, but its transparent with a totally different object behind it. I had a post earlier about that last problem, and the answer was to either turn off depth testing or draw the objects from back to front. but i HAVE drawn the objects back to front and the same problem happens. ok, this is getting a little confusing.

I'll just start with my first problem. blending is enabled, i draw a cube with backface culling disabled. The front face appears opaque as the other faces pass behind it as it rotates, as the right face comes around, you can only see the front face and back face or something, i don't remember exactly, but as each face passes around there are faces behind it that appear invisible, if that makes any sense. So drawing the object in the correct order from back to front would seem to fix the problem but it doesn't, its the same problem. turning off depth testing fixes the problem....

... until you add in another object which spins around the first object. since depth testing is disabled the last object is always in front.

i'm trying to do this with a completely transparent model, which is more complicating than a simple cube, so i'm testing with a cube right now. The entire cube is in a vertex buffer, and is drawn using an index buffer. i've tried reversing the index buffer and vertex buffer and still the same problem. is the only way to fix this to draw each face separately instead of the entire cube at once? that just doesn't seem right, but if it is i guess i'll have to work with it

Share this post


Link to post
Share on other sites
I still have the same problem whether i draw one face at a time or all together it seems...

Share this post


Link to post
Share on other sites
Hidden
When you draw a cube, some faces will be drawn before others. If the back faces are drawn first then it'd going to look ok. When your rotating though, those back faces become the front and now your no longer rendering back to front. That could be your problem.

Share this post


Link to post
BTW everything works just fine with backface culling enabled, its just i want to see the other side of the object though...

I've spent hours searching for similar problems but to no avail.... I can't be the only one with this problem...

oh yeah, and when i rearrange the order the faces are drawn, whichever one thats drawn first is the most opaque one, whether its the back, front or right face.

<div><br></div><div>heres the link to my last problem:&nbsp;<a href="http://www.gamedev.net/topic/597109-blending-not-updating/page__p__4783474#entry4783474">http://www.gamedev.net/topic/597109-blending-not-updating/page__p__4783474#entry4783474</a></div>

Share this post


Link to post
Share on other sites
Try this:


    1. Depth testing and writing is enabled all the time!
    2. Render opaque geometry.
    3. Enable blending.
    4. Sort your transparent objects back-to-front.
    5. For each transparent object:

      5a. Set culling mode to the opposite mode than you are normally using (CW or CCW) to render the back-facing polygons.
      5b. Render the object.
      5c. Set back your normal culling mode to render the front-facing polygons.
      5d. Render the same object again!

Share this post


Link to post
Share on other sites
although thats definitely not the way its supposed to be done i'm sure, it worked! thanks a ton!

Share this post


Link to post
Share on other sites

although thats definitely not the way its supposed to be done i'm sure, it worked! thanks a ton!


The back-to-front ordering doesn't apply only to whole objects, but also to individual polygons. If you want a part of one transparent object to be visible through other parts of the very same object, you have to make sure that also the faces (triangles) are drawn back-to-front. This is not needed usually, especially because many objects are convex. BUT - if you want to see also the back side of a transparent object (to make the rendering look much better), you must draw it first and then draw the front side. Which leads to what I said in my previous post, I described one valid way how to do it.

So, I don't know why are you sure it's definitely not the way it's supposed to be done, especially when it works ;) What are your other choices? Split the object into two halves and render the back one first and the front one later? Yea, and what happens when you rotate the object? Would you re-split it again, based on the actual view direction?

Share this post


Link to post
Share on other sites
oh no sorry, i didn't mean to say you were wrong or anything, haha. I was just thinking this seems like extra work to redraw the whole mesh. I was thinking of opengl or directx 9 (I think i did it with directx 9) where you can just make a simple transparent cube rotate and be able to see the other side and not have to redraw it, i know its possible turning off depth testing, but that won't work when other objects come into the scene. anyway, i'm starting to see there really is no other way around it, so thanks a bunch for the solution. It just seems odd this kind of transparency problem doesn't come up more often

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!