Shader Toy Conversion by scarm

so a friend of mine, scarm converted this shader, and i said screw it might as well share it

Shader code
shader_type canvas_item;

uniform float IdealDist = 100.0;

mat2 rot(float a) {
    float c = cos(a);
    float s = sin(a);
    return mat2(vec2(c,s),vec2(-s,c));
}

const float pi = 1.0 * acos(-1.0);
const float pi2 = pi*2.0;

vec2 pmod(vec2 p, float r) {
    float a = atan(p.x, p.y) + pi/r;
    float n = pi2 / r;
    a = floor(a/n)*n;
    return p*rot(-a);
}

float box( vec3 p, vec3 b ) {
    vec3 d = abs(p) - b;
    return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
}

float ifsBox(vec3 p, float time) {
    for (int i=0; i<5; i++) {
        p = abs(p) - 1.0;
        p.xy *= rot(time * 0.3);
        p.xz *= rot(time * 0.1);
    }
    p.xz *= rot(time);
    return box(p, vec3(0.4,0.8,0.3));
}

float map(vec3 p, vec3 cPos, float time) {
    vec3 p1 = p;
    p1.x = mod(p1.x-5., 10.) - 5.;
    p1.y = mod(p1.y-5., 10.) - 5.;
    p1.z = mod(p1.z, 16.)-8.;
    p1.xy = pmod(p1.xy, 5.0);
    return ifsBox(p1, time);
}

void fragment(){
    vec2 p = UV;

    vec3 cPos = vec3(0.0,0.0, -3.0 * TIME);
    // vec3 cPos = vec3(0.3*sin(TIME*0.8), 0.4*cos(TIME*0.3), -6.0 * TIME);
    vec3 cDir = normalize(vec3(0.0, 0.0, -1.0));
    vec3 cUp  = vec3(sin(TIME), 1.0, 0.0);
    vec3 cSide = cross(cDir, cUp);

    vec3 ray = normalize(cSide * (p.x - 0.5) + cUp * (p.y - 0.5) + cDir);

    // Phantom Mode https://www.shadertoy.com/view/MtScWW by aiekick
    float acc = 0.0;
    float acc2 = 0.0;
    float t = 0.0;
    for (int i = 0; i < 99; i++) {
        vec3 pos = cPos + ray * t;
        float dist = map(pos * (IdealDist / 100.0), cPos, TIME);
        dist = max(abs(dist), 0.02);
        float a = exp(-dist*3.0);
        if (mod(length(pos)+24.0*TIME, 30.0) < 3.0) {
            a *= 2.0;
            acc2 += a;
        }
        acc += a;
        t += dist * 0.5;
    }

    vec3 col = vec3(acc * 0.01, acc * 0.011 + acc2*0.002, acc * 0.012+ acc2*0.005);
    COLOR = vec4(col, 1.0 - t * 0.03);
}
Tags
#shadertoy
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from snesmocha

FireShader

shader gradient

background shader

Related shaders

Useful Gradient Effects All-in-one Shader

Film Grain Shader

Gerstner Wave Ocean Shader

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments