Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

(approximated) Order independent transparency

Discussion in 'Made With Unity' started by neginfinity, May 21, 2015.

  1. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    I've apploaded sample project onto bitbucket/github under MIT license.



    https://neginfinity.bitbucket.io/20...ansparency.html#weighted-blended-transparency
    https://github.com/NegInfinity/WeightedBlendedTransparency
    https://bitbucket.org/neginfinity/weightedblendedtransparency

    The issues I have encountered haven't been fixed, and the project is unsupported.

    Enjoy.

    ---previously---
    I developed (approximated) order independent transparency shader.

    Wanted to publish it on asset store BUT encountered certain technical problem which prevented that from happening (for now, anyway).

    Here are videos of the effect in action.





    Watch the cursor in bottom left cursor - it toggles various options. "Standard" (enabled at 1:03) demonstrates standard way of handling transparency, without order-independence.
     
    Last edited: Apr 19, 2017
    NSokolovskyi and candycat like this.
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    How is this different from normal transparency?
     
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    Normal transparency requires objects to be sorted. This one doesn't.

    In case of standard transparency, if you make several meshes that cannot be properly sorted by depth, (if they intersect, or if one object is within another), one object will "overdraw" another. This is demonstrated at 1:03 when I switch to standard transparency (smoke passes through other objects in the scene, and because it is considered to be "closer" to the camera than everything else, it is drawn last ,completely erasing car and standing character).

    In case of standard transparency you'll also get artifacts on complex concave object (like car's hull) with lighting on it, unless you split that object into many small parts - because sorting is performed on object level and not polygon level.

    However, it is still an approximation.

    Also, in the example, particle smoke reacts to unity lighting and receives shadows.

    ....

    I think I'll need to make better demonstration.
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    I've added new demo, supposedly better one.

     
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Cool, that shows the benefits quite well. So unity is not able to do proper transparency like this on its own?
     
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    Unless you split it into many small meshes, no.
     
  7. -Singularity-

    -Singularity-

    Joined:
    Jul 27, 2014
    Posts:
    122
    This is very interesting, I can think of lots of potential applications.

    What is the performance cost vs standard unity transparency?
     
  8. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    You know what, I have live demo here, so see for yourself. It is older demo that doesn't work in OpenGL.

    It should actually be really cheap, BUT
    Unity does not exactly let you reuse zbuffer (used by previously drawn objects - it just plain doesn't work in DirectX mode), so currently currently all solid objects will have to be drawn second time (with cheap shader) for the the effect to work.
    It is still much cheaper than proper non-approximated order independent transparency would have been.

    I also spent a lot of time trying to make lighting work on transparent objects (in 1st demo you can see shadows on semi-transparent car), it cannot be reliably done (without replacing unity lighting system with your own) because it does not work in OpenGL mode (and probably relies on undefined behavior in DX).

    You also cannot use the effect on standard unity shader unless you rewrite it.
     
  9. NeonTanto

    NeonTanto

    Joined:
    Jun 19, 2013
    Posts:
    156
    What kind of tehnique you use? =)
    About zbuffer... why don't use depth textures? Copy them by blit... I think it's more usefull than render solid geometry one more time.
     
  10. relativegames

    relativegames

    Joined:
    Nov 22, 2013
    Posts:
    32
  11. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    You know, the reason why I never released the original asset is because I couldn't make it work on OpenGL and there were problems with support for receiving shadows.

    Guess now I'll have to get it together and release it for free.
     
  12. Circool

    Circool

    Joined:
    Feb 5, 2013
    Posts:
    56

    Attached Files:

  13. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    Alright. Uploaded it. The project is unsupported and more of a "proof of concept".



    It uses blended weighted transparency algorithm.
     
    Circool likes this.
  14. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hi,
    i am interessted on your OIT Asset for BuiltIn RP.
    Did you have an idea for MSAA?

    Another question for HDRP.
    Do you know a method to apply oit to the HDRP hair shader?
    https://docs.unity3d.com/Packages/c...h-definition@7.1/manual/Master-Node-Hair.html