Search Unity

ShaderGraph - Can't offset vertex position by texture lookup

Discussion in 'General Graphics' started by hawaiian_lasagne, Aug 16, 2018.

  1. hawaiian_lasagne

    hawaiian_lasagne

    Joined:
    May 15, 2013
    Posts:
    124
    Hi!

    I'm playing around with shader graph and evaluating it to see if I can use it in a new project. I'm trying to do something fairly trivial and think I'm misunderstanding something somewhere.

    I'm trying to do a texture lookup (greyscale texture), then offset the vertex.y position by that amount.

    The problem I'm having is I can't connect the result of the Add to the position input on the PBR master node.

    I'm sure i'm doing something wrong here. Is it because I'm mixing color vec3 with positional vec3?

    I've attached a screenshot of my graph.
     

    Attached Files:

    luizero00 and Neogene like this.
  2. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    You're simply using the wrong node. "Sample Texture 2D" is a pixel shader node and can not be used for the vertex output.
    Use the "Sample Texture 2D LOD" node that works in vertex shader. You just have to supply the LOD you want to sample (probably 0).
     
  3. hawaiian_lasagne

    hawaiian_lasagne

    Joined:
    May 15, 2013
    Posts:
    124
    Amazing thanks very much, that fixed it!
     
  4. mathieumo

    mathieumo

    Joined:
    Sep 4, 2018
    Posts:
    3
    Nice, but can you explain the difference between these two nodes ?
     
  5. mathieumo

    mathieumo

    Joined:
    Sep 4, 2018
    Posts:
    3
    Because in this case the texture don't use the UV i made on my object.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The basic Sample Texture 2D uses a fragment shader function in which the GPU automatically determines the appropriate mip map level of detail to use based on how much the UV changes between the pixel being drawn and the pixels next to it.

    This doesn't work in a vertex shader because the GPU doesn't know where that vertex is on screen, or how it relates to the surfaces that will eventually be drawn with it.

    Sample Texture 2D LOD let's you explicitly choose the mip level yourself.
     
  7. MattMurch

    MattMurch

    Joined:
    Jul 29, 2012
    Posts:
    14
    Is there an alternative for the triplanar node we can use? (Other than building our own triplanar projection with Sample LOD nodes)
     
    ATMLVE and Beurg like this.