Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted LWRP Shader Graph Transparent Two Sided Problem

Discussion in 'Shader Graph' started by ALI3D69, May 28, 2019.

  1. ALI3D69

    ALI3D69

    Joined:
    Apr 20, 2014
    Posts:
    13
    Hi.
    Please look at this photo.
    Why the back face of my cube render in front of the front face?
    And in some angle front face not render at all!
    What am i doing wrong?
     

    Attached Files:

  2. ALI3D69

    ALI3D69

    Joined:
    Apr 20, 2014
    Posts:
    13
    Is it my problem or unity's problem?
    Is there a fix?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,842
    It's a real time rendering problem.

    Effecient and correct real time rendering of transparent surfaces is an unsolved problem.
    https://forum.unity3d.com/threads/render-mode-transparent-doesnt-work-see-video.357853/#post-2315934

    Unfortunately, apart from not using transparent mode, there aren't any real good solutions available when using Shader Graph. The only option would be for this specific case to use separate quad mesh renderers for each face of the cube so Unity can sort them individually.
     
    ALI3D69 likes this.
  4. lostminds

    lostminds

    Joined:
    Jan 17, 2019
    Posts:
    51
    I've grappled with a similar case where I wanted to make a transparent material where I could also see the back faces. The way I found to do this without running into the problems above is to make two transparent materials, one for the backsides and one for the front sides, and assigning both materials to the mesh. Then assigning a lower render queue number to the backside material so it will render before the front side material.

    This means that the game will first draw the fragment from the backside material blended with anything previously rendered behind it, then add the front material blended with that on top.

    This is relatively easy to do using the standard Lit shader as you can select render face. It can also be done with shader graph, but is a little trickier since to get the backside the only way I've managed it is to make a two-sided material and then use the IsFrontFace node and some logic to set alpha to zero for all front face fragments.

    It would be really convenient if there was an automatic mode to set up two-sided transparent materials to split into two render passes, an earlier one for drawing the inside backside faces and a later one to draw the front faces on top like this without having to make two separate materials.

    Screenshot 2019-11-25 at 13.54.07.jpg
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,842
    Agreed. It's already a feature of the HDRP Lit material, but not yet part of the URP or Shader Graph for any pipeline.
     
    lostminds likes this.
  6. Behaviour

    Behaviour

    Joined:
    Oct 4, 2015
    Posts:
    9
    I am still seeing this same issue in 2019.4.0f1 using URP. Does anyone know a workaround other than having separate mesh renderers for each of the faces or having 2 seperate materials as was suggested before because that's not feasible for me as I'm trying to create a generic 3d printing effect for a wide variety of meshes.

    upload_2020-6-17_13-26-36.png
     
  7. Beauque

    Beauque

    Joined:
    Mar 7, 2017
    Posts:
    39
    This is where I ask: Can this problem be solved using Amplify Shader Editor? How?

    I got the same problem in 2019.4 using URP..
     
  8. Dinamytes-Gabriel_Mota

    Dinamytes-Gabriel_Mota

    Joined:
    Nov 3, 2016
    Posts:
    42
    Maybe this could be solved with Render feature.
     
  9. LeonelAmaral

    LeonelAmaral

    Joined:
    Nov 3, 2018
    Posts:
    6
    So, is there a solution for this or not?
     
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,842
    There is not. This remains an essential unsolved problem in real time computer graphics, as it has been for the last 30 years, and may continue to be for the next decade.

    One “solution” is raytracing, and while that’s becoming “a thing” in high end consumer graphics cards and the new consoles, it’s not fast enough yet to 100% replace all parts of rendering. Nor is it ubiquitous enough that it can be relied on. Generally raytracing is currently only fast enough to help augment some effects for traditional rasterization; reflections, ambient occlusion, shadows, etc. Having correctly sorted transparency is one of those options, but it would require having all transparent objects be rendered with raytracing and likely mean you get that at the cost of not being able to use raytracing for anything else. Humorously, transparent objects in raytraced reflections are likely to be correctly sorted.

    So, basically this is a feature that might show up someday in the HDRP (kind of already is if you enable ray traced refraction), but won’t be something that shows up in the URP or the built in rendering paths, at least not from Unity themselves.

    The current work around mentioned above of using multiple materials remains the most viable option. Technically it could be solved with a custom Render Feature as well, but that comes with the problem of your “sorted transparent object” won’t sort with any other transparent objects, only with itself... sort of.
     
  11. LeonelAmaral

    LeonelAmaral

    Joined:
    Nov 3, 2018
    Posts:
    6
    @bgolus

    do you think baking would fix this? i dont understand very much about baking so im sorry if my question is dumb...

    ps: Im using URP
     
  12. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,842
    Baking doesn't help or hinder here. It's unrelated.
     
  13. Dinamytes-Gabriel_Mota

    Dinamytes-Gabriel_Mota

    Joined:
    Nov 3, 2016
    Posts:
    42
    If instancing, I think the instances could be sorted with something like those who are closer to the camera will be drawn last, but it wouldn't have any sort with other instancing draws right?
     
  14. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,842
    Please read the post I linked to in my first response to this thread. Baking, instancing, even draw sorting, none of these really help here at all because the issue is a more fundamental limitation of rasterization, which is the way all GPUs past and present render.

    If you go for full sorting of individual triangles within a mesh, that’d solve the specific cases in this thread, but that’s expensive and not something Unity has built in (because it’s expensive, and because it’s rarely actually needed).
     
    Beauque likes this.
  15. EagleG

    EagleG

    Joined:
    Mar 17, 2018
    Posts:
    40
    PLZ!! can someone help me!! how to expose the two sided property in Shader graph?!
     
  16. Dinamytes-Gabriel_Mota

    Dinamytes-Gabriel_Mota

    Joined:
    Nov 3, 2016
    Posts:
    42
    What do you mean expose? Like a property? At least you can duplicate the shader and change between them.
     
  17. EagleG

    EagleG

    Joined:
    Mar 17, 2018
    Posts:
    40
    Yes like a property
     
  18. Dinamytes-Gabriel_Mota

    Dinamytes-Gabriel_Mota

    Joined:
    Nov 3, 2016
    Posts:
    42
    There is no way, you either duplicate the shader or make use of the Is Front Face Node.
     
unityunity