Home Technical Talk

Drawing Order for Transparent Materials

polycounter lvl 10
Offline / Send Message
Cactus on Fire polycounter lvl 10
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

  • JoakimMellergard
    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 ?


    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.
  • Cactus on Fire
    Options
    Offline / Send Message
    Cactus on Fire polycounter lvl 10
    JoakimMellergard

    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.
  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    it's a really hard problem for real-time engines using rasterizer (easy for raytracer). The trend to do a lot of post processing, lighting... in image space, more or less requires information (depth, potential shading inputs...) per pixel. While for transparent you would have to have a list of fragments per pixel. This is possible, though the complexities quickly explode.

    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
  • Cactus on Fire
    Options
    Offline / Send Message
    Cactus on Fire polycounter lvl 10
    CrazyButcher

    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.
  • throttlekitty
    Options
    Offline / Send Message
    The bigger cost of rendering transparency in realtime is the overdraw: you need to draw the furthest objects first, moving closer to the camera each step in order to get the final value for a given pixel on-screen. You can reduce the shapes of a mesh to optimize for some shapes, a quad plane could be cut to suit the shape of the alpha in a bush model for example, but a pane of glass wouldn't benefit from cutting any polygons out.
  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    cactus,
    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.
  • Cactus on Fire
    Options
    Offline / Send Message
    Cactus on Fire polycounter lvl 10
    I see. And if the multiple drawing of the pixels due to many transparent layers is the problem, I don't think any method would work. But depth peeling seems like an acceptable workaround for this problem.

    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.

    depthpeelingicon.jpg
  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    Depth peeling is not only a "shader" effect but requires special passes in the engine, as you have to render all transparent objects many times. I have no idea about how much Unity would expose.
    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).
  • claydough
    Options
    Offline / Send Message
    claydough polycounter lvl 10
    wondered bout the op myself and now I am more confused ( despite referring to the wiki again )
    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?
  • Cactus on Fire
    Options
    Offline / Send Message
    Cactus on Fire polycounter lvl 10
    Thanks for the info CrazyButcher, I really appreciate the input.

    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.

    Dy3jPFP.jpg
Sign In or Register to comment.