mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 07:07:03 +07:00
Added cubemap stars
This commit is contained in:
parent
7ba7e14282
commit
fc65812263
BIN
core/assets/cubemaps/stars/back.png
Normal file
BIN
core/assets/cubemaps/stars/back.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 239 KiB |
BIN
core/assets/cubemaps/stars/bottom.png
Normal file
BIN
core/assets/cubemaps/stars/bottom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 447 KiB |
BIN
core/assets/cubemaps/stars/front.png
Normal file
BIN
core/assets/cubemaps/stars/front.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 398 KiB |
BIN
core/assets/cubemaps/stars/left.png
Normal file
BIN
core/assets/cubemaps/stars/left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 316 KiB |
BIN
core/assets/cubemaps/stars/right.png
Normal file
BIN
core/assets/cubemaps/stars/right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 229 KiB |
BIN
core/assets/cubemaps/stars/top.png
Normal file
BIN
core/assets/cubemaps/stars/top.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 280 KiB |
7
core/assets/shaders/cubemap.frag
Normal file
7
core/assets/shaders/cubemap.frag
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
varying vec3 v_texCoords;
|
||||||
|
|
||||||
|
uniform samplerCube u_cubemap;
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
gl_FragColor = textureCube(u_cubemap, v_texCoords);
|
||||||
|
}
|
12
core/assets/shaders/cubemap.vert
Normal file
12
core/assets/shaders/cubemap.vert
Normal file
@ -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);
|
||||||
|
}
|
85
core/src/mindustry/graphics/CubemapMesh.java
Normal file
85
core/src/mindustry/graphics/CubemapMesh.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -52,6 +52,8 @@ public class Planet extends UnlockableContent{
|
|||||||
public Color lightColor = Color.white.cpy();
|
public Color lightColor = Color.white.cpy();
|
||||||
/** Atmosphere tint for landable planets. */
|
/** Atmosphere tint for landable planets. */
|
||||||
public Color atmosphereColor = new Color(0.3f, 0.7f, 1.0f);
|
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.*/
|
/** 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;
|
public @Nullable Planet parent;
|
||||||
/** The root parent of the whole solar system this planet is in. */
|
/** The root parent of the whole solar system this planet is in. */
|
||||||
|
@ -63,11 +63,16 @@ public class PlanetDialog extends FloatingDialog{
|
|||||||
public Color getColor(Vec3 position){
|
public Color getColor(Vec3 position){
|
||||||
return Color.white;
|
return Color.white;
|
||||||
}
|
}
|
||||||
}, 3, false, 1.5f, 0f);
|
}, 2, false, 1.5f, 0f);
|
||||||
|
|
||||||
|
//seed: 8kmfuix03fw
|
||||||
|
private CubemapMesh skybox;
|
||||||
|
|
||||||
public PlanetDialog(){
|
public PlanetDialog(){
|
||||||
super("", Styles.fullDialog);
|
super("", Styles.fullDialog);
|
||||||
|
|
||||||
|
skybox = new CubemapMesh(new Cubemap("cubemaps/stars/"));
|
||||||
|
|
||||||
addCloseButton();
|
addCloseButton();
|
||||||
buttons.addImageTextButton("$techtree", Icon.tree, () -> ui.tech.show()).size(230f, 64f);
|
buttons.addImageTextButton("$techtree", Icon.tree, () -> ui.tech.show()).size(230f, 64f);
|
||||||
|
|
||||||
@ -150,6 +155,8 @@ public class PlanetDialog extends FloatingDialog{
|
|||||||
|
|
||||||
bloom.capture();
|
bloom.capture();
|
||||||
|
|
||||||
|
skybox.render(cam.combined);
|
||||||
|
|
||||||
renderPlanet(solarSystem);
|
renderPlanet(solarSystem);
|
||||||
|
|
||||||
bloom.render();
|
bloom.render();
|
||||||
@ -188,7 +195,6 @@ public class PlanetDialog extends FloatingDialog{
|
|||||||
|
|
||||||
private void renderPlanet(Planet planet){
|
private void renderPlanet(Planet planet){
|
||||||
//render planet at offsetted position in the world
|
//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);
|
renderOrbit(planet);
|
||||||
@ -197,9 +203,8 @@ public class PlanetDialog extends FloatingDialog{
|
|||||||
renderSectors(planet);
|
renderSectors(planet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(planet.parent != null){
|
if(planet.parent != null && planet.hasAtmosphere){
|
||||||
Gl.blendFunc(Gl.one, Gl.one);
|
Blending.additive.apply();
|
||||||
Gl.enable(Gl.blend);
|
|
||||||
|
|
||||||
Shaders.atmosphere.camera = cam;
|
Shaders.atmosphere.camera = cam;
|
||||||
Shaders.atmosphere.planet = planet;
|
Shaders.atmosphere.planet = planet;
|
||||||
@ -208,7 +213,7 @@ public class PlanetDialog extends FloatingDialog{
|
|||||||
|
|
||||||
atmosphere.render(Shaders.atmosphere, Gl.triangles);
|
atmosphere.render(Shaders.atmosphere, Gl.triangles);
|
||||||
|
|
||||||
Gl.blendFunc(Blending.normal.src, Blending.normal.dst);
|
Blending.normal.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Planet child : planet.children){
|
for(Planet child : planet.children){
|
||||||
|
Loading…
Reference in New Issue
Block a user