Search Unity

Question How to modify output uv in the graph

Discussion in 'Shader Graph' started by danbrani, Jun 23, 2019.

  1. danbrani

    danbrani

    Joined:
    Nov 22, 2012
    Posts:
    46
    Hey, I want to modify the output uvs, however I can't find how to do it in shadergraph.

    Here's what I want to do:

    upload_2019-6-23_19-55-39.png

    so in the last line, as you can see, I want to clamp uv.y between two values.

    Please help!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Use a UV, split, clamp, then vector2 node?
     
  3. danbrani

    danbrani

    Joined:
    Nov 22, 2012
    Posts:
    46
    This seems to clamp uvs in the fragment shader, produces totally different result
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Ah, you specifically want to clamp the UVs in the vertex shader. Not possible in Shader Graph. You'll have to find another way to achieve the effect, or modify the generated shader code by hand.
     
    danbrani likes this.
  5. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    found my way over here because i'm wanting to modify the UVs in the vertex shader part of my shadergraph, *before* deforming the vertex position. i hadn't realized that UVs couldn't be modified at the vertex stage of the shadergraph!

    i'm trying to alter the UVs so that they are based on the screen space position of the vertices before i then deform the vertex positions.

    @bgolus i wonder if you have any suggestions for how to achieve something like this. i thought maybe i could put my altered UVs in the tangent coordinates, but that gets transformed on its way into the frag shader. could I do some kind of inverse matrix multiplication to get them back to how I put them in?

    otherwise, the best idea i've got is to run the mesh through a compute shader to set the UVs before then rendering with my shadergraph, but that seems like a pretty complex setup :/
     
  6. rootools

    rootools

    Joined:
    Nov 25, 2013
    Posts:
    20
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You could store a duplicate vertex position in an extra UV channel, then do the transforms in Shader Graph to that position.
     
  8. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    that is a good idea. thank you!
     
  9. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    @bgolus so I'm trying to get this working now and so I find myself needing to recreate the functionality of the Shader Graph Screen Position node so that I can calculate the screen position based on the vertex position I have stuffed into UV1. Easier said than done! But lo & behold, in my searching, I came across another thread where you saved the day: https://forum.unity.com/threads/wha...tyobjecttoclippos-inside-shader-graph.809778/

    I recreated your Shader Graph from that thread and yet somehow it doesn't look correct. Here is a sphere at (0,0,0) using a Shader Graph that ought to just be using the derived screen position to sample Scene Color, but it's misaligned somehow:
    upload_2020-12-23_16-26-37.png

    Do you have any inclination as to what might be going wrong? If just multiply the world position by the ViewProjection matrix, the sky part is on the bottom, so your Shader Graph additions are at least flipping it properly, but if everything we working as intended, the sphere would be imperceivable because it would just be passing the background through.
     
    daneobyrd likes this.