This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Graphics/UI/Background.shader

64 lines
1.7 KiB
Text
Raw Permalink Normal View History

2020-07-10 13:20:56 +00:00
// Based on https://www.shadertoy.com/view/XlfGRj by Pablo Roman Andrioli
// Licensed under MIT
shader_type canvas_item;
render_mode unshaded;
2020-07-14 12:18:18 +00:00
const int volsteps = 20;
const int iterations = 17;
const float formuparam = 0.53;
const float stepsize = 0.1;
const float brightness = 0.0015;
const float darkmatter = 0.300;
const float distfading = 0.730;
const float saturation = 0.850;
const float rotx = 0.;
const float roty = 0.001;
const float tile = 0.85;
2020-07-10 13:20:56 +00:00
uniform float speed = 0.001;
2020-07-14 12:18:18 +00:00
uniform float zoom = 0.80;
2020-07-10 13:20:56 +00:00
void fragment() {
vec2 uv = FRAGCOORD.xy * SCREEN_PIXEL_SIZE - 0.5;
uv.y *= SCREEN_PIXEL_SIZE.x/SCREEN_PIXEL_SIZE.y;
2020-07-12 15:26:40 +00:00
vec3 dir = vec3(uv*(zoom+sin(TIME*0.01)*0.4), 1.);
2020-07-10 13:20:56 +00:00
float time = TIME*speed+.25;
float a1=.5+TIME*rotx;
float a2=.8+TIME*roty;
mat2 rot1=mat2(vec2(cos(a1),sin(a1)),vec2(-sin(a1),cos(a1)));
mat2 rot2=mat2(vec2(cos(a2),sin(a2)),vec2(-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;
//volumetric rendering
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.))); // tiling fold
float pa,a=pa=0.;
for (int i=0; i<iterations; i++) {
p=abs(p)/dot(p,p)-formuparam; // the magic formula
a+=abs(length(p)-pa); // absolute sum of average change
pa=length(p);
}
float dm=max(0.,darkmatter-a*a*.001); //dark matter
a*=a*a; // add contrast
if (r>6) fade*=1.-dm; // dark matter, don't render near
//v+=vec3(dm,dm*.5,0.);
v+=fade;
v+=vec3(s,s*s,s*s*s*s)*a*brightness*fade; // coloring based on distance
fade*=distfading; // distance fading
s+=stepsize;
}
v=mix(vec3(length(v)),v,saturation); //color adjust
COLOR = vec4(v*.01,1.);
}