PDA

View Full Version : Random Values



john_connor
04-24-2017, 05:54 AM
hi,

i'm trying to create random values in shader, the first thing i found was the "float noise1(float)" function. i tried it, it didnt work, i tried all of those 4 noise functions, none worked, so i read about it in the registry:
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/noise.xhtml

which appears do be wrong or deprecated (or i'm doing something wrong), so i read about it in the GLSL 4.5 specs, and it says these functions are all deprecated since 4.4 :confused:

on the web i found some pseudo-random stuff:
http://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl

but isnt there another way to generate random (or pseudo-random) numbers ??
currently i'm using:
float rand(vec2 co)
{
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

Silence
04-24-2017, 07:36 AM
One thing you could do is simply to send the time as a uniform. Then use a random number generator algorithm. There are many (https://en.wikipedia.org/wiki/List_of_random_number_generators). You would certainly be able to find one that you could implement in a shader.

GClements
04-24-2017, 11:12 AM
which appears do be wrong or deprecated (or i'm doing something wrong), so i read about it in the GLSL 4.5 specs, and it says these functions are all deprecated since 4.4

The main reason that they're deprecated is that they were never implemented.

mhagain
04-24-2017, 12:29 PM
AFAIK it's actually conformant for all of the noise() functions to just return 0 every time they're used.

An alternative is to pre-generate the noise into a texture, then do a lookup using the same params as you would use for a GLSL noise() call.