Java 类net.minecraftforge.client.model.pipeline.LightUtil 实例源码

项目:DankNull    文件:RenderModel.java   
public static void renderQuads(VertexBuffer renderer, List<BakedQuad> quads, int color, ItemStack stack) {
    boolean flag = (color == -1) && (!stack.isEmpty());
    int i = 0;
    for (int j = quads.size(); i < j; i++) {
        BakedQuad bakedquad = quads.get(i);
        int k = color;
        if ((flag) && (bakedquad.hasTintIndex())) {
            ItemColors itemColors = Minecraft.getMinecraft().getItemColors();
            k = itemColors.getColorFromItemstack(stack, bakedquad.getTintIndex());
            if (EntityRenderer.anaglyphEnable) {
                k = TextureUtil.anaglyphColor(k);
            }
            k |= 0xFF000000;
        }
        LightUtil.renderQuadColor(renderer, bakedquad, k);
    }
}
项目:BrokkGUI    文件:GuiRenderItemHelper.java   
private void renderQuads(BufferBuilder renderer, List<BakedQuad> quads, int color, ItemStack stack)
{
    boolean flag = color == -1 && !stack.isEmpty();
    int i = 0;

    for (int j = quads.size(); i < j; ++i)
    {
        BakedQuad bakedquad = quads.get(i);
        int k = color;

        if (flag && bakedquad.hasTintIndex())
        {
            k = this.mc.getItemColors().getColorFromItemstack(stack, bakedquad.getTintIndex());

            if (EntityRenderer.anaglyphEnable)
                k = TextureUtil.anaglyphColor(k);
            k = k | -16777216;
        }
        LightUtil.renderQuadColor(renderer, bakedquad, k);
    }
}
项目:TombManyGraves    文件:ModelHelper.java   
public static void renderModel(IBakedModel model, int color)
    {
        Tessellator tessellator = Tessellator.getInstance();
        VertexBuffer buffer = tessellator.getBuffer();
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
//        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
//        GlStateManager.disableLighting();

        List<BakedQuad> quads = model.getQuads(null,null,0);

        for (BakedQuad quad : quads)
        {
            LightUtil.renderQuadColor(buffer, quad, color);
        }

        tessellator.draw();
    }
项目:CodeChickenLib    文件:VertexDataUtils.java   
public static List<BakedQuad> shadeQuadFaces(List<BakedQuad> quads) {
    LinkedList<BakedQuad> shadedQuads = new LinkedList<>();
    for (BakedQuad quad : quads) {
        int[] rawData = quad.getVertexData();
        for (int v = 0; v < 4; v++) {
            for (int e = 0; e < quad.getFormat().getElementCount(); e++) {
                VertexFormatElement element = quad.getFormat().getElement(e);
                if (element.getUsage() == EnumUsage.COLOR) {
                    float[] data = new float[4];
                    LightUtil.unpack(rawData, data, quad.getFormat(), v, e);

                    data = diffuseFaceLight(quad.getFace(), data);

                    LightUtil.pack(data, rawData, quad.getFormat(), v, e);
                }
            }
        }
        shadedQuads.add(new BakedQuad(rawData, quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting(), quad.getFormat()));
    }

    return shadedQuads;
}
项目:InfinityLib    文件:TessellatorAbstractBase.java   
public final UnpackedBakedQuad transformQuad(BakedQuad quad) {
    // Fetch required information
    final VertexFormat format = quad.getFormat();
    final float[][][] vertexData = new float[4][format.getElementCount()][4];

    // Objects to be reused in the loop
    final Vector4f temp = new Vector4f();

    //unpack and transform vertex data
    for (int v = 0; v < 4; v++) {
        for (int e = 0; e < format.getElementCount(); e++) {
            LightUtil.unpack(quad.getVertexData(), vertexData[v][e], format, v, e);
            transformUnpackedVertexDataElement(format.getElement(e).getUsage(), vertexData[v][e], temp);
        }
    }
    //create new quad with the transformed vertex data
    return new UnpackedBakedQuad(vertexData, quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting(), format);
}
项目:EnderIO    文件:HalfBakedQuad.java   
private void putVertexData(@Nonnull Builder builder, @Nonnull Vertex v, float w) {
  VertexFormat format = builder.getVertexFormat();
  for (int e = 0; e < format.getElementCount(); e++) {
    switch (format.getElement(e).getUsage()) {
    case POSITION:
      builder.put(e, (float) v.x(), (float) v.y(), (float) v.z(), 1);
      break;
    case COLOR:
      float d = LightUtil.diffuseLight(v.nx(), v.ny(), v.nz());
      builder.put(e, d * color.x, d * color.y, d * color.z, color.w);
      break;
    case UV:
      builder.put(e, tex.getInterpolatedU(v.u() * 16) * w, tex.getInterpolatedV(v.v() * 16) * w, 0, w);
      break;
    case NORMAL:
      builder.put(e, v.nx(), v.ny(), v.nz(), 0);
      break;
    default:
      builder.put(e);
    }
  }
}
项目:genera    文件:ModelHandle.java   
private static void renderModel(IBakedModel model, VertexFormat fmt, int color)
{
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    worldrenderer.begin(GL11.GL_QUADS, fmt);
    for (BakedQuad bakedquad : model.getQuads(null, null, 0))
    {
        LightUtil.renderQuadColor(worldrenderer, bakedquad, color);
    }
    tessellator.draw();
}
项目:placementpreview    文件:RenderEventHandler.java   
private void renderQuads(final World world, final IBlockState actualState, final BlockPos pos, final List<BakedQuad> quads, final int alpha)
{
    final Tessellator tessellator = Tessellator.getInstance();
    final BufferBuilder buffer = tessellator.getBuffer();

    for (final BakedQuad quad : quads)
    {
        buffer.begin(GL11.GL_QUADS, quad.getFormat());

        final int color = quad.hasTintIndex() ? this.getTint(world, actualState, pos, alpha, quad.getTintIndex()) : alpha | 0xffffff;
        LightUtil.renderQuadColor(buffer, quad, color);

        tessellator.draw();
    }
}
项目:Qbar    文件:ModelTransformer.java   
private static BakedQuad transform(final BakedQuad quad, final IVertexTransformer transformer)
{
    final VertexFormat format = quad.getFormat();
    final UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
    LightUtil.putBakedQuad(new VertexTransformerWrapper(builder, quad, transformer), quad);
    return builder.build();
}
项目:Qbar    文件:RenderUtil.java   
private static final void renderQuads(final List<BakedQuad> quads, final int alpha)
{
    final Tessellator tessellator = Tessellator.getInstance();
    final BufferBuilder buffer = tessellator.getBuffer();

    if (quads == null || quads.isEmpty())
        return;
    buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
    quads.forEach(quad -> LightUtil.renderQuadColor(buffer, quad, alpha | 0xffffff));
    tessellator.draw();
}
项目:CodeChickenLib    文件:AbstractBakedPropertiesModel.java   
protected boolean checkDepth(BakedQuad quad, Vector3 hit, EnumFacing hitFace) {
    int[] quadData = quad.getVertexData();
    VertexFormat format = quad.getFormat();
    int e = VertexDataUtils.getPositionElement(format);

    Vector3 posVec = new Vector3();
    float[] pos = new float[4];
    for (int v = 0; v < 4; v++) {
        LightUtil.unpack(quadData, pos, format, v, e);
        posVec.add(pos[0], pos[1], pos[2]);
    }
    posVec.divide(4);

    double diff = 0;
    switch (hitFace.getAxis()) {
        case X:
            diff = Math.abs(hit.x - posVec.x);
            break;
        case Y:
            diff = Math.abs(hit.y - posVec.y);
            break;
        case Z:
            diff = Math.abs(hit.z - posVec.z);
            break;
    }
    return !(diff > 0.01);
}
项目:CodeChickenLib    文件:VertexDataUtils.java   
public static void fullyPackQuads(int[] packedData, float[][][] unpackedData, VertexFormat format) {
    for (int e = 0; e < format.getElementCount(); e++) {
        for (int v = 0; v < 4; v++) {
            LightUtil.pack(unpackedData[v][e], packedData, format, v, e);
        }
    }
}
项目:CodeChickenLib    文件:VertexDataUtils.java   
public static void fullyUnPackQuads(int[] packedData, float[][][] unpackedData, VertexFormat format) {
    for (int e = 0; e < format.getElementCount(); e++) {
        for (int v = 0; v < 4; v++) {
            LightUtil.unpack(packedData, unpackedData[v][e], format, v, e);
        }
    }
}
项目:TechStack-s-HeavyMachineryMod    文件:MachineModModelHelper.java   
public static void renderBakedModel(IBakedModel bakedModel) {
    Tessellator tessellator = Tessellator.getInstance();

    BufferBuilder worldrenderer = tessellator.getBuffer();
    // VertexFormat VF = new VertexFormat();
    // worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);// bakedModel.getFormat());
    // OPTION A
    BakedQuad bakedQuad1 = (BakedQuad) bakedModel.getQuads(null, null, 0).get(0);

    // DARK no normal :( due to baked quad not having it worldrenderer.begin(GL11.GL_QUADS, MYFORMAT);// bakedModel.getFormat());
    worldrenderer.begin(GL11.GL_QUADS, bakedQuad1.getFormat());

    // for (BakedQuad bakedQuad : bakedModel.getQuads(null, null, 0)) {
    // worldrenderer.addVertexData(bakedQuad.getVertexData());
    //
    // }
    // alt version if ever needed

    for (BakedQuad bakedQuad : bakedModel.getQuads(null, null, 0)) {
        int j = -1;
        j = j | -16777216;
        LightUtil.renderQuadColor(worldrenderer, bakedQuad, j);

    }

    tessellator.draw();
}
项目:Hard-Science    文件:QuadContainer.java   
private int computeOcclusionHash(EnumFacing face)
{
    List<BakedQuad> quads = getQuads(face);
    QuadListKeyBuilder keyBuilder = new QuadListKeyBuilder(face);
    for(BakedQuad q : quads)
    {
        LightUtil.putBakedQuad(keyBuilder, q);
    }
    return keyBuilder.getQuadListKey();
}
项目:enderutilities    文件:BuildersWandRenderer.java   
private void renderQuads(final IBlockState state, final BlockPos pos, final BufferBuilder buffer, final List<BakedQuad> quads, final int alpha)
{
    final int size = quads.size();

    for (int i = 0; i < size; i++)
    {
        final BakedQuad quad = quads.get(i);
        final int color = quad.getTintIndex() == -1 ? alpha | 0xffffff : this.getTint(state, pos, alpha, quad.getTintIndex());
        LightUtil.renderQuadColor(buffer, quad, color);
    }
}
项目:Extra-Food    文件:OBJRender.java   
public static void renderModel(IBakedModel model, int color)
{
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer worldrenderer = tessellator.getBuffer();
    worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);
    for (BakedQuad bakedquad : model.getQuads(null, null, 0))
    {
        LightUtil.renderQuadColor(worldrenderer, bakedquad, color);
    }
    tessellator.draw();
}
项目:CodeChickenLib    文件:BakingVertexBuffer.java   
/**
 * Bakes the data inside the VertexBuffer to a baked quad.
 *
 * @return The list of quads baked.
 */
public List<BakedQuad> bake() {
    if (isDrawing) {
        CCLLog.log(Level.WARN, new IllegalStateException("Bake called before finishDrawing!"), "Someone is calling bake before finishDrawing!");
        finishDrawing();
    }
    State state = getVertexState();
    VertexFormat format = state.getVertexFormat();
    if (!format.hasUvOffset(0)) {
        throw new IllegalStateException("Unable to bake format that does not have UV mappings!");
    }
    int[] rawBuffer = Arrays.copyOf(state.getRawBuffer(), state.getRawBuffer().length);

    List<BakedQuad> quads = new LinkedList<>();
    TextureAtlasSprite sprite = TextureUtils.getMissingSprite();

    int curr = 0;
    int next = format.getNextOffset();
    int i = 0;
    while (rawBuffer.length >= next) {
        int[] quadData = Arrays.copyOfRange(rawBuffer, curr, next);
        Vector3 normal = new Vector3();
        if (format.hasNormal()) {
            //Grab first normal.
            float[] normalData = new float[4];
            LightUtil.unpack(quadData, normalData, format, 0, VertexDataUtils.getNormalElement(format));
            normal = Vector3.fromArray(normalData);
        } else {
            //No normal provided in format, so we calculate.
            float[][] posData = new float[4][4];
            for (int v = 0; v < 4; v++) {
                LightUtil.unpack(quadData, posData[v], format, v, VertexDataUtils.getPositionElement(format));
            }
            normal.set(VectorUtils.calculateNormal(Vector3.fromArray(posData[0]), Vector3.fromArray(posData[1]), Vector3.fromArray(posData[3])));
        }
        if (useSprites) {
            //Attempt to get sprite for vertex.
            if (spriteMap.containsKey(i)) {
                //Use provided sprite for vertex.
                sprite = spriteMap.get(i);
            } else {
                //Sprite not found for vertex, so we attempt to calculate the sprite.
                float[] uvData = new float[4];
                LightUtil.unpack(quadData, uvData, format, 0, VertexDataUtils.getUVElement(format));
                UV uv = new UV(uvData[0], uvData[1]);
                sprite = VertexDataUtils.getSpriteForUV(TextureUtils.getTextureMap(), uv);
            }
        }
        //Use normal to calculate facing.
        EnumFacing facing = VectorUtils.calcNormalSide(normal);
        if (facing == null) {
            facing = EnumFacing.UP;
        }
        BakedQuad quad = new BakedQuad(quadData, -1, facing, sprite, useDiffuseLighting, format);
        quads.add(quad);
        curr = next;
        next += format.getNextOffset();
        i++;
    }
    return ImmutableList.copyOf(quads);
}
项目:ExNihiloAdscensio    文件:RenderInfestedLeaves.java   
@Override
public void renderTileEntityAt(TileInfestedLeaves tile, double x, double y, double z, float partialTicks, int destroyStage)
{
    if(tile != null)
    {
        long seed = tile.getWorld().rand.nextLong();
        int color = tile.getColor();

        IBlockState leafBlock = tile.getLeafBlock();
        IBakedModel leafModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(leafBlock);

        if(leafModel == null)
        {
            leafModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(Blocks.LEAVES.getDefaultState());
        }

        List<BakedQuad> leafQuads = Lists.newArrayList();

        for(EnumFacing side : EnumFacing.VALUES)
        {
            if(leafBlock.shouldSideBeRendered(tile.getWorld(), tile.getPos(), side))
            {
                leafQuads.addAll(leafModel.getQuads(leafBlock, side, seed));
            }
        }

        Tessellator tessellator = Tessellator.getInstance();
        VertexBuffer buffer = tessellator.getBuffer();

        bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

        GlStateManager.pushMatrix();
        GlStateManager.translate(x, y, z);
        RenderHelper.disableStandardItemLighting();

        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);

        for(BakedQuad quad : leafQuads)
        {
            LightUtil.renderQuadColor(buffer, quad, color);
        }

        tessellator.draw();

        RenderHelper.enableStandardItemLighting();
        GlStateManager.popMatrix();
    }
}
项目:Hard-Science    文件:QuadPainter.java   
private void recolorQuad(RawQuad result)
{
    int color = this.myColorMap.getColor(this.isFullBrightnessIntended ? EnumColorMap.LAMP : EnumColorMap.BASE);

    if(this.renderPass.blockRenderLayer == BlockRenderLayer.TRANSLUCENT)
    {
        color = this.translucencyArgb | (color & 0x00FFFFFF);
    }

    if(this.isFullBrightnessIntended)
    {
        // If the surface has a lamp gradient or is otherwise pre-shaded 
        // we don't want to see a gradient when rendering at full brightness
        // so make all vertices white before we recolor.
        result.replaceColor(color);
    }

    else if(result.surfaceInstance.isLampGradient && this.lampColorMap != null)
    {
        // if surface has a lamp gradient and rendered with shading, need
        // to replace the colors to form the gradient.
        int shadedColor = QuadHelper.shadeColor(color, (LightUtil.diffuseLight(result.getNormalFace()) + 2) / 3, false);
        int lampColor = this.lampColorMap.getColor(EnumColorMap.LAMP);
        for(int i = 0; i < result.getVertexCount(); i++)
        {
            Vertex v = result.getVertex(i);
            if(v != null)
            {
                int vColor = v.color == Color.WHITE ? lampColor : shadedColor;
                result.setVertex(i, v.withColor(vColor));
            }
        }

        // if needed, change render pass of gradient surface to flat so that it doesn't get darkened by AO
        if(!this.lampRenderPass.isShaded && this.renderPass.isShaded)
        {
            result.renderPass = this.renderPass.flipShading();
        }
    }
    else
    {
        // normal shaded surface - tint existing colors, usually WHITE to start with
        result.multiplyColor(color);
    }
}
项目:OpenBlocks    文件:TileEntityTrophyRenderer.java   
private static void renderQuads(BufferBuilder wr, List<BakedQuad> quads) {
    for (BakedQuad quad : quads)
        LightUtil.renderQuadColor(wr, quad, 0xFFFFFFFF);
}
项目:EnderIO    文件:EnchanterModelRenderer.java   
private void renderQuads(VertexBuffer renderer, List<BakedQuad> quads) {
  for (BakedQuad quad : quads) {
    LightUtil.renderQuadColor(renderer, quad, -1);
  }
}