Search Unity

Question 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:
    19
    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:

    Dinamytes likes this.
  2. ALI3D69

    ALI3D69

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

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    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
     
    Dinamytes likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    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:
    10
    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:
    61
    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

    Dinamytes

    Joined:
    Nov 3, 2016
    Posts:
    51
    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:
    12,352
    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.
     
    Beauque and Dinamytes like this.
  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:
    12,352
    Baking doesn't help or hinder here. It's unrelated.
     
  13. Dinamytes

    Dinamytes

    Joined:
    Nov 3, 2016
    Posts:
    51
    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:
    12,352
    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. Deleted User

    Deleted User

    Guest

    PLZ!! can someone help me!! how to expose the two sided property in Shader graph?!
     
  16. Dinamytes

    Dinamytes

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

    Deleted User

    Guest

    Yes like a property
     
  18. Dinamytes

    Dinamytes

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

    patrick_murphy_

    Joined:
    Apr 16, 2017
    Posts:
    24
    Many years late, but there is an extremely convenient drop-down option now in URP Shader Graph: Render Face. It simply cannot get easier:

    upload_2023-1-17_13-24-18.png

    upload_2023-1-17_13-29-40.png

    Note that your Blending Mode may introduce intricacies that you'll have to be aware of and manage... the final cube in this series has alpha at 255:

    upload_2023-1-17_13-30-33.png

    And you can notice in the previous cube (alpha at 192) and the one before that (alpha 128) that the white lines aren't drawing quite as we might expect. So experiment and hopefully your desired effect is achievable without strange behavior.

    Otherwise the above options are appealing. But I think this is a manageable compromise for the convenience offered.