Added cubemap stars

This commit is contained in:
Anuken 2020-03-29 19:39:29 -04:00
parent 7ba7e14282
commit fc65812263
11 changed files with 117 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 KiB

View File

@ -0,0 +1,7 @@
varying vec3 v_texCoords;
uniform samplerCube u_cubemap;
void main(){
gl_FragColor = textureCube(u_cubemap, v_texCoords);
}

View 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);
}

View 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();
}
}

View File

@ -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. */

View File

@ -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){