1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-23 06:18:00 +03:00
Mindustry/core/assets/shaders/space2.fragment
2018-04-07 19:31:42 -04:00

89 lines
2.1 KiB
Plaintext

#ifdef GL_ES
precision highp float;
precision mediump int;
#endif
uniform sampler2D u_texture;
uniform vec2 u_center;
uniform vec2 camerapos;
uniform vec2 screensize;
uniform float time;
varying vec4 v_color;
varying vec2 v_texCoord;
const float tau = 6.28318530717958647692;
const float tscl = 0.4;
// Gamma correction
#define GAMMA (2.2)
vec3 ToLinear(vec3 col ){
// simulate a monitor, converting colour values into light values
return pow( col, vec3(GAMMA) );
}
vec3 ToGamma(vec3 col ){
// convert back into colour values, so the correct light will come out of the monitor
return pow( col, vec3(1.0/GAMMA) );
}
float srand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
vec4 Noise(ivec2 x ){
return vec4(srand((vec2(x)+0.5)/256.0));
}
void main(){
vec4 resultc = texture2D(u_texture, v_texCoord.xy);
if(resultc.a > 0.0){
vec2 coords = v_texCoord.xy*screensize;
vec3 ray;
ray.xy = 2.0*(coords-screensize.xy*.5)/screensize.x;
ray.z = 1.0;
float literallyzero = 0.000000000001;
float offset = time/60.0*.5 * tscl + camerapos.x * u_center.x * resultc.r * literallyzero;
float speed2 = 0.3;
float speed = speed2+.1;
offset += .1;
offset *= 2.0;
vec3 col = vec3(0.0);
vec3 stp = ray/max(abs(ray.x),abs(ray.y));
vec3 pos = 2.0*stp+.5;
for ( int i=0; i < 20; i++){
float z = Noise(ivec2(pos.xy)).x;
z = fract(z-offset);
float d = 50.0*z-pos.z;
float w = pow(max(0.0,1.0-8.0*length(fract(pos.xy)-.5)),2.0);
vec3 c = max(vec3(0),vec3(1.0-abs(d+speed2*.5)/speed,1.0-abs(d)/speed,1.0-abs(d-speed2*.5)/speed));
col += 1.5*(1.0-z)*c*w;
pos += stp;
}
vec3 color = ToGamma(col);
if(color.r > 0.3 && color.b > 0.3){
color = vec3(240.0, 245.0, 255.0) / 255.0;
}else{
color = vec3(0.0);
}
gl_FragColor = vec4(color,1.0);
}else{
gl_FragColor = vec4(0.0);
}
}