'*Fixed*' the T-junction pixel issue... kinda.
This commit is contained in:
+27
-4
@@ -234,7 +234,7 @@ public class LodQuadBuilder
|
||||
|
||||
|
||||
|
||||
private static void putVertex(ByteBuffer bb, short x, short y, short z, int color, byte skylight, byte blocklight)
|
||||
private static void putVertex(ByteBuffer bb, short x, short y, short z, int color, byte skylight, byte blocklight, int mx, int my, int mz)
|
||||
{
|
||||
skylight %= 16;
|
||||
blocklight %= 16;
|
||||
@@ -242,8 +242,21 @@ public class LodQuadBuilder
|
||||
bb.putShort(x);
|
||||
bb.putShort(y);
|
||||
bb.putShort(z);
|
||||
|
||||
bb.putShort((short) (skylight | (blocklight << 4)));
|
||||
|
||||
short meta = 0;
|
||||
meta |= (skylight | (blocklight << 4));
|
||||
byte mirco = 0;
|
||||
// mirco offset which is a xyz 2bit value
|
||||
// 0b00 = no offset
|
||||
// 0b01 = positive offset
|
||||
// 0b11 = negative offset
|
||||
// format is: 0b00zzyyxx
|
||||
if (mx != 0) mirco |= mx > 0 ? 0b01 : 0b11;
|
||||
if (my != 0) mirco |= my > 0 ? 0b0100 : 0b1100;
|
||||
if (mz != 0) mirco |= mz > 0 ? 0b010000 : 0b110000;
|
||||
meta |= mirco << 8;
|
||||
|
||||
bb.putShort(meta);
|
||||
byte r = (byte) ColorUtil.getRed(color);
|
||||
byte g = (byte) ColorUtil.getGreen(color);
|
||||
byte b = (byte) ColorUtil.getBlue(color);
|
||||
@@ -263,28 +276,38 @@ public class LodQuadBuilder
|
||||
for (int i = 0; i < quadBase.length; i++)
|
||||
{
|
||||
short dx, dy, dz;
|
||||
int mx, my, mz;
|
||||
switch (axis)
|
||||
{
|
||||
case X: // ZY
|
||||
dx = 0;
|
||||
dy = quadBase[i][1] == 1 ? widthNorthSouth : 0;
|
||||
dz = quadBase[i][0] == 1 ? widthEastWest : 0;
|
||||
mx = 0;
|
||||
my = quadBase[i][1] == 1 ? 1 : -1;
|
||||
mz = quadBase[i][0] == 1 ? 1 : -1;
|
||||
break;
|
||||
case Y: // XZ
|
||||
dx = quadBase[i][0] == 1 ? widthEastWest : 0;
|
||||
dy = 0;
|
||||
dz = quadBase[i][1] == 1 ? widthNorthSouth : 0;
|
||||
mx = quadBase[i][0] == 1 ? 1 : -1;
|
||||
my = 0;
|
||||
mz = quadBase[i][1] == 1 ? 1 : -1;
|
||||
break;
|
||||
case Z: // XY
|
||||
dx = quadBase[i][0] == 1 ? widthEastWest : 0;
|
||||
dy = quadBase[i][1] == 1 ? widthNorthSouth : 0;
|
||||
dz = 0;
|
||||
mx = quadBase[i][0] == 1 ? 1 : -1;
|
||||
my = quadBase[i][1] == 1 ? 1 : -1;
|
||||
mz = 0;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid Axis enum: " + axis);
|
||||
}
|
||||
putVertex(bb, (short) (quad.x + dx), (short) (quad.y + dy), (short) (quad.z + dz), quad.color,
|
||||
quad.skyLight, quad.blockLight);
|
||||
quad.skyLight, quad.blockLight, mx, my, mz);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ public class LodRenderProgram extends ShaderProgram {
|
||||
public final int modelOffsetUniform;
|
||||
public final int worldYOffsetUniform;
|
||||
|
||||
public final int mircoOffsetUniform;
|
||||
|
||||
public final int lightMapUniform;
|
||||
// Fog Uniforms
|
||||
public final int fogColorUniform;
|
||||
@@ -61,6 +63,7 @@ public class LodRenderProgram extends ShaderProgram {
|
||||
combinedMatUniform = getUniformLocation("combinedMatrix");
|
||||
modelOffsetUniform = getUniformLocation("modelOffset");
|
||||
worldYOffsetUniform = tryGetUniformLocation("worldYOffset");
|
||||
mircoOffsetUniform = getUniformLocation("mircoOffset");
|
||||
|
||||
lightMapUniform = getUniformLocation("lightMap");
|
||||
|
||||
@@ -81,9 +84,9 @@ public class LodRenderProgram extends ShaderProgram {
|
||||
vao = new VertexAttributePreGL43(); // also binds VertexAttribute
|
||||
vao.bind();
|
||||
// Now a pos+light.
|
||||
vao.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addUnsignedShortsPointer(4, false)); // 2+2+2+2
|
||||
vao.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addUnsignedShortsPointer(4, false, true)); // 2+2+2+2
|
||||
//vao.setVertexAttribute(0, posAttrib, VertexAttribute.VertexPointer.addVec3Pointer(false)); // 4+4+4
|
||||
vao.setVertexAttribute(0, 1, VertexAttribute.VertexPointer.addUnsignedBytesPointer(4, true)); // +4
|
||||
vao.setVertexAttribute(0, 1, VertexAttribute.VertexPointer.addUnsignedBytesPointer(4, true, false)); // +4
|
||||
//vao.setVertexAttribute(0, lightAttrib, VertexAttribute.VertexPointer.addUnsignedBytesPointer(2, false)); // +4 due to how it aligns
|
||||
try {
|
||||
vao.completeAndCheck(vertexByteCount);
|
||||
@@ -132,6 +135,7 @@ public class LodRenderProgram extends ShaderProgram {
|
||||
vanillaDrawDistance += 32; // Give it a 2 chunk boundary for near fog.
|
||||
// uniforms
|
||||
setUniform(combinedMatUniform, combinedMatrix);
|
||||
setUniform(mircoOffsetUniform, 0.005f); // 0.005 block offset
|
||||
|
||||
// setUniform(skyLightUniform, skyLight);
|
||||
setUniform(lightMapUniform, lightmapBindPoint);
|
||||
|
||||
@@ -322,10 +322,13 @@ public class LodRenderer
|
||||
lightmap.bind();
|
||||
|
||||
if (ENABLE_IBO) quadIBO.bind();
|
||||
|
||||
|
||||
//lightmapTexture.fillData(MC_RENDER.getLightmapTextureWidth(), MC_RENDER.getLightmapTextureHeight(), MC_RENDER.getLightmapPixels());
|
||||
drawFillLightmap.end("drawFillLightmap");
|
||||
drawFillData.end("DrawFillData");
|
||||
//GL32.glEnable( GL32.GL_POLYGON_OFFSET_FILL );
|
||||
//GL32.glPolygonOffset( 1f, 1f );
|
||||
|
||||
//===========//
|
||||
// rendering //
|
||||
//===========//
|
||||
|
||||
@@ -31,11 +31,16 @@ public abstract class VertexAttribute {
|
||||
public final int glType;
|
||||
public final boolean normalized;
|
||||
public final int byteSize;
|
||||
public VertexPointer(int elementCount, int glType, boolean normalized, int byteSize) {
|
||||
public final boolean useInteger;
|
||||
public VertexPointer(int elementCount, int glType, boolean normalized, int byteSize, boolean useInteger) {
|
||||
this.elementCount = elementCount;
|
||||
this.glType = glType;
|
||||
this.normalized = normalized;
|
||||
this.byteSize = byteSize;
|
||||
this.useInteger = useInteger;
|
||||
}
|
||||
public VertexPointer(int elementCount, int glType, boolean normalized, int byteSize) {
|
||||
this(elementCount, glType, normalized, byteSize, false);
|
||||
}
|
||||
private static int _align(int bytes) {
|
||||
return LodUtil.ceilDiv(bytes, 4)*4;
|
||||
@@ -53,26 +58,29 @@ public abstract class VertexAttribute {
|
||||
public static VertexPointer addVec4Pointer(boolean normalized) {
|
||||
return new VertexPointer(4, GL32.GL_FLOAT, normalized, 16);
|
||||
}
|
||||
public static VertexPointer addUnsignedBytePointer(boolean normalized) {
|
||||
return new VertexPointer(1, GL32.GL_UNSIGNED_BYTE, normalized, 4); // Always aligned to 4 bytes
|
||||
public static VertexPointer addUnsignedBytePointer(boolean normalized, boolean useInteger) {
|
||||
return new VertexPointer(1, GL32.GL_UNSIGNED_BYTE, normalized, 4, useInteger); // Always aligned to 4 bytes
|
||||
}
|
||||
public static VertexPointer addUnsignedBytesPointer(int elementCount, boolean normalized) {
|
||||
return new VertexPointer(elementCount, GL32.GL_UNSIGNED_BYTE, normalized, _align(elementCount)); // aligned to 4 bytes
|
||||
public static VertexPointer addUnsignedBytesPointer(int elementCount, boolean normalized, boolean useInteger) {
|
||||
return new VertexPointer(elementCount, GL32.GL_UNSIGNED_BYTE, normalized, _align(elementCount), useInteger); // aligned to 4 bytes
|
||||
}
|
||||
public static VertexPointer addUnsignedShortsPointer(int elementCount, boolean normalized) {
|
||||
return new VertexPointer(elementCount, GL32.GL_UNSIGNED_SHORT, normalized, _align(elementCount*2));
|
||||
public static VertexPointer addUnsignedShortsPointer(int elementCount, boolean normalized, boolean useInteger) {
|
||||
return new VertexPointer(elementCount, GL32.GL_UNSIGNED_SHORT, normalized, _align(elementCount*2), useInteger);
|
||||
}
|
||||
public static VertexPointer addIntPointer(boolean normalized) {
|
||||
return new VertexPointer(1, GL32.GL_INT, normalized, 4);
|
||||
public static VertexPointer addShortsPointer(int elementCount, boolean normalized, boolean useInteger) {
|
||||
return new VertexPointer(elementCount, GL32.GL_SHORT, normalized, _align(elementCount*2), useInteger);
|
||||
}
|
||||
public static VertexPointer addIvec2Pointer(boolean normalized) {
|
||||
return new VertexPointer(2, GL32.GL_INT, normalized, 8);
|
||||
public static VertexPointer addIntPointer(boolean normalized, boolean useInteger) {
|
||||
return new VertexPointer(1, GL32.GL_INT, normalized, 4, useInteger);
|
||||
}
|
||||
public static VertexPointer addIvec3Pointer(boolean normalized) {
|
||||
return new VertexPointer(3, GL32.GL_INT, normalized, 12);
|
||||
public static VertexPointer addIvec2Pointer(boolean normalized, boolean useInteger) {
|
||||
return new VertexPointer(2, GL32.GL_INT, normalized, 8, useInteger);
|
||||
}
|
||||
public static VertexPointer addIvec4Pointer(boolean normalized) {
|
||||
return new VertexPointer(4, GL32.GL_INT, normalized, 16);
|
||||
public static VertexPointer addIvec3Pointer(boolean normalized, boolean useInteger) {
|
||||
return new VertexPointer(3, GL32.GL_INT, normalized, 12, useInteger);
|
||||
}
|
||||
public static VertexPointer addIvec4Pointer(boolean normalized, boolean useInteger) {
|
||||
return new VertexPointer(4, GL32.GL_INT, normalized, 16, useInteger);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,10 @@ public final class VertexAttributePostGL43 extends VertexAttribute {
|
||||
@Override
|
||||
// Requires VertexAttribute binded
|
||||
public void setVertexAttribute(int bindingPoint, int attributeIndex, VertexPointer attribute) {
|
||||
GL43.glVertexAttribFormat(attributeIndex, attribute.elementCount, attribute.glType,
|
||||
if (attribute.useInteger)
|
||||
GL43.glVertexAttribIFormat(attributeIndex, attribute.elementCount, attribute.glType, strideSize);
|
||||
else
|
||||
GL43.glVertexAttribFormat(attributeIndex, attribute.elementCount, attribute.glType,
|
||||
attribute.normalized, strideSize); // Here strideSize is new attrib offset
|
||||
strideSize += attribute.byteSize;
|
||||
if (numberOfBindingPoints <= bindingPoint) numberOfBindingPoints = bindingPoint+1;
|
||||
|
||||
@@ -59,7 +59,10 @@ public final class VertexAttributePreGL43 extends VertexAttribute {
|
||||
for (int i=0; i< pointers.length; i++) {
|
||||
VertexPointer pointer = pointers[i];
|
||||
if (pointer==null) continue;
|
||||
GL32.glVertexAttribPointer(i, pointer.elementCount, pointer.glType,
|
||||
if (pointer.useInteger)
|
||||
GL32.glVertexAttribIPointer(i, pointer.elementCount, pointer.glType,
|
||||
strideSize, pointersOffset[i]);
|
||||
else GL32.glVertexAttribPointer(i, pointer.elementCount, pointer.glType,
|
||||
pointer.normalized, strideSize, pointersOffset[i]);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +80,10 @@ public final class VertexAttributePreGL43 extends VertexAttribute {
|
||||
VertexPointer pointer = pointers[j];
|
||||
if (pointer == null)
|
||||
continue;
|
||||
GL32.glVertexAttribPointer(j, pointer.elementCount, pointer.glType,
|
||||
if (pointer.useInteger)
|
||||
GL32.glVertexAttribIPointer(j, pointer.elementCount, pointer.glType,
|
||||
strideSize, pointersOffset[j]);
|
||||
else GL32.glVertexAttribPointer(j, pointer.elementCount, pointer.glType,
|
||||
pointer.normalized, strideSize, pointersOffset[j]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#version 150 core
|
||||
|
||||
in vec4 vPosition;
|
||||
in uvec4 vPosition;
|
||||
in vec4 color;
|
||||
|
||||
out vec4 vertexColor;
|
||||
@@ -13,6 +13,7 @@ uniform float worldYOffset;
|
||||
|
||||
uniform int worldSkyLight;
|
||||
uniform sampler2D lightMap;
|
||||
uniform float mircoOffset;
|
||||
|
||||
|
||||
/**
|
||||
@@ -27,11 +28,28 @@ uniform sampler2D lightMap;
|
||||
void main()
|
||||
{
|
||||
vertexWorldPos = vPosition.xyz + modelOffset;
|
||||
|
||||
vertexYPos = vPosition.y + worldYOffset;
|
||||
|
||||
float light2 = (mod(vPosition.a, 16)+0.5) / 16.0;
|
||||
float light = (floor(vPosition.a/16)+0.5) / 16.0;
|
||||
uint meta = vPosition.a;
|
||||
|
||||
uint mirco = (meta & 0xFF00u) >> 8u; // mirco offset which is a xyz 2bit value
|
||||
// 0b00 = no offset
|
||||
// 0b01 = positive offset
|
||||
// 0b11 = negative offset
|
||||
// format is: 0b00zzyyxx
|
||||
float mx = (mirco & 1u)!=0u ? mircoOffset : 0.0;
|
||||
mx = (mirco & 2u)!=0u ? -mx : mx;
|
||||
float my = (mirco & 4u)!=0u ? mircoOffset : 0.0;
|
||||
my = (mirco & 8u)!=0u ? -my : my;
|
||||
float mz = (mirco & 16u)!=0u ? mircoOffset : 0.0;
|
||||
mz = (mirco & 32u)!=0u ? -mz : mz;
|
||||
|
||||
uint lights = meta & 0xFFu;
|
||||
|
||||
float light2 = (mod(float(lights), 16.0)+0.5) / 16.0;
|
||||
float light = (float(lights/16u)+0.5) / 16.0;
|
||||
vertexColor = color * vec4(texture(lightMap, vec2(light, light2)).xyz, 1.0);
|
||||
|
||||
gl_Position = combinedMatrix * vec4(vertexWorldPos, 1.0);
|
||||
gl_Position = combinedMatrix * vec4(vertexWorldPos + vec3(mx, my, mz), 1.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user