Blending order

Started by
5 comments, last by 21st Century Moose 7 years, 10 months ago

Hello. I've read that to make blending work you have to first render all opaque objects and then the transparent, because the opaque object would spoil the effect when rendered on the transparent. Is there any way around this? It seems extremely hard to separate transparent and opaque objects to render them in proper order when you have many objects on your scene. Whats the solution?

Greetz

Advertisement

You also have to render all your transparent triangle back to front. This is the basic reason you need to lay down opaque objects first... you need a dest color "to begin with".

edit - also are you talking about a forward or deferred renderer?

-potential energy is easily made kinetic-

Hello. I've read that to make blending work you have to first render all opaque objects and then the transparent, because the opaque object would spoil the effect when rendered on the transparent. Is there any way around this? It seems extremely hard to separate transparent and opaque objects to render them in proper order when you have many objects on your scene. Whats the solution?

Greetz

You have to separate transparent stuff from opaque, transparents require separate handling no matter what technique you use. There are ways around the order dependence of rendering transparent objects, but those come with their own drawbacks, and you have to still handle the rendering of these objects separately. Now the thing is, that separating the two types of objects is a problem that can be solved easily, simply by marking either the object or the objects materials as transparent manually. (Basicly puting a checkbox up in the level editor or somewhere that marks if the object is transparent or not. If I remember correctly UE4 does it similarly.) It's something that cannot be automated properly, even if you detect somehow that the objects texture have a valid alpha channel, who knows if that channel's values are actually use for transparency, or the shader that reads the texture uses them for something entirely different. After you have the bool flags set, the rendering itself is easy, either you loop through your objects twice, or you build two separate lists of objects, and loop through those during rendering.

I'm afraid there's no shortcut here if you want "real world" results with blending vs opaque objects

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Okay, so the basic idea is - first render all opaque, then all transparent (no difference in order of transparent) - profit?

There are "order independent transparency" methods, but they are more complicated, require more resources, and have corner-cases where they give wrong results.
So, in general, you need to render opaque first.

Okay, so the basic idea is - first render all opaque, then all transparent (no difference in order of transparent) - profit?


Render all opaque (preferably front to back, for speed reasons, but it's not required).
Render all transparent objects (must be back to front, or the visuals will be wrong).

The only case where you don't have to render translucent objects in back-to-front order is where they don't overlap. The whole point of back-to-front order is so that rendering of overlapping translucent objects will work right, both in terms of the blend equation and of depth testing.

Checking that objects don't overlap might be more expensive than just doing the sort, however.

Some cases you're just not going to bother sorting every single translucent object. If, for example, you have multiple particle emitters in a scene, each emitting hundreds of particles, you're probably going to want to sort by emitter rather than by particle, and the result can look OK.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement