Is there an equivalent of randi(), randf() or rand_range() in Godot's shading language? There aren't any built-in functions that I know that allow me to generate random numbers.

If there aren't any, how can I generate a pseudo-random number using TIME? Thanks.

you can create a uniform int/float that you pass your random number into from a script if there is no alternative(looking through the shading language docs right now).

edit: yep, go the uniform route since I can't see any convenience feature implemented for this. But then one isn't really needed, so...

Thanks! I think I'll go the uniform route, then.

12 days later

This is a fairly standard function that you can find dotted around the web (in this case I pulled it from here):

float rand(vec2 co){
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

It is useful for creating noise inside a shader (eg perlin noise). There are many other noise functions that can be created. In this video, the terrain was randomly generated inside the vertex shader using a ported version of blender's hetero_terrain generator (and some other modifications).

I've done that back in godot 2 and it's got it's problems.

Specifically: it's view dependent.

11 days later

Only if you feed in the view coordinates. If you make a 1-d equivalent function, and feed in time, then it isn't view dependent.

5 years later