From 7ba7e142824f9eaba9d510421ed3121da4f00a96 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 29 Mar 2020 18:34:00 -0400 Subject: [PATCH] Atmosphere tweaks --- core/assets/shaders/atmosphere.frag | 17 ++++++------- core/assets/shaders/sun.frag | 25 +++++++++++-------- core/src/mindustry/content/Planets.java | 1 + core/src/mindustry/graphics/Shaders.java | 2 ++ core/src/mindustry/graphics/g3d/SunMesh.java | 12 ++++++--- core/src/mindustry/mod/Mods.java | 8 ++++-- .../mindustry/ui/dialogs/PlanetDialog.java | 7 +++--- gradle.properties | 2 +- 8 files changed, 44 insertions(+), 30 deletions(-) diff --git a/core/assets/shaders/atmosphere.frag b/core/assets/shaders/atmosphere.frag index 1c54340eda..4792af80fb 100644 --- a/core/assets/shaders/atmosphere.frag +++ b/core/assets/shaders/atmosphere.frag @@ -6,9 +6,6 @@ const float FLARE = 0.0025; const float INTENSITY = 14.3; const float G_M = -0.85; -const float INNER_RADIUS = 1.02; -const float OUTER_RADIUS = 1.3; - const int numOutScatter = 10; const float fNumOutScatter = 10.0; const int numInScatter = 10; @@ -17,6 +14,8 @@ const float fNumInScatter = 10.0; varying vec4 v_position; varying mat4 v_model; +uniform float u_innerRadius; +uniform float u_outerRadius; uniform vec3 u_color; uniform vec2 u_resolution; uniform float u_time; @@ -58,7 +57,7 @@ float rayleighPhase(float cc) { } float density(vec3 p) { - return exp(-(length(p) - INNER_RADIUS) * (4.0 / (OUTER_RADIUS - INNER_RADIUS))); + return exp(-(length(p) - u_innerRadius) * (4.0 / (u_outerRadius - u_innerRadius))); } float optic(vec3 p, vec3 q) { @@ -70,7 +69,7 @@ float optic(vec3 p, vec3 q) { sum += density(v); v += step; } - sum *= length(step)*(1.0 / (OUTER_RADIUS - INNER_RADIUS)); + sum *= length(step)*(1.0 / (u_outerRadius - u_innerRadius)); return sum; } @@ -82,14 +81,14 @@ vec3 inScatter(vec3 o, vec3 dir, vec2 e, vec3 l) { vec3 sum = vec3(0.0); for(int i = 0; i < numInScatter; i++){ - vec2 f = rayIntersection(v, l, OUTER_RADIUS); + vec2 f = rayIntersection(v, l, u_outerRadius); vec3 u = v + l * f.y; float n = (optic(p, v) + optic(v, u))*(PI * 4.0); sum += density(v) * exp(-n * (PEAK * u_color + FLARE)); v += step; } - sum *= len * (1.0 / (OUTER_RADIUS - INNER_RADIUS)); + sum *= len * (1.0 / (u_outerRadius - u_innerRadius)); float c = dot(dir, -l); float cc = c * c; return sum * (PEAK * u_color * rayleighPhase(cc) + FLARE * miePhase(G_M, c, cc)) * INTENSITY; @@ -106,12 +105,12 @@ void main(){ vec3 l = u_light; - vec2 e = rayIntersection(eye, dir, OUTER_RADIUS); + vec2 e = rayIntersection(eye, dir, u_outerRadius); if (e.x > e.y){ gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); return; } - vec2 f = rayIntersection(eye, dir, INNER_RADIUS); + vec2 f = rayIntersection(eye, dir, u_innerRadius); e.y = min(e.y, f.x); vec3 result = inScatter(eye, dir, e, l); diff --git a/core/assets/shaders/sun.frag b/core/assets/shaders/sun.frag index 84a7e26625..bae2a3cbf8 100755 --- a/core/assets/shaders/sun.frag +++ b/core/assets/shaders/sun.frag @@ -6,7 +6,8 @@ precision lowp int; #define INTEGER int #endif -#define gradients false +//#define GRADIENTS +#define step 0.5 const int MAX_COLORS = 10; @@ -16,14 +17,18 @@ uniform vec4 u_colors[MAX_COLORS]; varying float v_height; void main() { - if(gradients){ - int from = int(v_height * float(u_colornum)); - int to = int(clamp(float(int(v_height * float(u_colornum) + 1.0)), 0.0, float(u_colornum)-1.0)); - float alpha = fract(v_height * float(u_colornum)); + #ifdef GRADIENTS - gl_FragColor = vec4(mix(u_colors[from], u_colors[to], alpha)); - }else{ - int from = int(v_height * float(u_colornum)); - gl_FragColor = u_colors[from]; - } + int from = int(v_height * float(u_colornum)); + int to = int(clamp(float(int(v_height * float(u_colornum) + 1.0)), 0.0, float(u_colornum)-1.0)); + float alpha = fract(v_height * float(u_colornum)); + alpha = floor(alpha / step) * step; + + gl_FragColor = vec4(mix(u_colors[from], u_colors[to], alpha)); + + #else + + gl_FragColor = u_colors[int(v_height * float(u_colornum))]; + + #endif } \ No newline at end of file diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index 0f370551fc..a2c319dd1d 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -18,6 +18,7 @@ public class Planets implements ContentList{ //lightColor = Color.valueOf("f4ee8e"); meshLoader = () -> new SunMesh(this, 3){{ setColors( + 1.1f, Color.valueOf("ff7a38"), Color.valueOf("ff9638"), Color.valueOf("ffc64c"), diff --git a/core/src/mindustry/graphics/Shaders.java b/core/src/mindustry/graphics/Shaders.java index e9a960d896..c2509b73fe 100644 --- a/core/src/mindustry/graphics/Shaders.java +++ b/core/src/mindustry/graphics/Shaders.java @@ -68,6 +68,8 @@ public class Shaders{ setUniformf("u_rcampos", Tmp.v31.set(camera.position).sub(planet.position)); setUniformf("u_light", planet.getLightNormal()); setUniformf("u_color", planet.atmosphereColor.r, planet.atmosphereColor.g, planet.atmosphereColor.b); + setUniformf("u_innerRadius", planet.radius + 0.02f); + setUniformf("u_outerRadius", planet.radius * 1.3f); setUniformMatrix4("u_model", planet.getTransform(mat).val); setUniformMatrix4("u_projection", camera.combined.val); diff --git a/core/src/mindustry/graphics/g3d/SunMesh.java b/core/src/mindustry/graphics/g3d/SunMesh.java index a01328bcd2..254ff4d37e 100644 --- a/core/src/mindustry/graphics/g3d/SunMesh.java +++ b/core/src/mindustry/graphics/g3d/SunMesh.java @@ -16,13 +16,17 @@ public class SunMesh extends ShaderSphereMesh{ } public void setColors(Color... colors){ + setColors(1f, colors); + } + + public void setColors(float scl, Color... colors){ colorValues = new float[colors.length*4]; for(int i = 0; i < colors.length; i ++){ - colorValues[i*4] = colors[i].r; - colorValues[i*4 + 1] = colors[i].g; - colorValues[i*4 + 2] = colors[i].b; - colorValues[i*4 + 3] = colors[i].a; + colorValues[i*4] = colors[i].r * scl; + colorValues[i*4 + 1] = colors[i].g * scl; + colorValues[i*4 + 2] = colors[i].b * scl; + colorValues[i*4 + 3] = colors[i].a * scl; } } diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 7e5b78dfaf..de789d5743 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -246,8 +246,12 @@ public class Mods implements Loadable{ LoadedMod mod = loadMod(file); mods.add(mod); }catch(Throwable e){ - Log.err("Failed to load mod file {0}. Skipping.", file); - Log.err(e); + if(e instanceof ClassNotFoundException && e.getMessage().contains("mindustry.plugin.Plugin")){ + Log.info("Plugin {0} is outdated and needs to be ported to 6.0! Update its main class to inherit from 'mindustry.mod.Plugin'."); + }else{ + Log.err("Failed to load mod file {0}. Skipping.", file); + Log.err(e); + } } } diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index a9e15f2080..d661ade2f6 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -1,7 +1,6 @@ package mindustry.ui.dialogs; import arc.*; -import arc.fx.util.*; import arc.graphics.*; import arc.graphics.g2d.*; import arc.graphics.g3d.*; @@ -46,6 +45,7 @@ public class PlanetDialog extends FloatingDialog{ private final Bloom bloom = new Bloom(Core.graphics.getWidth()/4, Core.graphics.getHeight()/4, true, false, true){{ setClearColor(0, 0, 0, 0); + setThreshold(0.8f); blurPasses = 6; }}; @@ -53,7 +53,6 @@ public class PlanetDialog extends FloatingDialog{ private float lastX, lastY; private @Nullable Sector selected, hovered; private Table stable; - private ScreenQuad quad = new ScreenQuad(); private Mesh atmosphere = MeshBuilder.buildHex(new HexMesher(){ @Override public float getHeight(Vec3 position){ @@ -149,11 +148,11 @@ public class PlanetDialog extends FloatingDialog{ projector.proj(cam.combined()); batch.proj(cam.combined()); - //bloom.capture(); + bloom.capture(); renderPlanet(solarSystem); - //bloom.render(); + bloom.render(); Gl.enable(Gl.blend); diff --git a/gradle.properties b/gradle.properties index 8abbe7724f..2bf79e63e4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=9659841bc145ba3db1dff036cfa1ca8f4ebdfabd +archash=be91508b5491f1697c4996ef93bfad2d0243f147