From 41b04481aadb7bd9ffc9441ad558eeb80cb05466 Mon Sep 17 00:00:00 2001 From: m11 Date: Wed, 4 Feb 2026 19:29:12 +0100 Subject: [PATCH] Added some more example shaders --- shaders/checkerboard_rotate.frag | 17 ++++ shaders/checkerboard_shift.frag | 91 +++++++++++++++++++++ shaders/cineshader_lava.frag | 92 ++++++++++++++++++++++ shaders/example.glsl | 35 -------- shaders/gradient.frag | 10 +++ shaders/raymarching_template_2026_Y28.frag | 86 ++++++++++++++++++++ 6 files changed, 296 insertions(+), 35 deletions(-) create mode 100644 shaders/checkerboard_rotate.frag create mode 100644 shaders/checkerboard_shift.frag create mode 100644 shaders/cineshader_lava.frag delete mode 100644 shaders/example.glsl create mode 100644 shaders/gradient.frag create mode 100644 shaders/raymarching_template_2026_Y28.frag diff --git a/shaders/checkerboard_rotate.frag b/shaders/checkerboard_rotate.frag new file mode 100644 index 0000000..cfe1076 --- /dev/null +++ b/shaders/checkerboard_rotate.frag @@ -0,0 +1,17 @@ + +// Related examples and context: https://observablehq.com/@mbostock/shader + +#define M_PI 3.1415926535897932384626433832795 + +const float size = 10.0; + +mat2 rotate2d(float a) { + return mat2(cos(a), -sin(a), sin(a), cos(a)); +} + +void mainImage(out vec4 fragColor, in vec2 fragCoord) { + float angle = iTime; + vec2 p = (fragCoord.xy - iResolution.xy / 2.0) * rotate2d(angle); + float k = float(mod(p.x, size * 2.0) < size == mod(p.y, size * 2.0) < size); + fragColor = vec4(vec3(k), 1.0); +} diff --git a/shaders/checkerboard_shift.frag b/shaders/checkerboard_shift.frag new file mode 100644 index 0000000..87c4ac7 --- /dev/null +++ b/shaders/checkerboard_shift.frag @@ -0,0 +1,91 @@ +int numRows = 5; +int numCols = 5; + +#define period (2.0) +#define halfperiod (period * 0.5) +#define dt (mod(iTime, period)) +#define dth (mod(iTime, halfperiod)) + +#define moveFlip (int(mod(iTime, period * 2.0) > period)) +#define moveRows (int(mod(iTime, period) > halfperiod)) +#define moveEvens (int(mod(iTime, period) > halfperiod)) + + + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) +{ + int move_evens = moveEvens; + if (moveFlip > 0) + { + move_evens = 1 - moveEvens; + } + + float dx = iResolution.x / float(numRows); + float dy = iResolution.y / float(numCols); + + float x = fragCoord.x; + float y = fragCoord.y; + + x *= iResolution.x/iResolution.y; + + + int rowx = int(x / dx); + int rowy = int(y / dy); + + int xeven = int(mod(float(rowx), 2.0)); + int yeven = int(mod(float(rowy), 2.0)); + + float t = dth / halfperiod; + + float dtx = dx * t * 2.0; + float dty = dy * t * 2.0; + + if (moveEvens == 1) + { + if (moveRows == 1 && xeven == 1) + { + y = y + dty; + rowy = int(y / dy); + } + else if (moveRows == 0 && yeven == 0) + { + x = x + dtx; + rowx = int(x / dx); + } + } + else + { + if (moveRows == 1 && xeven == 0) + { + y = y + dty; + rowy = int(y / dy); + } + else if (moveRows == 0 && yeven == 1) + { + x = x + dtx; + rowx = int(x / dx); + } + } + + xeven = int(mod(float(rowx), 2.0)); + yeven = int(mod(float(rowy), 2.0)); + + if (xeven == yeven) + { +// vec4 c = texture(iChannel0, fragCoord.xy / iResolution.xy); +// +// if (c.x == 0.0 && c.y == 0.0 && c.z == 0.0) +// { +// c = vec4(1.0, 1.0, 1.0, 1.0); +// } +// +// fragColor = c; + fragColor = vec4(1.0, 1.0, 1.0, 1.0); + } + else + { +// vec4 c = texture(iChannel1, fragCoord.xy / iResolution.xy); +// fragColor = c; + fragColor = vec4(0.0, 0.0, 0.0, 1.0); + } +} diff --git a/shaders/cineshader_lava.frag b/shaders/cineshader_lava.frag new file mode 100644 index 0000000..f9a7140 --- /dev/null +++ b/shaders/cineshader_lava.frag @@ -0,0 +1,92 @@ +/* Based on shader by edankwan: https://www.shadertoy.com/view/3sySRK + * CC BY-NC-SA 3.0 - https://creativecommons.org/licenses/by-nc-sa/3.0/ + * Modified by m11 + */ + +float opSmoothUnion( float d1, float d2, float k ) +{ + float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 ); + return mix( d2, d1, h ) - k*h*(1.0-h); +} + +float sdSphere( vec3 p, float s ) +{ + return length(p)-s; +} + +float map(vec3 p) +{ + float aspect = iResolution.x / iResolution.y; + vec2 worldSize = vec2(6.0 * aspect, 6.0); + vec3 motionExtent = vec3(worldSize * 0.5 - 1.5, 0.2); + + float d = 10.0; + for (int i = 0; i < 16; i++) { + float fi = float(i); + float time = iTime * (fract(fi * 412.531 + 0.513) - 0.5) * 2.0; + d = opSmoothUnion( + sdSphere(p + sin(time + fi * vec3(52.5126, 64.62744, 632.25)) * motionExtent, mix(0.7, 1.4, fract(fi * 412.531 + 0.5124))), + d, + 0.3 + ); + } + return d; +} + +vec3 calcNormal( in vec3 p ) +{ + const float h = 1e-5; // or some other value + const vec2 k = vec2(1,-1); + return normalize( k.xyy*map( p + k.xyy*h ) + + k.yyx*map( p + k.yyx*h ) + + k.yxy*map( p + k.yxy*h ) + + k.xxx*map( p + k.xxx*h ) ); +} + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) +{ + vec2 uv = fragCoord/iResolution.xy; + + float aspect = iResolution.x / iResolution.y; + vec2 worldSize = vec2(6.0 * aspect, 6.0); + + float pixelSize = worldSize.y / iResolution.y; + + // screen size is... + vec3 rayOri = vec3((uv - 0.5) * worldSize, 3.0); + vec3 rayDir = vec3(0.0, 0.0, -1.0); + + float depth = 0.0; + float dist = 0.0; + vec3 p; + + for(int i = 0; i < 64; i++) { + p = rayOri + rayDir * depth; + dist = map(p); + depth += dist; + if (dist < 1e-6) { + break; + } + } + + depth = min(6.0, depth); + vec3 n = calcNormal(p); + float b = max(0.0, dot(n, vec3(0.577))); + vec3 col = (0.5 + 0.5 * cos((b + iTime * 3.0) + uv.xyx * 2.0 + vec3(0,2,4))) * (0.85 + b * 0.35); + col *= exp( -depth * 0.15 ); + + float hit = step(dist, 1e-6); + float aa = hit * smoothstep(pixelSize, 0.0, dist); + fragColor = vec4(col, aa); + + // maximum thickness is 2m in alpha channel + //fragColor = vec4(col, 1.0 - (depth - 0.5) / 2.0); +} + +/** SHADERDATA + * { * + * "title": "My Shader 0", + * "description": "Lorem ipsum dolor", + * "model": "person" + * } + */ diff --git a/shaders/example.glsl b/shaders/example.glsl deleted file mode 100644 index aaae69a..0000000 --- a/shaders/example.glsl +++ /dev/null @@ -1,35 +0,0 @@ -/** - * The MIT License - * - * Copyright (c) 2011 Mr.doob - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -void mainImage(out vec4 fragColor, in vec2 fragCoord) { - vec2 position = ( fragCoord.xy / iResolution.xy ); - - float color = 0.0; - color += sin( position.x * cos( iTime / 15.0 ) * 80.0 ) + cos( position.y * cos( iTime / 15.0 ) * 10.0 ); - color += sin( position.y * sin( iTime / 10.0 ) * 40.0 ) + cos( position.x * sin( iTime / 25.0 ) * 40.0 ); - color += sin( position.x * sin( iTime / 5.0 ) * 10.0 ) + sin( position.y * sin( iTime / 35.0 ) * 80.0 ); - color *= sin( iTime / 10.0 ) * 0.5; - - fragColor = vec4( vec3( color, color * 0.5, sin( color + iTime / 3.0 ) * 0.75 ), 1.0 ); -} diff --git a/shaders/gradient.frag b/shaders/gradient.frag new file mode 100644 index 0000000..b167080 --- /dev/null +++ b/shaders/gradient.frag @@ -0,0 +1,10 @@ +// https://www.shadertoy.com/new + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) +{ + vec2 uv = fragCoord/iResolution.xy; + + vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4)); + + fragColor = vec4(col,1.0); +} diff --git a/shaders/raymarching_template_2026_Y28.frag b/shaders/raymarching_template_2026_Y28.frag new file mode 100644 index 0000000..934a5ca --- /dev/null +++ b/shaders/raymarching_template_2026_Y28.frag @@ -0,0 +1,86 @@ +/* Based on shader by Yusef28: https://www.shadertoy.com/view/WXGyDG + * CC BY-NC-SA 3.0 - https://creativecommons.org/licenses/by-nc-sa/3.0/ + * Minor modifications by m11 + */ + +/* + * + I *f you write code you might be able to understand a week later, +You might come back to it in a month. + +If you write code that you will probably understand 5 years later, +You will probably come back to it tomorrow. + +~ Proverbs by a Shady Character, Jan 2026 + +*/ + +float map(vec3 p){ + p = mod(p, 2.)-1.; + return length(p)-0.5; +} + +//basic high accuracy raymarch +float trace(vec3 ro, vec3 rd){ + #define FAR 50. + float t = 0., d; + for (int i = 0; i < 96; i++){ + d = map(ro + rd*t); + if(abs(d)<.0001 || t>FAR) break; + t += d*.95; // Lot's of accuracy, not as efficient + } + return t; +} + +//Normal function using a matrix found here +vec3 normal(vec3 p){ + //https://www.shadertoy.com/view/l3fSDr + //but originally by blackle: + mat3 k = mat3(p,p,p) - mat3(0.0001); + return normalize(map(p) - vec3(map(k[0]), map(k[1]) ,map(k[2]))); +} + + +//moving cam function by elsio +vec3 camRay(vec2 u, out vec3 ro){ + ///https://www.shadertoy.com/view/33V3R3 + float t = iTime; + ro = mix( + vec3(0, 15. - 15. * sin(t * .2), 20.), + vec3( + -18. * sin(t * .2), + (10. - 20. * ceil(sin(t * .2))) * sign(sin(t * .1)), + 15. + ), + ceil(cos(t * .2)) + ); + vec3 + cw = normalize(0. - ro), + cu = normalize(cross(cw, vec3(0, 1, 0))), + cv = normalize(cross(cu, cw)); + + return normalize(mat3(cu, cv, cw) * vec3(u, 1)); +} + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) +{ + // Normalized pixel coordinates (from 0 to 1) + vec2 uv = (fragCoord - iResolution.xy*.5)/iResolution.y; + vec3 ro = vec3(0, .0, 1.5); + vec3 rd = camRay(uv, ro); + float t = trace(ro, rd); + vec3 sp = ro + rd*t; + vec3 sn = normal(sp); + vec3 col = vec3(0.); + + if(t < FAR){ + col = sn*0.5+0.5; + } + + //Fog function based on one by Elsio with the exp + //https://www.shadertoy.com/view/33V3R3 + col = mix(vec3(0.0),col, exp(-.001 * t * t * t)); + + // Output to screen + fragColor = vec4(col,1.0); +}