mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Remove emissive items hook, add small utility for bakedquad lighting
This commit is contained in:
1 parent
1936eb1f36
commit
380366e25f
5 files changed
+25
-186
No files matched your search
@@ -557,166 +557,6 @@ public class ForgeHooksClient
|
||||
return new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, loc);
|
||||
}
|
||||
|
||||
private static class LightGatheringTransformer extends QuadGatheringTransformer {
|
||||
|
||||
private static final VertexFormat FORMAT = new VertexFormat(ImmutableList.of(DefaultVertexFormats.TEX_2F, DefaultVertexFormats.TEX_2S));
|
||||
|
||||
int blockLight, skyLight;
|
||||
|
||||
{ setVertexFormat(FORMAT); }
|
||||
|
||||
boolean hasLighting()
|
||||
{
|
||||
return dataLength[1] >= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processQuad()
|
||||
{
|
||||
// Reset light data
|
||||
blockLight = 0;
|
||||
skyLight = 0;
|
||||
// Compute average light for all 4 vertices
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
blockLight += (int) ((quadData[1][i][0] * 0xFFFF) / 0x20);
|
||||
skyLight += (int) ((quadData[1][i][1] * 0xFFFF) / 0x20);
|
||||
}
|
||||
// Values must be multiplied by 16, divided by 4 for average => x4
|
||||
blockLight *= 4;
|
||||
skyLight *= 4;
|
||||
}
|
||||
|
||||
// Dummy overrides
|
||||
|
||||
@Override
|
||||
public void setQuadTint(int tint) {}
|
||||
|
||||
@Override
|
||||
public void setQuadOrientation(Direction orientation) {}
|
||||
|
||||
@Override
|
||||
public void setApplyDiffuseLighting(boolean diffuse) {}
|
||||
|
||||
@Override
|
||||
public void setTexture(TextureAtlasSprite texture) {}
|
||||
}
|
||||
|
||||
private static final LightGatheringTransformer lightGatherer = new LightGatheringTransformer();
|
||||
|
||||
// TODO: Fix: Vanilla now batches rendering items, so our hack of forcing the GL lighting state does not work.
|
||||
public static void renderLitItem(ItemRenderer ri, MatrixStack mat, IVertexBuilder consumer, IBakedModel model, ItemStack stack)
|
||||
{
|
||||
List<BakedQuad> allquads = new ArrayList<>();
|
||||
Random random = new Random();
|
||||
long seed = 42L;
|
||||
|
||||
for (Direction enumfacing : Direction.values())
|
||||
{
|
||||
random.setSeed(seed);
|
||||
allquads.addAll(model.getQuads(null, enumfacing, random, EmptyModelData.INSTANCE));
|
||||
}
|
||||
|
||||
random.setSeed(seed);
|
||||
allquads.addAll(model.getQuads(null, null, random, EmptyModelData.INSTANCE));
|
||||
|
||||
if (allquads.isEmpty()) return;
|
||||
|
||||
// Current list of consecutive quads with the same lighting
|
||||
List<BakedQuad> segment = new ArrayList<>();
|
||||
|
||||
// Lighting of the current segment
|
||||
int segmentBlockLight = 0;
|
||||
int segmentSkyLight = 0;
|
||||
// Diffuse lighting state
|
||||
boolean segmentShading = true;
|
||||
// State changed by the current segment
|
||||
boolean segmentLightingDirty = false;
|
||||
boolean segmentShadingDirty = false;
|
||||
// If the current segment contains lighting data
|
||||
boolean hasLighting = false;
|
||||
|
||||
for (int i = 0; i < allquads.size(); i++)
|
||||
{
|
||||
BakedQuad q = allquads.get(i);
|
||||
|
||||
// Lighting of the current quad
|
||||
int bl = 0;
|
||||
int sl = 0;
|
||||
|
||||
LightUtil.putBakedQuad(lightGatherer, q);
|
||||
if (lightGatherer.hasLighting())
|
||||
{
|
||||
bl = lightGatherer.blockLight;
|
||||
sl = lightGatherer.skyLight;
|
||||
}
|
||||
|
||||
boolean shade = q.shouldApplyDiffuseLighting();
|
||||
|
||||
boolean lightingDirty = segmentBlockLight != bl || segmentSkyLight != sl;
|
||||
boolean shadeDirty = shade != segmentShading;
|
||||
|
||||
// If lighting or color data has changed, draw the segment and flush it
|
||||
if (lightingDirty || shadeDirty)
|
||||
{
|
||||
if (i > 0) // Make sure this isn't the first quad being processed
|
||||
drawSegment(ri, mat, consumer, stack, segment, segmentBlockLight, segmentSkyLight, segmentShading, segmentLightingDirty && (hasLighting || segment.size() < i), segmentShadingDirty);
|
||||
segmentBlockLight = bl;
|
||||
segmentSkyLight = sl;
|
||||
segmentShading = shade;
|
||||
segmentLightingDirty = lightingDirty;
|
||||
segmentShadingDirty = shadeDirty;
|
||||
hasLighting = segmentBlockLight > 0 || segmentSkyLight > 0 || !segmentShading;
|
||||
}
|
||||
|
||||
segment.add(q);
|
||||
}
|
||||
|
||||
drawSegment(ri, mat, consumer, stack, segment, segmentBlockLight, segmentSkyLight, segmentShading, segmentLightingDirty && (hasLighting || segment.size() < allquads.size()), segmentShadingDirty);
|
||||
|
||||
// Clean up render state if necessary
|
||||
if (hasLighting)
|
||||
{
|
||||
RenderSystem.glMultiTexCoord2f(GL13.GL_TEXTURE1, GlStateManager.lastBrightnessX, GlStateManager.lastBrightnessY);
|
||||
RenderSystem.enableLighting();
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawSegment(ItemRenderer ir, MatrixStack mat, IVertexBuilder cons, ItemStack stack, List<BakedQuad> segment, int bl, int sl, boolean shade, boolean updateLighting, boolean updateShading)
|
||||
{
|
||||
float lastBl = GlStateManager.lastBrightnessX;
|
||||
float lastSl = GlStateManager.lastBrightnessY;
|
||||
|
||||
if (updateShading)
|
||||
{
|
||||
if (shade)
|
||||
{
|
||||
// (Re-)enable lighting for normal look with shading
|
||||
RenderSystem.enableLighting();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable lighting to simulate a lack of diffuse lighting
|
||||
RenderSystem.disableLighting();
|
||||
}
|
||||
}
|
||||
|
||||
if (updateLighting)
|
||||
{
|
||||
// Force lightmap coords to simulate synthetic lighting
|
||||
RenderSystem.glMultiTexCoord2f(GL13.GL_TEXTURE1, Math.max(bl, lastBl), Math.max(sl, lastSl));
|
||||
}
|
||||
|
||||
// TODO can we just use this light value ??
|
||||
ir.func_229112_a_(mat, cons, segment, stack, (bl << 16) | sl, OverlayTexture.field_229196_a_);
|
||||
|
||||
// Preserve this as it represents the "world" lighting
|
||||
GlStateManager.lastBrightnessX = lastBl;
|
||||
GlStateManager.lastBrightnessY = lastSl;
|
||||
|
||||
segment.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* internal, relies on fixed format of FaceBakery
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,8 @@ import net.minecraft.client.renderer.Vector4f;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -108,8 +110,9 @@ public interface IForgeVertexBuilder
|
||||
default int applyBakedLighting(int lightmapCoord, ByteBuffer data) {
|
||||
int bl = LightTexture.func_228450_a_(lightmapCoord);
|
||||
int sl = LightTexture.func_228454_b_(lightmapCoord);
|
||||
int blBaked = Short.toUnsignedInt(data.getShort(24)) >> 4;
|
||||
int slBaked = Short.toUnsignedInt(data.getShort(26)) >> 4;
|
||||
int offset = LightUtil.getLightOffset(0) * 4; // int offset for vertex 0 * 4 bytes per int
|
||||
int blBaked = Short.toUnsignedInt(data.getShort(offset)) >> 4;
|
||||
int slBaked = Short.toUnsignedInt(data.getShort(offset + 2)) >> 4;
|
||||
bl = Math.max(bl, blBaked);
|
||||
sl = Math.max(sl, slBaked);
|
||||
return LightTexture.func_228451_a_(bl, sl);
|
||||
|
||||
@@ -247,6 +247,20 @@ public class LightUtil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getLightOffset(int v)
|
||||
{
|
||||
return (v * 8) + 6;
|
||||
}
|
||||
|
||||
public static void setLightData(BakedQuad q, int light)
|
||||
{
|
||||
int[] data = q.getVertexData();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
data[getLightOffset(i)] = light;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ItemPipeline
|
||||
{
|
||||
|
||||
@@ -133,8 +133,6 @@ public class ForgeConfig
|
||||
|
||||
public final BooleanValue showLoadWarnings;
|
||||
|
||||
public final BooleanValue allowEmissiveItems;
|
||||
|
||||
Client(ForgeConfigSpec.Builder builder) {
|
||||
builder.comment("Client only settings, mostly things related to rendering")
|
||||
.push("client");
|
||||
@@ -176,11 +174,6 @@ public class ForgeConfig
|
||||
.translation("forge.configgui.showloadwarnings")
|
||||
.define("showLoadWarnings", true);
|
||||
|
||||
allowEmissiveItems = builder
|
||||
.comment("Allow item rendering to detect emissive quads and draw them properly. This allows glowing blocks to look the same in item form, but incurs a very slight performance hit.")
|
||||
.translation("forge.configgui.allowEmissiveItems")
|
||||
.define("allowEmissiveItems", true);
|
||||
|
||||
builder.pop();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user