Improve rendering of empty or thin LODs
This commit is contained in:
@@ -99,7 +99,7 @@ public class BuildBufferThread implements Callable<ByteBuffer>
|
||||
blue = colors[i][j].getBlue();
|
||||
alpha = colors[i][j].getAlpha();
|
||||
|
||||
// only draw all 6 sides if there is some thickness to the box
|
||||
|
||||
if (bb.minY != bb.maxY)
|
||||
{
|
||||
// top (facing up)
|
||||
@@ -137,17 +137,40 @@ public class BuildBufferThread implements Callable<ByteBuffer>
|
||||
}
|
||||
else
|
||||
{
|
||||
// bottom (facing up)
|
||||
// buffer.pos(bb.minX, bb.minY, bb.minZ).color(red, green, blue, alpha).endVertex();
|
||||
// buffer.pos(bb.minX, bb.minY, bb.maxZ).color(red, green, blue, alpha).endVertex();
|
||||
// buffer.pos(bb.maxX, bb.minY, bb.maxZ).color(red, green, blue, alpha).endVertex();
|
||||
// buffer.pos(bb.maxX, bb.minY, bb.minZ).color(red, green, blue, alpha).endVertex();
|
||||
// render this LOD as one block thick
|
||||
|
||||
// top (facing up)
|
||||
// bufferBuilder.pos(bb.minX, bb.maxY, bb.minZ).color(red, green, blue, alpha).endVertex();
|
||||
// bufferBuilder.pos(bb.minX, bb.maxY, bb.maxZ).color(red, green, blue, alpha).endVertex();
|
||||
// bufferBuilder.pos(bb.maxX, bb.maxY, bb.maxZ).color(red, green, blue, alpha).endVertex();
|
||||
// bufferBuilder.pos(bb.maxX, bb.maxY, bb.minZ).color(red, green, blue, alpha).endVertex();
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
// bottom (facing down)
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
|
||||
// south (facing -Z)
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
// north (facing +Z)
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
|
||||
// west (facing -X)
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
// east (facing +X)
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
} // z axis
|
||||
|
||||
@@ -274,7 +274,14 @@ public class LodRenderer
|
||||
// add the color to the array
|
||||
colorArray[i][j] = c;
|
||||
// add the new box to the array
|
||||
lodArray[i][j] = new AxisAlignedBB(0, lod.bottom[LodLocation.NE.value], 0, LOD_WIDTH, lod.top[LodLocation.NE.value], LOD_WIDTH).offset(xOffset, yOffset, zOffset);
|
||||
int topPoint = getLodHeightPoint(lod.top);
|
||||
int bottomPoint = getLodHeightPoint(lod.bottom);
|
||||
|
||||
// don't draw an LOD if it is empty
|
||||
if (topPoint == -1 && bottomPoint == -1)
|
||||
continue;
|
||||
|
||||
lodArray[i][j] = new AxisAlignedBB(0, bottomPoint, 0, LOD_WIDTH, topPoint, LOD_WIDTH).offset(xOffset, yOffset, zOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,20 +312,21 @@ public class LodRenderer
|
||||
|
||||
GL11.glEnable(GL11.GL_COLOR_MATERIAL); // have the color be used as the material (this allows lighting to be enabled)
|
||||
|
||||
// System.out.println(mc.world.provider.getSunBrightnessFactor(partialTicks) + "\t" + sunBrightness);
|
||||
// mc.gameSettings.gammaSetting
|
||||
float lightStrength = sunBrightness; // TODO change based on day and gamma setting
|
||||
float lightAmbient[] = {lightStrength, lightStrength, lightStrength, 1.0f}; // Ambient Light Values
|
||||
float lightDiffuse[] = {0.0f, 0.0f, 0.0f, 0.0f}; // Diffuse Light Values
|
||||
float lightPosition[] = {0.0f, 0.0f, 0.0f, 1.0f}; // Light Position
|
||||
|
||||
ByteBuffer temp = ByteBuffer.allocateDirect(16);
|
||||
temp.order(ByteOrder.nativeOrder());
|
||||
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer) temp.asFloatBuffer().put(lightAmbient).flip());
|
||||
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer) temp.asFloatBuffer().put(lightDiffuse).flip());
|
||||
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, (FloatBuffer) temp.asFloatBuffer().put(lightPosition).flip());
|
||||
GL11.glEnable(GL11.GL_LIGHT1); // Enable the above lighting
|
||||
float lightStrength = sunBrightness * mc.world.provider.getSunBrightnessFactor(partialTicks); // TODO change based on day and gamma setting
|
||||
float lightAmbient[] = {lightStrength, lightStrength, lightStrength, 1.0f};
|
||||
// float lightDiffuse[] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
// float lightPosition[] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
ByteBuffer temp = ByteBuffer.allocateDirect(16);
|
||||
temp.order(ByteOrder.nativeOrder());
|
||||
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer) temp.asFloatBuffer().put(lightAmbient).flip());
|
||||
// GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer) temp.asFloatBuffer().put(lightDiffuse).flip());
|
||||
// GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, (FloatBuffer) temp.asFloatBuffer().put(lightPosition).flip());
|
||||
GL11.glEnable(GL11.GL_LIGHT1); // Enable the above lighting
|
||||
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.enableLighting();
|
||||
|
||||
|
||||
//===========//
|
||||
@@ -534,5 +542,19 @@ public class LodRenderer
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns -1 if there are no valid points
|
||||
*/
|
||||
private int getLodHeightPoint(short[] heightPoints)
|
||||
{
|
||||
if (heightPoints[LodLocation.NE.value] != -1)
|
||||
return heightPoints[LodLocation.NE.value];
|
||||
if (heightPoints[LodLocation.NW.value] != -1)
|
||||
return heightPoints[LodLocation.NW.value];
|
||||
if (heightPoints[LodLocation.SE.value] != -1)
|
||||
return heightPoints[LodLocation.NE.value];
|
||||
return heightPoints[LodLocation.NE.value];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user