Search Unity

Feature Request Shadergraph varyings / interpolators

Discussion in 'Shader Graph' started by huwb, May 19, 2019.

  1. huwb

    huwb

    Joined:
    Oct 19, 2013
    Posts:
    24
    Hello, this is my first time posting this format so forgive me if I make some rookie errors. I work on an ocean asset and I would very much like to move it to shadergraph.

    Is there a way to pass data through interpolators, i.e. add 'Varyings' as they would be in the shader?

    I do a fair bit of work in my current vertex shader, like compute various ocean attributes like foam, and pass them through varyings such as TEXCOORD2, 3, etc. I also use need the original vertex location (pre-displacement) for some shading features. The former is a significant performance concern, whereas the latter may not be solvable in a nice way - I guess I'd need to do some kind of search to go from displaced location to undisplaced.

    (Random idea - it would be a pretty cool if it were possible to add a node that would accept vertex data and 'convert' it to fragment data (via varyings under the hood). No idea if this is possible!)

    Thanks
    Huw
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Nope.

    Currently the Shader Graph passes only the pre-displaced world position from the vertex to the fragment, and not the post-displaced position... which is obviously a bug. Eventually it should at least be passing the post-displaced position, but there currently is no way to pass access both.

    Having an “Original Vertex Position” node would be a nice thing to have.

    I’d also love to have a “pass data from vertex to fragment” node where the input would always be calculated in the vertex.
     
  3. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
    It's these kind of limitations that make people shy away from using visual scripting for shaders. Give some power options for the power user!
     
    chadfranklin47 and rustinlee like this.
  4. huwb

    huwb

    Joined:
    Oct 19, 2013
    Posts:
    24
    I thought I had a workaround for this - I thought maybe using a Position node with space set to Object would give me the raw vertex position which I could then transform into world space, but it appears to give the object position with the position offset applied, so I don't think I can get the undisplaced position without committing multiple shader programming crimes to try to find it for each pixel. I guess I will switch back to writing a shader manually in code.
     
    rustinlee likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The position node set to object space unfortunately just applies the world to object transform the to interpolated world position.
     
    huwb likes this.
  6. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    This limitation seems to still exist in 7.3.1. I can't really do much work with Shader Graph without the ability to define my own interpolators. That's not too bad for unlit shaders, where I can just go about writing them as I had before URP, but with any kind of lit shader, this is going to be a big problem, as working in Shader Graph seems to be the only solution to avoid a maintenance nightmare.
     
    hippocoder likes this.
  7. BaronBoese

    BaronBoese

    Joined:
    Jul 1, 2014
    Posts:
    11
    Same issue here!
    I tried to have a fancy Custom Function outputting UV coordinates and modified Vertex positions. ShaderGraph put the code into the right position somewhere in the Vertex stage, yay! But when using the UV coordinates to generate my surface pattern, it too ended up in the Vertex stage.
    I really would love to have 2 things:
    1. Varyings / stage control, indicators
    2. Documentation on how to write vertex / fragment shader in the classical sense. This includes proper handling of SRP Batching, Hybrid Instancing and so on.
     
    hippocoder and cultureulterior like this.
  8. rustinlee

    rustinlee

    Joined:
    May 31, 2014
    Posts:
    20
    This is a big omission, making it very difficult to access the original vertex position in the fragment context / stage.
     
    hippocoder likes this.
  9. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    62
    Anyway I can pass my own vertex colors into the fragment shader? I'm trying to animate vertex colors..
     
  10. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    486
    Shader graph got interpolators in 2021.2 alpha
     
    azmi_unity likes this.