Search Unity

Resolved Moving objects with noise

Discussion in 'Shader Graph' started by T3CHNOCIDE, Mar 18, 2020.

  1. T3CHNOCIDE

    T3CHNOCIDE

    Joined:
    Mar 29, 2018
    Posts:
    3
    Hi all,

    I'm relatively new to shader graph so please forgive me if this is a really simple and stupid mistake. I am trying to make a shader which makes a group of objects bob up and down in the Y axis as if floating on waves.

    I have adapted a wind shader to apply to the y axis of an object (original shader: https://blogs.unity3d.com/2018/10/05/art-that-moves-creating-animated-materials-with-shader-graph/). Using noise has worked great to make the up down motion which flows like a wave, however this applies to each vertex making the whole object distort.

    Is there a way to get this to apply to the object position as a whole and not each individual vertex?

    Any help would be greatly appeciated. upload_2020-3-18_22-19-30.png upload_2020-3-18_22-19-57.png
     
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Bake the pivot position into the vertex color, you probably need only 2 channels, apply bobing to it, then use that as the offset on the vertex. idk if there is a more elegant way of doing it.
     
    T3CHNOCIDE likes this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Use the Object node's Position output instead of the Position node.
     
  4. T3CHNOCIDE

    T3CHNOCIDE

    Joined:
    Mar 29, 2018
    Posts:
    3
    Hi both, thank you for your replies!

    @neoshaman - Is there a particular way to bake the pivot position? Or any guides?

    @bgolus - I tried to use the object node, however even when feeding the object position into the vertex position input of the master, the object doesn't render.
     
  5. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    I'll guess you need to code a custom baker ... I haven't done it yet, it's on the pile of thing I should do, look around if there is some forum posts who already answer that
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Sorry, I should be more specific.

    Use the Object node's Position output instead of the Position node on the far left of the graph you showed above. This means you're using the object's pivot position to drive the noise lookup so it'll be consistent across the entire object.

    The other Position node needs to remain as the position node it is. The Position node gives you the position of each vertex (either in world or object space). The Object node gives you the position of that object's pivot in world space. (The pivot's position in object space is always 0,0,0, so there's no need to have a node for that.)


    @neoshaman's suggestion for baking in the pivot into the mesh data is only needed if these meshes are being statically batched (ie: you've set the meshes game object to be Static and you still have static batching enabled for the project) or you've manually combined all of the meshes into one single mesh that has multiple lanterns in it. In this case the Object node doesn't know about the individual lanterns anymore so it's up to you to provide each lantern's pivot data though the vertex color or an extra UV set.
     
    Last edited: Mar 20, 2020
    neoshaman likes this.
  7. T3CHNOCIDE

    T3CHNOCIDE

    Joined:
    Mar 29, 2018
    Posts:
    3
    Hi both, thank you for all your help!

    @bgolus - Switching the position node for the object node worked like an absolute charm :D I was switching the other position node too, but now I see that as it is 0,0,0 then it's setting all the verticies to 0 and not rendering. Keeping it as a position node fixed it as you suggested.

    @neoshaman - Thanks for suggesting baking. I am going to take a look into baking anyway as I'll probably end up needing this for another part of the project.

    Thank you again :)
     
  8. ricmageyt

    ricmageyt

    Joined:
    Oct 29, 2023
    Posts:
    1
    Hi! I want also move a object(control part of a rig) with noise from a shader,
    But i dont found the PBRmaster to me plug the Out to object(pivot, axis).
    Im using URP, Can be because this?!

    Regards!
    ricmage
     
    Last edited: Oct 29, 2023
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Shaders can move where the visual representation of an object is. It cannot affect the CPU side representation of that object.

    If you want to move an object's actual pivot on the CPU side, you need to do that from c#.