Revive forge lighting pipeline, disabled by default for now

Remove a lot of light value convolution by using 0..1 for nearly everything
Fix a lot of TODOs that are needed for the lighting pipeline to function
Potential fix for #6425
This commit is contained in:
tterrag 2020-04-04 16:21:41 -04:00
parent cf9b1b2193
commit d84a88d78d
7 changed files with 102 additions and 68 deletions

View file

@ -1,5 +1,14 @@
--- a/net/minecraft/client/renderer/BlockRendererDispatcher.java --- a/net/minecraft/client/renderer/BlockRendererDispatcher.java
+++ b/net/minecraft/client/renderer/BlockRendererDispatcher.java +++ b/net/minecraft/client/renderer/BlockRendererDispatcher.java
@@ -32,7 +32,7 @@
public BlockRendererDispatcher(BlockModelShapes p_i46577_1_, BlockColors p_i46577_2_) {
this.field_175028_a = p_i46577_1_;
this.field_228790_e_ = p_i46577_2_;
- this.field_175027_c = new BlockModelRenderer(this.field_228790_e_);
+ this.field_175027_c = new net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer(this.field_228790_e_);
this.field_175025_e = new FluidBlockRenderer();
}
@@ -40,18 +40,26 @@ @@ -40,18 +40,26 @@
return this.field_175028_a; return this.field_175028_a;
} }

View file

@ -22,6 +22,8 @@ package net.minecraftforge.client.model.pipeline;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.color.BlockColors; import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -113,7 +115,7 @@ public class BlockInfo
if (s1 == 0 && !t1) s1 = Math.max(0, c - 1); if (s1 == 0 && !t1) s1 = Math.max(0, c - 1);
if (s2 == 0 && !t2) s2 = Math.max(0, c - 1); if (s2 == 0 && !t2) s2 = Math.max(0, c - 1);
if (s3 == 0 && !t3) s3 = Math.max(0, Math.max(s1, s2) - 1); if (s3 == 0 && !t3) s3 = Math.max(0, Math.max(s1, s2) - 1);
return (float) (c + s1 + s2 + s3) * 0x20 / (4 * 0xFFFF); return (c + s1 + s2 + s3) / (0xF * 4f);
} }
public void updateLightMatrix() public void updateLightMatrix()
@ -127,9 +129,9 @@ public class BlockInfo
BlockPos pos = blockPos.add(x - 1, y - 1, z - 1); BlockPos pos = blockPos.add(x - 1, y - 1, z - 1);
BlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
t[x][y][z] = state.getOpacity(world, pos) < 15; t[x][y][z] = state.getOpacity(world, pos) < 15;
int brightness = 0x00FF00FF; // FIXME: state.getPackedLightmapCoords(world, pos); int brightness = WorldRenderer.getCombinedLight(world, pos);
s[x][y][z] = (brightness >> 0x14) & 0xF; s[x][y][z] = LightTexture.getLightSky(brightness);
b[x][y][z] = (brightness >> 0x04) & 0xF; b[x][y][z] = LightTexture.getLightBlock(brightness);
ao[x][y][z] = state.getAmbientOcclusionLightValue(world, pos); ao[x][y][z] = state.getAmbientOcclusionLightValue(world, pos);
} }
} }
@ -195,12 +197,12 @@ public class BlockInfo
public void updateFlatLighting() public void updateFlatLighting()
{ {
full = Block.isOpaque(state.getCollisionShape(world, blockPos)); full = Block.isOpaque(state.getCollisionShape(world, blockPos));
packed[0] = 0x00FF00FF; // FIXME: state.getPackedLightmapCoords(world, blockPos); packed[0] = WorldRenderer.getCombinedLight(world, blockPos);
for (Direction side : SIDES) for (Direction side : SIDES)
{ {
int i = side.ordinal() + 1; int i = side.ordinal() + 1;
packed[i] = 0x00FF00FF; // FIXME: state.getPackedLightmapCoords(world, blockPos.offset(side)); packed[i] = WorldRenderer.getCombinedLight(world, blockPos.offset(side));
} }
} }

View file

@ -36,7 +36,6 @@ import net.minecraft.world.ILightReader;
import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.common.ForgeConfig; import net.minecraftforge.common.ForgeConfig;
/*
public class ForgeBlockModelRenderer extends BlockModelRenderer public class ForgeBlockModelRenderer extends BlockModelRenderer
{ {
private final ThreadLocal<VertexLighterFlat> lighterFlat; private final ThreadLocal<VertexLighterFlat> lighterFlat;
@ -54,16 +53,16 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
@Override @Override
public boolean renderModelFlat(ILightReader world, IBakedModel model, BlockState state, BlockPos pos, MatrixStack matrixStack, IVertexBuilder buffer, boolean checkSides, Random rand, long seed, int p_228806_11_, IModelData modelData) public boolean renderModelFlat(ILightReader world, IBakedModel model, BlockState state, BlockPos pos, MatrixStack matrixStack, IVertexBuilder buffer, boolean checkSides, Random rand, long seed, int p_228806_11_, IModelData modelData)
{ {
if(ForgeConfig.CLIENT.forgeLightPipelineEnabled.get()) if(ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get())
{ {
VertexBufferConsumer consumer = consumerFlat.get(); VertexBufferConsumer consumer = consumerFlat.get();
consumer.setBuffer(buffer); consumer.setBuffer(buffer);
consumer.setOffset(pos);
VertexLighterFlat lighter = lighterFlat.get(); VertexLighterFlat lighter = lighterFlat.get();
lighter.setParent(consumer); lighter.setParent(consumer);
lighter.setTransform(matrixStack.getLast());
return render(lighter, world, model, state, pos, checkSides, rand, seed, modelData); return render(lighter, world, model, state, pos, matrixStack, checkSides, rand, seed, modelData);
} }
else else
{ {
@ -74,16 +73,16 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
@Override @Override
public boolean renderModelSmooth(ILightReader world, IBakedModel model, BlockState state, BlockPos pos, MatrixStack matrixStack, IVertexBuilder buffer, boolean checkSides, Random rand, long seed, int p_228805_11_, IModelData modelData) public boolean renderModelSmooth(ILightReader world, IBakedModel model, BlockState state, BlockPos pos, MatrixStack matrixStack, IVertexBuilder buffer, boolean checkSides, Random rand, long seed, int p_228805_11_, IModelData modelData)
{ {
if(ForgeConfig.CLIENT.forgeLightPipelineEnabled.get()) if(ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get())
{ {
VertexBufferConsumer consumer = consumerSmooth.get(); VertexBufferConsumer consumer = consumerSmooth.get();
consumer.setBuffer(buffer); consumer.setBuffer(buffer);
consumer.setOffset(pos);
VertexLighterSmoothAo lighter = lighterSmooth.get(); VertexLighterSmoothAo lighter = lighterSmooth.get();
lighter.setParent(consumer); lighter.setParent(consumer);
lighter.setTransform(matrixStack.getLast());
return render(lighter, world, model, state, pos, checkSides, rand, seed, modelData); return render(lighter, world, model, state, pos, matrixStack, checkSides, rand, seed, modelData);
} }
else else
{ {
@ -91,7 +90,7 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
} }
} }
public static boolean render(VertexLighterFlat lighter, ILightReader world, IBakedModel model, BlockState state, BlockPos pos, boolean checkSides, Random rand, long seed, IModelData modelData) public static boolean render(VertexLighterFlat lighter, ILightReader world, IBakedModel model, BlockState state, BlockPos pos, MatrixStack matrixStack, boolean checkSides, Random rand, long seed, IModelData modelData)
{ {
lighter.setWorld(world); lighter.setWorld(world);
lighter.setState(state); lighter.setState(state);
@ -129,4 +128,3 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
return !empty; return !empty;
} }
} }
*/

View file

@ -20,25 +20,20 @@
package net.minecraftforge.client.model.pipeline; package net.minecraftforge.client.model.pipeline;
import com.mojang.blaze3d.vertex.IVertexBuilder; import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement.Usage; import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.MathHelper;
/** /**
* Assumes VertexFormatElement is present in the BufferBuilder's vertex format. * Assumes VertexFormatElement is present in the BufferBuilder's vertex format.
*/ */
public class VertexBufferConsumer implements IVertexConsumer public class VertexBufferConsumer implements IVertexConsumer
{ {
private static final float[] dummyColor = new float[]{ 1, 1, 1, 1 };
private IVertexBuilder renderer; private IVertexBuilder renderer;
private int[] quadData;
private int v = 0;
private BlockPos offset = BlockPos.ZERO;
public VertexBufferConsumer() {} public VertexBufferConsumer() {}
@ -53,48 +48,60 @@ public class VertexBufferConsumer implements IVertexConsumer
return DefaultVertexFormats.BLOCK; // renderer.getVertexFormat(); return DefaultVertexFormats.BLOCK; // renderer.getVertexFormat();
} }
private int expandTextureCoord(final float c, final int max)
{
return (int) (MathHelper.clamp(c, 0, 1) * max);
}
@Override @Override
public void put(int e, float... data) public void put(int e, float... data)
{ {
// TODO
/*
VertexFormat format = getVertexFormat(); VertexFormat format = getVertexFormat();
if(renderer.isColorDisabled() && format.getElements().get(e).getUsage() == Usage.COLOR) VertexFormatElement element = format.getElements().get(e);
final float d0 = data.length <= 0 ? 0 : data[0];
final float d1 = data.length <= 1 ? 0 : data[1];
final float d2 = data.length <= 2 ? 0 : data[2];
final float d3 = data.length <= 3 ? 0 : data[3];
switch (element.getUsage())
{ {
data = dummyColor; case POSITION:
renderer.pos(d0, d1, d2);
break;
case NORMAL:
renderer.normal(d0, d1, d2);
break;
case COLOR:
renderer.color(d0, d1, d2, d3);
break;
case UV:
switch (element.getIndex())
{
case 0:
renderer.tex(d0, d1);
break;
case 1:
renderer.overlay(expandTextureCoord(d0, 0xF), expandTextureCoord(d1, 0xF));
break;
case 2:
renderer.lightmap(expandTextureCoord(d0, 0xF0), expandTextureCoord(d1, 0xF0));
break;
}
break;
default:
case PADDING:
case GENERIC:
break;
} }
LightUtil.pack(data, quadData, format, v, e);
if(e == format.getElements().size() - 1) if(e == format.getElements().size() - 1)
{ {
v++; renderer.endVertex();
if(v == 4)
{
renderer.addVertexData(quadData);
renderer.putPosition(offset.getX(), offset.getY(), offset.getZ());
//Arrays.fill(quadData, 0);
v = 0;
}
}
*/
}
private void checkVertexFormat()
{
if (quadData == null || getVertexFormat().getSize() != quadData.length)
{
quadData = new int[getVertexFormat().getSize()];
} }
} }
public void setBuffer(IVertexBuilder buffer) public void setBuffer(IVertexBuilder buffer)
{ {
this.renderer = buffer; this.renderer = buffer;
checkVertexFormat();
}
public void setOffset(BlockPos offset)
{
this.offset = new BlockPos(offset);
} }
@Override @Override

View file

@ -21,8 +21,11 @@ package net.minecraftforge.client.model.pipeline;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.color.BlockColors; import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@ -51,6 +54,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer
protected int lightmapIndex = -1; protected int lightmapIndex = -1;
protected VertexFormat baseFormat; protected VertexFormat baseFormat;
protected MatrixStack.Entry pose;
public VertexLighterFlat(BlockColors colors) public VertexLighterFlat(BlockColors colors)
{ {
@ -64,6 +68,11 @@ public class VertexLighterFlat extends QuadGatheringTransformer
setVertexFormat(parent.getVertexFormat()); setVertexFormat(parent.getVertexFormat());
} }
public void setTransform(final MatrixStack.Entry pose)
{
this.pose = pose;
}
private void updateIndices() private void updateIndices()
{ {
for(int i = 0; i < getVertexFormat().getElements().size(); i++) for(int i = 0; i < getVertexFormat().getElements().size(); i++)
@ -137,9 +146,9 @@ public class VertexLighterFlat extends QuadGatheringTransformer
float[][] color = quadData[colorIndex]; float[][] color = quadData[colorIndex];
if (dataLength[normalIndex] >= 3 if (dataLength[normalIndex] >= 3
&& (quadData[normalIndex][0][0] != -1 && (quadData[normalIndex][0][0] != 0
|| quadData[normalIndex][0][1] != -1 || quadData[normalIndex][0][1] != 0
|| quadData[normalIndex][0][2] != -1)) || quadData[normalIndex][0][2] != 0))
{ {
normal = quadData[normalIndex]; normal = quadData[normalIndex];
} }
@ -213,22 +222,29 @@ public class VertexLighterFlat extends QuadGatheringTransformer
switch(element.getUsage()) switch(element.getUsage())
{ {
case POSITION: case POSITION:
// position adding moved to VertexBufferConsumer due to x and z not fitting completely into a float final net.minecraft.client.renderer.Vector4f pos = new net.minecraft.client.renderer.Vector4f(
/*float[] pos = new float[4]; position[v][0], position[v][1], position[v][2], 1);
System.arraycopy(position[v], 0, pos, 0, position[v].length); pos.transform(pose.getMatrix());
pos[0] += blockInfo.getBlockPos().getX();
pos[1] += blockInfo.getBlockPos().getY(); position[v][0] = pos.getX();
pos[2] += blockInfo.getBlockPos().getZ();*/ position[v][1] = pos.getY();
position[v][2] = pos.getZ();
parent.put(e, position[v]); parent.put(e, position[v]);
break; break;
case NORMAL: case NORMAL:
final net.minecraft.client.renderer.Vector3f norm = new net.minecraft.client.renderer.Vector3f(normal[v]);
norm.transform(pose.getNormal());
normal[v][0] = norm.getX();
normal[v][1] = norm.getY();
normal[v][2] = norm.getZ();
parent.put(e, normal[v]); parent.put(e, normal[v]);
break; break;
case COLOR: case COLOR:
parent.put(e, color[v]); parent.put(e, color[v]);
break; break;
case UV: case UV:
if(element.getIndex() == 1) if(element.getIndex() == 2)
{ {
parent.put(e, lightmap[v]); parent.put(e, lightmap[v]);
break; break;
@ -260,8 +276,8 @@ public class VertexLighterFlat extends QuadGatheringTransformer
int i = side == null ? 0 : side.ordinal() + 1; int i = side == null ? 0 : side.ordinal() + 1;
int brightness = blockInfo.getPackedLight()[i]; int brightness = blockInfo.getPackedLight()[i];
lightmap[0] = ((float)((brightness >> 0x04) & 0xF) * 0x20) / 0xFFFF; lightmap[0] = LightTexture.getLightBlock(brightness) / (float) 0xF;
lightmap[1] = ((float)((brightness >> 0x14) & 0xF) * 0x20) / 0xFFFF; lightmap[1] = LightTexture.getLightSky(brightness) / (float) 0xF;
} }
protected void updateColor(float[] normal, float[] color, float x, float y, float z, float tint, int multiplier) protected void updateColor(float[] normal, float[] color, float x, float y, float z, float tint, int multiplier)

View file

@ -139,10 +139,7 @@ public class VertexLighterSmoothAo extends VertexLighterFlat
} }
l /= s; l /= s;
l = MathHelper.clamp(l, 0, 1);
if(l > 15f * 0x20 / 0xFFFF) l = 15f * 0x20 / 0xFFFF;
if(l < 0) l = 0;
return l; return l;
} }

View file

@ -127,6 +127,7 @@ public class ForgeConfig
public final BooleanValue alwaysSetupTerrainOffThread; public final BooleanValue alwaysSetupTerrainOffThread;
public final BooleanValue forgeLightPipelineEnabled; public final BooleanValue forgeLightPipelineEnabled;
public final BooleanValue experimentalForgeLightPipelineEnabled;
public final BooleanValue selectiveResourceReloadEnabled; public final BooleanValue selectiveResourceReloadEnabled;
@ -162,6 +163,10 @@ public class ForgeConfig
.comment("Enable the Forge block rendering pipeline - fixes the lighting of custom models.") .comment("Enable the Forge block rendering pipeline - fixes the lighting of custom models.")
.translation("forge.configgui.forgeLightPipelineEnabled") .translation("forge.configgui.forgeLightPipelineEnabled")
.define("forgeLightPipelineEnabled", true); .define("forgeLightPipelineEnabled", true);
experimentalForgeLightPipelineEnabled = builder
.comment("EXPERIMENTAL: Enable the Forge block rendering pipeline - fixes the lighting of custom models.")
.translation("forge.configgui.forgeLightPipelineEnabled")
.define("experimentalForgeLightPipelineEnabled", false);
selectiveResourceReloadEnabled = builder selectiveResourceReloadEnabled = builder
.comment("When enabled, makes specific reload tasks such as language changing quicker to run.") .comment("When enabled, makes specific reload tasks such as language changing quicker to run.")