Atmosphere tweaks

This commit is contained in:
Anuken 2020-03-29 18:34:00 -04:00
parent f22e1bdeb3
commit 7ba7e14282
8 changed files with 44 additions and 30 deletions

View File

@ -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);

View File

@ -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
}

View File

@ -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"),

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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);

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=9659841bc145ba3db1dff036cfa1ca8f4ebdfabd
archash=be91508b5491f1697c4996ef93bfad2d0243f147