Jump to content
  • Advertisement
Sign in to follow this  
fireye

OpenGL rendering translucent polygons (depth sorting)

This topic is 5135 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 am working on my rendering engine, and I am trying to figure out how to handle translucent polygons. I don't know whether this would be better asked in the OpenGL forum, but here goes: Should I render all opaque shapes (polygons, NURBS, quadrics, etc.), and as I render those depth sort the translucent ones? I would sort while rendering because my model heirarchy looks like this: ModelGroup --Model ----Mesh ------Vertex list When I render each model group and model, I translate and rotate the current modelview matrix, so when I get to the mesh, I can calculate the world position of each vertex. I would then sort by that depth. A single mesh object can have some opaque polys and some translucent. Is this a bad idea? I could loop through each poly, checking to see whether it's opaque. If it is, render it. If it's not, then store it somewhere, sorted by depth, and render it in a second pass. Does this seem like a decent idea? Does anyone have a better one? I'm relatively new at this.

Share this post


Link to post
Share on other sites
Advertisement
Rather than trying to sort all of your polys as you go, the usual (and probably more efficient) method is to render all your opaque polys first (either with no sorting, or with rough front to back sorting to take advantage of early z out, which really has nothing to do with translucency, but...), and then render your translucent polys, sorted from back to front.

If you have both opaque and translucent polys in the same object, the solution depends on how your renderer is set up. Ideally, your renderer would know nothing about 'objects' per se, and only deal with surfaces and surface properties. You would send all surfaces to be rendered (including the opaque and translucent components of your model) to the renderer, and the renderer would sort them appropriately, batch them by render state and transform, and render them all in one go.

Your method of looping through the polys, etc. would work, but wouldn't be very efficient. But if your poly count is low and you're just experimenting, it's certainly something you could try.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
If you have both opaque and translucent polys in the same object, the solution depends on how your renderer is set up. Ideally, your renderer would know nothing about 'objects' per se, and only deal with surfaces and surface properties. You would send all surfaces to be rendered (including the opaque and translucent components of your model) to the renderer, and the renderer would sort them appropriately, batch them by render state and transform, and render them all in one go.
What he said. You're much better off if your meshes have the vertices grouped by 'material' - possibly as triangle strips or something. When rendering you then make state changes (like texture or blend mode) for a whole bunch of polygons, instead of on a per-polygon basis, which should be a massive speed increase.

Once you're doing that it's pretty simple to skip non-opaque polygons on the first pass, adding them to a list to be handled later - you just test the material flags.

Share this post


Link to post
Share on other sites
jyk said:
Rather than trying to sort all of your polys as you go, the usual (and probably more efficient) method is to render all your opaque polys first (either with no sorting, or with rough front to back sorting to take advantage of early z out, which really has nothing to do with translucency, but...), and then render your translucent polys, sorted from back to front.

If you have both opaque and translucent polys in the same object, the solution depends on how your renderer is set up. Ideally, your renderer would know nothing about 'objects' per se, and only deal with surfaces and surface properties. You would send all surfaces to be rendered (including the opaque and translucent components of your model) to the renderer, and the renderer would sort them appropriately, batch them by render state and transform, and render them all in one go.

------

I'm using OpenGL, so depth sorting is built in for opaque polygons. For translucent ones, you have to sort them yourself to make the blending come out right.
My meshes are organized by material (texture), but not by color/alpha. I might optimize this later.

In general, you think this is the right approach?

Share this post


Link to post
Share on other sites
Quote:
Original post by fireye
jyk said:
Rather than trying to sort all of your polys as you go, the usual (and probably more efficient) method is to render all your opaque polys first (either with no sorting, or with rough front to back sorting to take advantage of early z out, which really has nothing to do with translucency, but...), and then render your translucent polys, sorted from back to front.

If you have both opaque and translucent polys in the same object, the solution depends on how your renderer is set up. Ideally, your renderer would know nothing about 'objects' per se, and only deal with surfaces and surface properties. You would send all surfaces to be rendered (including the opaque and translucent components of your model) to the renderer, and the renderer would sort them appropriately, batch them by render state and transform, and render them all in one go.

------

I'm using OpenGL, so depth sorting is built in for opaque polygons. For translucent ones, you have to sort them yourself to make the blending come out right.
My meshes are organized by material (texture), but not by color/alpha. I might optimize this later.

In general, you think this is the right approach?
no, openGL has no depth sorting, just depth testing :)

what he means by 'early z' is a hardware feature on gf3+ generation where fragments are rejected before processing if their z values mean they wont affect the final framebuffer. (ie. behind other completed fragments) this feature would be helped along if you sent the data to video card in an order that would improve the chances of an early Z rejection.

sometimes its just not worth it to do the sorting, it can look ugly though, but an example of a successfull commercial title that dosn't sort transparent polys by Z is .... DICE's BattleField 1942 Engine :)

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!