#!/usr/pkg/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 "starnest" \
xshadertoy "$@" \
 --program0 - \
<< "_XSCREENSAVER_EOF_"

// Title:  Star Nest
// Author: Kali
// URL:    https://www.shadertoy.com/view/XlfGRj
// Date:   16-Jun-2013
// Desc:   3D kaliset fractal - volumetric rendering and some tricks. I put the params on top to play with. Mouse enabled to explore different regions.

// Star Nest by Pablo Roman Andrioli
// License: MIT


	#define iterations 17
	#define formuparam 0.53
	#define volsteps 20
	#define stepsize 0.1
	#define zoom   0.800
	#define tile   0.850
	#define speed  0.010
	#define brightness 0.0015
	#define darkmatter 0.300
	#define distfading 0.730
	#define saturation 0.850
	void mainImage( out vec4 fragColor, in vec2 fragCoord )
	{
	vec2 uv=fragCoord.xy/iResolution.xy-.5;
	uv.y*=iResolution.y/iResolution.x;
	vec3 dir=vec3(uv*zoom,1.);
	float time=iTime*speed+.25;
	float a1=.5+iMouse.x/iResolution.x*2.;
	float a2=.8+iMouse.y/iResolution.y*2.;
	mat2 rot1=mat2(cos(a1),sin(a1),-sin(a1),cos(a1));
	mat2 rot2=mat2(cos(a2),sin(a2),-sin(a2),cos(a2));
	dir.xz*=rot1;
	dir.xy*=rot2;
	vec3 from=vec3(1.,.5,0.5);
	from+=vec3(time*2.,time,-2.);
	from.xz*=rot1;
	from.xy*=rot2;
	float s=0.1,fade=1.;
	vec3 v=vec3(0.);
	for (int r=0; r<volsteps; r++) {
	vec3 p=from+s*dir*.5;
	p = abs(vec3(tile)-mod(p,vec3(tile*2.)));
	float pa,a=pa=0.;
	for (int i=0; i<iterations; i++) {
	p=abs(p)/dot(p,p)-formuparam;
	a+=abs(length(p)-pa);
	pa=length(p);
	}
	float dm=max(0.,darkmatter-a*a*.001);
	a*=a*a;
	if (r>6) fade*=1.-dm;
	v+=fade;
	v+=vec3(s,s*s,s*s*s*s)*a*brightness*fade;
	fade*=distfading;
	s+=stepsize;
	}
	v=mix(vec3(length(v)),v,saturation);
	fragColor = vec4(v*.01,1.);
	}

_XSCREENSAVER_EOF_
