dotfiles/scripts/wlbg/src/bg_frag.glsl

70 lines
1.3 KiB
Text
Raw Normal View History

2023-10-27 00:54:07 +02:00
#version 300 es
2023-10-28 12:17:47 +02:00
precision highp float;
2023-10-27 00:54:07 +02:00
uniform float time;
uniform vec2 offset;
in vec2 fragCoord;
2023-10-28 12:17:47 +02:00
// shader: https://www.shadertoy.com/view/tsXBzS
vec3 palette(float d){
return mix(vec3(0.2,0.0,0.0),vec3(.5,0.,0.),d);
}
vec2 rotate(vec2 p,float a){
float c = cos(a);
float s = sin(a);
return p*mat2(c,s,-s,c);
2023-10-27 00:54:07 +02:00
}
2023-10-28 12:17:47 +02:00
float map(vec3 p){
for( int i = 0; i<8; ++i){
float t = time*0.2;
p.xz =rotate(p.xz,t);
p.xy =rotate(p.xy,t*1.89);
p.xz = abs(p.xz);
p.xz-=.5;
}
return dot(sign(p),p)/5.;
}
vec4 rm (vec3 ro, vec3 rd){
float t = 0.;
vec3 col = vec3(0.);
float d;
for(float i =0.; i<64.; i++){
vec3 p = ro + rd*t;
d = map(p)*.5;
if(d<0.02){
break;
}
if(d>100.){
break;
}
//col+=vec3(0.6,0.8,0.8)/(400.*(d));
col+=palette(length(p)*.1)/(400.*(d));
t+=d;
}
return vec4(col,1./(d*100.));
}
void main()
{
vec2 uv = fragCoord / 5.0;
vec3 ro = vec3(0.,0.,-50.);
ro.xz = rotate(ro.xz,time);
vec3 cf = normalize(-ro);
vec3 cs = normalize(cross(cf,vec3(0.,1.,0.)));
vec3 cu = normalize(cross(cf,cs));
vec3 uuv = ro+cf*3. + uv.x*cs + uv.y*cu;
vec3 rd = normalize(uuv-ro);
vec4 col = rm(ro,rd);
gl_FragColor = col;
}