lundi 30 août 2021

GLSL Pseudo Random in Range

I need to generate a pseudo random number, in specified range, using glsl

Something like this

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

or this

highp float rand(vec2 co)
{
    highp float a = 12.9898;
    highp float b = 78.233;
    highp float c = 43758.5453;
    highp float dt= dot(co.xy ,vec2(a,b));
    highp float sn= mod(dt,3.14);
    return fract(sin(sn) * c);
}

both from here and here respectively, would probably work, but I need to be able to specify a range (ie 1-10) for each pseudo random number.

In addition, I am using a glsl compute shader, not a vertex shader, so I do not have access to the typical vertex shader variables such as st




Aucun commentaire:

Enregistrer un commentaire