#!/usr/bin/bash
# XScreenSaver, Copyright © 2026 Jamie Zawinski <jwz@jwz.org>
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation.  No representations are made about the suitability of this
# software for any purpose.  It is provided "as is" without express or 
# implied warranty.

PATH="$PATH":"$(dirname "$0")"
exec -a "darktransit" \
xshadertoy "$@" \
 --program0 - \
<< "_XSCREENSAVER_EOF_"

// Title:  Dark Transit
// Author: Matt Vianueva <diatribes@gmail.com>
// URL:    https://www.shadertoy.com/view/WcdczB
// Date:   21-Nov-2025
// Desc:   Dark Transit

// Relicensed as MIT License, by permission, 8-Mar-2026.

// low tech tunnel
// 28 steps

/*
    @FabriceNeyret2 -40 chars
    → 611 (from 651)!
    
    Further golfing below shader code
    
*/

	#define T        iTime*4. + 5. + 5.*sin(iTime*.3)
	#define P(z)     vec3( 12.* cos( (z)*vec2(.1,.12) ) , z)
	#define A(F,H,K) abs(dot( sin(F*p*K), H +p-p )) / K
	void mainImage(out vec4 o, in vec2 u) {
	o = vec4(0,0,0,0);
	float t=0.,s=0.,i=0.,d=0.,e=0.;
	vec3  c=vec3(0),r = iResolution;
	u = ( u - r.xy/2. ) / r.y;
	if (abs(u.y) > .375) { o*= i; return;}
	vec3  p = P(T),
	Z = normalize( P(T+4.) - p),
	X = normalize(vec3(Z.z,0,-Z)),
	D = vec3(u, 1) * mat3(-X, cross(X, Z), Z);
	for(; i++ < 28. && d < 3e1 ;
	c += 1./s + 1e1*vec3(1,2,5)/max(e, .6)
	)
	p += D * s,
	X = P(p.z),
	t = sin(iTime),
	e = length(p - vec3(
	X.x + t,
	X.y + t*2.,
	6.+T + t*2.))-.01,
	s = cos(p.z*.6)*2.+ 4.
	- min( length(p.xy - X.x - 6.)
	, length((p-X).xy) )
	+ A(  4., .25, .1)
	+ A(T+8., .22, 2.),
	d += s = min(e,.01+.3*abs(s));
	o.rgb = c*c/1e6;
	}

_XSCREENSAVER_EOF_
