Skip to content

Commit

Permalink
add new function
Browse files Browse the repository at this point in the history
  • Loading branch information
miccall committed May 7, 2019
1 parent 9eb49d3 commit 6611c3c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
4 changes: 3 additions & 1 deletion SDF.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ void main() {
tot /= float(AA*AA);
#endif

/*
vec2 crtUV = CRTCurveUV( uv );
if ( crtUV.x < 0.0 || crtUV.x > 1.0 || crtUV.y < 0.0 || crtUV.y > 1.0 )
{
Expand All @@ -273,5 +274,6 @@ void main() {
DrawVignette(tot, crtUV );
DrawScanline(tot,uv);
gl_FragColor = vec4( tot, 1.0 );
*/
gl_FragColor = vec4( tot, 1.0 );
}
5 changes: 4 additions & 1 deletion SomeFunction/noise/noise.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ vec2 random2(vec2 p) {
return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453);
}


float cellular(vec2 p) {
p*=10.0;
vec2 i_st = floor(p);
Expand All @@ -11,7 +12,8 @@ float cellular(vec2 p) {
for (int j=-1; j<=1; j++ ) {
for (int i=-1; i<=1; i++ ) {
vec2 neighbor = vec2(float(i),float(j));
vec2 point = random2(i_st + neighbor);
vec2 point = random2(i_st+neighbor);
//point *= iGlobalTime;
point = 0.5 + 0.5*sin(6.2831*point);
vec2 diff = neighbor + point - f_st;
float dist = length(diff);
Expand All @@ -28,5 +30,6 @@ void main() {
vec2 uv = (gl_FragCoord.xy / iResolution.xx );
float n = 1.0 ;
n = cellular(uv);
// n = length(0.5 + 0.5*sin(6.2831*random2(uv)));
gl_FragColor = vec4(n,n,n, 1.0);
}
11 changes: 6 additions & 5 deletions SomeFunction/random/random.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ float random_1( vec2 p )
23.14069263277926, // e^pi (Gelfond's constant)
2.665144142690225 // 2^sqrt(2) (Gelfond–Schneider constant)
);
return fract( cos( mod( 12345678., 256. * dot(p,r) ) ) );
return fract( cos( mod( 12345678.0, 512.0 * dot(p,r) ) ) );
}

float random_2(vec2 p)
Expand Down Expand Up @@ -98,14 +98,15 @@ float noise( in vec2 p ) {
hash( i + vec2(1.0,1.0) ), u.x), u.y);
}


void main() {
float time = iGlobalTime * 1.0;
vec2 uv = (gl_FragCoord.xy / iResolution.xx );
float n = 1.0 ;
// n = random_linear(uv);
// n = random_1(uv);
// n = random_2(uv);
// n = snoise(uv);
//n = random_linear(uv);
//n = random_1(uv);
//n = random_2(uv);
//n = snoise(uv);
// n = random_sony(uv);
// n = noise(uv);
// n = hash(uv);
Expand Down
67 changes: 67 additions & 0 deletions SomeFunction/random/random_02.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
float randSeed;

uint tausStep(uint z,int s1,int s2,int s3,uint M){
uint b=(((z << s1) ^ z) >> s2);
return (((z & M) << s3) ^ b);
}

void initRandom(uint seed1,uint seed2,uint seed3){
uint seed = seed1 * 1099087573U;
uint seedb = seed2 * 1099087573U;
uint seedc = seed3 * 1099087573U;

// Round 1: Randomise seed
uint z1 = tausStep(seed,13,19,12,429496729U);
uint z2 = tausStep(seed,2,25,4,4294967288U);
uint z3 = tausStep(seed,3,11,17,429496280U);
uint z4 = (1664525U*seed + 1013904223U);

// Round 2: Randomise seed again using second seed
uint r1 = (z1^z2^z3^z4^seedb);

z1 = tausStep(r1,13,19,12,429496729U);
z2 = tausStep(r1,2,25,4,4294967288U);
z3 = tausStep(r1,3,11,17,429496280U);
z4 = (1664525U*r1 + 1013904223U);

// Round 3: Randomise seed again using third seed
r1 = (z1^z2^z3^z4^seedc);

z1 = tausStep(r1,13,19,12,429496729U);
z2 = tausStep(r1,2,25,4,4294967288U);
z3 = tausStep(r1,3,11,17,429496280U);
z4 = (1664525U*r1 + 1013904223U);

randSeed = float(z1^z2^z3^z4) * 2.3283064365387e-10;
}

float getRand(){
uint hashed_seed = uint(randSeed * float(1099087573U));

uint z1 = tausStep(hashed_seed,13,19,12,429496729U);
uint z2 = tausStep(hashed_seed,2,25,4,4294967288U);
uint z3 = tausStep(hashed_seed,3,11,17,429496280U);
uint z4 = (1664525U*hashed_seed + 1013904223U);

float old_seed = randSeed;

randSeed = float(z1^z2^z3^z4) * 2.3283064365387e-10;

return old_seed;
}

void main() {
float time = iGlobalTime * 1.0;
vec2 uv = gl_FragCoord.xy / iResolution.xy;
//uv -= 0.5;
//uv.x *= iResolution.x / iResolution.y;
//uv *= 2.0;

uint seedX=uint((uv*vec2(1024)).x);
uint seedY=uint((uv*vec2(1024)).y);
uint seedZ=uint(iFrame);
initRandom(seedX,seedY,seedZ);
float d = getRand();
gl_FragColor = vec4(d,d,d,1.0);
gl_FragColor.a = 1.0;
}

0 comments on commit 6611c3c

Please sign in to comment.