Planet rendering infrastructure stuff
This commit is contained in:
@@ -7,4 +7,7 @@ import arc.math.geom.*;
|
|||||||
public interface HexMesher{
|
public interface HexMesher{
|
||||||
float getHeight(Vec3 position);
|
float getHeight(Vec3 position);
|
||||||
Color getColor(Vec3 position);
|
Color getColor(Vec3 position);
|
||||||
|
default boolean skip(Vec3 position){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ public class MeshBuilder{
|
|||||||
begin(grid.tiles.length * 12 * (3 + 3 + 1));
|
begin(grid.tiles.length * 12 * (3 + 3 + 1));
|
||||||
|
|
||||||
for(Ptile tile : grid.tiles){
|
for(Ptile tile : grid.tiles){
|
||||||
|
if(mesher.skip(tile.v)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Corner[] c = tile.corners;
|
Corner[] c = tile.corners;
|
||||||
|
|
||||||
|
|||||||
@@ -158,22 +158,11 @@ public class PlanetRenderer implements Disposable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(cam.frustum.containsSphere(planet.position, planet.clipRadius) && planet.parent != null && planet.hasAtmosphere && Core.settings.getBool("atmosphere")){
|
if(cam.frustum.containsSphere(planet.position, planet.clipRadius) && planet.parent != null && planet.hasAtmosphere && Core.settings.getBool("atmosphere")){
|
||||||
Gl.depthMask(false);
|
planet.drawAtmosphere(atmosphere, cam);
|
||||||
|
|
||||||
Blending.additive.apply();
|
|
||||||
|
|
||||||
Shaders.atmosphere.camera = cam;
|
|
||||||
Shaders.atmosphere.planet = planet;
|
|
||||||
Shaders.atmosphere.bind();
|
|
||||||
Shaders.atmosphere.apply();
|
|
||||||
|
|
||||||
atmosphere.render(Shaders.atmosphere, Gl.triangles);
|
|
||||||
|
|
||||||
Blending.normal.apply();
|
|
||||||
|
|
||||||
Gl.depthMask(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
planet.drawClouds(cam.combined, planet.getTransform(mat));
|
||||||
|
|
||||||
for(Planet child : planet.children){
|
for(Planet child : planet.children){
|
||||||
renderTransparent(child);
|
renderTransparent(child);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package mindustry.type;
|
|||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
|
import arc.graphics.g3d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
@@ -23,6 +24,8 @@ public class Planet extends UnlockableContent{
|
|||||||
private static final Vec3 intersectResult = new Vec3();
|
private static final Vec3 intersectResult = new Vec3();
|
||||||
/** Mesh used for rendering. Created on load() - will be null on the server! */
|
/** Mesh used for rendering. Created on load() - will be null on the server! */
|
||||||
public @Nullable PlanetMesh mesh;
|
public @Nullable PlanetMesh mesh;
|
||||||
|
/** Mesh used for rendering planet clouds. Null if no clouds are present. */
|
||||||
|
public @Nullable PlanetMesh cloudMesh;
|
||||||
/** Position in global coordinates. Will be 0,0,0 until the Universe updates it. */
|
/** Position in global coordinates. Will be 0,0,0 until the Universe updates it. */
|
||||||
public Vec3 position = new Vec3();
|
public Vec3 position = new Vec3();
|
||||||
/** Grid used for the sectors on the planet. Null if this planet can't be landed on. */
|
/** Grid used for the sectors on the planet. Null if this planet can't be landed on. */
|
||||||
@@ -74,7 +77,7 @@ public class Planet extends UnlockableContent{
|
|||||||
/** Satellites orbiting this planet. */
|
/** Satellites orbiting this planet. */
|
||||||
public Seq<Satellite> satellites = new Seq<>();
|
public Seq<Satellite> satellites = new Seq<>();
|
||||||
/** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */
|
/** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */
|
||||||
protected Prov<PlanetMesh> meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2);
|
protected Prov<PlanetMesh> meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2), cloudMeshLoader = () -> null;
|
||||||
|
|
||||||
public Planet(String name, Planet parent, int sectorSize, float radius){
|
public Planet(String name, Planet parent, int sectorSize, float radius){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -220,6 +223,7 @@ public class Planet extends UnlockableContent{
|
|||||||
super.load();
|
super.load();
|
||||||
|
|
||||||
mesh = meshLoader.get();
|
mesh = meshLoader.get();
|
||||||
|
cloudMesh = cloudMeshLoader.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -293,4 +297,28 @@ public class Planet extends UnlockableContent{
|
|||||||
public void draw(Mat3D projection, Mat3D transform){
|
public void draw(Mat3D projection, Mat3D transform){
|
||||||
mesh.render(projection, transform);
|
mesh.render(projection, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void drawAtmosphere(Mesh atmosphere, Camera3D cam){
|
||||||
|
//atmosphere does not contribute to depth buffer
|
||||||
|
Gl.depthMask(false);
|
||||||
|
|
||||||
|
Blending.additive.apply();
|
||||||
|
|
||||||
|
Shaders.atmosphere.camera = cam;
|
||||||
|
Shaders.atmosphere.planet = this;
|
||||||
|
Shaders.atmosphere.bind();
|
||||||
|
Shaders.atmosphere.apply();
|
||||||
|
|
||||||
|
atmosphere.render(Shaders.atmosphere, Gl.triangles);
|
||||||
|
|
||||||
|
Blending.normal.apply();
|
||||||
|
|
||||||
|
Gl.depthMask(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawClouds(Mat3D projection, Mat3D transform){
|
||||||
|
if(cloudMesh != null){
|
||||||
|
cloudMesh.render(projection, transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user