Fixed MultiLayerModel not getting correct submodels; Unified the gui lighting of normal and custom models - diffuse lighting is now done in the pipeline, no need for IColoredBakedQuad anymore.

This commit is contained in:
RainWarrior committed 2016-03-17 07:29:44 +03:00
1 parent 0b0b5097e5
commit b8bb8c374c
18 files changed
+36 -128

No files matched your search

@@ -149,13 +149,7 @@ public class ForgeHooksClient
renderPass = pass;
}
static final ThreadLocal<BlockRenderLayer> renderLayer = new ThreadLocal<BlockRenderLayer>()
{
protected BlockRenderLayer initialValue()
{
return BlockRenderLayer.SOLID;
}
};
static final ThreadLocal<BlockRenderLayer> renderLayer = new ThreadLocal<BlockRenderLayer>();
public static void setRenderLayer(BlockRenderLayer layer)
{
@@ -525,13 +519,16 @@ public class ForgeHooksClient
public static void putQuadColor(VertexBuffer renderer, BakedQuad quad, int color)
{
float cr = color & 0xFF;
float cb = color & 0xFF;
float cg = (color >>> 8) & 0xFF;
float cb = (color >>> 16) & 0xFF;
float cr = (color >>> 16) & 0xFF;
float ca = (color >>> 24) & 0xFF;
VertexFormat format = quad.getFormat();
int size = format.getIntegerSize();
int offset = format.getColorOffset() / 4; // assumes that color is aligned
for(int i = 0; i < 4; i++)
{
int vc = quad.getVertexData()[3 + 7 * i];
int vc = quad.getVertexData()[offset + size * i];
float vcr = vc & 0xFF;
float vcg = (vc >>> 8) & 0xFF;
float vcb = (vc >>> 16) & 0xFF;
@@ -1,16 +0,0 @@
package net.minecraftforge.client.model;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.EnumFacing;
public interface IColoredBakedQuad {
public static class ColoredBakedQuad extends BakedQuad implements IColoredBakedQuad
{
public ColoredBakedQuad(int[] data, int tintIndex, EnumFacing side, TextureAtlasSprite sprite, VertexFormat format)
{
super(data, tintIndex, side, sprite, format);
}
}
}
@@ -206,7 +206,6 @@ public final class ItemTextureQuadConverter
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
builder.setQuadTint(-1);
builder.setQuadOrientation(side);
builder.setQuadColored();
if (side == EnumFacing.NORTH)
{
@@ -209,7 +209,6 @@ public final class ModelFluid implements IModelCustomData
EnumFacing side = gas ? EnumFacing.DOWN : EnumFacing.UP;
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
builder.setQuadOrientation(side);
builder.setQuadColored();
for(int i = gas ? 3 : 0; i != (gas ? -1 : 4); i+= (gas ? -1 : 1))
{
putVertex(
@@ -225,7 +224,6 @@ public final class ModelFluid implements IModelCustomData
side = side.getOpposite();
builder = new UnpackedBakedQuad.Builder(format);
builder.setQuadOrientation(side);
builder.setQuadColored();
for(int i = gas ? 3 : 0; i != (gas ? -1 : 4); i+= (gas ? -1 : 1))
{
putVertex(
@@ -247,7 +245,6 @@ public final class ModelFluid implements IModelCustomData
{
builder = new UnpackedBakedQuad.Builder(format);
builder.setQuadOrientation(side);
builder.setQuadColored();
for(int j = 0; j < 4; j++)
{
int l = (k * 3) + (1 - 2 * k) * j;
@@ -269,7 +266,6 @@ public final class ModelFluid implements IModelCustomData
// 1 quad for inventory
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
builder.setQuadOrientation(EnumFacing.UP);
builder.setQuadColored();
for(int i = 0; i < 4; i++)
{
putVertex(
@@ -299,11 +295,10 @@ public final class ModelFluid implements IModelCustomData
builder.put(e, data);
break;
case COLOR:
float d = LightUtil.diffuseLight(side);
builder.put(e,
d * ((color >> 16) & 0xFF) / 255f,
d * ((color >> 8) & 0xFF) / 255f,
d * (color & 0xFF) / 255f,
((color >> 16) & 0xFF) / 255f,
((color >> 8) & 0xFF) / 255f,
(color & 0xFF) / 255f,
((color >> 24) & 0xFF) / 255f);
break;
case UV: if(format.getElement(e).getIndex() == 0)
@@ -164,7 +164,7 @@ public final class MultiLayerModel implements IModelCustomData
{
return quads.get(Optional.fromNullable(side));
}
else if(!models.containsKey(layer))
else if(!models.containsKey(Optional.of(layer)))
{
model = missing;
}
@@ -172,6 +172,7 @@ public final class MultiLayerModel implements IModelCustomData
{
model = models.get(Optional.of(layer));
}
// assumes that child model will handle this state properly. FIXME?
return model.getQuads(state, side, rand);
}
@@ -717,7 +717,6 @@ public final class B3DLoader implements ICustomModelLoader
{
UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format);
quadBuilder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
quadBuilder.setQuadColored();
List<Texture> textures = null;
if(f.getBrush() != null) textures = f.getBrush().getTextures();
TextureAtlasSprite sprite;
@@ -744,14 +743,13 @@ public final class B3DLoader implements ICustomModelLoader
builder.put(e, v.getPos().x, v.getPos().y, v.getPos().z, 1);
break;
case COLOR:
float d = LightUtil.diffuseLight(faceNormal.x, faceNormal.y, faceNormal.z);
if(v.getColor() != null)
{
builder.put(e, d * v.getColor().x, d * v.getColor().y, d * v.getColor().z, v.getColor().w);
builder.put(e, v.getColor().x, v.getColor().y, v.getColor().z, v.getColor().w);
}
else
{
builder.put(e, d, d, d, 1);
builder.put(e, 1, 1, 1, 1);
}
break;
case UV:
@@ -1400,7 +1400,6 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
} else sprite = this.textures.get(f.getMaterialName());
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
builder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
builder.setQuadColored();
Normal faceNormal = f.getNormal();
putVertexData(builder, f.verts[0], faceNormal, TextureCoordinate.getDefaultUVs()[0], sprite);
putVertexData(builder, f.verts[1], faceNormal, TextureCoordinate.getDefaultUVs()[1], sprite);
@@ -1423,20 +1422,14 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
builder.put(e, v.getPos().x, v.getPos().y, v.getPos().z, v.getPos().w);
break;
case COLOR:
float d;
if (v.hasNormal())
d = LightUtil.diffuseLight(v.getNormal().x, v.getNormal().y, v.getNormal().z);
else
d = LightUtil.diffuseLight(faceNormal.x, faceNormal.y, faceNormal.z);
if (v.getMaterial() != null)
builder.put(e,
d * v.getMaterial().getColor().x,
d * v.getMaterial().getColor().y,
d * v.getMaterial().getColor().z,
v.getMaterial().getColor().x,
v.getMaterial().getColor().y,
v.getMaterial().getColor().z,
v.getMaterial().getColor().w);
else
builder.put(e, d, d, d, 1);
builder.put(e, 1, 1, 1, 1);
break;
case UV:
if (!v.hasTextureCoordinate())
@@ -17,7 +17,6 @@ public interface IVertexConsumer
void setQuadTint(int tint);
void setQuadOrientation(EnumFacing orientation);
void setQuadColored();
void put(int element, float... data);
}
@@ -8,7 +8,6 @@ import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.IColoredBakedQuad;
import org.apache.commons.lang3.tuple.Pair;
@@ -89,10 +88,6 @@ public class LightUtil
{
consumer.setQuadTint(quad.getTintIndex());
}
if(quad instanceof IColoredBakedQuad)
{
consumer.setQuadColored();
}
//int[] eMap = mapFormats(consumer.getVertexFormat(), DefaultVertexFormats.ITEM);
float[] data = new float[4];
VertexFormat formatFrom = consumer.getVertexFormat();
@@ -281,19 +276,11 @@ public class LightUtil
public static void renderQuadColor(VertexBuffer wr, BakedQuad quad, int auxColor)
{
wr.addVertexData(quad.getVertexData());
if(quad instanceof IColoredBakedQuad)
{
ForgeHooksClient.putQuadColor(wr, quad, auxColor);
}
else
{
wr.putColor4(auxColor);
}
ForgeHooksClient.putQuadColor(wr, quad, auxColor);
}
public static class ItemConsumer extends VertexTransformer
{
private boolean colored = false;
private int vertices = 0;
private float[] auxColor = new float[]{1, 1, 1, 1};
@@ -309,23 +296,14 @@ public class LightUtil
System.arraycopy(auxColor, 0, this.auxColor, 0, this.auxColor.length);
}
@Override
public void setQuadColored()
{
colored = true;
}
public void put(int element, float... data)
{
if(getVertexFormat().getElement(element).getUsage() == EnumUsage.COLOR)
{
System.arraycopy(auxColor, 0, buf, 0, buf.length);
if(colored)
for(int i = 0; i < 4; i++)
{
for(int i = 0; i < 4; i++)
{
buf[i] *= data[i];
}
buf[i] *= data[i];
}
super.put(element, buf);
}
@@ -339,7 +317,6 @@ public class LightUtil
if(vertices == 4)
{
vertices = 0;
colored = false;
}
}
}
@@ -4,7 +4,6 @@ import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.model.IColoredBakedQuad;
// advantages: non-fixed-length vertex format, no overhead of packing and unpacking attributes to transform the model
// disadvantages: (possibly) larger memory footprint, overhead on packing the attributes at the final rendering stage
@@ -48,10 +47,6 @@ public class UnpackedBakedQuad extends BakedQuad
consumer.setQuadTint(getTintIndex());
}
consumer.setQuadOrientation(getFace());
if(this instanceof IColoredBakedQuad)
{
consumer.setQuadColored();
}
for(int v = 0; v < 4; v++)
{
for(int e = 0; e < consumer.getVertexFormat().getElementCount(); e++)
@@ -68,14 +63,6 @@ public class UnpackedBakedQuad extends BakedQuad
}
}
public static class Colored extends UnpackedBakedQuad implements IColoredBakedQuad
{
public Colored(float[][][] unpackedData, int tint, EnumFacing orientation, TextureAtlasSprite texture, VertexFormat format)
{
super(unpackedData, tint, orientation, texture, format);
}
}
public static class Builder implements IVertexConsumer
{
private final VertexFormat format;
@@ -83,7 +70,6 @@ public class UnpackedBakedQuad extends BakedQuad
private int tint = -1;
private EnumFacing orientation;
private TextureAtlasSprite texture;
private boolean isColored = false;
private int vertices = 0;
private int elements = 0;
@@ -115,11 +101,6 @@ public class UnpackedBakedQuad extends BakedQuad
this.texture = texture;
}
public void setQuadColored()
{
this.isColored = true;
}
public void put(int element, float... data)
{
for(int i = 0; i < 4; i++)
@@ -151,10 +132,6 @@ public class UnpackedBakedQuad extends BakedQuad
{
throw new IllegalStateException("not enough data");
}
if(isColored)
{
return new Colored(unpackedData, tint, orientation, texture, format);
}
return new UnpackedBakedQuad(unpackedData, tint, orientation, texture, format);
}
}
@@ -57,5 +57,4 @@ public class VertexBufferConsumer implements IVertexConsumer
public void setQuadTint(int tint) {}
public void setQuadOrientation(EnumFacing orientation) {}
public void setQuadColored() {}
}
@@ -148,6 +148,11 @@ public class VertexLighterFlat extends QuadGatheringTransformer
if(skyLight > lightmap[v][1]) lightmap[v][1] = skyLight;
}
updateColor(normal[v], color[v], x, y, z, tint, multiplier);
float diffuse = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
for(int i = 0; i < 3; i++)
{
color[v][i] *= diffuse;
}
if(EntityRenderer.anaglyphEnable)
{
applyAnaglyph(color[v]);
@@ -234,7 +239,6 @@ public class VertexLighterFlat extends QuadGatheringTransformer
}
public void setQuadOrientation(EnumFacing orientation) {}
public void setQuadCulled() {}
public void setQuadColored() {}
public void setWorld(IBlockAccess world)
{
@@ -27,11 +27,6 @@ public class VertexTransformer implements IVertexConsumer
parent.setQuadOrientation(orientation);
}
public void setQuadColored()
{
parent.setQuadColored();
}
public void put(int element, float... data)
{
parent.put(element, data);