Skip to content
Snippets Groups Projects
Commit 18b21654 authored by DarkGod's avatar DarkGod
Browse files

Improved shields shader

parent 7d7e12db
No related branches found
No related tags found
No related merge requests found
......@@ -9,32 +9,52 @@ uniform vec2 impact;
uniform float impact_tick;
uniform float impact_time;
uniform float llpow;
uniform float ellipsoidalFactor; //1 is perfect circle, >1 is ellipsoidal
uniform float oscillationSpeed; //oscillation between ellipsoidal and spherical form
float antialiasingRadius = 0.98; //1.0 is no antialiasing, 0.0 - fully smoothed(looks worse)
void main(void)
{
vec2 uv = vec2(0.5, 0.5) - gl_TexCoord[0].xy;
float l = length(uv) * 2.0;
float ll = pow(l, llpow);
vec4 c1 = texture2D(tex, (uv * ll / 1.3 + vec2(tick / time_factor, 0.0)));
vec4 c2 = texture2D(tex, (uv * ll / 1.3 + vec2(0.0, tick / time_factor)));
//uv.x *= ellispoidalFactor; //for simple ellipsoid
//comment next line for regular spherical shield
uv.x *= (1.0 + ellipsoidalFactor) * 0.5 + (ellipsoidalFactor - 1.0) * 0.5 * pow(cos(tick / time_factor * oscillationSpeed), 2.0);
float uvLen = length(uv);
float antialiasingCoef = 1.0;
float hordeLen = uvLen * 2.0;
if(hordeLen > 1.0)
{
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
return;
}else
{
if(hordeLen > antialiasingRadius)
{
antialiasingCoef = (1.0 - hordeLen) / (1.0 - antialiasingRadius);
}
hordeLen = asin(length(uv) * 2.0);
}
vec2 sphericalProjectedCoord = vec2(0.5, 0.5) + uv * (hordeLen / (3.141592 / 2.0)) / uvLen;
vec4 c1 = texture2D(tex, (sphericalProjectedCoord + vec2(tick / time_factor, 0.0)));
vec4 c2 = texture2D(tex, (sphericalProjectedCoord + vec2(0.0, tick / time_factor)));
vec4 c = c1 * c2;
float dist = max(min(1.0, 1.0 - l), 0.0) * 3.0;
c.a *= c.a * dist;
float transperency = 1.0 - exp(-0.07f / cos(hordeLen));
c.a = c.a * transperency;
float z = l;
c.a *= z;
if (l > 1.0) c.a = 0.0;
if (l < 0.5) {
c.a *= ll * 4.0;
}
// Impact
float it = tick - impact_tick;
float vaadjust = aadjust;
if (it < impact_time) {
float l = uvLen * 2.0;
float ll = pow(l, llpow);
float v = (impact_time - it) / impact_time;
float il = distance(impact / ll, (vec2(0.5) - gl_TexCoord[0].xy) / ll);
if (il < 0.5 * (1.0 - v)) {
......@@ -46,9 +66,9 @@ void main(void)
}
c.a *= vaadjust;
c.rgb *= color;
if (l <= 1.0) c.a = max(0.15, c.a);
c.a *= min(1.0, c.a) * antialiasingCoef;
c.rgb *= color;
gl_FragColor = c;
}
......@@ -29,8 +29,10 @@ return {
impact = {0, 0},
impact_tick = -1000,
impact_color = {1.0, 0.3, 1.0},
impact_time = 400,
impact_time = 800,
llpow = 2,
ellipsoidalFactor = ellipsoidalFactor or 1.2,
oscillationSpeed = oscillationSpeed or 0,
},
clone = false,
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment