Jump to content
  • Advertisement
Sign in to follow this  
plastic_dragon99

OpenGL Sorting objects based on opacity

This topic is 3881 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

hi everyone, I started opengl a while ago but one subject I've never really understood and just skipped at the time was blending. Since then I've come a long way and I went back and understood the concept of blending. now my problem is that all the tutorials and books I read say to render all the opaque objects first and then the translucent ones. I've tried but i just can't figure out how to determine whether an object is opaque or not. Any help would be greatly appreciated. I've tried searching but i can't find anything. thanks Plastic_dragon

Share this post


Link to post
Share on other sites
Advertisement
By definition, transparent objects are those with a partly transparent texture. You should keep your own record of what textures you are using; the only general technique is keeping the data structures for objects nicely sorted and separated to avoid inspecting them over and over every frame.

But probably you are misunderstanding the tutorials you read: on one hand, you need an opaque background behind transparent objects; on the other hand, you need to draw objects that overlap in screen space in the correct order regardless of opacity.

The real problem here is that with transparent objects you need to sort drawing calls, without the shortcut of using the Z-buffer to sort fragments automatically.
Depending on what you are rendering, you might be able to guarantee that some objects are in front of other objects or that they do not overlap in screen space; otherwise you need to use any of several different types of spatial indexing data structure, e.g. a BSP tree or a quadtree, and possibly to split nonconvex or intersecting objects.

Share this post


Link to post
Share on other sites
Quote:
Original post by LorenzoGatti
By definition, transparent objects are those with a partly transparent texture.
A bit oversimplified.
The transparency may come from various sources starting from a vertex color to a texture or a blend color, or it may be injected at a vertex/fragment shader level. Yes, it is generally a texture property but this is far from being a "definition".
Anyway, even if the final fragment lands with alpha!=1 it will be just appear "as is" until a "real" blendmode is used and enabled.
Quote:
Original post by LorenzoGatti
You should keep your own record of what textures you are using; the only general technique is keeping the data structures for objects nicely sorted and separated to avoid inspecting them over and over every frame.
Correct idea. Extend at least with vertex colors.

As a note, some (commercial!) engines don't consider blending unless it's explicitly turned on at a engine-shader level. Once this info is extracted from their internal shading system, it's tracked as noted. Using a "transparent" vertex color or texture without turning on blending in those systems typically works as standard RGB, meaning that blending is NOT turned on by inspecting the runtime data. Rationale: no one says the alpha in the texture is really an alpha term, it could be for example a occlusion term as well.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!