53 lines
No EOL
1.5 KiB
Text
53 lines
No EOL
1.5 KiB
Text
/*
|
|
contributors: Patricio Gonzalez Vivo
|
|
description: Signed Random
|
|
use: srandomX(<float2|float3> x)
|
|
license:
|
|
- Copyright (c) 2021 Patricio Gonzalez Vivo under Prosperity License - https://prosperitylicense.com/versions/3.0.0
|
|
- Copyright (c) 2021 Patricio Gonzalez Vivo under Patron License - https://lygia.xyz/license
|
|
*/
|
|
|
|
#ifndef FNC_SRANDOM
|
|
#define FNC_SRANDOM
|
|
|
|
float srandom(float x) {
|
|
return -1. + 2. * fract(sin(x) * 43758.5453);
|
|
}
|
|
|
|
float srandom(float2 st) {
|
|
return -1. + 2. * fract(sin(dot(st.xy, float2(12.9898, 78.233))) * 43758.5453);
|
|
}
|
|
|
|
float srandom(float3 pos) {
|
|
return -1. + 2. * fract(sin(dot(pos.xyz, float3(70.9898, 78.233, 32.4355))) * 43758.5453123);
|
|
}
|
|
|
|
float srandom(float4 pos) {
|
|
float dot_product = dot(pos, float4(12.9898,78.233,45.164,94.673));
|
|
return -1. + 2. * fract(sin(dot_product) * 43758.5453);
|
|
}
|
|
|
|
float2 srandom2(float2 st) {
|
|
const float2 k = float2(.3183099, .3678794);
|
|
st = st * k + k.yx;
|
|
return -1. + 2. * fract(16. * k * fract(st.x * st.y * (st.x + st.y)));
|
|
}
|
|
|
|
float3 srandom3(float3 p) {
|
|
p = float3( dot(p, float3(127.1, 311.7, 74.7)),
|
|
dot(p, float3(269.5, 183.3, 246.1)),
|
|
dot(p, float3(113.5, 271.9, 124.6)));
|
|
return -1. + 2. * fract(sin(p) * 43758.5453123);
|
|
}
|
|
|
|
float2 srandom2(float2 p, const float tileLength) {
|
|
p = mod(p, float2(tileLength));
|
|
return srandom2(p);
|
|
}
|
|
|
|
float3 srandom3(float3 p, const float tileLength) {
|
|
p = mod(p, float3(tileLength));
|
|
return srandom3(p);
|
|
}
|
|
|
|
#endif |