mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 18:57:39 +07:00
Better previews
This commit is contained in:
parent
a1fd621eb6
commit
fdaac290ac
@ -5,5 +5,5 @@ precision mediump float;
|
||||
varying vec4 v_col;
|
||||
|
||||
void main(){
|
||||
gl_FragColor = v_col;
|
||||
gl_FragColor = v_col;
|
||||
}
|
||||
|
14
core/assets/shaders/planetgrid.fragment.glsl
Normal file
14
core/assets/shaders/planetgrid.fragment.glsl
Normal file
@ -0,0 +1,14 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
varying vec4 v_col;
|
||||
varying vec4 v_position;
|
||||
|
||||
uniform vec3 u_mouse;
|
||||
|
||||
const vec4 shadow = vec4(0, 0, 0, 0);
|
||||
|
||||
void main(){
|
||||
gl_FragColor = mix(v_col, shadow, distance(u_mouse, v_position.xyz));
|
||||
}
|
12
core/assets/shaders/planetgrid.vertex.glsl
Normal file
12
core/assets/shaders/planetgrid.vertex.glsl
Normal file
@ -0,0 +1,12 @@
|
||||
attribute vec4 a_position;
|
||||
attribute vec4 a_color;
|
||||
|
||||
uniform mat4 u_projModelView;
|
||||
varying vec4 v_col;
|
||||
varying vec4 v_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = u_projModelView * a_position;
|
||||
v_col = a_color;
|
||||
v_position = a_position;
|
||||
}
|
@ -43,6 +43,12 @@ public class PlanetMesh{
|
||||
generateMesh();
|
||||
}
|
||||
|
||||
public @Nullable Vec3 intersect(Ray ray){
|
||||
boolean found = Intersector3D.intersectRaySphere(ray, center, radius, Tmp.v33);
|
||||
if(!found) return null;
|
||||
return Tmp.v33;
|
||||
}
|
||||
|
||||
/** @return the sector that is hit by this ray, or null if nothing intersects it. */
|
||||
public @Nullable Ptile getTile(Ray ray){
|
||||
boolean found = Intersector3D.intersectRaySphere(ray, center, radius, Tmp.v33);
|
||||
@ -51,10 +57,15 @@ public class PlanetMesh{
|
||||
}
|
||||
|
||||
public void render(Mat3D mat){
|
||||
Shaders.planet.begin();
|
||||
Shaders.planet.setUniformMatrix4("u_projModelView", mat.val);
|
||||
mesh.render(Shaders.planet, lines ? Gl.lines : Gl.triangles);
|
||||
Shaders.planet.end();
|
||||
render(mat, Shaders.planet);
|
||||
}
|
||||
|
||||
public void render(Mat3D mat, Shader shader){
|
||||
shader.begin();
|
||||
shader.setUniformMatrix4("u_projModelView", mat.val);
|
||||
shader.apply();
|
||||
mesh.render(shader, lines ? Gl.lines : Gl.triangles);
|
||||
shader.end();
|
||||
}
|
||||
|
||||
private void generateMesh(){
|
||||
|
@ -4,6 +4,7 @@ import arc.Core;
|
||||
import arc.graphics.Color;
|
||||
import arc.graphics.g2d.TextureRegion;
|
||||
import arc.graphics.gl.Shader;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.ui.layout.Scl;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.Time;
|
||||
@ -18,6 +19,7 @@ public class Shaders{
|
||||
public static LightShader light;
|
||||
public static SurfaceShader water, tar, slag;
|
||||
public static Shader planet;
|
||||
public static PlanetGridShader planetGrid;
|
||||
|
||||
public static void init(){
|
||||
shadow = new Shadow();
|
||||
@ -37,6 +39,20 @@ public class Shaders{
|
||||
tar = new SurfaceShader("tar");
|
||||
slag = new SurfaceShader("slag");
|
||||
planet = new LoadShader("planet", "planet");
|
||||
planetGrid = new PlanetGridShader();
|
||||
}
|
||||
|
||||
public static class PlanetGridShader extends LoadShader{
|
||||
public Vec3 mouse = new Vec3();
|
||||
|
||||
public PlanetGridShader(){
|
||||
super("planetgrid", "planetgrid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
setUniformf("u_mouse", mouse);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LightShader extends LoadShader{
|
||||
|
@ -22,7 +22,11 @@ import mindustry.ui.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class PlanetDialog extends FloatingDialog{
|
||||
private static final Color outlineColor = Pal.accent.cpy().a(0.6f), shadowColor = new Color(0, 0, 0, 0.7f);
|
||||
private static final Color
|
||||
outlineColor = Pal.accent.cpy().a(1f),
|
||||
hoverColor = Pal.accent.cpy().a(0.5f),
|
||||
borderColor = Pal.accent.cpy().a(0.3f),
|
||||
shadowColor = new Color(0, 0, 0, 0.7f);
|
||||
private static final float camLength = 4f;
|
||||
float outlineRad = 1.15f;
|
||||
|
||||
@ -126,9 +130,11 @@ public class PlanetDialog extends FloatingDialog{
|
||||
batch.proj(cam.combined());
|
||||
|
||||
PlanetMesh outline = outline(planet.size);
|
||||
Vec3 tile = outline.intersect(cam.getPickRay(Core.input.mouseX(), Core.input.mouseY()));
|
||||
Shaders.planetGrid.mouse.lerp(tile == null ? Vec3.Zero : tile, 0.2f);
|
||||
|
||||
planet.mesh.render(cam.combined());
|
||||
outline.render(cam.combined());
|
||||
outline.render(cam.combined(), Shaders.planetGrid);
|
||||
|
||||
for(Sector sec : planet.sectors){
|
||||
if(sec.save == null){
|
||||
@ -137,20 +143,24 @@ public class PlanetDialog extends FloatingDialog{
|
||||
}
|
||||
|
||||
if(hovered != null){
|
||||
draw(hovered, outlineColor, 0.001f);
|
||||
|
||||
//if(Core.input.keyTap(KeyCode.SPACE)){
|
||||
// control.playSector(hovered);
|
||||
// ui.planet.hide();
|
||||
//}
|
||||
draw(hovered, hoverColor, -0.001f);
|
||||
drawBorders(hovered, borderColor);
|
||||
}
|
||||
|
||||
if(selected != null){
|
||||
drawSelection(selected);
|
||||
drawBorders(selected, borderColor);
|
||||
|
||||
//TODO use better input
|
||||
if(Core.input.keyTap(KeyCode.SPACE)){
|
||||
control.playSector(selected);
|
||||
ui.planet.hide();
|
||||
}
|
||||
}
|
||||
|
||||
batch.flush(Gl.triangles);
|
||||
|
||||
if(true)
|
||||
Draw.batch(projector, () -> {
|
||||
if(hovered != null){
|
||||
setPlane(hovered);
|
||||
@ -163,13 +173,43 @@ public class PlanetDialog extends FloatingDialog{
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
Vec3 pos = cam.project(Tmp.v31.set(selected.tile.v).setLength(outlineRad));
|
||||
selectTable.setPosition(pos.x, pos.y, Align.center);
|
||||
selectTable.draw();
|
||||
*/
|
||||
//3D aligned table
|
||||
|
||||
Gl.disable(Gl.cullFace);
|
||||
Gl.disable(Gl.depthTest);
|
||||
|
||||
if(false && selected != null){
|
||||
Vec3 pos = cam.project(Tmp.v31.set(selected.tile.v).setLength(outlineRad));
|
||||
stable.setPosition(pos.x, pos.y, Align.center);
|
||||
stable.draw();
|
||||
}
|
||||
}
|
||||
|
||||
private void drawBorders(Sector sector, Color base){
|
||||
Color color = Tmp.c1.set(base).a(base.a + 0.3f + Mathf.absin(Time.globalTime(), 5f, 0.3f));
|
||||
|
||||
float r1 = 1f;
|
||||
float r2 = outlineRad + 0.001f;
|
||||
|
||||
for(int i = 0; i < sector.tile.corners.length; i++){
|
||||
Corner c = sector.tile.corners[i], next = sector.tile.corners[(i+1) % sector.tile.corners.length];
|
||||
|
||||
Tmp.v31.set(c.v).setLength(r2);
|
||||
Tmp.v32.set(next.v).setLength(r2);
|
||||
Tmp.v33.set(c.v).setLength(r1);
|
||||
|
||||
batch.tri2(Tmp.v31, Tmp.v32, Tmp.v33, color);
|
||||
|
||||
Tmp.v31.set(next.v).setLength(r2);
|
||||
Tmp.v32.set(next.v).setLength(r1);
|
||||
Tmp.v33.set(c.v).setLength(r1);
|
||||
|
||||
batch.tri2(Tmp.v31, Tmp.v32, Tmp.v33, color);
|
||||
}
|
||||
|
||||
if(batch.getNumVertices() >= batch.getMaxVertices() - 6 * 6){
|
||||
batch.flush(Gl.triangles);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSelected(){
|
||||
@ -205,7 +245,7 @@ public class PlanetDialog extends FloatingDialog{
|
||||
private void setPlane(Sector sector){
|
||||
projector.setPlane(
|
||||
//origin on sector position
|
||||
Tmp.v33.set(sector.tile.v).setLength(outlineRad + 0.001f),
|
||||
Tmp.v33.set(sector.tile.v).setLength(outlineRad + 0.1f),
|
||||
//face up
|
||||
sector.plane.project(Tmp.v32.set(sector.tile.v).add(Vec3.Y)).sub(sector.tile.v).nor(),
|
||||
//right vector
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=7dd0965f3ca6684d3bd78b821c5a69e8922fa71b
|
||||
archash=4db0d154520aa33bbd35c0a71a6e1d9794f3f403
|
||||
|
Loading…
Reference in New Issue
Block a user