Better sun
This commit is contained in:
@@ -15,25 +15,20 @@ public class Planets implements ContentList{
|
||||
public void load(){
|
||||
sun = new Planet("sun", null, 0, 2){{
|
||||
bloom = true;
|
||||
//lightColor = Color.valueOf("f4ee8e");
|
||||
meshLoader = () -> new SunMesh(this, 3){{
|
||||
setColors(
|
||||
1.1f,
|
||||
Color.valueOf("ff7a38"),
|
||||
Color.valueOf("ff9638"),
|
||||
Color.valueOf("ffc64c"),
|
||||
Color.valueOf("ffc64c"),
|
||||
Color.valueOf("ffe371"),
|
||||
Color.valueOf("f4ee8e")
|
||||
);
|
||||
|
||||
scale = 1f;
|
||||
speed = 1000f;
|
||||
falloff = 0.3f;
|
||||
octaves = 4;
|
||||
spread = 1.2f;
|
||||
magnitude = 0f;
|
||||
}};
|
||||
//lightColor = Color.valueOf("f4ee8e");
|
||||
|
||||
meshLoader = () -> new SunMesh(
|
||||
this, 4,
|
||||
5, 0.3, 1.7, 1.2, 1,
|
||||
1.1f,
|
||||
Color.valueOf("ff7a38"),
|
||||
Color.valueOf("ff9638"),
|
||||
Color.valueOf("ffc64c"),
|
||||
Color.valueOf("ffc64c"),
|
||||
Color.valueOf("ffe371"),
|
||||
Color.valueOf("f4ee8e")
|
||||
);
|
||||
}};
|
||||
|
||||
starter = new Planet("TODO", sun, 3, 1){{
|
||||
|
||||
@@ -6,7 +6,6 @@ import arc.graphics.Texture.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.graphics.g3d.*;
|
||||
import arc.graphics.gl.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
@@ -26,9 +25,9 @@ public class Shaders{
|
||||
public static SurfaceShader water, tar, slag;
|
||||
public static PlanetShader planet;
|
||||
public static PlanetGridShader planetGrid;
|
||||
public static SunShader sun;
|
||||
public static AtmosphereShader atmosphere;
|
||||
public static MeshShader mesh = new MeshShader();
|
||||
public static Shader unlit;
|
||||
|
||||
public static void init(){
|
||||
shadow = new Shadow();
|
||||
@@ -49,8 +48,8 @@ public class Shaders{
|
||||
slag = new SurfaceShader("slag");
|
||||
planet = new PlanetShader();
|
||||
planetGrid = new PlanetGridShader();
|
||||
sun = new SunShader();
|
||||
atmosphere = new AtmosphereShader();
|
||||
unlit = new LoadShader("planet", "unlit");
|
||||
}
|
||||
|
||||
public static class AtmosphereShader extends LoadShader{
|
||||
@@ -105,32 +104,6 @@ public class Shaders{
|
||||
}
|
||||
}
|
||||
|
||||
public static class SunShader extends LoadShader{
|
||||
public int octaves = 5;
|
||||
public float falloff = 0.5f, scale = 1f, power = 1.3f, magnitude = 0.6f, speed = 99999999999f, spread = 1.3f, seed = Mathf.random(9999f);
|
||||
public Texture colors;
|
||||
|
||||
public SunShader(){
|
||||
super("sun", "sun");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
colors.bind(1);
|
||||
Gl.activeTexture(Gl.texture0);
|
||||
|
||||
setUniformi("u_colors", 1);
|
||||
setUniformi("u_octaves", octaves);
|
||||
setUniformf("u_falloff", falloff);
|
||||
setUniformf("u_scale", scale);
|
||||
setUniformf("u_power", power);
|
||||
setUniformf("u_magnitude", magnitude);
|
||||
setUniformf("u_time", Time.globalTime() / speed);
|
||||
setUniformf("u_seed", seed);
|
||||
setUniformf("u_spread", spread);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlanetGridShader extends LoadShader{
|
||||
public Vec3 mouse = new Vec3();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.graphics.gl.*;
|
||||
import arc.math.geom.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
@@ -10,6 +11,10 @@ public class HexMesh extends PlanetMesh{
|
||||
super(planet, MeshBuilder.buildHex(planet.generator, divisions, false, planet.radius, 0.2f), Shaders.planet);
|
||||
}
|
||||
|
||||
public HexMesh(Planet planet, HexMesher mesher, int divisions, Shader shader){
|
||||
super(planet, MeshBuilder.buildHex(mesher, divisions, false, planet.radius, 0.2f), shader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
Shaders.planet.lightDir.set(planet.solarSystem.position).sub(planet.position).rotate(Vec3.Y, planet.getRotation()).nor();
|
||||
|
||||
@@ -3,9 +3,14 @@ package mindustry.graphics.g3d;
|
||||
import arc.graphics.gl.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
public abstract class ShaderSphereMesh extends PlanetMesh{
|
||||
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(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,45 +2,33 @@ package mindustry.graphics.g3d;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.noise.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.Shaders.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
public class SunMesh extends ShaderSphereMesh{
|
||||
public int octaves = 5;
|
||||
public float falloff = 0.5f, scale = 1f, power = 1.3f, magnitude = 0.6f, speed = 99999999999f, spread = 1.3f, seed = Mathf.random(9999f);
|
||||
public Texture colors;
|
||||
public class SunMesh extends HexMesh{
|
||||
|
||||
public SunMesh(Planet planet, int divisions){
|
||||
super(planet, Shaders.sun, divisions);
|
||||
}
|
||||
public SunMesh(Planet planet, int divisions, double octaves, double persistence, double scl, double pow, double mag, float colorScale, Color... colors){
|
||||
super(planet, new HexMesher(){
|
||||
Simplex sim = new Simplex();
|
||||
|
||||
public void setColors(float scl, Color... colors){
|
||||
Pixmap pix = new Pixmap(colors.length, 1);
|
||||
for(int i = 0; i < colors.length; i++){
|
||||
pix.draw(i, 0, Tmp.c1.set(colors[i]).mul(scl));
|
||||
}
|
||||
this.colors = new Texture(pix);
|
||||
pix.dispose();
|
||||
@Override
|
||||
public float getHeight(Vec3 position){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor(Vec3 position){
|
||||
double height = Math.pow(sim.octaveNoise3D(octaves, persistence, scl, position.x, position.y, position.z), pow) * mag;
|
||||
return Tmp.c1.set(colors[Mathf.clamp((int)(height * colors.length), 0, colors.length - 1)]).mul(colorScale);
|
||||
}
|
||||
}, divisions, Shaders.unlit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
SunShader s = (SunShader)shader;
|
||||
s.octaves = octaves;
|
||||
s.falloff = falloff;
|
||||
s.scale = scale;
|
||||
s.power = power;
|
||||
s.magnitude = magnitude;
|
||||
s.speed = speed;
|
||||
s.seed = seed;
|
||||
s.colors = colors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
super.dispose();
|
||||
colors.dispose();
|
||||
//do absolutely nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.g3d.*;
|
||||
import mindustry.graphics.g3d.PlanetGrid.*;
|
||||
import mindustry.maps.generators.*;
|
||||
@@ -63,7 +64,7 @@ public class Planet extends UnlockableContent{
|
||||
/** Sattelites orbiting this planet. */
|
||||
public Array<Satellite> satellites = new Array<>();
|
||||
/** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */
|
||||
protected Prov<PlanetMesh> meshLoader = () -> new SunMesh(this, 2);
|
||||
protected Prov<PlanetMesh> meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2);
|
||||
|
||||
public Planet(String name, Planet parent, int sectorSize, float radius){
|
||||
super(name);
|
||||
|
||||
Reference in New Issue
Block a user