Search Unity

Feedback Opinion on Fragment Shaders vs Shader Graph

Discussion in 'Shader Graph' started by David42142, Nov 11, 2020.

  1. David42142

    David42142

    Joined:
    Jul 15, 2015
    Posts:
    13
    Someone on the Internet said you'd have to be out of your mind to learn coding shaders (fragment shaders) in 2020. Im starting to get into shaders right now and I'm not sure if this is true.
    Basically are there any things I can do in code but can't achive in Shader Graph and vice versa?
    What's your general opinion on learning one or the other
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    Node based shader editors for real time renderers are all just vertex fragment shader generators. There’s nothing a shader graph can do that a vertex fragment shader can’t.

    However there’s lots of stuff a Shader Graph can’t that a vertex fragment shader can, because by design all node based shader editors exist to hide the complex parts of the systems from the user. The only thing users can do is what the nodes and the shade generation systems, have been written to do. Anything they haven’t written support to do might be completely impossible, even if it’s relatively trivial to do in a vertex fragment shader.

    However learning to use a node based shader system can in itself be a good tool for learning how shaders in general work, as they can make it easier to visualize what specific operations are doing.
     
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    This is 100% true. I found it 10x easier to get into Shader Graph then go back and learn coding shaders.
     
  4. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    What I like about Shader Graph (coming from someone who knows just enough to fiddle with shader code but not write their own) is that you can have an idea, create a shader in a few minutes dragging nodes and noodles around then get back to working on other stuff. In all my time since learning SG, it has met my needs as-is and has saved me a lot of time I would otherwise have spent poring over shader code, learning another language and searching for answers. Unless you need to do something you can't do with SG, I'd say start by getting comfortable with that.. then expand your knowledge.

    In other words I'd say learn to drive a car first.. and then learn specific mechanics as needed. Of course the more you know the better - so you could just learn everything :D
     
  5. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    I just stumbled on Custom Function Node - of course it still means needing to write shader code to do stuff that's not already included, but is there anything you couldn't do because it's Shader Graph-based vs. exclusively code?
    https://docs.unity3d.com/Packages/com.unity.shadergraph@6.7/manual/Custom-Function-Node.html
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    The Custom Function node let’s you do some code in the fragment or vertex shader stages that there might not be functions for, or things like for loops which node based tools generally don’t allow for, sure. But you can’t do things like modify what the inputs and outputs of the shader stages are. Or modify some of the outputs directly.

    Here’s a some things you cannot do in Shader Graph:

    After the fragment shader has done all it’s work, just before outputting the final color, you want to tint or desaturate the shaded & fogged output. That’s impossible with Shader Graph because you can only modify the shader before the lighting and fog, not after.

    You’re doing something with a mesh that needs more than 4 texture coordinates, say foliage that’s using the extra UV sets to store information about rotation pivots or per vertex GI. Can’t do that in Shader Graph because it only exposes the first 4 texture coordinates.

    You want to replicate some retro game console like the original PlayStation, which used integer screen space vertex positions, and non-perspective corrected texture sampling. You can’t do either of these because you can’t directly modify the clip space (the vertex position the vertex shader outputs), or change the texture coordinate interpolation to disable perspective correction.

    What about having a shader with multiple custom passes? Can’t do that in
    Shader Graph. Can’t support multiple render target outputs. Can’t do stencils. Etc. etc.