Added planet atmosphere shader

This commit is contained in:
Anuken
2020-03-29 17:08:25 -04:00
parent 65bf97bc03
commit f22e1bdeb3
8 changed files with 212 additions and 28 deletions

View File

@@ -38,6 +38,7 @@ public class Planets implements ContentList{
starter = new Planet("TODO", sun, 3, 1){{
generator = new TODOPlanetGenerator();
meshLoader = () -> new HexMesh(this, 6);
atmosphereColor = Color.valueOf("3c1b8f");
}};
}
}

View File

@@ -3,12 +3,14 @@ package mindustry.graphics;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.graphics.g3d.*;
import arc.graphics.gl.*;
import arc.math.*;
import arc.math.geom.*;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.type.*;
public class Shaders{
public static Shadow shadow;
@@ -22,6 +24,7 @@ public class Shaders{
public static PlanetShader planet;
public static PlanetGridShader planetGrid;
public static SunShader sun;
public static AtmosphereShader atmosphere;
public static void init(){
shadow = new Shadow();
@@ -43,6 +46,33 @@ public class Shaders{
planet = new PlanetShader();
planetGrid = new PlanetGridShader();
sun = new SunShader();
atmosphere = new AtmosphereShader();
}
public static class AtmosphereShader extends LoadShader{
public Camera3D camera;
public Planet planet;
Mat3D mat = new Mat3D();
public AtmosphereShader(){
super("atmosphere", "atmosphere");
}
@Override
public void apply(){
setUniformf("u_resolution", Core.graphics.getWidth(), Core.graphics.getHeight());
setUniformf("u_time", Time.globalTime() / 10f);
setUniformf("u_campos", camera.position);
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);
setUniformMatrix4("u_model", planet.getTransform(mat).val);
setUniformMatrix4("u_projection", camera.combined.val);
setUniformMatrix4("u_invproj", camera.invProjectionView.val);
}
}
public static class PlanetShader extends LoadShader{

View File

@@ -8,6 +8,7 @@ import arc.math.geom.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.ctype.*;
@@ -49,6 +50,8 @@ public class Planet extends UnlockableContent{
public boolean bloom = false;
/** For suns, this is the color that shines on other planets. Does nothing for children. */
public Color lightColor = Color.white.cpy();
/** Atmosphere tint for landable planets. */
public Color atmosphereColor = new Color(0.3f, 0.7f, 1.0f);
/** Parent body that this planet orbits around. If null, this planet is considered to be in the middle of the solar system.*/
public @Nullable Planet parent;
/** The root parent of the whole solar system this planet is in. */
@@ -128,6 +131,10 @@ public class Planet extends UnlockableContent{
}
}
public Vec3 getLightNormal(){
return Tmp.v31.set(solarSystem.position).sub(position).nor();
}
/** Calculates orbital rotation based on universe time.*/
public float getOrbitAngle(){
//applies random offset to prevent planets from starting out in a line

View File

@@ -1,6 +1,7 @@
package mindustry.ui.dialogs;
import arc.*;
import arc.fx.util.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.graphics.g3d.*;
@@ -51,7 +52,19 @@ public class PlanetDialog extends FloatingDialog{
private Planet planet = Planets.starter;
private float lastX, lastY;
private @Nullable Sector selected, hovered;
private Table stable, infoTable;
private Table stable;
private ScreenQuad quad = new ScreenQuad();
private Mesh atmosphere = MeshBuilder.buildHex(new HexMesher(){
@Override
public float getHeight(Vec3 position){
return 0;
}
@Override
public Color getColor(Vec3 position){
return Color.white;
}
}, 3, false, 1.5f, 0f);
public PlanetDialog(){
super("", Styles.fullDialog);
@@ -103,17 +116,8 @@ public class PlanetDialog extends FloatingDialog{
}
});
infoTable = new Table();
stable = new Table(t -> {
t.background(Styles.black3);
t.margin(12f);
t.add("this is some arbitrary text.");
});
stable.act(1f);
stable.pack();
stable.setPosition(0, 0, Align.center);
stable = new Table();
stable.background(Styles.black3);
shown(this::setup);
}
@@ -145,14 +149,11 @@ public class PlanetDialog extends FloatingDialog{
projector.proj(cam.combined());
batch.proj(cam.combined());
bloom.capture();
//bloom.capture();
renderPlanet(solarSystem);
if(planet.isLandable()){
renderSectors(planet);
}
bloom.render();
//bloom.render();
Gl.enable(Gl.blend);
@@ -189,10 +190,28 @@ public class PlanetDialog extends FloatingDialog{
private void renderPlanet(Planet planet){
//render planet at offsetted position in the world
planet.mesh.render(cam.combined(), planet.getTransform(mat));
planet.mesh.render(cam.combined, planet.getTransform(mat));
renderOrbit(planet);
if(planet.isLandable() && planet == this.planet){
renderSectors(planet);
}
if(planet.parent != null){
Gl.blendFunc(Gl.one, Gl.one);
Gl.enable(Gl.blend);
Shaders.atmosphere.camera = cam;
Shaders.atmosphere.planet = planet;
Shaders.atmosphere.bind();
Shaders.atmosphere.apply();
atmosphere.render(Shaders.atmosphere, Gl.triangles);
Gl.blendFunc(Blending.normal.src, Blending.normal.dst);
}
for(Planet child : planet.children){
renderPlanet(child);
}
@@ -218,7 +237,7 @@ public class PlanetDialog extends FloatingDialog{
}
if(sec.hostility >= 0.02f){
drawSelection(sec, Color.scarlet, 0.11f * sec.hostility);
//drawSelection(sec, Color.scarlet, 0.11f * sec.hostility);
}
}
@@ -230,6 +249,7 @@ public class PlanetDialog extends FloatingDialog{
if(selected != null){
drawSelection(selected);
drawBorders(selected, borderColor);
}
batch.flush(Gl.triangles);