aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/assets/firmament
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-03 01:24:24 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-09 01:01:18 +0100
commit22f0cc59a2d3bc7900764e3916c670075ff9d35e (patch)
treeb503ff607cf818a539cbbaa403f6851ef979e03d /src/main/resources/assets/firmament
parent646843ba3b960ac48f9866b3640438d3cc1dafc4 (diff)
downloadFirmament-22f0cc59a2d3bc7900764e3916c670075ff9d35e.tar.gz
Firmament-22f0cc59a2d3bc7900764e3916c670075ff9d35e.tar.bz2
Firmament-22f0cc59a2d3bc7900764e3916c670075ff9d35e.zip
1.21.3 WIP
Diffstat (limited to 'src/main/resources/assets/firmament')
-rw-r--r--src/main/resources/assets/firmament/shaders/core/rendertype_lines.fsh18
-rw-r--r--src/main/resources/assets/firmament/shaders/core/rendertype_lines.json17
-rw-r--r--src/main/resources/assets/firmament/shaders/core/rendertype_lines.vsh62
3 files changed, 97 insertions, 0 deletions
diff --git a/src/main/resources/assets/firmament/shaders/core/rendertype_lines.fsh b/src/main/resources/assets/firmament/shaders/core/rendertype_lines.fsh
new file mode 100644
index 0000000..057f31f
--- /dev/null
+++ b/src/main/resources/assets/firmament/shaders/core/rendertype_lines.fsh
@@ -0,0 +1,18 @@
+#version 150
+
+#moj_import <fog.glsl>
+
+uniform vec4 ColorModulator;
+uniform float FogStart;
+uniform float FogEnd;
+uniform vec4 FogColor;
+
+in float vertexDistance;
+in vec4 vertexColor;
+
+out vec4 fragColor;
+
+void main() {
+ vec4 color = vertexColor * ColorModulator;
+ fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor);
+}
diff --git a/src/main/resources/assets/firmament/shaders/core/rendertype_lines.json b/src/main/resources/assets/firmament/shaders/core/rendertype_lines.json
new file mode 100644
index 0000000..e4537ca
--- /dev/null
+++ b/src/main/resources/assets/firmament/shaders/core/rendertype_lines.json
@@ -0,0 +1,17 @@
+{
+ "vertex": "firmament:core/rendertype_lines",
+ "fragment": "firmament:core/rendertype_lines",
+ "samplers": [
+ ],
+ "uniforms": [
+ { "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
+ { "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
+ { "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] },
+ { "name": "LineWidth", "type": "float", "count": 1, "values": [ 1.0 ] },
+ { "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
+ { "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] },
+ { "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
+ { "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
+ { "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] }
+ ]
+}
diff --git a/src/main/resources/assets/firmament/shaders/core/rendertype_lines.vsh b/src/main/resources/assets/firmament/shaders/core/rendertype_lines.vsh
new file mode 100644
index 0000000..b2d0f99
--- /dev/null
+++ b/src/main/resources/assets/firmament/shaders/core/rendertype_lines.vsh
@@ -0,0 +1,62 @@
+#version 150
+
+#moj_import <fog.glsl>
+
+in vec3 Position;
+in vec4 Color;
+in vec3 Normal;
+
+uniform mat4 ModelViewMat;
+uniform mat4 ProjMat;
+uniform float LineWidth;
+uniform vec2 ScreenSize;
+uniform int FogShape;
+
+out float vertexDistance;
+out vec4 vertexColor;
+
+const float VIEW_SHRINK = 1.0 - (1.0 / 256.0);
+const mat4 VIEW_SCALE = mat4(
+ VIEW_SHRINK, 0.0, 0.0, 0.0,
+ 0.0, VIEW_SHRINK, 0.0, 0.0,
+ 0.0, 0.0, VIEW_SHRINK, 0.0,
+ 0.0, 0.0, 0.0, 1.0
+);
+
+void main() {
+ vec4 linePosStart = ProjMat * VIEW_SCALE * ModelViewMat * vec4(Position, 1.0);
+ vec4 linePosEnd = ProjMat * VIEW_SCALE * ModelViewMat * vec4(Position + Normal, 1.0);
+
+ vec3 ndc1 = linePosStart.xyz / linePosStart.w;
+ vec3 ndc2 = linePosEnd.xyz / linePosEnd.w;
+
+ bool linePosStartBehind = ndc1.z <= -1;
+ bool linePosEndBehind = ndc2.z <= -1;
+
+ if ((linePosStartBehind && linePosEndBehind)) {
+ gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);
+ return; // I don't care for these people
+ }
+ if ((linePosStartBehind || linePosEndBehind) && false) {
+ ndc1.z = 0.0;
+ ndc2.z = 0.0;
+ linePosStart.w = 1.0;
+ // TODO: use mx + b to find move the two coordinates around to extend lines
+ }
+
+ vec2 lineScreenDirection = normalize((ndc2.xy - ndc1.xy) * ScreenSize);
+ vec2 lineOffset = vec2(-lineScreenDirection.y, lineScreenDirection.x) * LineWidth / ScreenSize;
+
+ if (lineOffset.x < 0.0) {
+ lineOffset *= -1.0;
+ }
+
+ if (gl_VertexID % 2 == 0) {
+ gl_Position = vec4((ndc1 + vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);
+ } else {
+ gl_Position = vec4((ndc1 - vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);
+ }
+
+ vertexDistance = fog_distance(Position, FogShape);
+ vertexColor = Color;
+}