Search Unity

Help Wanted Depth/Intersect and vertex movement in shader producing strange results

Discussion in 'Shader Graph' started by JamhammerDev, Jul 10, 2019.

  1. JamhammerDev

    JamhammerDev

    Joined:
    Jul 11, 2015
    Posts:
    5
    Hey there, i'm trying to create an intersection shader based off a few tutorials, and the implementation works nicely until I bring in some vertex movement ( in my case, for waves in water ).

    This is the desired effect :


    This is what happens when I implement vertex movement.


    This is the shader in question:



    Thank you!
     
  2. romanpapush

    romanpapush

    Joined:
    Sep 20, 2012
    Posts:
    23
    Yes, I have the same issue in LWRP.
    In HDRP this is a non-issue (at least with HDRP Graphs), so I presume it has to do with how these pipelines render the frame... Sadly don't know the solution to this.
    Be sure to post the answer, if you'll ever solve it yourself :)
     
  3. SilverSharp

    SilverSharp

    Joined:
    Jan 20, 2016
    Posts:
    1
    I am also experiencing this issue. Hopefully, this can be resolved soon!
     
  4. Ggd07

    Ggd07

    Joined:
    May 12, 2019
    Posts:
    4
    I am also experiencing the same issue when I tried to do an intersection shader to achieve a foam effect in the water. When I bring in waves, I have the same undesired effect. I have also went through several tutorials and threads and from what I read, most think that this is an issue with the way Shader Graph works currently.

    Is there anyone that knows if this can be resolved somehow, and what direction one would try to take, or is it really a problem with Shader Graph?

    sg.png
     
  5. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    114
    My 2cts so you don't look for a solution forever.
    I can confirm it's a "problem" with ShaderGraph, more precisely with the shader code generated by the master node.
    If you know how to read a bit of HLSL, you can right clic on the master node -> show generated code. Then you'll see in the vertex shader that your vertices are being displaced, but then what's being read in the pixel shader (using the Position or Screen position node) is the vertex position before displacement. I haven't seen a node that read the correct, post-displacement position yet.

    The problem being in ShaderGraph itself, the only way for you to fix it would be to copy the ShaderGraph (and probably LWRP) package in your asset folder instead of using the package directly, then figure out how it generates the shader in the C# / HLSL files and fix the bug.
    If you go this way, then be prepared for a lot of trouble when updating Unity, as you will need to manually port the changes they did in LWRP / ShaderGraph package to your version. It's doable, but a LOT of trouble.
     
  6. Ggd07

    Ggd07

    Joined:
    May 12, 2019
    Posts:
    4
    Thank you a lot for the informative response, I really appreciate it.

    Unfortunately for me that would be way too time-consuming. Time which would be better put elsewhere. I know how to read a bit of HLSL, but if I knew how to write it, I wouldn't even need ShaderGraph. This defeats the purpose of ShaderGraph, which was to easily implement Shaders with the visual graph editor.

    I noticed you wrote (problem) in quotation marks, which probably means it is not really a problem but intended to work that way, so that probably means this will not be fixed by Unity, or a proper graph will not be added in the future? I have tried the latest alpha and beta, and I still have the same unwanted visuals there, which means there is no fix for this or the removed "depth" from Clear Flags(Background) and camera stacking in LWRP..

    I have been following Unity for a long time, and have been fiddling around with some prototypes, but in the end I got pretty disappointed by it. They market it as something that it is clearly not and by the time you realize that you would have invested a lot of time in it...

    Thankfully, I didn't invest that much time in the project I have started building, so an alternative path for me would be to either switch back to the legacy rp and fork out money for Amplify (which is pretty expensive), or just switch to Unreal Engine, which is pretty FREE, and seeing how the Mordhau developers dropped Unity after having issues with it, which issues were resolved just by importing their assets into UE..

    It's kind of sad :\ , because I really liked the Workflow which Unity had to offer previously..

    Cheers
     
    Last edited: Jul 18, 2019
  7. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    114
    I don't know anything about what Unity devs are working on. I wrote "problem" because when you look at the code, it's clearly working as intended at the moment. It doesn't mean it's necessarily hard to fix or that they will never fix it; only that it's not just a ";" missing somewhere, it just wasn't intended to work this way.

    To be honest, I know this much about this specific issue because I've fixed it in an upcoming version of my plugin (ShaderGraph Essentials). I'm actually working on a simple water shader to showcase the problem and that the bug is fixed. I don't have an ETA yet, but it should be soon™. Also even if I wanted I can't give you the code to fix this, as it relies on everything else in the plugin (you have to use my master nodes instead of Unity ...etc).

    Cheers,
     
  8. Ggd07

    Ggd07

    Joined:
    May 12, 2019
    Posts:
    4
    Yeah, alright. Makes sense. I wasn't asking for a missing semicolon or for you to provide me any code, just directions, and yours were helpful for me to understand where the issue lies.

    As I was having several other issues in addition to this one, I decided to ditch Unity completely for now and restart my project using Unreal Engine 4, and I have to say, after I imported the assets and applied basic materials, without doing ANYTHING at all, they look freaking amazing, and the performance when I imported my terrain was so much better than Unity's LWRP! My only issue is that I am rusty with C++ as I haven't used it for several years since uni, but It will benefit me more in the long run than spending countless hours trying to modify LWRP/ShaderGraph.

    Still, Unity is better than UE4 in some aspects, and it's great for prototyping. I also see what Unity Devs are doing, and I am sure that when HDRP gets a production version and ShaderGraph gets built upon with more features, it will be even more flexible, better documented and just a better platform.

    Thank you again for the comprehensives responses, I really appreciate them!
     
    ph_ likes this.
  9. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    114
    Glad I could help, good luck with your projects!
     
  10. JamhammerRob

    JamhammerRob

    Joined:
    Jan 15, 2016
    Posts:
    5
    Thanks for the discussions all! I've since adopted a new look and feel for my water and will cross my fingers that something comes up in the future. Hoping someone from the Shadergraph team could chime in since many are having this "issue".
     
    SilverSharp and ph_ like this.
  11. dansitnick

    dansitnick

    Joined:
    Jun 9, 2016
    Posts:
    13
    Just to chime in here, I also had experiences with this issue a few months ago. Every month or so I check back on the forum to see if this absolutely critical issue has been fixed yet, which it doesn't look like it has.

    I ended up implementing a node which would simply give me the position within the triangle (represented by 3 weights which would add up to 1). I had to duplicate my vertex displacement to plug into my custom node. This gave me the "real" position of each fragment after vertex displacement, which let me get around this issue.

    This issue is worse than just depth detection issues by the way. This mean you can not calculate your own lighting in any shader with vertex displacement. Looking at preview versions of shader graph, it really doesn't look like they're making any progress. Very unfortunate
     
    Ggd07 and ph_ like this.
  12. Ggd07

    Ggd07

    Joined:
    May 12, 2019
    Posts:
    4
    Yeah, I downloaded a bunch of betas and alphas to experiment with that. They simply don't care at this point, because "ItS tHe WaY iTs MeAnT tO WoRk"

    Seriously, do yourself a favor and try Unreal Engine 4. The time you spend bashing your head against the wall with issues like this will be rewarded greatly over there. I've learned a ton since I ditched unity and have already ported a couple of materials that work perfectly there : - ). No more waiting for Unity Devs!

    P.S. UE4 C++ is a beast
     
  13. cptSwing

    cptSwing

    Joined:
    Jul 2, 2015
    Posts:
    8
    Problem persists..
     
    ph_ likes this.