diff --git a/core/assets/cubemaps/stars/back.png b/core/assets/cubemaps/stars/back.png new file mode 100644 index 0000000000..05f3375811 Binary files /dev/null and b/core/assets/cubemaps/stars/back.png differ diff --git a/core/assets/cubemaps/stars/bottom.png b/core/assets/cubemaps/stars/bottom.png new file mode 100644 index 0000000000..bfcded64e3 Binary files /dev/null and b/core/assets/cubemaps/stars/bottom.png differ diff --git a/core/assets/cubemaps/stars/front.png b/core/assets/cubemaps/stars/front.png new file mode 100644 index 0000000000..8e9dbcd437 Binary files /dev/null and b/core/assets/cubemaps/stars/front.png differ diff --git a/core/assets/cubemaps/stars/left.png b/core/assets/cubemaps/stars/left.png new file mode 100644 index 0000000000..f99a70ab1b Binary files /dev/null and b/core/assets/cubemaps/stars/left.png differ diff --git a/core/assets/cubemaps/stars/right.png b/core/assets/cubemaps/stars/right.png new file mode 100644 index 0000000000..f1c6f5c807 Binary files /dev/null and b/core/assets/cubemaps/stars/right.png differ diff --git a/core/assets/cubemaps/stars/top.png b/core/assets/cubemaps/stars/top.png new file mode 100644 index 0000000000..078e1a3d3f Binary files /dev/null and b/core/assets/cubemaps/stars/top.png differ diff --git a/core/assets/shaders/cubemap.frag b/core/assets/shaders/cubemap.frag new file mode 100644 index 0000000000..17fbeff2a3 --- /dev/null +++ b/core/assets/shaders/cubemap.frag @@ -0,0 +1,7 @@ +varying vec3 v_texCoords; + +uniform samplerCube u_cubemap; + +void main(){ + gl_FragColor = textureCube(u_cubemap, v_texCoords); +} \ No newline at end of file diff --git a/core/assets/shaders/cubemap.vert b/core/assets/shaders/cubemap.vert new file mode 100644 index 0000000000..546cec8f46 --- /dev/null +++ b/core/assets/shaders/cubemap.vert @@ -0,0 +1,12 @@ +attribute vec3 a_position; + +varying vec3 v_texCoords; + +uniform mat4 u_proj; + +const float SCALE = 50.0; + +void main(){ + v_texCoords = a_position; + gl_Position = u_proj * vec4(a_position * SCALE, 1.0); +} \ No newline at end of file diff --git a/core/src/mindustry/graphics/CubemapMesh.java b/core/src/mindustry/graphics/CubemapMesh.java new file mode 100644 index 0000000000..d0901670dd --- /dev/null +++ b/core/src/mindustry/graphics/CubemapMesh.java @@ -0,0 +1,85 @@ +package mindustry.graphics; + +import arc.*; +import arc.graphics.*; +import arc.graphics.Texture.*; +import arc.graphics.VertexAttributes.*; +import arc.graphics.gl.*; +import arc.math.geom.*; +import arc.util.*; + +public class CubemapMesh implements Disposable{ + private static final float[] vertices = { + -1.0f, 1.0f, -1.0f, + -1.0f, -1.0f, -1.0f, + 1.0f, -1.0f, -1.0f, + 1.0f, -1.0f, -1.0f, + 1.0f, 1.0f, -1.0f, + -1.0f, 1.0f, -1.0f, + + -1.0f, -1.0f, 1.0f, + -1.0f, -1.0f, -1.0f, + -1.0f, 1.0f, -1.0f, + -1.0f, 1.0f, -1.0f, + -1.0f, 1.0f, 1.0f, + -1.0f, -1.0f, 1.0f, + + 1.0f, -1.0f, -1.0f, + 1.0f, -1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, -1.0f, + 1.0f, -1.0f, -1.0f, + + -1.0f, -1.0f, 1.0f, + -1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, -1.0f, 1.0f, + -1.0f, -1.0f, 1.0f, + + -1.0f, 1.0f, -1.0f, + 1.0f, 1.0f, -1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + -1.0f, 1.0f, 1.0f, + -1.0f, 1.0f, -1.0f, + + -1.0f, -1.0f, -1.0f, + -1.0f, -1.0f, 1.0f, + 1.0f, -1.0f, -1.0f, + 1.0f, -1.0f, -1.0f, + -1.0f, -1.0f, 1.0f, + 1.0f, -1.0f, 1.0f + }; + + private final Mesh mesh; + private final Cubemap map; + private final Shader shader; + + public CubemapMesh(Cubemap map){ + this.map = map; + this.map.setFilter(TextureFilter.Linear); + this.mesh = new Mesh(true, vertices.length, 0, + new VertexAttribute(Usage.position, 3, "a_position") + ); + mesh.getVerticesBuffer().limit(vertices.length); + mesh.getVerticesBuffer().put(vertices, 0, vertices.length); + + shader = new Shader(Core.files.internal("shaders/cubemap.vert"), Core.files.internal("shaders/cubemap.frag")); + } + + public void render(Mat3D projection){ + map.bind(); + shader.bind(); + shader.setUniformi("u_cubemap", 0); + shader.setUniformMatrix4("u_proj", projection.val); + mesh.render(shader, Gl.triangles); + } + + @Override + public void dispose(){ + mesh.dispose(); + map.dispose(); + } +} diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index 6d0aec0fb2..51affdd4ba 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -52,6 +52,8 @@ public class Planet extends UnlockableContent{ public Color lightColor = Color.white.cpy(); /** Atmosphere tint for landable planets. */ public Color atmosphereColor = new Color(0.3f, 0.7f, 1.0f); + /** Whether this planet has an atmosphere. */ + public boolean hasAtmosphere = true; /** 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. */ diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index d661ade2f6..834a79f018 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -63,11 +63,16 @@ public class PlanetDialog extends FloatingDialog{ public Color getColor(Vec3 position){ return Color.white; } - }, 3, false, 1.5f, 0f); + }, 2, false, 1.5f, 0f); + + //seed: 8kmfuix03fw + private CubemapMesh skybox; public PlanetDialog(){ super("", Styles.fullDialog); + skybox = new CubemapMesh(new Cubemap("cubemaps/stars/")); + addCloseButton(); buttons.addImageTextButton("$techtree", Icon.tree, () -> ui.tech.show()).size(230f, 64f); @@ -150,6 +155,8 @@ public class PlanetDialog extends FloatingDialog{ bloom.capture(); + skybox.render(cam.combined); + renderPlanet(solarSystem); bloom.render(); @@ -188,7 +195,6 @@ 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)); renderOrbit(planet); @@ -197,9 +203,8 @@ public class PlanetDialog extends FloatingDialog{ renderSectors(planet); } - if(planet.parent != null){ - Gl.blendFunc(Gl.one, Gl.one); - Gl.enable(Gl.blend); + if(planet.parent != null && planet.hasAtmosphere){ + Blending.additive.apply(); Shaders.atmosphere.camera = cam; Shaders.atmosphere.planet = planet; @@ -208,7 +213,7 @@ public class PlanetDialog extends FloatingDialog{ atmosphere.render(Shaders.atmosphere, Gl.triangles); - Gl.blendFunc(Blending.normal.src, Blending.normal.dst); + Blending.normal.apply(); } for(Planet child : planet.children){