Skip to content

Commit

Permalink
Debug lines
Browse files Browse the repository at this point in the history
  • Loading branch information
GlennFolker committed Feb 8, 2024
1 parent 4640c2f commit d832bf2
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jobs:
buildJar:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
Expand All @@ -17,7 +17,7 @@ jobs:
chmod +x gradlew
./gradlew clean dex
- name: Upload built mod artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Confictura (zipped)
path: build/libs/Confictura.jar
19 changes: 19 additions & 0 deletions assets/shaders/confictura/planet-debug.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
varying vec3 v_near;
varying vec3 v_far;

vec4 grid(vec3 pos, float scale) {
vec2 coord = pos.xz * scale;
vec2 derivative = fwidth(coord);
vec2 grid = abs(fract(coord - 0.5) - 0.5) / derivative;

float line = min(grid.x, grid.y);
return vec4(0.2, 0.2, 0.2, 1.0 - min(line, 1.0));
}

void main() {
float t = -v_near.y / (v_far.y - v_near.y);
if(t <= 0.0) discard;

vec3 pos = v_near + t * (v_far - v_near);
gl_FragColor = grid(pos, 1.0) * vec4(1.0, 1.0, 1.0, 1.0 - t * 2.0);
}
18 changes: 18 additions & 0 deletions assets/shaders/confictura/planet-debug.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
attribute vec2 a_position;

varying vec3 v_near;
varying vec3 v_far;

uniform mat4 u_invProj;

vec3 unproj(float x, float y, float z){
vec4 point = u_invProj * vec4(x, y, z, 1.0);
return point.xyz / point.w;
}

void main(){
vec2 pos = a_position;
v_near = unproj(pos.x, pos.y, 0.0);
v_far = unproj(pos.x, pos.y, 1.0);
gl_Position = vec4(pos, 0.0, 1.0);
}
7 changes: 7 additions & 0 deletions src/confictura/ConficturaMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import confictura.content.*;
import confictura.gen.*;
import confictura.graphics.*;
import confictura.ui.*;
import confictura.util.*;
import mindustry.game.EventType.*;
import mindustry.mod.*;
Expand All @@ -27,6 +28,8 @@ public class ConficturaMod extends Mod{
public static Seq<String> packages;
public static Seq<Class<?>> classes;

public static PlanetDebug planetDebug;

public ConficturaMod(){
try{
Class<? extends DevBuild> devImpl = (Class<? extends DevBuild>)Class.forName("confictura.DevBuildImpl", true, mods.mainLoader());
Expand Down Expand Up @@ -60,6 +63,10 @@ public ConficturaMod(){
app.post(() -> {
ScriptUtils.init();
ScriptUtils.importDefaults(ScriptUtils.modScope);

if(!headless){
planetDebug = new PlanetDebug();
}
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/confictura/DevBuildImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import confictura.util.*;
import mindustry.ui.dialogs.*;

import static confictura.ConficturaMod.*;
import static mindustry.Vars.*;

/**
* Implementation class for {@link DevBuild}. This class is excluded in the built JARs for non-developer builds.
* @author GlennFolker
Expand All @@ -18,5 +21,6 @@ public DevBuildImpl(){
@Override
public void init(){
ScriptUtils.importDefaults(ScriptUtils.vanillaScope);
if(!headless) planetDebug.enabled = true;
}
}
6 changes: 5 additions & 1 deletion src/confictura/content/CPlanets.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import arc.graphics.*;
import arc.math.*;
import arc.util.*;
import arc.util.noise.*;
import confictura.*;
import confictura.graphics.g3d.*;
Expand Down Expand Up @@ -72,7 +73,10 @@ public static void load(){
minZoom = 0.75f;

structureMeshLoader = () -> new MeshDrawer<CelestialVertex>(){{
face(new CelestialRect(0f, 1f, 0f, 0f, 0f, 0f, 1f, 1f, monolithMid));
for(int i = 0; i < 6; i++){
Tmp.v1.trns(i * 360f / 6f, 0.5f);
face(new CelestialRect(0f, 1f, 0f, 0f, 0f, 0f, 1f, 1f, monolithMid));
}
}}.build();

islands = new Island[]{
Expand Down
4 changes: 4 additions & 0 deletions src/confictura/graphics/CShaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public final class CShaders{
public static DepthAtmosphereShader depthAtmosphere;
public static PortalForcefieldShader portalForcefield;

public static PlanetDebugShader planetDebug;

private CShaders(){
throw new AssertionError();
}
Expand All @@ -25,6 +27,8 @@ public static void load(){
depth = new DepthShader();
depthAtmosphere = new DepthAtmosphereShader();
portalForcefield = new PortalForcefieldShader();

planetDebug = new PlanetDebugShader();
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/confictura/graphics/shaders/PlanetDebugShader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package confictura.graphics.shaders;

import arc.graphics.g3d.*;
import arc.graphics.gl.*;

import static confictura.graphics.CShaders.*;

/**
* Draws an infinite plane grid on the planet dialog.
* @author GlennFolker
*/
public class PlanetDebugShader extends Shader{
public Camera3D camera;

public PlanetDebugShader(){
super(file("planet-debug.vert"), file("planet-debug.frag"));
}

@Override
public void apply(){
setUniformMatrix4("u_invProj", camera.invProjectionView.val);
}
}
32 changes: 32 additions & 0 deletions src/confictura/ui/PlanetDebug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package confictura.ui;

import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import confictura.graphics.*;
import mindustry.game.EventType.*;

import static mindustry.Vars.*;

/**
* Debugging element added to the planet dialog. Currently draws an infinite grid for helpers.
* @author GlennFolker
*/
public class PlanetDebug{
public boolean enabled = false;

public PlanetDebug(){
Events.run(Trigger.universeDrawEnd, this::draw);
}

public void draw(){
if(!enabled) return;
Gl.enable(Gl.blend);

var shader = CShaders.planetDebug;
shader.camera = renderer.planets.cam;
Draw.blit(shader);

Gl.disable(Gl.blend);
}
}

0 comments on commit d832bf2

Please sign in to comment.