Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Vertex Shader graph - waving flag - rotational problem

Discussion in 'Shaders' started by whidzee, Dec 17, 2018.

  1. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    Hello, I am very new to the shader graph and i am looking to make a waving flag shader.

    I have found this flag in the example scene and it works great.

    https://blogs.unity3d.com/2018/10/05/art-that-moves-creating-animated-materials-with-shader-graph/

    If my flag was a regular rectangular flag then this would be fine, however my flags are like the ones you see in a used car yard.

    https://www.runcam.com/images/RunCam-Flag/RunCam-Flag-1.jpg

    I have been trying for a while now to be able to understand the unity sample shader in that scene and to try to rotate it's effect. my goal is to have the free hanging corner of this flag to have the waving effect.

    Can anyone offer assistance with this? I have tried googling it and have had no luck
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The usual solution to this kind of thing is to use the vertex color to mask where you want the flag to move.
     
  3. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    that makes sense, how can i use the vertex colour from my model and plug it into the shader? the vertex color node doesn't appear to have an input where I'd be able to connect my model
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The input from the model is implicit. Whatever mesh is currently being rendered by the shader is where the vertex color values will be read from.
     
  5. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    when i connect the waviness and the vertex color node into the color mask mode (i'm assuming this is the node i need) it only gives me a black output. is there something tricky here i need to do?
     
  6. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    Ah I got it. I needed to connect the vertex color node into the range node of the mask, I was plugging it into the mask. Thanks for this.

    Now, for some reason by adding this mask in it has offset my flag from the flagpole. now to sort out that challenge
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Nope, you should use a split node.
    https://github.com/Unity-Technologies/ShaderGraph/wiki/Channel-Nodes

    If you've just set the vertex color to be white where you want it to move, grab any of the RGB channels.

    However, I'd double check that Unity actually grabbed the vertex color to begin with. Plug in the vertex color directly to the emission, and if that shows black try looking at the mesh asset itself in the inspector. Each mesh lists out what properties it's vertices have, usually "uv" (position is implicit), yours should also show "color".
     
  8. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    fantastic. thanks mate! you rock! I just connected the vertex color node to a split, then connected the R output to a multiply node and it sorted it right out. Thanks a bunch!