Search in sources :

Example 1 with VertexFormat

use of com.mojang.blaze3d.vertex.VertexFormat in project MinecraftForge by MinecraftForge.

the class VertexLighterFlat method processQuad.

@Override
protected void processQuad() {
    float[][] position = quadData[posIndex];
    float[][] normal = null;
    float[][] lightmap = quadData[lightmapIndex];
    float[][] color = quadData[colorIndex];
    if (dataLength[normalIndex] >= 3 && (quadData[normalIndex][0][0] != 0 || quadData[normalIndex][0][1] != 0 || quadData[normalIndex][0][2] != 0)) {
        normal = quadData[normalIndex];
    } else // normals must be generated
    {
        normal = new float[4][4];
        Vector3f v1 = new Vector3f(position[3]);
        Vector3f t = new Vector3f(position[1]);
        Vector3f v2 = new Vector3f(position[2]);
        v1.sub(t);
        t.set(position[0]);
        v2.sub(t);
        v2.cross(v1);
        v2.normalize();
        for (int v = 0; v < 4; v++) {
            normal[v][0] = v2.x();
            normal[v][1] = v2.y();
            normal[v][2] = v2.z();
            normal[v][3] = 0;
        }
    }
    int multiplier = -1;
    if (tint != -1) {
        multiplier = blockInfo.getColorMultiplier(tint);
    }
    VertexFormat format = parent.getVertexFormat();
    int count = format.getElements().size();
    for (int v = 0; v < 4; v++) {
        float x = position[v][0] - .5f;
        float y = position[v][1] - .5f;
        float z = position[v][2] - .5f;
        // if(blockInfo.getState().getBlock().isFullCube(blockInfo.getState()))
        {
            x += normal[v][0] * .5f;
            y += normal[v][1] * .5f;
            z += normal[v][2] * .5f;
        }
        float blockLight = lightmap[v][0] * LIGHTMAP_RESCALE, skyLight = lightmap[v][1] * LIGHTMAP_RESCALE;
        updateLightmap(normal[v], lightmap[v], x, y, z);
        if (dataLength[lightmapIndex] > 1) {
            if (blockLight > lightmap[v][0])
                lightmap[v][0] = blockLight;
            if (skyLight > lightmap[v][1])
                lightmap[v][1] = skyLight;
        }
        updateColor(normal[v], color[v], x, y, z, tint, multiplier);
        if (diffuse) {
            float d = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
            for (int i = 0; i < 3; i++) {
                color[v][i] *= d;
            }
        }
        // no need for remapping cause all we could've done is add 1 element to the end
        for (int e = 0; e < count; e++) {
            VertexFormatElement element = format.getElements().get(e);
            switch(element.getUsage()) {
                case POSITION:
                    final Vector4f pos = new Vector4f(position[v][0], position[v][1], position[v][2], 1);
                    pos.transform(pose.pose());
                    position[v][0] = pos.x();
                    position[v][1] = pos.y();
                    position[v][2] = pos.z();
                    parent.put(e, position[v]);
                    break;
                case NORMAL:
                    final Vector3f norm = new Vector3f(normal[v]);
                    norm.transform(pose.normal());
                    normal[v][0] = norm.x();
                    normal[v][1] = norm.y();
                    normal[v][2] = norm.z();
                    parent.put(e, normal[v]);
                    break;
                case COLOR:
                    parent.put(e, color[v]);
                    break;
                case UV:
                    if (element.getIndex() == 2) {
                        parent.put(e, lightmap[v]);
                        break;
                    }
                // else fallthrough to default
                default:
                    parent.put(e, quadData[e][v]);
            }
        }
    }
    tint = -1;
}
Also used : Vector4f(com.mojang.math.Vector4f) Vector3f(com.mojang.math.Vector3f) VertexFormatElement(com.mojang.blaze3d.vertex.VertexFormatElement) DefaultVertexFormat(com.mojang.blaze3d.vertex.DefaultVertexFormat) VertexFormat(com.mojang.blaze3d.vertex.VertexFormat)

Example 2 with VertexFormat

use of com.mojang.blaze3d.vertex.VertexFormat in project MinecraftForge by MinecraftForge.

the class LightUtil method putBakedQuad.

public static void putBakedQuad(IVertexConsumer consumer, BakedQuad quad) {
    consumer.setTexture(quad.getSprite());
    consumer.setQuadOrientation(quad.getDirection());
    if (quad.isTinted()) {
        consumer.setQuadTint(quad.getTintIndex());
    }
    consumer.setApplyDiffuseLighting(quad.isShade());
    float[] data = new float[4];
    VertexFormat formatFrom = consumer.getVertexFormat();
    VertexFormat formatTo = DefaultVertexFormat.BLOCK;
    int countFrom = formatFrom.getElements().size();
    int countTo = formatTo.getElements().size();
    int[] eMap = mapFormats(formatFrom, formatTo);
    for (int v = 0; v < 4; v++) {
        for (int e = 0; e < countFrom; e++) {
            if (eMap[e] != countTo) {
                unpack(quad.getVertices(), data, formatTo, v, eMap[e]);
                consumer.put(e, data);
            } else {
                consumer.put(e);
            }
        }
    }
}
Also used : DefaultVertexFormat(com.mojang.blaze3d.vertex.DefaultVertexFormat) VertexFormat(com.mojang.blaze3d.vertex.VertexFormat)

Example 3 with VertexFormat

use of com.mojang.blaze3d.vertex.VertexFormat in project MinecraftForge by MinecraftForge.

the class ItemTextureQuadConverter method putVertex.

private static void putVertex(IVertexConsumer consumer, Direction side, float x, float y, float z, float u, float v, int color, int luminosity) {
    VertexFormat format = consumer.getVertexFormat();
    for (int e = 0; e < format.getElements().size(); e++) {
        VertexFormatElement element = format.getElements().get(e);
        switch(element.getUsage()) {
            case POSITION:
                consumer.put(e, x, y, z, 1f);
                break;
            case COLOR:
                // red
                float r = ((color >> 16) & 0xFF) / 255f;
                // green
                float g = ((color >> 8) & 0xFF) / 255f;
                // blue
                float b = ((color >> 0) & 0xFF) / 255f;
                // alpha
                float a = ((color >> 24) & 0xFF) / 255f;
                consumer.put(e, r, g, b, a);
                break;
            case NORMAL:
                float offX = (float) side.getStepX();
                float offY = (float) side.getStepY();
                float offZ = (float) side.getStepZ();
                consumer.put(e, offX, offY, offZ, 0f);
                break;
            case UV:
                if (element.getIndex() == 0) {
                    consumer.put(e, u, v, 0f, 1f);
                    break;
                } else if (element.getIndex() == 2) {
                    consumer.put(e, (luminosity << 4) / 32768.0f, (luminosity << 4) / 32768.0f, 0f, 1f);
                    break;
                }
            // else fallthrough to default
            default:
                consumer.put(e);
                break;
        }
    }
}
Also used : VertexFormatElement(com.mojang.blaze3d.vertex.VertexFormatElement) VertexFormat(com.mojang.blaze3d.vertex.VertexFormat)

Aggregations

VertexFormat (com.mojang.blaze3d.vertex.VertexFormat)3 DefaultVertexFormat (com.mojang.blaze3d.vertex.DefaultVertexFormat)2 VertexFormatElement (com.mojang.blaze3d.vertex.VertexFormatElement)2 Vector3f (com.mojang.math.Vector3f)1 Vector4f (com.mojang.math.Vector4f)1