diff --git a/core/assets/shaders/sun.frag b/core/assets/shaders/sun.frag deleted file mode 100755 index d0ec6a77cc..0000000000 --- a/core/assets/shaders/sun.frag +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef GL_ES -precision mediump float; -precision lowp int; -#endif - -#define step 0.5 - -const int MAX_COLORS = 10; - -varying float v_height; - -uniform sampler2D u_colors; - -void main(){ - gl_FragColor = texture2D(u_colors, vec2(v_height, 0.0)); -} \ No newline at end of file diff --git a/core/assets/shaders/sun.vert b/core/assets/shaders/sun.vert deleted file mode 100755 index e362e68718..0000000000 --- a/core/assets/shaders/sun.vert +++ /dev/null @@ -1,92 +0,0 @@ -#ifdef GL_ES -precision mediump float; -precision lowp int; -#endif - -attribute vec4 a_position; -attribute vec3 a_normal; - -uniform mat4 u_proj; -uniform mat4 u_trans; - -uniform float u_time; -uniform int u_octaves; -uniform float u_falloff; -uniform float u_scale; -uniform float u_power; -uniform float u_spread; - -uniform float u_magnitude; -uniform float u_seed; - -varying float v_height; - -float rand(vec2 co){ - return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); -} - -vec4 permute(vec4 x){ return mod(((x*34.0)+1.0)*x, 289.0); } -float permute(float x){ return floor(mod(((x*34.0)+1.0)*x, 289.0)); } -vec4 taylorInvSqrt(vec4 r){ return 1.79284291400159 - 0.85373472095314 * r; } -float taylorInvSqrt(float r){ return 1.79284291400159 - 0.85373472095314 * r; } - -vec4 grad4(float j, vec4 ip){ - const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0); - vec4 p, s; - p.xyz = floor(fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0; - p.w = 1.5 - dot(abs(p.xyz), ones.xyz); - s = vec4(lessThan(p, vec4(0.0))); - p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www; - return p; -} - -float snoise(vec4 v){ - const vec2 C = vec2(0.138196601125010504, 0.309016994374947451); - vec4 i = floor(v + dot(v, C.yyyy)); - vec4 x0 = v - i + dot(i, C.xxxx); - vec4 i0; - vec3 isX = step(x0.yzw, x0.xxx); - vec3 isYZ = step(x0.zww, x0.yyz); - i0.x = isX.x + isX.y + isX.z; - i0.yzw = 1.0 - isX; - i0.y += isYZ.x + isYZ.y; - i0.zw += 1.0 - isYZ.xy; - i0.z += isYZ.z; - i0.w += 1.0 - isYZ.z; - vec4 i3 = clamp(i0, 0.0, 1.0); - vec4 i2 = clamp(i0-1.0, 0.0, 1.0); - vec4 i1 = clamp(i0-2.0, 0.0, 1.0); - vec4 x1 = x0 - i1 + 1.0 * C.xxxx; - vec4 x2 = x0 - i2 + 2.0 * C.xxxx; - vec4 x3 = x0 - i3 + 3.0 * C.xxxx; - vec4 x4 = x0 - 1.0 + 4.0 * C.xxxx; - i = mod(i, 289.0); - float j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x); - vec4 j1 = permute(permute(permute(permute ( - i.w + vec4(i1.w, i2.w, i3.w, 1.0)) - + i.z + vec4(i1.z, i2.z, i3.z, 1.0)) - + i.y + vec4(i1.y, i2.y, i3.y, 1.0)) - + i.x + vec4(i1.x, i2.x, i3.x, 1.0)); - vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0); - vec4 p0 = grad4(j0, ip); - vec4 p1 = grad4(j1.x, ip); - vec4 p2 = grad4(j1.y, ip); - vec4 p3 = grad4(j1.z, ip); - vec4 p4 = grad4(j1.w, ip); - vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); - p0 *= norm.x; - p1 *= norm.y; - p2 *= norm.z; - p3 *= norm.w; - p4 *= taylorInvSqrt(dot(p4, p4)); - vec3 m0 = max(0.6 - vec3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0); - vec2 m1 = max(0.6 - vec2(dot(x3, x3), dot(x4, x4)), 0.0); - m0 = m0 * m0; - m1 = m1 * m1; - return 49.0 * (dot(m0*m0, vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2)))+ dot(m1*m1, vec2(dot(p3, x3), dot(p4, x4)))); -} - -void main(){ - v_height = clamp((snoise(vec4(a_position.xyz, u_time + u_seed*2.0) / u_scale) + 0.7) / 2.0, 0.0, 1.0); - gl_Position = u_proj * u_trans * a_position; -} \ No newline at end of file diff --git a/core/assets/shaders/unlit.vert b/core/assets/shaders/unlit.vert new file mode 100755 index 0000000000..a75a12fe59 --- /dev/null +++ b/core/assets/shaders/unlit.vert @@ -0,0 +1,13 @@ +attribute vec4 a_position; +attribute vec3 a_normal; +attribute vec4 a_color; + +uniform mat4 u_proj; +uniform mat4 u_trans; + +varying vec4 v_col; + +void main(){ + v_col = a_color; + gl_Position = u_proj * u_trans * a_position; +} diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index a2c319dd1d..04371e86f1 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -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){{ diff --git a/core/src/mindustry/graphics/Shaders.java b/core/src/mindustry/graphics/Shaders.java index 2bcca0d886..6012792469 100644 --- a/core/src/mindustry/graphics/Shaders.java +++ b/core/src/mindustry/graphics/Shaders.java @@ -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(); diff --git a/core/src/mindustry/graphics/g3d/HexMesh.java b/core/src/mindustry/graphics/g3d/HexMesh.java index eff0c53101..e3ba7b9f27 100644 --- a/core/src/mindustry/graphics/g3d/HexMesh.java +++ b/core/src/mindustry/graphics/g3d/HexMesh.java @@ -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(); diff --git a/core/src/mindustry/graphics/g3d/ShaderSphereMesh.java b/core/src/mindustry/graphics/g3d/ShaderSphereMesh.java index 229cf7f710..e70dd07c29 100644 --- a/core/src/mindustry/graphics/g3d/ShaderSphereMesh.java +++ b/core/src/mindustry/graphics/g3d/ShaderSphereMesh.java @@ -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(){ + + } } diff --git a/core/src/mindustry/graphics/g3d/SunMesh.java b/core/src/mindustry/graphics/g3d/SunMesh.java index 58056a3e68..bef0761d5f 100644 --- a/core/src/mindustry/graphics/g3d/SunMesh.java +++ b/core/src/mindustry/graphics/g3d/SunMesh.java @@ -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 } } diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index 51affdd4ba..cfee9eeddc 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -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 satellites = new Array<>(); /** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */ - protected Prov meshLoader = () -> new SunMesh(this, 2); + protected Prov meshLoader = () -> new ShaderSphereMesh(this, Shaders.unlit, 2); public Planet(String name, Planet parent, int sectorSize, float radius){ super(name);