Hello all.
I was wondering why most game engines still fail to sort the drawing orders for transparent objects, but the default rendering engines on Max and Maya can sort them out on their renders with no issues.
I'm using Unity and there seems to be no workaround to that problem unless you're using Unlit soft edge transparency, in which case you lose the normals, speculars and every other shading aspect.
So is there still no solution to this problem ?
Replies
No, no engine I know can handle transparency correctly in all cases. Neither can Maya (in real time) . I can't say for sure if Max can but I would assume it can't.
You have to choose transparency approach on a from case to case basis. You can often get away with unlit materials if you use pre captured reflections - which means that you can use normals.
Yep, Max realtime viewport fails to sort drawing orders on transparents as well, but when you render your scene it renders them with the right order. I was wondering what does it do to sort them right so maybe there's a way to use that sorting method for realtime applications. It's odd that this is a problem that even the modern game engines can't fix.
Hence tricks like dithering and other special treatment for transparent surfaces will prevail for a bit..
To give you an idea about complexities for just "simple" shading:
http://on-demand.gputechconf.com/gtc/2014/presentations/S4385-order-independent-transparency-opengl.pdf
Since these transparent objects are polygons, they can apply Zwrite just as solid meshes, so it's much easier to sort them out. Just as how rendering solid meshes that intersect with each other cause no drawing order bugs. And the realtime renderer can start drawing from the further to the front so there is no order issues. I'm not sure if there is a way for the post processing to ignore transparent objects though.
Thanks to your post I now have a better understanding of the complexity that comes with data fragments of pixels. Modern engines are much capable of drawing a decent amount of polygons with post processing so I don't think having accurate transparecny would cost too much compared to everything else going on. If not, you cn always optimize your transparent meshes down.
While the zwrite method you describe would work, as the ordering is unknown, you have to render your transparent objects a lot of times. This technique is called depth-peeling. As you don't know what fragments end up on top, this multi-passing must be done as many times as you have layers in your scene. That amount is also view dependent. Now in my research I presented above you saw that it's technically possible to do this sorted capture in one go. But then comes the next problem:
Post processing is still troublesome, cause when and how would you do it?
Many post effects work because they can access neighboring pixels, but what is a solid's object neighboring transparent pixel, when there can be many on top of each other.
Post processing is a weapon of choice as it's mostly well suited for the hardware, it can run over all pixels doing nearly the same amount of work and grabbing similar data. With those per-pixel lists it would mean some pixels have to do a lot more work than others (have to fetch more data...), which the hardware typically doesn't like.
So some of these things tend to break or become very complex/slow.
It is not a matter of polygons, polygons we can draw insane amounts, it's the organization of the input and output data and how the hardware is processing it, that make things complex here. It doesn't rule out improvement and there is plenty "hacks" to get things going nevertheless, but there is good reasons those hacks have to be applied still.
Would you happen to know if there is any way to implement this in Unity ? I know the default shaders don't have such operations.
And depth peeling is still not exactly post processing friendly, and things like deferred shading, depth of field all would need extensive changes that are so big that it's unlikely a generic solution will happen.
So I am afraid your best bet would be to ping Unity about what enhances to their transparency they plan under what limitations, describe what you are after.
Though while it's possible to write a specialized renderer for high quality transparency, it's not so practical given the majority will not benefit, and it will be very costly. You might remember how 3dsmax "jittered" the camera for Depth of Field in the past, stuff like that is basically what you would need to do, all shading would have to be forward shading (which means you need a different approach to deal with many lights, if you want to keep that)...
The context I dealt with such quality demands was either scentific vis (basically no post processing) or product vis, where you can throw all hw to come up with great images and 30 fps or less on high-end hardware is fine and you can do things like improving image quality over many frames (like you see in many raytracers). Actually raytracing tends to be used in that context a lot more...
Because to actually render glass correctly, a simple "alpha" is not enough, you need full RGB modulation as well, to do properly color-tinted glass...
so you see it's somewhat a pain (unless you raytrace).
when u guys say that sorting does not work in Maya viewports either in "realtime"...
What is meant by "realtime"?
Any viewport that is reporting frames and/or in motion?
Or perhaps viewport 2.0 and/or directX option?
Which is what I suspect since I remember the last time I made an honest attempt to research the topic...
openGL maya viewports handle alpha transparency predictably????
I imagine I am missing something but even if there r some gotchas I am overlooking...
what hurdle would it take to at least get the same level of predictability in engine sorting?
Apparently there is a Unity workaround for this, which renders the shader in two passes. First the completely transparent meshes with the wrong order, and the cutout meshes with the right order on top of it. It wouldn't work for materials like glass, but it kinda does the trick for plants since they appear like they have soft edges. I'll try to find a way to customize shaders so they render it with this method.
Again, thanks for taking the time to answer.