aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/makamys/neodymium/renderer/MeshQuad.java27
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java2
-rw-r--r--src/main/resources/shaders/chunk.frag15
3 files changed, 30 insertions, 14 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/MeshQuad.java b/src/main/java/makamys/neodymium/renderer/MeshQuad.java
index 0f275f7..9192f8d 100644
--- a/src/main/java/makamys/neodymium/renderer/MeshQuad.java
+++ b/src/main/java/makamys/neodymium/renderer/MeshQuad.java
@@ -51,6 +51,9 @@ public class MeshQuad {
public int offset;
public ChunkMesh.Flags flags;
+ // positive U direction is parallel to edge 0-1
+ public boolean uDirectionIs01;
+
// 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};
@@ -94,6 +97,8 @@ public class MeshQuad {
public MeshQuad(int[] rawBuffer, int offset, ChunkMesh.Flags flags, int offsetX, int offsetY, int offsetZ) {
read(rawBuffer, offset, offsetX, offsetY, offsetZ);
+ uDirectionIs01 = us[0] != us[1];
+
updateMinMaxXYZ();
if(ys[0] == ys[1] && ys[1] == ys[2] && ys[2] == ys[3]) {
@@ -108,9 +113,11 @@ public class MeshQuad {
}
public void writeToBuffer(BufferWriter out) throws IOException {
+ int[] vertexI_to_vi = new int[]{3, 0, 1, 1, 2, 3};
for(int vertexI = 0; vertexI < 6; vertexI++) {
- int vi = new int[]{0, 1, 2, 2, 3, 0}[vertexI];
- int tvi = vertexI % 3;
+ int vi = vertexI_to_vi[vertexI];
+ int ti = vertexI / 3;
+ int provokingI = vertexI_to_vi[ti * 3 + 2];
float x = xs[vi];
float y = ys[vi];
@@ -134,10 +141,10 @@ public class MeshQuad {
out.writeInt(c);
- 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
+ out.writeByte(us[vi] == us[provokingI] ? 0 : (byte)quadCountByUVDirection(false));
+ out.writeByte(vs[vi] == vs[provokingI] ? 0 : (byte)quadCountByUVDirection(true));
+ out.writeByte(us[vi] == us[provokingI] ? (byte)0 : 1);
+ out.writeByte(vs[vi] == vs[provokingI] ? (byte)0 : 1);
assert out.position() % getStride() == 0;
@@ -145,6 +152,14 @@ public class MeshQuad {
}
}
+ public int quadCountByUVDirection(boolean v) {
+ if(v) {
+ return quadCountByDirection[uDirectionIs01 ? 0 : 1];
+ } else {
+ return quadCountByDirection[uDirectionIs01 ? 1 : 0];
+ }
+ }
+
public static int getStride() {
return
3 * 4 // XYZ (float)
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index e5bc886..e39b59b 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -402,7 +402,7 @@ public class NeoRenderer {
}
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- //glMultiDrawArrays(GL_TRIANGLES, piFirst[1], piCount[1]);
+ glMultiDrawArrays(GL_TRIANGLES, piFirst[1], piCount[1]);
glBindVertexArray(0);
glUseProgram(0);
diff --git a/src/main/resources/shaders/chunk.frag b/src/main/resources/shaders/chunk.frag
index d399114..be904a0 100644
--- a/src/main/resources/shaders/chunk.frag
+++ b/src/main/resources/shaders/chunk.frag
@@ -16,14 +16,15 @@ uniform sampler2D lightTex;
void main()
{
- float relU = SPos.x;
- float relV = SPos.y;
+ float relU = mod(SPos.x, 1.0);
+ float relV = mod(SPos.y, 1.0);
//if(true||relU > 1 || relV > 1){
- if(true){
+ if(false){
//FragColor = vec4(1, 1, 1, 1);
//FragColor = vec4((SPos.x), (SPos.y), 0, 1);
- FragColor = vec4(SPos.xy, 0, 1);
+ //FragColor = vec4(SPos.xy, 0, 1);
+ FragColor = vec4(relU, relV, 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 {
@@ -40,17 +41,17 @@ void main()
vec4 texColor = texture(atlas, goodTexCoord);
//vec4 texColor = texture(atlas, TexCoord);
- /*vec4 colorMult = Color/256.0;
+ 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 = texColor;
//FragColor = vec4(relU, relV, 0, 1);
}