RenderHooks.java 文件源码

java
阅读 18 收藏 0 点赞 0 评论 0

项目:CCTweaks 作者:
private static void renderQuad(BakedQuad quad, IBlockAccess world, IBlockState state, BlockPos pos, VertexBuffer buffer, long rand, boolean useAO) {
    AOLightMatrix matrix = new AOLightMatrix();
    matrix.locate(world, pos, useAO);
    CCQuad ccQuad = new CCQuad(quad);
    ccQuad.quadulate();
    ccQuad.computeNormals();
    VertexFormat format = buffer.getVertexFormat();
    BlockColors colours = Minecraft.getMinecraft().getBlockColors();
    LightModel lightModel = quad.shouldApplyDiffuseLighting() ? standardLightModel : noDifuseLightModel;
    int quadTintRenderPass = quad.getTintIndex();
    int tintMultiplier = -1;
    if (quadTintRenderPass != -1) {
        tintMultiplier = colours.colorMultiplier(state, world, pos, quadTintRenderPass);
    }
    for (int v = 0; v < 4; v++) {
        Vertex5 vert = ccQuad.vertices[v].copy();
        Vector3 normal = ccQuad.normals[v].copy();
        Colour colour = ccQuad.colours[v].copy().multiply(new ColourRGBA(lightModel.apply(tintMultiplier, normal)));
        LC lc = new LC();
        lc.compute(vert.vec, normal);
        TripleABC<Integer, Integer, ?> lm = matrix.apply(lc, colour);
        int finalColour = lm.getA();
        int brightness = lm.getB();
        for (int e = 0; e < format.getElementCount(); e++) {
            VertexFormatElement element = format.getElement(e);
            switch (element.getUsage()){
                case POSITION:
                    buffer.pos(vert.vec.x, vert.vec.y, vert.vec.z);
                    break;
                case UV:
                    if (element.getIndex() == 0) {
                        buffer.tex(vert.uv.u, vert.uv.v);
                    } else {
                        buffer.lightmap(brightness >> 16 & 65535, brightness & 65535);
                    }
                    break;
                case COLOR:
                    buffer.color(finalColour >>> 24, finalColour >> 16 & 0xFF, finalColour >> 8 & 0xFF, finalColour & 0xFF);
                    break;
                case NORMAL:
                    buffer.normal((float) normal.x, (float) normal.y, (float) normal.z);
                    break;
                case PADDING:
                    break;
                default:
                    throw new UnsupportedOperationException("Generic vertex format element");
            }
        }
        buffer.endVertex();
    }
    buffer.putPosition(pos.getX(), pos.getY(), pos.getZ());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号