Add caching of data for flat lighting (#4358)

This commit is contained in:
Ben Staddon 2017-10-31 17:09:39 +00:00 committed by LexManos
parent ac634a2049
commit 8d938660e7
3 changed files with 44 additions and 19 deletions

View file

@ -28,6 +28,8 @@ import net.minecraft.world.IBlockAccess;
public class BlockInfo
{
private static final EnumFacing[] SIDES = EnumFacing.values();
private final BlockColors colors;
private IBlockAccess world;
private IBlockState state;
@ -40,6 +42,10 @@ public class BlockInfo
private final float[][][][] blockLight = new float[3][2][2][2];
private final float[][][] ao = new float[3][3][3];
private final int[] packed = new int[7];
private boolean full;
private float shx = 0, shy = 0, shz = 0;
private int cachedTint = -1;
@ -123,7 +129,7 @@ public class BlockInfo
}
if(!full)
{
for(EnumFacing side : EnumFacing.values())
for(EnumFacing side : SIDES)
{
int x = side.getFrontOffsetX() + 1;
int y = side.getFrontOffsetY() + 1;
@ -158,6 +164,18 @@ public class BlockInfo
}
}
public void updateFlatLighting()
{
full = state.isFullCube();
packed[0] = state.getPackedLightmapCoords(world, blockPos);
for (EnumFacing side : SIDES)
{
int i = side.ordinal() + 1;
packed[i] = state.getPackedLightmapCoords(world, blockPos.offset(side));
}
}
public IBlockAccess getWorld()
{
return world;
@ -193,6 +211,16 @@ public class BlockInfo
return ao;
}
public int[] getPackedLight()
{
return packed;
}
public boolean isFullCube()
{
return full;
}
public float getShx()
{
return shx;

View file

@ -231,20 +231,21 @@ public class VertexLighterFlat extends QuadGatheringTransformer
protected void updateLightmap(float[] normal, float[] lightmap, float x, float y, float z)
{
float e1 = 1 - 1e-2f;
float e2 = 0.95f;
BlockPos pos = blockInfo.getBlockPos();
final float e1 = 1f - 1e-2f;
final float e2 = 0.95f;
boolean full = blockInfo.getState().isFullCube();
boolean full = blockInfo.isFullCube();
EnumFacing side = null;
if((full || y < -e1) && normal[1] < -e2) pos = pos.down();
if((full || y > e1) && normal[1] > e2) pos = pos.up();
if((full || z < -e1) && normal[2] < -e2) pos = pos.north();
if((full || z > e1) && normal[2] > e2) pos = pos.south();
if((full || x < -e1) && normal[0] < -e2) pos = pos.west();
if((full || x > e1) && normal[0] > e2) pos = pos.east();
if((full || y < -e1) && normal[1] < -e2) side = EnumFacing.DOWN;
else if((full || y > e1) && normal[1] > e2) side = EnumFacing.UP;
else if((full || z < -e1) && normal[2] < -e2) side = EnumFacing.NORTH;
else if((full || z > e1) && normal[2] > e2) side = EnumFacing.SOUTH;
else if((full || x < -e1) && normal[0] < -e2) side = EnumFacing.WEST;
else if((full || x > e1) && normal[0] > e2) side = EnumFacing.EAST;
int brightness = blockInfo.getState().getPackedLightmapCoords(blockInfo.getWorld(), pos);
int i = side == null ? 0 : side.ordinal() + 1;
int brightness = blockInfo.getPackedLight()[i];
lightmap[0] = ((float)((brightness >> 0x04) & 0xF) * 0x20) / 0xFFFF;
lightmap[1] = ((float)((brightness >> 0x14) & 0xF) * 0x20) / 0xFFFF;
@ -294,5 +295,6 @@ public class VertexLighterFlat extends QuadGatheringTransformer
public void updateBlockInfo()
{
blockInfo.updateShift();
blockInfo.updateFlatLighting();
}
}

View file

@ -40,12 +40,7 @@ public class VertexLighterSmoothAo extends VertexLighterFlat
@Override
protected void updateColor(float[] normal, float[] color, float x, float y, float z, float tint, int multiplier)
{
if(tint != -1)
{
color[0] *= (float)(multiplier >> 0x10 & 0xFF) / 0xFF;
color[1] *= (float)(multiplier >> 0x8 & 0xFF) / 0xFF;
color[2] *= (float)(multiplier & 0xFF) / 0xFF;
}
super.updateColor(normal, color, x, y, z, tint, multiplier);
float a = getAo(x, y, z);
color[0] *= a;
color[1] *= a;
@ -179,7 +174,7 @@ public class VertexLighterSmoothAo extends VertexLighterFlat
@Override
public void updateBlockInfo()
{
super.updateBlockInfo();
blockInfo.updateShift();
blockInfo.updateLightMatrix();
}
}