diff --git a/2D/Noise.glsl b/2D/Noise.glsl index aef6cfd..2a7f0c8 100644 --- a/2D/Noise.glsl +++ b/2D/Noise.glsl @@ -39,5 +39,9 @@ float SmoothNoise2(vec2 uv, int ocataves) { void mainImage ( out vec4 fragColor, in vec2 fragCoord) { vec2 uv = fragCoord/iResolution.xy; - fragColor = vec4( vec3(SmoothNoise2(uv*4.+iTime*2.,3)), 1.0 ); + float x = SmoothNoise(uv*4.+mod(127.+iTime*2000.7, 337.)); + float y = SmoothNoise(uv*4.+mod(111.+iTime*11110.7, 1337.)); + float r = SmoothNoise2(vec2(x,y),1); + fragColor = vec4( vec3(SmoothNoise2(uv+r+iTime*2.,3)), 1.0 )*0.5; + fragColor -= vec4(r)*0.1; } \ No newline at end of file diff --git a/2D/indexed/indexed.glsl b/2D/indexed/indexed.glsl new file mode 100644 index 0000000..283e696 --- /dev/null +++ b/2D/indexed/indexed.glsl @@ -0,0 +1,34 @@ + +#iChannel0 "file://./Textures/colorful.jpg" +#iChannel0::WrapMode "Mirror" + + +#iChannel1 "file://./Textures/palette_LUT_opt.png" +#iChannel1::MinFilter "Nearest" +#iChannel1::MagFilter "Nearest" +#iChannel1::WrapMode "Mirror" + +#define S(a,b,c) smoothstep(a,b,c) + +float map(float value, float min1, float max1, float min2, float max2) { + return min2 + (value - min1) * (max2 - min2) / (max1 - min1); +} + +void mainImage ( out vec4 fragColor, in vec2 fragCoord) { + vec2 uv = (fragCoord/iResolution.y); + + vec4 col = vec4(0,0,0,1.0); + + vec3 texCol = texture(iChannel0, uv).rgb; + + vec2 coords; + coords.x = texCol.r; + //float g = floor(map(texCol.g, 0., 1., 0., 63.)); + //float b = floor(map(texCol.b, 0., 1., 0., 63.)); + //coords.y = map(g+b*64., 0., 4095., 0., 1.); + coords.y = (texCol.g*63.+floor(texCol.b*63.)*64.)/(4095.); + vec3 tmp = texture(iChannel1, coords).rgb; + + col.rgb = tmp; + fragColor = col; +} diff --git a/2D/indexed/indexed_dist.glsl b/2D/indexed/indexed_dist.glsl new file mode 100644 index 0000000..280b268 --- /dev/null +++ b/2D/indexed/indexed_dist.glsl @@ -0,0 +1,87 @@ +#iChannel0 "file://./Textures/colorful.jpg" +#iChannel0::WrapMode "Mirror" + +float pow2(float x) { + return x*x; +} + +/* euclidian */ +float colDist(vec3 col1, vec3 col2) { + return distance(col1, col2); +} + +/* optimized L*a*b*-like */ +float colDist2(vec3 col1, vec3 col2) { + float r_mean = (col1.r + col2.r) * 256./2.0; + + float r = (col1.r - col2.r) * 256.; + float g = (col1.g - col2.g) * 256.; + float b = (col1.b - col2.b) * 256.; + + //float dc = sqrt((2.0+r_mean/256.) * pow2(r) + // + 4.0*pow2(g) + // + (2.0 + (255.-r_mean)/256.) * pow2(b) ); + float dc = sqrt( (512.+r_mean)*r*r/256. + + 4.*g*g + + (767.-r_mean)*b*b/256.); + + return dc; +} + +vec3 bestColor(vec3 col, vec3 pal[22]) { + //col = pow(col, vec3(1./2.2)); + //col.r = pow(col.r,1./1.7); + //col.g = pow(col.g,1./1.7); + //col.b = pow(col.b,1./2.2); + float mdist = colDist2(col, pal[0]); + vec3 bcolor = pal[0]; + + for(int i=0;i<22;i++) { + float d = colDist2(col, pal[i]); + if (d < mdist ) { + mdist = d; + bcolor = pal[i]; + } + } + return bcolor; +} + + +void mainImage ( out vec4 fragColor, in vec2 fragCoord) { + + vec3 pal[22]; + + pal[0]=vec3(0.953125,0.953125,0.953125); + pal[1] = vec3(0.578125,0.6875,0.7578125); + pal[2] = vec3(0.3359375,0.421875,0.5234375); + pal[3] = vec3(0.19921875,0.234375,0.33984375); + pal[4] = vec3(0.1015625,0.109375,0.171875); + pal[5] = vec3(0.99609375,0.80078125,0.45703125); + pal[6] = vec3(0.93359375,0.48828125,0.33984375); + pal[7] = vec3(0.55859375,0.3359375,0.23046875); + pal[8] = vec3(0.3984375,0.22265625,0.19140625); + pal[9] = vec3(0.65234375,0.9375,0.4375); + pal[10] = vec3(0.21875,0.71484375,0.390625); + pal[11] = vec3(0.14453125,0.44140625,0.47265625); + pal[12] = vec3(0.84765625,0.33984375,0.38671875); + pal[13] = vec3(0.921875,0.19921875,0.296875); + pal[14] = vec3(0.69140625,0.2421875,0.32421875); + pal[15] = vec3(0.4609375,0.2578125,0.5390625); + pal[16] = vec3(0.36328125,0.15234375,0.36328125); + pal[17] = vec3(0.26953125,0.15625,0.234375); + pal[18] = vec3(0.5859375,0.78125,0.93359375); + pal[19] = vec3(0.25390625,0.6484375,0.9609375); + pal[20] = vec3(0.23046875,0.36328125,0.78515625); + pal[21] = vec3(0.24609375,0.24609375,0.453125); + + + vec2 uv = (fragCoord/iResolution.y); + + vec4 col = vec4(0,0,0,1.0); + + vec3 texCol = texture(iChannel0, uv).rgb; + vec3 tmp = bestColor( texCol, pal); + + col.rgb = tmp; + fragColor = col; +} \ No newline at end of file diff --git a/2D/indexed/indexed_dither.glsl b/2D/indexed/indexed_dither.glsl new file mode 100644 index 0000000..cb345fc --- /dev/null +++ b/2D/indexed/indexed_dither.glsl @@ -0,0 +1,42 @@ + +#iChannel0 "file://./Textures/colorful.jpg" +#iChannel0::WrapMode "Mirror" + + +#iChannel1 "file://./Textures/palette_LUT_opt.png" +#iChannel1::MinFilter "Nearest" +#iChannel1::MagFilter "Nearest" +#iChannel1::WrapMode "Mirror" + +mat4 bayerIndex = mat4( + vec4(00.0/16.0, 12.0/16.0, 03.0/16.0, 15.0/16.0), + vec4(08.0/16.0, 04.0/16.0, 11.0/16.0, 07.0/16.0), + vec4(02.0/16.0, 14.0/16.0, 01.0/16.0, 13.0/16.0), + vec4(10.0/16.0, 06.0/16.0, 09.0/16.0, 05.0/16.0)); + +float map(float value, float min1, float max1, float min2, float max2) { + return min2 + (value - min1) * (max2 - min2) / (max1 - min1); +} + +void mainImage ( out vec4 fragColor, in vec2 fragCoord) { + vec2 uv = (fragCoord/iResolution.y); + + vec4 col = vec4(0,0,0,1.0); + + vec3 texCol = texture(iChannel0, uv).rgb; + + float bayerVal = bayerIndex[int(fragCoord.x) % 4][int(fragCoord.y) % 4]; + texCol.r = step(bayerVal, texCol.r); + texCol.g = step(bayerVal, texCol.g); + texCol.b = step(bayerVal, texCol.b); + + texCol = pow(texCol, vec3(2.2)); + + vec2 coords; + coords.x = texCol.r; + coords.y = (texCol.g*63.+floor(texCol.b*63.)*64.)/(4095.); + vec3 tmp = texture(iChannel1, coords).rgb; + + col.rgb = tmp; + fragColor = col; +} diff --git a/2D/pixel_art_sampling/pixel_art_sampling.glsl b/2D/pixel_art_sampling/pixel_art_sampling.glsl new file mode 100644 index 0000000..554500b --- /dev/null +++ b/2D/pixel_art_sampling/pixel_art_sampling.glsl @@ -0,0 +1,53 @@ + +#iChannel0 "file://./Textures/pixelart.png" +//#iChannel0::MinFilter "LinearMipMapLinear" +#iChannel0::WrapMode "Mirror" +// this work is licenced under a CC0 1.0 Universal License +// https://creativecommons.org/publicdomain/zero/1.0/ +// https://www.shadertoy.com/view/MllBWf + +#define PI 3.14159265359 +#define rot(a) mat2(cos(a+PI*vec4(0,1.5,0.5,0))) + +vec4 myTexture(vec2 uv) { + + vec2 res = iChannelResolution[0].xy; + uv = uv*res + 0.5; + + // tweak fractionnal value of the texture coordinate + vec2 fl = floor(uv); + vec2 fr = fract(uv); + vec2 aa = fwidth(uv)*0.75; + fr = smoothstep( vec2(0.5)-aa, vec2(0.5)+aa, fr); + + uv = (fl+fr-0.5) / res; + return texture(iChannel0, uv); + +} + +vec4 nearest(vec2 uv) { + uv *= iChannelResolution[0].xy; + uv = floor(uv)+0.5; + uv /= iChannelResolution[0].xy; + return textureLod(iChannel0, uv, 0.0); +} + +vec4 mipmap(vec2 uv) { + return texture(iChannel0, uv); +} + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) { + vec2 uv = (fragCoord.xy - iResolution.xy*0.5) / iResolution.x; + vec2 prevUV = uv; + + uv *= rot(iTime*0.2); + uv.x *= iChannelResolution[0].y / iChannelResolution[0].x; + uv *= exp2(iMouse.x*0.01); + + fragColor = myTexture(uv).rgba; + + if (prevUV.x < -0.25) fragColor = nearest(uv); + if (prevUV.x > 0.25) fragColor = mipmap(uv); + if (abs(prevUV.x+0.25) < 0.005) fragColor.rgb = vec3(0); + if (abs(prevUV.x-0.25) < 0.005) fragColor.rgb = vec3(0); +} \ No newline at end of file diff --git a/2D/rainyWindow/rainyWindow.glsl b/2D/rainyWindow/rainyWindow.glsl index 2ef0dac..47ba2f5 100644 --- a/2D/rainyWindow/rainyWindow.glsl +++ b/2D/rainyWindow/rainyWindow.glsl @@ -67,9 +67,9 @@ void mainImage ( out vec4 fragColor, in vec2 fragCoord) { vec4 col = vec4(0,0,0,1.0); vec3 rain = RainLayer(uv,t); - rain += RainLayer(uv*1.2+7.21,t); - rain += RainLayer(uv*1.35+1.21,t); - rain += RainLayer(uv*1.55-1.21,t); + rain += RainLayer(uv*1.2+7.21,t+22.721); + rain += RainLayer(uv*1.35+111.21,t-102.); + rain += RainLayer(uv*1.55-232.21,t+10.); float blur = 4.0*(1.-rain.z); diff --git a/Textures/colorful.jpg b/Textures/colorful.jpg new file mode 100644 index 0000000..e404275 Binary files /dev/null and b/Textures/colorful.jpg differ diff --git a/Textures/palette_LUT_euclid.png b/Textures/palette_LUT_euclid.png new file mode 100644 index 0000000..c2b418b Binary files /dev/null and b/Textures/palette_LUT_euclid.png differ diff --git a/Textures/palette_LUT_nop.png b/Textures/palette_LUT_nop.png new file mode 100644 index 0000000..18ebf95 Binary files /dev/null and b/Textures/palette_LUT_nop.png differ diff --git a/Textures/palette_LUT_opt.png b/Textures/palette_LUT_opt.png new file mode 100644 index 0000000..0710945 Binary files /dev/null and b/Textures/palette_LUT_opt.png differ diff --git a/Textures/pixelart.png b/Textures/pixelart.png new file mode 100644 index 0000000..2ddc74b Binary files /dev/null and b/Textures/pixelart.png differ