feat(default): faster rand in default project
This commit is contained in:
+11
-5
@@ -1,14 +1,20 @@
|
||||
#ifndef INC_RAND
|
||||
#define INC_RAND
|
||||
|
||||
// https://thebookofshaders.com/10/
|
||||
// https://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
|
||||
|
||||
float rand(float seed){
|
||||
float v = pow(abs(seed), .8571429); // 6. / 7.
|
||||
v *= sin(v) + 1.;
|
||||
return fract(v);
|
||||
const float c = 43758.5453;
|
||||
return fract(sin(seed) * c);
|
||||
}
|
||||
|
||||
float rand(vec2 n){
|
||||
return rand(n.x * 1234. + n.y * 9876.);
|
||||
float rand(vec2 co)
|
||||
{
|
||||
const float a = 12.9898;
|
||||
const float b = 78.233;
|
||||
float dt= dot(co.xy ,vec2(a,b));
|
||||
return rand(dt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user