diff --git a/fragment.glsl b/fragment.glsl index b7da654..05ce917 100644 --- a/fragment.glsl +++ b/fragment.glsl @@ -1,23 +1,49 @@ #version 320 es -precision mediump float; +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; uniform vec2 WindowSize; uniform float time; layout(location = 0) out vec4 color; -float rand(ivec2 co) { - return fract(sin(dot(vec2(co), vec2(12.9898, 78.233))) * 43758.5453); +float lerp(float a, float b, float x) { + return a + x*(b-a); +} + +uint xxhash32(uvec2 p) { + const uint PRIME32_2 = 2246822519U, PRIME32_3 = 3266489917U; + const uint PRIME32_4 = 668265263U, PRIME32_5 = 374761393U; + uint h32 = p.y + PRIME32_5 + p.x*PRIME32_3; + h32 = PRIME32_4*((h32 << 17) | (h32 >> (32 - 17))); + h32 = PRIME32_2*(h32^(h32 >> 15)); + h32 = PRIME32_3*(h32^(h32 >> 13)); + return h32^(h32 >> 16); +} + +//const uint k = 1103515245U; +// +//vec3 hash33( uvec3 x ) { +// x = ((x >> 8U) ^ x.yzx) * k; +// x = ((x >> 8U) ^ x.yzx) * k; +// x = ((x >> 8U) ^ x.yzx) * k; +// return vec3(x) * (1.0 / float(0xffffffffU)); +//} + +float rand(vec2 v, float seed) { + uint hash = xxhash32(uvec2(v * 10000.0 + seed * 10000.0)); + return float(hash) * (1.0/float(0xffffffffu)); } float cell_size = 0.01; - #define PI 3.1415926538 // whatever that corner contributes float c_dot(vec2 point, vec2 corner) { - ivec2 c = ivec2(round(corner * 100.0)); - float angle = rand(c) * 2.0*PI; + vec2 c = vec2(ivec2(round(corner * 100.0))); + float angle = rand(c, 0.0) * 2.0*PI; vec2 random_corner_vec = vec2(cos(angle), sin(angle)); vec2 offset = (point - corner) / cell_size; float dot_product = dot(random_corner_vec, offset); @@ -25,15 +51,12 @@ float c_dot(vec2 point, vec2 corner) { return dot_product; } -float lerp(float a, float b, float x) { - return a + x*(b-a); -} - // better than built in smoothstep. float fade(float t) { return ((6.0*t - 15.0)*t + 10.0)*t*t*t; } + void main() { // We'll make origin in the top-left. vec2 uv = gl_FragCoord.xy / WindowSize; @@ -57,24 +80,13 @@ void main() { float v = fade(tile_uv.y); //float u = tile_uv.x; //float v = tile_uv.y; - //float u = smoothstep(0, 1, tile_uv.x); - //float v = smoothstep(0, 1, tile_uv.y); - //float val = smoothstep(tile_uv.x, smoothstep(tile_uv.y, c_bl_dot, c_tl_dot), smoothstep(tile_uv.y, c_br_dot, c_tr_dot)); float val = lerp(lerp(c_tl_dot, c_bl_dot, v), lerp(c_tr_dot, c_br_dot, v), u); - //float val = tile_uv.y; - //float val = c_bl_dot*2 + 0.5; - //val = val * 20; float out_val = val /2.0 + 0.5; - color = vec4(out_val, out_val, out_val, 1.0); - - //float yes = 0.5 + (c_dot(uv, c_tl) + c_dot(uv, c_tr) + c_dot(uv, c_bl) + c_dot(uv, c_br)) / 2; - //FragColor = vec4(yes, yes, yes, 1); + //uvec3 p = uvec3(uint(round(uv.x * 500.0)), uint(round(uv.y * 500.0)), 1); + //color = vec4( hash33(p), 1.0 ); + //float lel = noise(vec3(uv * 10.0, 1.0)); + //float lel = gold_noise(uv, time * 100.0); + //float lel = random( uv.x * 100.0 ); + float lel = rand(uv, 0.0); + color = vec4(lel, lel, lel, 1.0); } - -//#version 320 es -//precision mediump float; -//layout(location = 0) out vec4 outColor; -// -//void main() { -// outColor = vec4(1.0, 0.0, 0.0, 1.0); -//}