get system time/single random value once a shader is generated

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By findaeden

Hello. I’ve been working on a procedurally generated visual shader to use on the background of my game, but I discovered that there are parts of it that are really easy to remember, and since the effect looks the same way every time the game opens, it looks very clearly repetitive.

Is there a way to prevent this? I wanted to fix it by simply getting the system time and adding that to the shader’s coordinates, but I couldn’t find a way to do it. Any help is appreciated.

:bust_in_silhouette: Reply From: DaddyMonster

Sure, you can pick up the pixel’s uv with UV and you can get the time with TIME.

You can use a hashing function to make white noise:

float hash (vec2 st) {
    return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123);
}

I recommend these exact magic numbers as they avoid constructive and disruptive wave interference (which makes non-random patterns) as far as possible.

Or if you want “hilly noise” for a landscape you can make OpenSimplexNoise in the editor and just pick it up in the shader. This is also possible to compute in the shader but you have to loop your hashes. Best just to google an optimum solution, no need to reinvent the wheel.