1
0
Fork 0

improve rendering, fix lightmap

This commit is contained in:
Sen 2025-08-31 00:30:48 +02:00
parent 82b57873c2
commit ec9173433e
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
12 changed files with 186 additions and 102 deletions

View file

@ -431,6 +431,10 @@ public class Client implements IThreadListener {
public int getCombinedLight(BlockPos pos) {
return Client.this.renderer.getCombinedLight(pos);
}
public int getCombinedBrightness(BlockPos pos) {
return Client.this.renderer.getCombinedBrightness(pos);
}
}
public static final String VERSION = Version.NAME + " Client " + Util.VERSION;

View file

@ -18,14 +18,15 @@ public class DefaultVertexFormats
public static final VertexFormatElement TEX_2F = new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.UV, 2);
public static final VertexFormatElement TEX_2S = new VertexFormatElement(1, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.UV, 2);
public static final VertexFormatElement NORMAL_3B = new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 3);
public static final VertexFormatElement NORMAL_4B = new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.NORMAL, 4);
public static final VertexFormatElement PADDING_1B = new VertexFormatElement(0, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.PADDING, 1);
static
{
BLOCK.addElement(POSITION_3F);
BLOCK.addElement(COLOR_4UB);
BLOCK.addElement(NORMAL_4B);
BLOCK.addElement(TEX_2F);
BLOCK.addElement(TEX_2S);
BLOCK.addElement(COLOR_4UB);
ITEM.addElement(POSITION_3F);
ITEM.addElement(COLOR_4UB);
ITEM.addElement(TEX_2F);

View file

@ -78,7 +78,7 @@ public class EffectRenderer {
public int getBrightness(float partial) {
BlockPos pos = new BlockPos(this.posX, this.posY, this.posZ);
return world.isBlockLoaded(pos) ? world.getCombinedLight(pos) : 0;
return world.isBlockLoaded(pos) ? world.getCombinedBrightness(pos) : 0;
}
}

View file

@ -126,7 +126,7 @@ public class ItemRenderer
private void setLightMapFromPlayer(EntityNPC clientPlayer)
{
int i = this.gm.world.getCombinedLight(new BlockPos(clientPlayer.posX, clientPlayer.posY + (double)clientPlayer.getEyeHeight(), clientPlayer.posZ));
int i = this.gm.renderer.getCombinedBrightness(new BlockPos(clientPlayer.posX, clientPlayer.posY + (double)clientPlayer.getEyeHeight(), clientPlayer.posZ));
float f = (float)(i & 65535);
float f1 = (float)(i >> 16);
GL46.glMultiTexCoord2f(GL46.GL_TEXTURE1, f, f1);

View file

@ -179,6 +179,16 @@ public class RenderBuffer
this.rawIntBuffer.put(i + j * 3, p_178962_4_);
}
public void putColor4Light(int p_178962_1_, int p_178962_2_, int p_178962_3_, int p_178962_4_)
{
int i = (this.vertexCount - 4) * this.vertexFormat.getIntegerSize() + this.vertexFormat.getColorOffset() / 4;
int j = this.vertexFormat.getNextOffset() >> 2;
this.rawIntBuffer.put(i, p_178962_1_);
this.rawIntBuffer.put(i + j, p_178962_2_);
this.rawIntBuffer.put(i + j * 2, p_178962_3_);
this.rawIntBuffer.put(i + j * 3, p_178962_4_);
}
public void putPosition(double x, double y, double z)
{
int i = this.vertexFormat.getIntegerSize();
@ -241,6 +251,24 @@ public class RenderBuffer
return this.color(color >> 16 & 255, color >> 8 & 255, color & 255, color >> 24 & 255);
}
public RenderBuffer lightColor(int light)
{
return this.color(light & 255, light >> 8 & 255, light >> 16 & 255, light >> 24 & 255);
}
public RenderBuffer lightNormal(int data)
{
int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
this.byteBuffer.put(i, (byte)(data & 255));
this.byteBuffer.put(i + 1, (byte)(data >> 8 & 255));
this.byteBuffer.put(i + 2, (byte)(data >> 16 & 255));
this.byteBuffer.put(i + 3, (byte)(data >> 24 & 255));
this.nextVertexFormatIndex();
return this;
}
public RenderBuffer color(int red, int green, int blue, int alpha)
{
int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);

View file

@ -21,6 +21,7 @@ import org.lwjgl.opengl.GL46;
import client.Client;
import client.renderer.Shader.ShaderContext;
import client.renderer.blockmodel.BakedQuad;
import client.renderer.blockmodel.FaceBakery;
import client.renderer.blockmodel.IBakedModel;
import client.renderer.blockmodel.ModelManager;
import client.renderer.chunk.ChunkRenderDispatcher;
@ -188,6 +189,8 @@ public class Renderer {
private float moonColorGreen;
private float moonColorBlue;
private final int[] lightUpdate = new int[32768];
private boolean skyLight;
private boolean moonLight;
public Renderer(Client gm, ModelManager manager)
{
@ -1157,6 +1160,15 @@ public class Renderer {
public void renderWorld(float partialTicks, long finishTimeNano)
{
finishTimeNano = System.nanoTime() + Math.max((long)this.gm.maxBuildTime * 1000000L - finishTimeNano, 0L);
boolean moon = false;
for(int color : this.gm.world.dimension.getMoonColors()) {
if((color & 0xff000000) == 0) {
moon = true;
break;
}
}
this.skyLight = this.gm.world.dimension.hasSkyLight() && !this.gm.setGamma && !this.gm.xrayActive;
this.moonLight = moon;
this.updateLightmap(partialTicks);
if (this.gm.getRenderViewEntity() == null)
@ -1469,7 +1481,7 @@ public class Renderer {
float dist = ExtMath.sqrtd(dx * dx + dz * dz) / (float)range;
float alpha = ((1.0F - dist * dist) * 0.5F + 0.5F) * rain;
pos.set(x, lpos, z);
int light = world.getCombinedLight(pos);
int light = this.getCombinedBrightness(pos);
int sky = light >> 16 & 65535;
int blk = light & 65535;
buf.pos((double)x - rx + 0.5D, (double)miny, (double)z - rz + 0.5D).tex(0.0D, (double)miny * 0.25D + offset)
@ -1498,7 +1510,7 @@ public class Renderer {
float dist = ExtMath.sqrtd(dx * dx + dz * dz) / (float)range;
float alpha = ((1.0F - dist * dist) * 0.3F + 0.5F) * rain;
pos.set(x, lpos, z);
int light = (world.getCombinedLight(pos) * 3 + 15728880) / 4;
int light = (this.getCombinedBrightness(pos) * 3 + 15728880) / 4;
int sky = light >> 16 & 65535;
int blk = light & 65535;
buf.pos((double)x - rx + 0.5D, (double)miny, (double)z - rz + 0.5D).tex(0.0D + tx, (double)miny * 0.25D + offset + ty)
@ -2563,15 +2575,8 @@ public class Renderer {
if (this.initialized)
{
ShaderContext context = Shader.WORLD.use();
boolean moon = false;
for(int color : this.theWorld.dimension.getMoonColors()) {
if((color & 0xff000000) == 0) {
moon = true;
break;
}
}
context.bool("sky_light", this.theWorld.dimension.hasSkyLight() && !this.gm.setGamma && !this.gm.xrayActive);
context.bool("moon_light", moon);
context.bool("sky_light", this.skyLight);
context.bool("moon_light", this.moonLight);
for (RenderChunk renderchunk : this.renderChunks)
{
VertexBuffer vertexbuffer = renderchunk.getVertexBuffer();
@ -3235,7 +3240,7 @@ public class Renderer {
{
if (state.getBlock() != Blocks.air && !state.getBlock().getMaterial().isLiquid())
{
int light = brightPos == null ? 0xffffffff : getLightmapValue(this.gm.world, brightPos);
int light = brightPos == null ? 0xffffffff : this.getLightColor(brightPos, null);
IBakedModel model = this.manager.getModelForState(state);
Block block = state.getBlock();
GL46.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
@ -3257,12 +3262,35 @@ public class Renderer {
{
worldrenderer.begin(GL46.GL_QUADS, DefaultVertexFormats.ITEM);
worldrenderer.addVertexData(bakedquad.getVertexData());
worldrenderer.putBrightness4(light, light, light, light);
worldrenderer.putColor4(light);
Vec3i vec3i = bakedquad.getFace().getDirectionVec();
worldrenderer.putNormal((float)vec3i.getX(), (float)vec3i.getY(), (float)vec3i.getZ());
Tessellator.draw();
}
}
public int getLightColor(BlockPos pos, Facing side) {
int light = this.getCombinedLight(pos);
float sky = this.skyLight ? pos.getY() < 0 ? 0.0f : (pos.getY() < 64 ? (float)pos.getY() / 64.0f : 1.0f) : 1.0f;
float shading = side == null ? 1.0f : FaceBakery.getFaceBrightness(side);
float max = (float)Math.max(Math.max((light >> 16) & 0xff, (light >> 8) & 0xff), light & 0xff) / 255.0f;
max = sky * (1.0f - max * this.gm.lightBlend);
float directR = (float)(light >> 16 & 0xff) / 255.0f * shading + this.sunColorRed * max;
float directG = (float)(light >> 8 & 0xff) / 255.0f * shading + this.sunColorGreen * max;
float directB = (float)(light & 0xff) / 255.0f * shading + this.sunColorBlue * max;
if(this.moonLight) {
directR += this.moonColorRed * max;
directG += this.moonColorGreen * max;
directB += this.moonColorBlue * max;
}
return 0xff000000 | (int)(Math.min(directR, 1.0f) * 255.0f) << 16 | (int)(Math.min(directG, 1.0f) * 255.0f) << 8 | (int)(Math.min(directB, 1.0f) * 255.0f);
}
public int getCombinedBrightness(BlockPos pos) {
int light = this.getLightColor(pos, null);
light = Math.max(Math.max((light >> 16) & 0xff, (light >> 8) & 0xff), light & 0xff) / 16;
return light << 20 | light << 4;
}
public boolean renderBlock(State state, BlockPos pos, IWorldAccess world, RenderBuffer rb) {
Block block = state.getBlock();
@ -3346,7 +3374,7 @@ public class Renderer {
}
worldRendererIn.addVertexData(bakedquad.getVertexData());
worldRendererIn.putBrightness4(light, light, light, light);
worldRendererIn.putColor4Light(light, light, light, light);
worldRendererIn.putPosition(d0, d1, d2);
}
}
@ -3433,7 +3461,7 @@ public class Renderer {
boolean up = blockliquid.canRender(blockAccess, blockPosIn.up(), Facing.UP);
boolean down = blockliquid.canRender(blockAccess, blockPosIn.down(), Facing.DOWN);
boolean[] aboolean = new boolean[] {blockliquid.canRender(blockAccess, blockPosIn.north(), Facing.NORTH), blockliquid.canRender(blockAccess, blockPosIn.south(), Facing.SOUTH), blockliquid.canRender(blockAccess, blockPosIn.west(), Facing.WEST), blockliquid.canRender(blockAccess, blockPosIn.east(), Facing.EAST)};
float shine = (blockliquid.getShinyness() / 32.0f) * 0.5f;
float shine = blockliquid.getShinyness();
if (!up && !down && !aboolean[0] && !aboolean[1] && !aboolean[2] && !aboolean[3])
{
@ -3501,20 +3529,19 @@ public class Renderer {
f20 = textureatlassprite.getInterpolatedV((double)(8.0F + (-f22 - f21) * 16.0F));
}
int k2 = getLightmapValueLiquid(blockAccess, blockPosIn);
int l2 = k2 >> 16 & 65535;
int i3 = k2 & 65535;
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex();
int light = getLightmapValueLiquid(blockAccess, blockPosIn);
int norm = FaceBakery.getFaceNormal(shine, Facing.UP);
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).lightNormal(norm).tex((double)f13, (double)f17).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).lightNormal(norm).tex((double)f14, (double)f18).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).lightNormal(norm).tex((double)f15, (double)f19).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).lightNormal(norm).tex((double)f16, (double)f20).lightColor(light).endVertex();
if (blockliquid.shouldRenderSides(blockAccess, blockPosIn.up()))
{
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).lightNormal(norm).tex((double)f13, (double)f17).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).lightNormal(norm).tex((double)f16, (double)f20).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).lightNormal(norm).tex((double)f15, (double)f19).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).lightNormal(norm).tex((double)f14, (double)f18).lightColor(light).endVertex();
}
}
@ -3524,13 +3551,12 @@ public class Renderer {
float f36 = atextureatlassprite[0].getMaxU();
float f37 = atextureatlassprite[0].getMinV();
float f38 = atextureatlassprite[0].getMaxV();
int l1 = getLightmapValueLiquid(blockAccess, blockPosIn.down());
int i2 = l1 >> 16 & 65535;
int j2 = l1 & 65535;
worldRendererIn.pos(d0, d1, d2 + 1.0D).color(0.0f, -1.0f, 0.0f, shine).tex((double)f35, (double)f38).lightmap(i2, j2).endVertex();
worldRendererIn.pos(d0, d1, d2).color(0.0f, -1.0f, 0.0f, shine).tex((double)f35, (double)f37).lightmap(i2, j2).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1, d2).color(0.0f, -1.0f, 0.0f, shine).tex((double)f36, (double)f37).lightmap(i2, j2).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1, d2 + 1.0D).color(0.0f, -1.0f, 0.0f, shine).tex((double)f36, (double)f38).lightmap(i2, j2).endVertex();
int light = getLightmapValueLiquid(blockAccess, blockPosIn.down());
int norm = FaceBakery.getFaceNormal(shine, Facing.DOWN);
worldRendererIn.pos(d0, d1, d2 + 1.0D).lightNormal(norm).tex((double)f35, (double)f38).lightColor(light).endVertex();
worldRendererIn.pos(d0, d1, d2).lightNormal(norm).tex((double)f35, (double)f37).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1, d2).lightNormal(norm).tex((double)f36, (double)f37).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1, d2 + 1.0D).lightNormal(norm).tex((double)f36, (double)f38).lightColor(light).endVertex();
rendered = true;
}
@ -3614,19 +3640,16 @@ public class Renderer {
float f28 = textureatlassprite1.getInterpolatedV((double)((1.0F - f39) * 16.0F * 0.5F));
float f29 = textureatlassprite1.getInterpolatedV((double)((1.0F - f40) * 16.0F * 0.5F));
float f30 = textureatlassprite1.getInterpolatedV(8.0D);
int j = getLightmapValueLiquid(blockAccess, blockpos);
int k = j >> 16 & 65535;
int l = j & 65535;
float xn = np == 2 ? -1.0f : (np == 3 ? 1.0f : 0.0f);
float zn = np == 0 ? -1.0f : (np == 1 ? 1.0f : 0.0f);
worldRendererIn.pos(d3, d1 + (double)f39, d4).color(xn, 0.0f, zn, shine).tex((double)f41, (double)f28).lightmap(k, l).endVertex();
worldRendererIn.pos(d5, d1 + (double)f40, d6).color(xn, 0.0f, zn, shine).tex((double)f27, (double)f29).lightmap(k, l).endVertex();
worldRendererIn.pos(d5, d1 + 0.0D, d6).color(xn, 0.0f, zn, shine).tex((double)f27, (double)f30).lightmap(k, l).endVertex();
worldRendererIn.pos(d3, d1 + 0.0D, d4).color(xn, 0.0f, zn, shine).tex((double)f41, (double)f30).lightmap(k, l).endVertex();
worldRendererIn.pos(d3, d1 + 0.0D, d4).color(xn, 0.0f, zn, shine).tex((double)f41, (double)f30).lightmap(k, l).endVertex();
worldRendererIn.pos(d5, d1 + 0.0D, d6).color(xn, 0.0f, zn, shine).tex((double)f27, (double)f30).lightmap(k, l).endVertex();
worldRendererIn.pos(d5, d1 + (double)f40, d6).color(xn, 0.0f, zn, shine).tex((double)f27, (double)f29).lightmap(k, l).endVertex();
worldRendererIn.pos(d3, d1 + (double)f39, d4).color(xn, 0.0f, zn, shine).tex((double)f41, (double)f28).lightmap(k, l).endVertex();
int light = getLightmapValueLiquid(blockAccess, blockpos);
int norm = FaceBakery.getFaceNormal(shine, np == 0 ? Facing.NORTH : (np == 1 ? Facing.SOUTH : (np == 2 ? Facing.WEST : Facing.EAST)));
worldRendererIn.pos(d3, d1 + (double)f39, d4).lightNormal(norm).tex((double)f41, (double)f28).lightColor(light).endVertex();
worldRendererIn.pos(d5, d1 + (double)f40, d6).lightNormal(norm).tex((double)f27, (double)f29).lightColor(light).endVertex();
worldRendererIn.pos(d5, d1 + 0.0D, d6).lightNormal(norm).tex((double)f27, (double)f30).lightColor(light).endVertex();
worldRendererIn.pos(d3, d1 + 0.0D, d4).lightNormal(norm).tex((double)f41, (double)f30).lightColor(light).endVertex();
worldRendererIn.pos(d3, d1 + 0.0D, d4).lightNormal(norm).tex((double)f41, (double)f30).lightColor(light).endVertex();
worldRendererIn.pos(d5, d1 + 0.0D, d6).lightNormal(norm).tex((double)f27, (double)f30).lightColor(light).endVertex();
worldRendererIn.pos(d5, d1 + (double)f40, d6).lightNormal(norm).tex((double)f27, (double)f29).lightColor(light).endVertex();
worldRendererIn.pos(d3, d1 + (double)f39, d4).lightNormal(norm).tex((double)f41, (double)f28).lightColor(light).endVertex();
}
}
@ -3685,7 +3708,7 @@ public class Renderer {
boolean up = block.canRender(blockAccess, blockPosIn.up(), Facing.UP);
boolean down = block.canRender(blockAccess, blockPosIn.down(), Facing.DOWN);
boolean[] aboolean = new boolean[] {block.canRender(blockAccess, blockPosIn.north(), Facing.NORTH), block.canRender(blockAccess, blockPosIn.south(), Facing.SOUTH), block.canRender(blockAccess, blockPosIn.west(), Facing.WEST), block.canRender(blockAccess, blockPosIn.east(), Facing.EAST)};
float shine = (block.getShinyness() / 32.0f) * 0.5f;
float shine = block.getShinyness();
if (!up && !down && !aboolean[0] && !aboolean[1] && !aboolean[2] && !aboolean[3])
{
@ -3729,20 +3752,19 @@ public class Renderer {
f16 = f15;
f20 = f17;
int k2 = getLightmapValueLiquid(blockAccess, blockPosIn);
int l2 = k2 >> 16 & 65535;
int i3 = k2 & 65535;
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex();
int light = getLightmapValueLiquid(blockAccess, blockPosIn);
int norm = FaceBakery.getFaceNormal(shine, Facing.UP);
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).lightNormal(norm).tex((double)f13, (double)f17).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).lightNormal(norm).tex((double)f14, (double)f18).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).lightNormal(norm).tex((double)f15, (double)f19).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).lightNormal(norm).tex((double)f16, (double)f20).lightColor(light).endVertex();
//
// if (block.shouldRenderSides(blockAccess, blockPosIn.up()))
// {
// worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex();
// worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex();
// worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex();
// worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex();
// worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f13, (double)f17).lightColor(k2).endVertex();
// worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f16, (double)f20).lightColor(k2).endVertex();
// worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f15, (double)f19).lightColor(k2).endVertex();
// worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(0.0f, 1.0f, 0.0f, shine).tex((double)f14, (double)f18).lightColor(k2).endVertex();
// }
}
@ -3752,13 +3774,12 @@ public class Renderer {
float f36 = textureatlassprite.getMaxU();
float f37 = textureatlassprite.getMinV();
float f38 = textureatlassprite.getMaxV();
int l1 = getLightmapValueLiquid(blockAccess, blockPosIn.down());
int i2 = l1 >> 16 & 65535;
int j2 = l1 & 65535;
worldRendererIn.pos(d0, d1, d2 + 1.0D).color(0.0f, -1.0f, 0.0f, shine).tex((double)f35, (double)f38).lightmap(i2, j2).endVertex();
worldRendererIn.pos(d0, d1, d2).color(0.0f, -1.0f, 0.0f, shine).tex((double)f35, (double)f37).lightmap(i2, j2).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1, d2).color(0.0f, -1.0f, 0.0f, shine).tex((double)f36, (double)f37).lightmap(i2, j2).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1, d2 + 1.0D).color(0.0f, -1.0f, 0.0f, shine).tex((double)f36, (double)f38).lightmap(i2, j2).endVertex();
int light = getLightmapValueLiquid(blockAccess, blockPosIn.down());
int norm = FaceBakery.getFaceNormal(shine, Facing.DOWN);
worldRendererIn.pos(d0, d1, d2 + 1.0D).lightNormal(norm).tex((double)f35, (double)f38).lightColor(light).endVertex();
worldRendererIn.pos(d0, d1, d2).lightNormal(norm).tex((double)f35, (double)f37).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1, d2).lightNormal(norm).tex((double)f36, (double)f37).lightColor(light).endVertex();
worldRendererIn.pos(d0 + 1.0D, d1, d2 + 1.0D).lightNormal(norm).tex((double)f36, (double)f38).lightColor(light).endVertex();
rendered = true;
}
@ -3842,19 +3863,16 @@ public class Renderer {
float f28 = textureatlassprite1.getInterpolatedV((double)((1.0F - f39) * 16.0F));
float f29 = textureatlassprite1.getInterpolatedV((double)((1.0F - f40) * 16.0F));
float f30 = textureatlassprite1.getInterpolatedV(16.0D);
int j = getLightmapValueLiquid(blockAccess, blockpos);
int k = j >> 16 & 65535;
int l = j & 65535;
float xn = np == 2 ? -1.0f : (np == 3 ? 1.0f : 0.0f);
float zn = np == 0 ? -1.0f : (np == 1 ? 1.0f : 0.0f);
worldRendererIn.pos(d3, d1 + (double)f39, d4).color(xn, 0.0f, zn, shine).tex((double)f41, (double)f28).lightmap(k, l).endVertex();
worldRendererIn.pos(d5, d1 + (double)f40, d6).color(xn, 0.0f, zn, shine).tex((double)f27, (double)f29).lightmap(k, l).endVertex();
worldRendererIn.pos(d5, d1 + 0.0D, d6).color(xn, 0.0f, zn, shine).tex((double)f27, (double)f30).lightmap(k, l).endVertex();
worldRendererIn.pos(d3, d1 + 0.0D, d4).color(xn, 0.0f, zn, shine).tex((double)f41, (double)f30).lightmap(k, l).endVertex();
worldRendererIn.pos(d3, d1 + 0.0D, d4).color(xn, 0.0f, zn, shine).tex((double)f41, (double)f30).lightmap(k, l).endVertex();
worldRendererIn.pos(d5, d1 + 0.0D, d6).color(xn, 0.0f, zn, shine).tex((double)f27, (double)f30).lightmap(k, l).endVertex();
worldRendererIn.pos(d5, d1 + (double)f40, d6).color(xn, 0.0f, zn, shine).tex((double)f27, (double)f29).lightmap(k, l).endVertex();
worldRendererIn.pos(d3, d1 + (double)f39, d4).color(xn, 0.0f, zn, shine).tex((double)f41, (double)f28).lightmap(k, l).endVertex();
int light = getLightmapValueLiquid(blockAccess, blockpos);
int norm = FaceBakery.getFaceNormal(shine, np == 0 ? Facing.NORTH : (np == 1 ? Facing.SOUTH : (np == 2 ? Facing.WEST : Facing.EAST)));
worldRendererIn.pos(d3, d1 + (double)f39, d4).lightNormal(norm).tex((double)f41, (double)f28).lightColor(light).endVertex();
worldRendererIn.pos(d5, d1 + (double)f40, d6).lightNormal(norm).tex((double)f27, (double)f29).lightColor(light).endVertex();
worldRendererIn.pos(d5, d1 + 0.0D, d6).lightNormal(norm).tex((double)f27, (double)f30).lightColor(light).endVertex();
worldRendererIn.pos(d3, d1 + 0.0D, d4).lightNormal(norm).tex((double)f41, (double)f30).lightColor(light).endVertex();
worldRendererIn.pos(d3, d1 + 0.0D, d4).lightNormal(norm).tex((double)f41, (double)f30).lightColor(light).endVertex();
worldRendererIn.pos(d5, d1 + 0.0D, d6).lightNormal(norm).tex((double)f27, (double)f30).lightColor(light).endVertex();
worldRendererIn.pos(d5, d1 + (double)f40, d6).lightNormal(norm).tex((double)f27, (double)f29).lightColor(light).endVertex();
worldRendererIn.pos(d3, d1 + (double)f39, d4).lightNormal(norm).tex((double)f41, (double)f28).lightColor(light).endVertex();
}
}

View file

@ -73,9 +73,9 @@ public class FaceBakery
FACINGS[Constants.EAST_INDEX] = EnumFaceDirection.EAST;
}
public BakedQuad makeBakedQuad(Vector3f posFrom, Vector3f posTo, BlockPartFace face, Sprite sprite, Facing facing, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade, float shine)
public BakedQuad makeBakedQuad(Vector3f posFrom, Vector3f posTo, BlockPartFace face, Sprite sprite, Facing facing, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade, float shine, boolean asItem)
{
int[] aint = this.makeQuadVertexData(face, sprite, facing, this.getPositionsDiv16(posFrom, posTo), modelRotationIn, partRotation, uvLocked, shade, shine);
int[] aint = this.makeQuadVertexData(face, sprite, facing, this.getPositionsDiv16(posFrom, posTo), modelRotationIn, partRotation, uvLocked, shade, shine, asItem);
Facing enumfacing = getFacingFromVertexData(aint);
if (uvLocked)
@ -91,24 +91,49 @@ public class FaceBakery
return new BakedQuad(aint, face.tint, enumfacing);
}
private int[] makeQuadVertexData(BlockPartFace partFace, Sprite sprite, Facing facing, float[] p_178405_4_, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade, float shine)
private int[] makeQuadVertexData(BlockPartFace partFace, Sprite sprite, Facing facing, float[] p_178405_4_, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade, float shine, boolean asItem)
{
int[] aint = new int[28];
for (int i = 0; i < 4; ++i)
{
this.fillVertexData(aint, i, facing, partFace, p_178405_4_, sprite, modelRotationIn, partRotation, uvLocked, shade, shine);
this.fillVertexData(aint, i, facing, partFace, p_178405_4_, sprite, modelRotationIn, partRotation, uvLocked, shade, shine, asItem);
}
return aint;
}
private int getFaceShadeColor(Facing facing)
private static int getFaceShadeColor(Facing facing)
{
return this.getFaceNormal(facing);
float f = getFaceBrightness(facing);
int i = ExtMath.clampi((int)(f * 255.0F), 0, 255);
return -16777216 | i << 16 | i << 8 | i;
}
public static float getFaceBrightness(Facing facing)
{
switch (facing)
{
case DOWN:
return 0.5F;
case UP:
return 1.0F;
case NORTH:
case SOUTH:
return 0.8F;
case WEST:
case EAST:
return 0.6F;
default:
return 1.0F;
}
}
private int getFaceNormal(Facing facing)
private static int getFaceNormal(Facing facing)
{
switch (facing)
{
@ -127,6 +152,10 @@ public class FaceBakery
return 0x7f0000;
}
}
public static int getFaceNormal(float shine, Facing shade) {
return (int)((shine / 32.0f) * 127.0f) << 24 | (shade != null ? getFaceNormal(shade) : 0x000000);
}
private float[] getPositionsDiv16(Vector3f pos1, Vector3f pos2)
{
@ -140,24 +169,24 @@ public class FaceBakery
return afloat;
}
private void fillVertexData(int[] faceData, int vertexIndex, Facing facing, BlockPartFace partFace, float[] p_178402_5_, Sprite sprite, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade, float shine)
private void fillVertexData(int[] faceData, int vertexIndex, Facing facing, BlockPartFace partFace, float[] p_178402_5_, Sprite sprite, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade, float shine, boolean asItem)
{
Facing enumfacing = modelRotationIn.rotateFace(facing);
int i = (int)((shine / 32.0f) * 127.0f) << 24 | (shade ? this.getFaceShadeColor(enumfacing) : 0x000000);
int normColor = asItem ? (shade ? getFaceShadeColor(enumfacing) : 0xffffffff) : getFaceNormal(shine, shade ? enumfacing : null);
VertexInformation enumfacedirection$vertexinformation = EnumFaceDirection.getFacing(facing).getVertexInformation(vertexIndex);
Vector3f vector3f = new Vector3f(p_178402_5_[enumfacedirection$vertexinformation.xIndex], p_178402_5_[enumfacedirection$vertexinformation.yIndex], p_178402_5_[enumfacedirection$vertexinformation.zIndex]);
this.rotatePart(vector3f, partRotation);
int j = this.rotateVertex(vector3f, facing, vertexIndex, modelRotationIn, uvLocked);
this.storeVertexData(faceData, j, vertexIndex, vector3f, i, sprite, partFace.uv);
this.storeVertexData(faceData, j, vertexIndex, vector3f, normColor, sprite, partFace.uv);
}
private void storeVertexData(int[] faceData, int storeIndex, int vertexIndex, Vector3f position, int shadeColor, Sprite sprite, BlockFaceUV faceUV)
private void storeVertexData(int[] faceData, int storeIndex, int vertexIndex, Vector3f position, int normColor, Sprite sprite, BlockFaceUV faceUV)
{
int i = storeIndex * 7;
faceData[i] = Float.floatToRawIntBits(position.x);
faceData[i + 1] = Float.floatToRawIntBits(position.y);
faceData[i + 2] = Float.floatToRawIntBits(position.z);
faceData[i + 3] = shadeColor;
faceData[i + 3] = normColor;
faceData[i + 4] = Float.floatToRawIntBits(sprite.getInterpolatedU((double)faceUV.getU(vertexIndex)));
faceData[i + 4 + 1] = Float.floatToRawIntBits(sprite.getInterpolatedV((double)faceUV.getV(vertexIndex)));
}

View file

@ -175,7 +175,7 @@ public abstract class ModelBakery
if (modelblock != null)
{
bakedRegistry.put(modelresourcelocation, bakeModel(sprites, faceBakery, textureMap.getMissingSprite(),
modelblock, modelblock.getRotation(), modelblock.isUvLocked()));
modelblock, modelblock.getRotation(), modelblock.isUvLocked(), false));
}
else
{
@ -196,7 +196,7 @@ public abstract class ModelBakery
else
{
bakedRegistry.put(entry, bakeModel(sprites, faceBakery, textureMap.getMissingSprite(),
modelblock1, modelblock1.getRotation(), modelblock1.isUvLocked()));
modelblock1, modelblock1.getRotation(), modelblock1.isUvLocked(), true));
}
}
else
@ -219,7 +219,7 @@ public abstract class ModelBakery
}
private static IBakedModel bakeModel(Map<String, Sprite> sprites, FaceBakery faceBakery,
Sprite fallback, ModelBlock modelBlockIn, ModelRotation modelRotationIn, boolean uvLocked)
Sprite fallback, ModelBlock modelBlockIn, ModelRotation modelRotationIn, boolean uvLocked, boolean asItem)
{
Sprite particle = sprites.get(modelBlockIn.getPrimary());
BakedModel.Builder builder = new BakedModel.Builder(modelBlockIn).setTexture(particle == null ? fallback : particle);
@ -232,9 +232,9 @@ public abstract class ModelBakery
sprite = sprite == null ? fallback : sprite;
if (face.cull == null)
builder.addGeneralQuad(faceBakery.makeBakedQuad(blockpart.positionFrom, blockpart.positionTo, face, sprite, enumfacing, modelRotationIn, blockpart.partRotation, uvLocked, blockpart.shade, modelBlockIn.getShinyness()));
builder.addGeneralQuad(faceBakery.makeBakedQuad(blockpart.positionFrom, blockpart.positionTo, face, sprite, enumfacing, modelRotationIn, blockpart.partRotation, uvLocked, blockpart.shade, modelBlockIn.getShinyness(), asItem));
else
builder.addFaceQuad(modelRotationIn.rotateFace(face.cull), faceBakery.makeBakedQuad(blockpart.positionFrom, blockpart.positionTo, face, sprite, enumfacing, modelRotationIn, blockpart.partRotation, uvLocked, blockpart.shade, modelBlockIn.getShinyness()));
builder.addFaceQuad(modelRotationIn.rotateFace(face.cull), faceBakery.makeBakedQuad(blockpart.positionFrom, blockpart.positionTo, face, sprite, enumfacing, modelRotationIn, blockpart.partRotation, uvLocked, blockpart.shade, modelBlockIn.getShinyness(), asItem));
}
}
return builder.makeBakedModel();

View file

@ -121,7 +121,7 @@ public class RenderManager {
public static int getBrightnessForRender(Entity entity) {
BlockPos pos = new BlockPos(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ);
return entity.worldObj.isBlockLoaded(pos) ? entity.worldObj.getCombinedLight(pos) : 0;
return entity.worldObj.isBlockLoaded(pos) ? entity.worldObj.getCombinedBrightness(pos) : 0;
}
public boolean renderEntity(Entity entity, float partialTicks) {

View file

@ -55,7 +55,7 @@ public class SpecialRenderer {
public void renderTile(TileEntity tile, float partial) {
if(tile.getDistanceSq(this.posX, this.posY, this.posZ) < tile.getMaxRenderDistanceSquared()) {
int light = this.world.getCombinedLight(tile.getPos());
int light = this.world.getCombinedBrightness(tile.getPos());
int block = light % 65536;
int sky = light / 65536;
GL46.glMultiTexCoord2f(GL46.GL_TEXTURE1, (float)block / 1.0F, (float)sky / 1.0F);

View file

@ -22,7 +22,7 @@ uniform bool shade;
void main() {
vec3 nvertex = vec3(model * vec4(pos, 1.0));
vertex = vec3(float(chunk_x) + pos.x, float(chunk_y) + pos.y, float(chunk_z) + pos.z);
shading = shade ? (norm.x != 0.0 ? 0.6 : (norm.z != 0.0 ? 0.8 : (norm.y > 0.0 ? 0.5 : 1.0))) : 1.0;
shading = shade ? (norm.x != 0.0 ? 0.6 : (norm.z != 0.0 ? 0.8 : (norm.y < 0.0 ? 0.5 : 1.0))) : 1.0;
normal = mat3(transpose(inverse(model))) * norm.xyz;
shine = norm.a * 32.0;
tex_coord = coord;

View file

@ -191,6 +191,10 @@ public abstract class World implements IWorldAccess {
return 0;
}
public int getCombinedBrightness(BlockPos pos) {
return 0;
}
public boolean setState(BlockPos pos, State state) {
return this.setState(pos, state, 3);
}