0 votes

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.

Godot version 3.2.3
in Engine by (23 points)

1 Answer

0 votes

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.

by (817 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.