aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/makamys/neodymium/renderer/MeshQuad.java27
-rw-r--r--src/main/resources/shaders/chunk.frag42
-rw-r--r--src/main/resources/shaders/chunk.vert6
3 files changed, 58 insertions, 17 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/MeshQuad.java b/src/main/java/makamys/neodymium/renderer/MeshQuad.java
index bebdafd..7d3c50b 100644
--- a/src/main/java/makamys/neodymium/renderer/MeshQuad.java
+++ b/src/main/java/makamys/neodymium/renderer/MeshQuad.java
@@ -17,17 +17,17 @@ import net.minecraft.util.EnumFacing;
/*
* This is what a quad looks like.
*
- * 2--1
+ * 0--1
* | |
- * 3--0
+ * 3--2
*
* We can glue quads together, forming a "quad squadron", or "squadron" for short.
* In the fragment shader we need to know which quad of the squadron we are operating on.
* For this reason, we store the "squadron X" and "squadron Y" coordinates in the vertices.
* Their values at vertex 0: (0, 0)
- * Their values at vertex 1: (0, squadron height)
+ * Their values at vertex 1: (sqadron width, 0)
* Their values at vertex 2: (squadron width, squadron height)
- * Their values at vertex 3: (squadron width, 0)
+ * Their values at vertex 3: (0, squadron height)
*/
public class MeshQuad {
@@ -51,8 +51,8 @@ public class MeshQuad {
public int offset;
public ChunkMesh.Flags flags;
- // 0: quads glued together on edge 0-1 or 2-3 ("squadron row length")
- // 1: quads glued together on edge 1-2 or 3-0 ("squadron column length")
+ // 0: quads glued together on edge 1-2 or 3-0 ("squadron row length")
+ // 1: quads glued together on edge 0-1 or 2-3 ("squadron column length")
private int[] quadCountByDirection = {1, 1};
public static int[] totalMergeCountByPlane = new int[3];
@@ -109,7 +109,8 @@ public class MeshQuad {
public void writeToBuffer(BufferWriter out) throws IOException {
for(int vertexI = 0; vertexI < 6; vertexI++) {
- int vi = new int[]{0, 1, 2, 0, 2, 3}[vertexI];
+ int vi = new int[]{0, 1, 2, 2, 3, 0}[vertexI];
+ int tvi = vertexI % 3;
float x = xs[vi];
float y = ys[vi];
@@ -133,10 +134,10 @@ public class MeshQuad {
out.writeInt(c);
- out.writeByte(vi < 2 ? (byte)0 : (byte)quadCountByDirection[0]); // squadron x
- out.writeByte((vi == 0 || vi == 3) ? (byte)0 : (byte)quadCountByDirection[1]); // quad z
- out.writeByte(vi < 2 ? (byte)0 : 1); // which squadron corner x
- out.writeByte((vi == 0 || vi == 3) ? (byte)0 : 1); // which squadron corner z
+ out.writeByte(tvi == 2 ? (byte)0 : (byte)quadCountByDirection[0]); // squadron x
+ out.writeByte(tvi != 0 ? (byte)0 : (byte)quadCountByDirection[1]); // squadron z
+ out.writeByte(tvi == 2 ? (byte)0 : 1); // which corner x
+ out.writeByte(tvi != 0 ? (byte)0 : 1); // which corner z
assert out.position() % getStride() == 0;
@@ -199,10 +200,10 @@ public class MeshQuad {
}
}
- if((verticesTouching[0] && verticesTouching[1]) || (verticesTouching[2] && verticesTouching[3])) {
+ if((verticesTouching[1] && verticesTouching[2]) || (verticesTouching[3] && verticesTouching[0])) {
quadCountByDirection[0] += o.quadCountByDirection[0];
}
- if((verticesTouching[1] && verticesTouching[2]) || (verticesTouching[3] && verticesTouching[0])) {
+ if((verticesTouching[0] && verticesTouching[1]) || (verticesTouching[2] && verticesTouching[3])) {
quadCountByDirection[1] += o.quadCountByDirection[1];
}
diff --git a/src/main/resources/shaders/chunk.frag b/src/main/resources/shaders/chunk.frag
index 1113a2f..e779d7c 100644
--- a/src/main/resources/shaders/chunk.frag
+++ b/src/main/resources/shaders/chunk.frag
@@ -4,22 +4,56 @@ out vec4 FragColor;
in vec2 TexCoord;
in vec2 BTexCoord;
in vec4 Color;
+in vec4 SPos;
in vec4 Viewport;
in mat4 ProjInv;
in vec4 FogColor;
in vec2 FogStartEnd;
+flat in vec2 ProvokingTexCoord;
uniform sampler2D atlas;
uniform sampler2D lightTex;
void main()
-{
- vec4 texColor = texture(atlas, TexCoord);
- vec4 colorMult = Color/256.0;
+{
+ float relU = SPos.x;
+ float relV = SPos.y;
+
+ //if(true||relU > 1 || relV > 1){
+ if(true){
+ //FragColor = vec4(1, 1, 1, 1);
+ //FragColor = vec4((SPos.x), (SPos.y), 0, 1);
+ FragColor = vec4(SPos.x>0.5?1:0,0, 0, 1);
+ //FragColor = vec4(abs(TexCoord.x - ProvokingTexCoord.x) * 100.0, abs(TexCoord.y - ProvokingTexCoord.y) * 100.0, 0, 1);
+ //FragColor = vec4((TexCoord.xy - ProvokingTexCoord.xy) * 100.0, 0, 1);
+ } else {
+
+ //float goodTexCoordU = ProvokingTexCoord.x + (TexCoord.x - ProvokingTexCoord.x) * relU;
+ //float goodTexCoordV = ProvokingTexCoord.y + (TexCoord.y - ProvokingTexCoord.y) * relV;
+
+ float goodTexCoordU = ProvokingTexCoord.x + (((TexCoord.x - ProvokingTexCoord.x) / SPos.z) * relU);
+ float goodTexCoordV = ProvokingTexCoord.y + (((TexCoord.y - ProvokingTexCoord.y) / SPos.w) * relV);
+
+ //vec2 goodTexCoord = vec2(goodTexCoordU, goodTexCoordV);
+
+ vec2 goodTexCoord = ProvokingTexCoord + vec2(SPos.x / 3.0, SPos.y) * (1.0/16.0);
+
+ vec4 texColor = texture(atlas, goodTexCoord);
+ //vec4 texColor = texture(atlas, TexCoord);
+ /*vec4 colorMult = Color/256.0;
vec4 lightyColor = texture(lightTex, (BTexCoord + 8.0) / 256.0);
vec4 rasterColor = ((texColor * colorMult) * lightyColor);
- FragColor = rasterColor;
+ FragColor = rasterColor;*/
+
+ //FragColor = vec4(SPos.z, 1, 1, 1);
+
+ FragColor = texColor;
+ //FragColor = vec4(relU, relV, 0, 1);
+
+ }
+
+ //FragColor = vec4(1, 1, 1, 1);
}
diff --git a/src/main/resources/shaders/chunk.vert b/src/main/resources/shaders/chunk.vert
index 75ee0ab..573acdd 100644
--- a/src/main/resources/shaders/chunk.vert
+++ b/src/main/resources/shaders/chunk.vert
@@ -3,6 +3,7 @@ layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
layout (location = 2) in vec2 aBTexCoord;
layout (location = 3) in vec4 aColor;
+layout (location = 4) in vec4 aSPos;
uniform mat4 modelView;
uniform mat4 proj;
@@ -16,11 +17,13 @@ uniform vec3 playerPos;
out vec2 TexCoord;
out vec2 BTexCoord;
out vec4 Color;
+out vec4 SPos;
out vec4 Viewport;
out mat4 ProjInv;
out vec4 FogColor;
out vec2 FogStartEnd;
out float FogFactor;
+flat out vec2 ProvokingTexCoord;
void main()
{
@@ -28,6 +31,7 @@ void main()
TexCoord = aTexCoord;
BTexCoord = aBTexCoord;
Color = aColor;
+ SPos = aSPos;
Viewport = viewport;
ProjInv = projInv;
FogColor = fogColor;
@@ -41,4 +45,6 @@ void main()
FogFactor = fogFactor;
FogStartEnd = fogStartEnd;
+
+ ProvokingTexCoord = aTexCoord;
} \ No newline at end of file