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:
parent
cf9b1b2193
commit
d84a88d78d
7 changed files with 102 additions and 68 deletions
|
@ -1,5 +1,14 @@
|
|||
--- a/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 @@
|
||||
return this.field_175028_a;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ package net.minecraftforge.client.model.pipeline;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
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.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -113,7 +115,7 @@ public class BlockInfo
|
|||
if (s1 == 0 && !t1) s1 = 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);
|
||||
return (float) (c + s1 + s2 + s3) * 0x20 / (4 * 0xFFFF);
|
||||
return (c + s1 + s2 + s3) / (0xF * 4f);
|
||||
}
|
||||
|
||||
public void updateLightMatrix()
|
||||
|
@ -127,9 +129,9 @@ public class BlockInfo
|
|||
BlockPos pos = blockPos.add(x - 1, y - 1, z - 1);
|
||||
BlockState state = world.getBlockState(pos);
|
||||
t[x][y][z] = state.getOpacity(world, pos) < 15;
|
||||
int brightness = 0x00FF00FF; // FIXME: state.getPackedLightmapCoords(world, pos);
|
||||
s[x][y][z] = (brightness >> 0x14) & 0xF;
|
||||
b[x][y][z] = (brightness >> 0x04) & 0xF;
|
||||
int brightness = WorldRenderer.getCombinedLight(world, pos);
|
||||
s[x][y][z] = LightTexture.getLightSky(brightness);
|
||||
b[x][y][z] = LightTexture.getLightBlock(brightness);
|
||||
ao[x][y][z] = state.getAmbientOcclusionLightValue(world, pos);
|
||||
}
|
||||
}
|
||||
|
@ -195,12 +197,12 @@ public class BlockInfo
|
|||
public void updateFlatLighting()
|
||||
{
|
||||
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)
|
||||
{
|
||||
int i = side.ordinal() + 1;
|
||||
packed[i] = 0x00FF00FF; // FIXME: state.getPackedLightmapCoords(world, blockPos.offset(side));
|
||||
packed[i] = WorldRenderer.getCombinedLight(world, blockPos.offset(side));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ import net.minecraft.world.ILightReader;
|
|||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.common.ForgeConfig;
|
||||
|
||||
/*
|
||||
public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||
{
|
||||
private final ThreadLocal<VertexLighterFlat> lighterFlat;
|
||||
|
@ -54,16 +53,16 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
|||
@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)
|
||||
{
|
||||
if(ForgeConfig.CLIENT.forgeLightPipelineEnabled.get())
|
||||
if(ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get())
|
||||
{
|
||||
VertexBufferConsumer consumer = consumerFlat.get();
|
||||
consumer.setBuffer(buffer);
|
||||
consumer.setOffset(pos);
|
||||
|
||||
VertexLighterFlat lighter = lighterFlat.get();
|
||||
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
|
||||
{
|
||||
|
@ -74,16 +73,16 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
|||
@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)
|
||||
{
|
||||
if(ForgeConfig.CLIENT.forgeLightPipelineEnabled.get())
|
||||
if(ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get())
|
||||
{
|
||||
VertexBufferConsumer consumer = consumerSmooth.get();
|
||||
consumer.setBuffer(buffer);
|
||||
consumer.setOffset(pos);
|
||||
|
||||
VertexLighterSmoothAo lighter = lighterSmooth.get();
|
||||
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
|
||||
{
|
||||
|
@ -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.setState(state);
|
||||
|
@ -129,4 +128,3 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
|||
return !empty;
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -20,25 +20,20 @@
|
|||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement.Usage;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
/**
|
||||
* Assumes VertexFormatElement is present in the BufferBuilder's vertex format.
|
||||
*/
|
||||
public class VertexBufferConsumer implements IVertexConsumer
|
||||
{
|
||||
private static final float[] dummyColor = new float[]{ 1, 1, 1, 1 };
|
||||
|
||||
private IVertexBuilder renderer;
|
||||
private int[] quadData;
|
||||
private int v = 0;
|
||||
private BlockPos offset = BlockPos.ZERO;
|
||||
|
||||
public VertexBufferConsumer() {}
|
||||
|
||||
|
@ -53,48 +48,60 @@ public class VertexBufferConsumer implements IVertexConsumer
|
|||
return DefaultVertexFormats.BLOCK; // renderer.getVertexFormat();
|
||||
}
|
||||
|
||||
private int expandTextureCoord(final float c, final int max)
|
||||
{
|
||||
return (int) (MathHelper.clamp(c, 0, 1) * max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(int e, float... data)
|
||||
{
|
||||
// TODO
|
||||
/*
|
||||
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)
|
||||
{
|
||||
v++;
|
||||
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()];
|
||||
renderer.endVertex();
|
||||
}
|
||||
}
|
||||
|
||||
public void setBuffer(IVertexBuilder buffer)
|
||||
{
|
||||
this.renderer = buffer;
|
||||
checkVertexFormat();
|
||||
}
|
||||
|
||||
public void setOffset(BlockPos offset)
|
||||
{
|
||||
this.offset = new BlockPos(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,8 +21,11 @@ package net.minecraftforge.client.model.pipeline;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
@ -51,6 +54,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
|||
protected int lightmapIndex = -1;
|
||||
|
||||
protected VertexFormat baseFormat;
|
||||
protected MatrixStack.Entry pose;
|
||||
|
||||
public VertexLighterFlat(BlockColors colors)
|
||||
{
|
||||
|
@ -64,6 +68,11 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
|||
setVertexFormat(parent.getVertexFormat());
|
||||
}
|
||||
|
||||
public void setTransform(final MatrixStack.Entry pose)
|
||||
{
|
||||
this.pose = pose;
|
||||
}
|
||||
|
||||
private void updateIndices()
|
||||
{
|
||||
for(int i = 0; i < getVertexFormat().getElements().size(); i++)
|
||||
|
@ -137,9 +146,9 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
|||
float[][] color = quadData[colorIndex];
|
||||
|
||||
if (dataLength[normalIndex] >= 3
|
||||
&& (quadData[normalIndex][0][0] != -1
|
||||
|| quadData[normalIndex][0][1] != -1
|
||||
|| quadData[normalIndex][0][2] != -1))
|
||||
&& (quadData[normalIndex][0][0] != 0
|
||||
|| quadData[normalIndex][0][1] != 0
|
||||
|| quadData[normalIndex][0][2] != 0))
|
||||
{
|
||||
normal = quadData[normalIndex];
|
||||
}
|
||||
|
@ -213,22 +222,29 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
|||
switch(element.getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
// position adding moved to VertexBufferConsumer due to x and z not fitting completely into a float
|
||||
/*float[] pos = new float[4];
|
||||
System.arraycopy(position[v], 0, pos, 0, position[v].length);
|
||||
pos[0] += blockInfo.getBlockPos().getX();
|
||||
pos[1] += blockInfo.getBlockPos().getY();
|
||||
pos[2] += blockInfo.getBlockPos().getZ();*/
|
||||
final net.minecraft.client.renderer.Vector4f pos = new net.minecraft.client.renderer.Vector4f(
|
||||
position[v][0], position[v][1], position[v][2], 1);
|
||||
pos.transform(pose.getMatrix());
|
||||
|
||||
position[v][0] = pos.getX();
|
||||
position[v][1] = pos.getY();
|
||||
position[v][2] = pos.getZ();
|
||||
parent.put(e, position[v]);
|
||||
break;
|
||||
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]);
|
||||
break;
|
||||
case COLOR:
|
||||
parent.put(e, color[v]);
|
||||
break;
|
||||
case UV:
|
||||
if(element.getIndex() == 1)
|
||||
if(element.getIndex() == 2)
|
||||
{
|
||||
parent.put(e, lightmap[v]);
|
||||
break;
|
||||
|
@ -260,8 +276,8 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
|||
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;
|
||||
lightmap[0] = LightTexture.getLightBlock(brightness) / (float) 0xF;
|
||||
lightmap[1] = LightTexture.getLightSky(brightness) / (float) 0xF;
|
||||
}
|
||||
|
||||
protected void updateColor(float[] normal, float[] color, float x, float y, float z, float tint, int multiplier)
|
||||
|
|
|
@ -139,10 +139,7 @@ public class VertexLighterSmoothAo extends VertexLighterFlat
|
|||
}
|
||||
|
||||
l /= s;
|
||||
|
||||
if(l > 15f * 0x20 / 0xFFFF) l = 15f * 0x20 / 0xFFFF;
|
||||
if(l < 0) l = 0;
|
||||
|
||||
l = MathHelper.clamp(l, 0, 1);
|
||||
return l;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,6 +127,7 @@ public class ForgeConfig
|
|||
public final BooleanValue alwaysSetupTerrainOffThread;
|
||||
|
||||
public final BooleanValue forgeLightPipelineEnabled;
|
||||
public final BooleanValue experimentalForgeLightPipelineEnabled;
|
||||
|
||||
public final BooleanValue selectiveResourceReloadEnabled;
|
||||
|
||||
|
@ -162,6 +163,10 @@ public class ForgeConfig
|
|||
.comment("Enable the Forge block rendering pipeline - fixes the lighting of custom models.")
|
||||
.translation("forge.configgui.forgeLightPipelineEnabled")
|
||||
.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
|
||||
.comment("When enabled, makes specific reload tasks such as language changing quicker to run.")
|
||||
|
|
Loading…
Reference in a new issue