0
\$\begingroup\$

I have created a shader using Unity's shaderGraph to move my clouds back and forth. I'm using Sine Time to alter the x-position of all the pixels in my sprite. Now, all the clouds are moving in sync, but I'd like to have them move a little more random.

In ShaderGraph, I'm trying to offset the sine wave by adding a random number to it, but it does not work the way I expect it to. Instead of having random movement, all the clouds change their starting position. I am probably going about it the wrong way. Any suggestions are more than welcome.

I have added my attempt in the table below.

What Screenshot from ShaderGraph
Change position using Sine Time.
All clouds moving in sync
default
Try to add offset with random range using the object's x-position as seed.
All clouds moving in sync, but start position is changed
add random range

Here are the clouds floating in my game

floating skies

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Add your random value to the time value (not sine time), then send that summed result to a sine function in its own graph node.

You can also optionally multiply that (time+random) input value by a randomized scale to make some clouds move with a different period.

\$\endgroup\$
3
  • \$\begingroup\$ It makes sense now, after studying the difference. I struggled to keep the clouds moving randomly even with this solution. Because copying the object in the scene, and then changing the position didn't seem to work. Creating a new object on the other hand did the trick. I wonder if this is a bug in my Unity version, or if there's a minor thing I have overlooked. I'm not sure. Anyway, it works now, and thanks for the extra tip! \$\endgroup\$
    – John
    Nov 6, 2021 at 13:10
  • \$\begingroup\$ This could be due to dynamic batching - you can disable batching on this material and see if that makes a difference, though at a slight performance cost if you have a lot of these. \$\endgroup\$
    – DMGregory
    Nov 6, 2021 at 13:20
  • \$\begingroup\$ Thanks for the additional comment. Yes, it looks like it can be a batching thing. I haven't figured where to disable this in Shader Graph, but someone in this forum thread, forum.unity.com/threads/…, suggested to create a new material through script instead, which seemed to do the trick. \$\endgroup\$
    – John
    Nov 7, 2021 at 11:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .