Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. 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

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:
    10,079
    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:
    397
    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!
     
    rustinlee likes 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:
    10,079
    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:
    430
    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.
unityunity