generated from GlennFolker/MindustryModTemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4640c2f
commit d832bf2
Showing
9 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |