More branch merging
This commit is contained in:
@@ -10,27 +10,29 @@ public class IndexedRenderer implements Disposable{
|
||||
private static final int vsize = 5;
|
||||
|
||||
private final Shader program = new Shader(
|
||||
"attribute vec4 a_position;\n" +
|
||||
"attribute vec4 a_color;\n" +
|
||||
"attribute vec2 a_texCoord0;\n" +
|
||||
"uniform mat4 u_projTrans;\n" +
|
||||
"varying vec4 v_color;\n" +
|
||||
"varying vec2 v_texCoords;\n" +
|
||||
"""
|
||||
attribute vec4 a_position;
|
||||
attribute vec4 a_color;
|
||||
attribute vec2 a_texCoord0;
|
||||
uniform mat4 u_projTrans;
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_texCoords;
|
||||
void main(){
|
||||
v_color = a_color;
|
||||
v_color.a = v_color.a * (255.0/254.0);
|
||||
v_texCoords = a_texCoord0;
|
||||
gl_Position = u_projTrans * a_position;
|
||||
}
|
||||
""",
|
||||
|
||||
"void main(){\n" +
|
||||
" v_color = a_color;\n" +
|
||||
" v_color.a = v_color.a * (255.0/254.0);\n" +
|
||||
" v_texCoords = a_texCoord0;\n" +
|
||||
" gl_Position = u_projTrans * a_position;\n" +
|
||||
"}",
|
||||
|
||||
"varying lowp vec4 v_color;\n" +
|
||||
"varying vec2 v_texCoords;\n" +
|
||||
"uniform sampler2D u_texture;\n" +
|
||||
|
||||
"void main(){\n" +
|
||||
" gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" +
|
||||
"}"
|
||||
"""
|
||||
varying lowp vec4 v_color;
|
||||
varying vec2 v_texCoords;
|
||||
uniform sampler2D u_texture;
|
||||
void main(){
|
||||
gl_FragColor = v_color * texture2D(u_texture, v_texCoords);
|
||||
}
|
||||
"""
|
||||
);
|
||||
private Mesh mesh;
|
||||
private float[] tmpVerts = new float[vsize * 6];
|
||||
|
||||
@@ -191,7 +191,10 @@ public class LightRenderer{
|
||||
|
||||
Draw.color();
|
||||
buffer.begin(Color.clear);
|
||||
Draw.sort(false);
|
||||
Gl.blendEquationSeparate(Gl.funcAdd, Gl.max);
|
||||
//apparently necessary
|
||||
Blending.normal.apply();
|
||||
|
||||
for(Runnable run : lights){
|
||||
run.run();
|
||||
@@ -202,6 +205,7 @@ public class LightRenderer{
|
||||
Draw.rect(circleRegion, cir.x, cir.y, cir.radius * 2, cir.radius * 2);
|
||||
}
|
||||
Draw.reset();
|
||||
Draw.sort(true);
|
||||
buffer.end();
|
||||
Gl.blendEquationSeparate(Gl.funcAdd, Gl.funcAdd);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Shaders{
|
||||
public static LightShader light;
|
||||
public static SurfaceShader water, mud, tar, slag, cryofluid, space, caustics;
|
||||
public static PlanetShader planet;
|
||||
public static CloudShader clouds;
|
||||
public static PlanetGridShader planetGrid;
|
||||
public static AtmosphereShader atmosphere;
|
||||
public static MeshShader mesh;
|
||||
@@ -56,6 +57,7 @@ public class Shaders{
|
||||
// }
|
||||
//};
|
||||
planet = new PlanetShader();
|
||||
clouds = new CloudShader();
|
||||
planetGrid = new PlanetGridShader();
|
||||
atmosphere = new AtmosphereShader();
|
||||
unlit = new LoadShader("planet", "unlit");
|
||||
@@ -94,6 +96,7 @@ public class Shaders{
|
||||
public Vec3 lightDir = new Vec3(1, 1, 1).nor();
|
||||
public Color ambientColor = Color.white.cpy();
|
||||
public Vec3 camDir = new Vec3();
|
||||
public Planet planet;
|
||||
|
||||
public PlanetShader(){
|
||||
super("planet", "planet");
|
||||
@@ -101,7 +104,7 @@ public class Shaders{
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
camDir.set(renderer.planets.cam.direction).rotate(Vec3.Y, renderer.planets.planet.getRotation());
|
||||
camDir.set(renderer.planets.cam.direction).rotate(Vec3.Y, planet.getRotation());
|
||||
|
||||
setUniformf("u_lightdir", lightDir);
|
||||
setUniformf("u_ambientColor", ambientColor.r, ambientColor.g, ambientColor.b);
|
||||
@@ -109,6 +112,27 @@ public class Shaders{
|
||||
}
|
||||
}
|
||||
|
||||
public static class CloudShader extends LoadShader{
|
||||
public Vec3 lightDir = new Vec3(1, 1, 1).nor();
|
||||
public Color ambientColor = Color.white.cpy();
|
||||
public Vec3 camDir = new Vec3();
|
||||
public float alpha = 1f;
|
||||
public Planet planet;
|
||||
|
||||
public CloudShader(){
|
||||
super("planet", "clouds");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
camDir.set(renderer.planets.cam.direction).rotate(Vec3.Y, planet.getRotation());
|
||||
|
||||
setUniformf("u_alpha", alpha);
|
||||
setUniformf("u_lightdir", lightDir);
|
||||
setUniformf("u_ambientColor", ambientColor.r, ambientColor.g, ambientColor.b);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MeshShader extends LoadShader{
|
||||
|
||||
public MeshShader(){
|
||||
@@ -176,6 +200,7 @@ public class Shaders{
|
||||
public static class BlockBuildShader extends LoadShader{
|
||||
public float progress;
|
||||
public TextureRegion region = new TextureRegion();
|
||||
public float time;
|
||||
|
||||
public BlockBuildShader(){
|
||||
super("blockbuild", "default");
|
||||
@@ -186,7 +211,7 @@ public class Shaders{
|
||||
setUniformf("u_progress", progress);
|
||||
setUniformf("u_uv", region.u, region.v);
|
||||
setUniformf("u_uv2", region.u2, region.v2);
|
||||
setUniformf("u_time", Time.time);
|
||||
setUniformf("u_time", time);
|
||||
setUniformf("u_texsize", region.texture.width, region.texture.height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ public class Voronoi{
|
||||
private void clipLine(Edge e){
|
||||
float pxmin, pxmax, pymin, pymax;
|
||||
Site s1, s2;
|
||||
float x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
||||
float x1, x2, y1, y2;
|
||||
|
||||
x1 = e.reg[0].coord.x;
|
||||
x2 = e.reg[1].coord.x;
|
||||
|
||||
7
core/src/mindustry/graphics/g3d/GenericMesh.java
Normal file
7
core/src/mindustry/graphics/g3d/GenericMesh.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.math.geom.*;
|
||||
|
||||
public interface GenericMesh{
|
||||
void render(PlanetParams params, Mat3D projection, Mat3D transform);
|
||||
}
|
||||
@@ -15,8 +15,12 @@ public class HexMesh extends PlanetMesh{
|
||||
super(planet, MeshBuilder.buildHex(mesher, divisions, false, planet.radius, 0.2f), shader);
|
||||
}
|
||||
|
||||
public HexMesh(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
public void preRender(PlanetParams params){
|
||||
Shaders.planet.planet = planet;
|
||||
Shaders.planet.lightDir.set(planet.solarSystem.position).sub(planet.position).rotate(Vec3.Y, planet.getRotation()).nor();
|
||||
Shaders.planet.ambientColor.set(planet.solarSystem.lightColor);
|
||||
}
|
||||
|
||||
60
core/src/mindustry/graphics/g3d/HexSkyMesh.java
Normal file
60
core/src/mindustry/graphics/g3d/HexSkyMesh.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.noise.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
public class HexSkyMesh extends PlanetMesh{
|
||||
static Mat3D mat = new Mat3D();
|
||||
|
||||
public float speed = 0f;
|
||||
|
||||
public HexSkyMesh(Planet planet, int seed, float speed, float radius, int divisions, Color color, int octaves, float persistence, float scl, float thresh){
|
||||
super(planet, MeshBuilder.buildHex(new HexMesher(){
|
||||
@Override
|
||||
public float getHeight(Vec3 position){
|
||||
return 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor(Vec3 position){
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skip(Vec3 position){
|
||||
return Simplex.noise3d(planet.id + seed, octaves, persistence, scl, position.x, position.y * 3f, position.z) >= thresh;
|
||||
}
|
||||
}, divisions, false, planet.radius, radius), Shaders.clouds);
|
||||
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public HexSkyMesh(){
|
||||
}
|
||||
|
||||
public float relRot(){
|
||||
return Time.globalTime * speed / 40f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
preRender(params);
|
||||
shader.bind();
|
||||
shader.setUniformMatrix4("u_proj", projection.val);
|
||||
shader.setUniformMatrix4("u_trans", mat.setToTranslation(planet.position).rotate(Vec3.Y, planet.getRotation() + relRot()).val);
|
||||
shader.apply();
|
||||
mesh.render(shader, Gl.triangles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(PlanetParams params){
|
||||
Shaders.clouds.planet = planet;
|
||||
Shaders.clouds.lightDir.set(planet.solarSystem.position).sub(planet.position).rotate(Vec3.Y, planet.getRotation() + relRot()).nor();
|
||||
Shaders.clouds.ambientColor.set(planet.solarSystem.lightColor);
|
||||
Shaders.clouds.alpha = 1f - params.uiAlpha;
|
||||
}
|
||||
}
|
||||
22
core/src/mindustry/graphics/g3d/MatMesh.java
Normal file
22
core/src/mindustry/graphics/g3d/MatMesh.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.math.geom.*;
|
||||
|
||||
//TODO maybe this is a bad idea
|
||||
/** A GenericMesh that wraps and applies an additional transform to a generic mesh. */
|
||||
public class MatMesh implements GenericMesh{
|
||||
private static final Mat3D tmp = new Mat3D();
|
||||
|
||||
GenericMesh mesh;
|
||||
Mat3D mat;
|
||||
|
||||
public MatMesh(GenericMesh mesh, Mat3D mat){
|
||||
this.mesh = mesh;
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
mesh.render(params, projection, tmp.set(transform).mul(mat));
|
||||
}
|
||||
}
|
||||
18
core/src/mindustry/graphics/g3d/MultiMesh.java
Normal file
18
core/src/mindustry/graphics/g3d/MultiMesh.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.math.geom.*;
|
||||
|
||||
public class MultiMesh implements GenericMesh{
|
||||
GenericMesh[] meshes;
|
||||
|
||||
public MultiMesh(GenericMesh... meshes){
|
||||
this.meshes = meshes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
for(var v : meshes){
|
||||
v.render(params, projection, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
43
core/src/mindustry/graphics/g3d/NoiseMesh.java
Normal file
43
core/src/mindustry/graphics/g3d/NoiseMesh.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.noise.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
public class NoiseMesh extends HexMesh{
|
||||
|
||||
public NoiseMesh(Planet planet, int seed, int divisions, Color color, float radius, int octaves, float persistence, float scale, float mag){
|
||||
this.planet = planet;
|
||||
this.shader = Shaders.planet;
|
||||
this.mesh = MeshBuilder.buildHex(new HexMesher(){
|
||||
@Override
|
||||
public float getHeight(Vec3 position){
|
||||
return Simplex.noise3d(planet.id + seed, octaves, persistence, scale, 5f + position.x, 5f + position.y, 5f + position.z) * mag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor(Vec3 position){
|
||||
return color;
|
||||
}
|
||||
}, divisions, false, radius, 0.2f);
|
||||
}
|
||||
|
||||
/** Two-color variant. */
|
||||
public NoiseMesh(Planet planet, int seed, int divisions, float radius, int octaves, float persistence, float scale, float mag, Color color1, Color color2, int coct, float cper, float cscl, float cthresh){
|
||||
this.planet = planet;
|
||||
this.shader = Shaders.planet;
|
||||
this.mesh = MeshBuilder.buildHex(new HexMesher(){
|
||||
@Override
|
||||
public float getHeight(Vec3 position){
|
||||
return Simplex.noise3d(planet.id + seed, octaves, persistence, scale, 5f + position.x, 5f + position.y, 5f + position.z) * mag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor(Vec3 position){
|
||||
return Simplex.noise3d(planet.id + seed + 1, coct, cper, cscl, 5f + position.x, 5f + position.y, 5f + position.z) > cthresh ? color2 : color1;
|
||||
}
|
||||
}, divisions, false, radius, 0.2f);
|
||||
}
|
||||
}
|
||||
@@ -221,6 +221,8 @@ public class PlanetGrid{
|
||||
}
|
||||
|
||||
public static class Ptile{
|
||||
public static final Ptile empty = new Ptile(0, 0);
|
||||
|
||||
public int id;
|
||||
public int edgeCount;
|
||||
|
||||
|
||||
@@ -3,14 +3,13 @@ package mindustry.graphics.g3d;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.gl.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
/** Defines a mesh that is rendered for a planet. Subclasses provide a mesh and a shader. */
|
||||
public abstract class PlanetMesh implements Disposable{
|
||||
protected final Mesh mesh;
|
||||
protected final Planet planet;
|
||||
protected final Shader shader;
|
||||
public abstract class PlanetMesh implements GenericMesh{
|
||||
protected Mesh mesh;
|
||||
protected Planet planet;
|
||||
protected Shader shader;
|
||||
|
||||
public PlanetMesh(Planet planet, Mesh mesh, Shader shader){
|
||||
this.planet = planet;
|
||||
@@ -18,20 +17,21 @@ public abstract class PlanetMesh implements Disposable{
|
||||
this.shader = shader;
|
||||
}
|
||||
|
||||
/** Should be overridden to set up any shader parameters such as planet position, normals, etc. */
|
||||
public abstract void preRender();
|
||||
public PlanetMesh(){}
|
||||
|
||||
public void render(Mat3D projection, Mat3D transform){
|
||||
preRender();
|
||||
/** Should be overridden to set up any shader parameters such as planet position, normals, etc.
|
||||
* @param params*/
|
||||
public void preRender(PlanetParams params){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
preRender(params);
|
||||
shader.bind();
|
||||
shader.setUniformMatrix4("u_proj", projection.val);
|
||||
shader.setUniformMatrix4("u_trans", transform.val);
|
||||
shader.apply();
|
||||
mesh.render(shader, Gl.triangles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
mesh.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
40
core/src/mindustry/graphics/g3d/PlanetParams.java
Normal file
40
core/src/mindustry/graphics/g3d/PlanetParams.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.graphics.g3d.PlanetRenderer.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
/** Parameters for rendering a solar system. */
|
||||
public class PlanetParams{
|
||||
/** Camera direction relative to the planet. Length is determined by zoom. */
|
||||
public Vec3 camPos = new Vec3(0f, 0f, 4f);
|
||||
/** Camera up vector. */
|
||||
public Vec3 camUp = new Vec3(0f, 1f, 0f);
|
||||
/** the unit length direction vector of the camera **/
|
||||
public Vec3 camDir = new Vec3(0, 0, -1);
|
||||
/** The sun/main planet of the solar system from which everything is rendered. */
|
||||
public Planet solarSystem = Planets.sun;
|
||||
/** Planet being looked at. */
|
||||
public Planet planet = Planets.serpulo;
|
||||
/** Zoom relative to planet. */
|
||||
public float zoom = 1f;
|
||||
/** Alpha of orbit rings and other UI elements. */
|
||||
public float uiAlpha = 1f;
|
||||
/** If false, orbit and sector grid are not drawn. */
|
||||
public boolean drawUi = false;
|
||||
/** If true, a space skybox is drawn. */
|
||||
public boolean drawSkybox = true;
|
||||
|
||||
/** Handles drawing details. */
|
||||
public @Nullable transient PlanetInterfaceRenderer renderer;
|
||||
/** Viewport size. <=0 to use screen size. Do not change in rules. */
|
||||
public transient int viewW = -1, viewH = -1;
|
||||
/** If true, atmosphere will be drawn regardless of player options. */
|
||||
public transient boolean alwaysDrawAtmosphere = false;
|
||||
|
||||
//TODO:
|
||||
//- blur
|
||||
//- darken
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.g3d.PlanetGrid.*;
|
||||
@@ -25,25 +24,15 @@ public class PlanetRenderer implements Disposable{
|
||||
|
||||
private static final Seq<Vec3> points = new Seq<>();
|
||||
|
||||
/** Camera direction relative to the planet. Length is determined by zoom. */
|
||||
public final Vec3 camPos = new Vec3();
|
||||
/** The sun/main planet of the solar system from which everything is rendered. */
|
||||
public final Planet solarSystem = Planets.sun;
|
||||
/** Planet being looked at. */
|
||||
public Planet planet = Planets.serpulo;
|
||||
/** Camera used for rendering. */
|
||||
public Camera3D cam = new Camera3D();
|
||||
public final Camera3D cam = new Camera3D();
|
||||
/** Raw vertex batch. */
|
||||
public final VertexBatch3D batch = new VertexBatch3D(20000, false, true, 0);
|
||||
|
||||
public float zoom = 1f;
|
||||
public float orbitAlpha = 1f;
|
||||
|
||||
private final Mesh[] outlines = new Mesh[10];
|
||||
public final PlaneBatch3D projector = new PlaneBatch3D();
|
||||
public final Mat3D mat = new Mat3D();
|
||||
public final FrameBuffer buffer = new FrameBuffer(2, 2, true);
|
||||
public PlanetInterfaceRenderer irenderer;
|
||||
|
||||
public final Bloom bloom = new Bloom(Core.graphics.getWidth()/4, Core.graphics.getHeight()/4, true, false){{
|
||||
setThreshold(0.8f);
|
||||
@@ -55,16 +44,13 @@ public class PlanetRenderer implements Disposable{
|
||||
public final CubemapMesh skybox = new CubemapMesh(new Cubemap("cubemaps/stars/"));
|
||||
|
||||
public PlanetRenderer(){
|
||||
camPos.set(0, 0f, camLength);
|
||||
projector.setScaling(1f / 150f);
|
||||
cam.fov = 60f;
|
||||
cam.far = 150f;
|
||||
}
|
||||
|
||||
/** Render the entire planet scene to the screen. */
|
||||
public void render(PlanetInterfaceRenderer irenderer){
|
||||
this.irenderer = irenderer;
|
||||
|
||||
public void render(PlanetParams params){
|
||||
Draw.flush();
|
||||
Gl.clear(Gl.depthBufferBit);
|
||||
Gl.enable(Gl.depthTest);
|
||||
@@ -73,49 +59,63 @@ public class PlanetRenderer implements Disposable{
|
||||
Gl.enable(Gl.cullFace);
|
||||
Gl.cullFace(Gl.back);
|
||||
|
||||
int w = params.viewW <= 0 ? Core.graphics.getWidth() : params.viewW;
|
||||
int h = params.viewH <= 0 ? Core.graphics.getHeight() : params.viewH;
|
||||
|
||||
bloom.blending = !params.drawSkybox;
|
||||
|
||||
//lock to up vector so it doesn't get confusing
|
||||
cam.up.set(Vec3.Y);
|
||||
|
||||
cam.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||
camPos.setLength(planet.radius * camLength + (zoom-1f) * planet.radius * 2);
|
||||
cam.position.set(planet.position).add(camPos);
|
||||
cam.lookAt(planet.position);
|
||||
cam.resize(w, h);
|
||||
params.camPos.setLength((params.planet.radius + params.planet.camRadius) * camLength + (params.zoom-1f) * (params.planet.radius + params.planet.camRadius) * 2);
|
||||
cam.position.set(params.planet.position).add(params.camPos);
|
||||
//cam.up.set(params.camUp); //TODO broken
|
||||
cam.lookAt(params.planet.position);
|
||||
cam.update();
|
||||
//write back once it changes.
|
||||
params.camUp.set(cam.up);
|
||||
params.camDir.set(cam.direction);
|
||||
|
||||
projector.proj(cam.combined);
|
||||
batch.proj(cam.combined);
|
||||
|
||||
Events.fire(Trigger.universeDrawBegin);
|
||||
|
||||
beginBloom();
|
||||
//begin bloom
|
||||
bloom.resize(w, h);
|
||||
bloom.capture();
|
||||
|
||||
//render skybox at 0,0,0
|
||||
Vec3 lastPos = Tmp.v31.set(cam.position);
|
||||
cam.position.setZero();
|
||||
cam.update();
|
||||
if(params.drawSkybox){
|
||||
//render skybox at 0,0,0
|
||||
Vec3 lastPos = Tmp.v31.set(cam.position);
|
||||
cam.position.setZero();
|
||||
cam.update();
|
||||
|
||||
Gl.depthMask(false);
|
||||
Gl.depthMask(false);
|
||||
|
||||
skybox.render(cam.combined);
|
||||
skybox.render(cam.combined);
|
||||
|
||||
Gl.depthMask(true);
|
||||
Gl.depthMask(true);
|
||||
|
||||
cam.position.set(lastPos);
|
||||
cam.update();
|
||||
cam.position.set(lastPos);
|
||||
cam.update();
|
||||
}
|
||||
|
||||
Events.fire(Trigger.universeDraw);
|
||||
|
||||
renderPlanet(solarSystem);
|
||||
renderPlanet(params.solarSystem, params);
|
||||
renderTransparent(params.solarSystem, params);
|
||||
|
||||
renderTransparent(solarSystem);
|
||||
|
||||
endBloom();
|
||||
bloom.render();
|
||||
|
||||
Events.fire(Trigger.universeDrawEnd);
|
||||
|
||||
Gl.enable(Gl.blend);
|
||||
|
||||
irenderer.renderProjections(planet);
|
||||
if(params.renderer != null){
|
||||
params.renderer.renderProjections(params.planet);
|
||||
}
|
||||
|
||||
Gl.disable(Gl.cullFace);
|
||||
Gl.disable(Gl.depthTest);
|
||||
@@ -123,68 +123,64 @@ public class PlanetRenderer implements Disposable{
|
||||
cam.update();
|
||||
}
|
||||
|
||||
public void beginBloom(){
|
||||
bloom.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||
bloom.capture();
|
||||
}
|
||||
|
||||
public void endBloom(){
|
||||
bloom.render();
|
||||
}
|
||||
|
||||
|
||||
public void renderPlanet(Planet planet){
|
||||
public void renderPlanet(Planet planet, PlanetParams params){
|
||||
if(!planet.visible()) return;
|
||||
|
||||
cam.update();
|
||||
|
||||
if(cam.frustum.containsSphere(planet.position, planet.clipRadius)){
|
||||
//render planet at offsetted position in the world
|
||||
planet.draw(cam.combined, planet.getTransform(mat));
|
||||
planet.draw(params, cam.combined, planet.getTransform(mat));
|
||||
}
|
||||
|
||||
renderOrbit(planet);
|
||||
|
||||
for(Planet child : planet.children){
|
||||
renderPlanet(child);
|
||||
renderPlanet(child, params);
|
||||
}
|
||||
}
|
||||
|
||||
public void renderTransparent(Planet planet){
|
||||
public void renderTransparent(Planet planet, PlanetParams params){
|
||||
if(!planet.visible()) return;
|
||||
|
||||
if(planet.hasGrid() && planet == this.planet){
|
||||
renderSectors(planet);
|
||||
planet.drawClouds(params, cam.combined, planet.getTransform(mat));
|
||||
|
||||
if(planet.hasGrid() && planet == params.planet && params.drawUi){
|
||||
renderSectors(planet, params);
|
||||
}
|
||||
|
||||
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 && (params.alwaysDrawAtmosphere || Core.settings.getBool("atmosphere"))){
|
||||
planet.drawAtmosphere(atmosphere, cam);
|
||||
}
|
||||
|
||||
planet.drawClouds(cam.combined, planet.getTransform(mat));
|
||||
|
||||
for(Planet child : planet.children){
|
||||
renderTransparent(child);
|
||||
renderTransparent(child, params);
|
||||
}
|
||||
|
||||
batch.proj(cam.combined);
|
||||
|
||||
if(params.drawUi){
|
||||
renderOrbit(planet, params);
|
||||
}
|
||||
}
|
||||
|
||||
public void renderOrbit(Planet planet){
|
||||
if(planet.parent == null || !planet.visible() || orbitAlpha <= 0.02f) return;
|
||||
public void renderOrbit(Planet planet, PlanetParams params){
|
||||
if(planet.parent == null || !planet.visible() || params.uiAlpha <= 0.02f || !planet.drawOrbit) return;
|
||||
|
||||
Vec3 center = planet.parent.position;
|
||||
float radius = planet.orbitRadius;
|
||||
int points = (int)(radius * 10);
|
||||
Angles.circleVectors(points, radius, (cx, cy) -> batch.vertex(Tmp.v32.set(center).add(cx, 0, cy), Pal.gray.write(Tmp.c1).a(orbitAlpha)));
|
||||
Angles.circleVectors(points, radius, (cx, cy) -> batch.vertex(Tmp.v32.set(center).add(cx, 0, cy), Pal.gray.write(Tmp.c1).a(params.uiAlpha)));
|
||||
batch.flush(Gl.lineLoop);
|
||||
}
|
||||
|
||||
public void renderSectors(Planet planet){
|
||||
if(orbitAlpha <= 0.02f) return;
|
||||
public void renderSectors(Planet planet, PlanetParams params){
|
||||
if(params.uiAlpha <= 0.02f) return;
|
||||
|
||||
//apply transformed position
|
||||
batch.proj().mul(planet.getTransform(mat));
|
||||
|
||||
irenderer.renderSectors(planet);
|
||||
if(params.renderer != null){
|
||||
params.renderer.renderSectors(planet);
|
||||
}
|
||||
|
||||
//render sector grid
|
||||
Mesh mesh = outline(planet.grid.size);
|
||||
@@ -262,12 +258,12 @@ public class PlanetRenderer implements Disposable{
|
||||
}
|
||||
|
||||
public void setPlane(Sector sector){
|
||||
float rotation = -planet.getRotation();
|
||||
float rotation = -sector.planet.getRotation();
|
||||
float length = 0.01f;
|
||||
|
||||
projector.setPlane(
|
||||
//origin on sector position
|
||||
Tmp.v33.set(sector.tile.v).setLength(outlineRad + length).rotate(Vec3.Y, rotation).add(planet.position),
|
||||
Tmp.v33.set(sector.tile.v).setLength(outlineRad + length).rotate(Vec3.Y, rotation).add(sector.planet.position),
|
||||
//face up
|
||||
sector.plane.project(Tmp.v32.set(sector.tile.v).add(Vec3.Y)).sub(sector.tile.v).rotate(Vec3.Y, rotation).nor(),
|
||||
//right vector
|
||||
|
||||
@@ -8,9 +8,4 @@ public class ShaderSphereMesh extends PlanetMesh{
|
||||
public ShaderSphereMesh(Planet planet, Shader shader, int divisions){
|
||||
super(planet, MeshBuilder.buildIcosphere(divisions, planet.radius), shader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,4 @@ public class SunMesh extends HexMesh{
|
||||
}
|
||||
}, divisions, Shaders.unlit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
//do absolutely nothing
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user