Search in sources :

Example 16 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project Indium by comp500.

the class QuadViewImpl method copyPos.

@Override
public Vector3f copyPos(int vertexIndex, Vector3f target) {
    if (target == null) {
        target = new Vector3f();
    }
    final int index = baseIndex + vertexIndex * VERTEX_STRIDE + VERTEX_X;
    target.set(Float.intBitsToFloat(data[index]), Float.intBitsToFloat(data[index + 1]), Float.intBitsToFloat(data[index + 2]));
    return target;
}
Also used : Vector3f(net.minecraft.client.util.math.Vector3f)

Example 17 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project Indium by comp500.

the class QuadViewImpl method copyNormal.

@Override
public Vector3f copyNormal(int vertexIndex, Vector3f target) {
    if (hasNormal(vertexIndex)) {
        if (target == null) {
            target = new Vector3f();
        }
        final int normal = data[normalIndex(vertexIndex)];
        target.set(NormalHelper.getPackedNormalComponent(normal, 0), NormalHelper.getPackedNormalComponent(normal, 1), NormalHelper.getPackedNormalComponent(normal, 2));
        return target;
    } else {
        return null;
    }
}
Also used : Vector3f(net.minecraft.client.util.math.Vector3f)

Example 18 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project Indium by comp500.

the class AoCalculator method irregularFace.

private void irregularFace(MutableQuadViewImpl quad) {
    final Vector3f faceNorm = quad.faceNormal();
    Vector3f normal;
    final float[] w = this.w;
    final float[] aoResult = this.ao;
    final int[] lightResult = this.light;
    for (int i = 0; i < 4; i++) {
        normal = quad.hasNormal(i) ? quad.copyNormal(i, vertexNormal) : faceNorm;
        float ao = 0, sky = 0, block = 0, maxAo = 0;
        int maxSky = 0, maxBlock = 0;
        final float x = normal.getX();
        if (!MathHelper.approximatelyEquals(0f, x)) {
            final Direction face = x > 0 ? Direction.EAST : Direction.WEST;
            final AoFaceData fd = gatherInsetFace(quad, i, face);
            AoFace.get(face).weightFunc.apply(quad, i, w);
            final float n = x * x;
            final float a = fd.weigtedAo(w);
            final int s = fd.weigtedSkyLight(w);
            final int b = fd.weigtedBlockLight(w);
            ao += n * a;
            sky += n * s;
            block += n * b;
            maxAo = a;
            maxSky = s;
            maxBlock = b;
        }
        final float y = normal.getY();
        if (!MathHelper.approximatelyEquals(0f, y)) {
            final Direction face = y > 0 ? Direction.UP : Direction.DOWN;
            final AoFaceData fd = gatherInsetFace(quad, i, face);
            AoFace.get(face).weightFunc.apply(quad, i, w);
            final float n = y * y;
            final float a = fd.weigtedAo(w);
            final int s = fd.weigtedSkyLight(w);
            final int b = fd.weigtedBlockLight(w);
            ao += n * a;
            sky += n * s;
            block += n * b;
            maxAo = Math.max(maxAo, a);
            maxSky = Math.max(maxSky, s);
            maxBlock = Math.max(maxBlock, b);
        }
        final float z = normal.getZ();
        if (!MathHelper.approximatelyEquals(0f, z)) {
            final Direction face = z > 0 ? Direction.SOUTH : Direction.NORTH;
            final AoFaceData fd = gatherInsetFace(quad, i, face);
            AoFace.get(face).weightFunc.apply(quad, i, w);
            final float n = z * z;
            final float a = fd.weigtedAo(w);
            final int s = fd.weigtedSkyLight(w);
            final int b = fd.weigtedBlockLight(w);
            ao += n * a;
            sky += n * s;
            block += n * b;
            maxAo = Math.max(maxAo, a);
            maxSky = Math.max(maxSky, s);
            maxBlock = Math.max(maxBlock, b);
        }
        aoResult[i] = (ao + maxAo) * 0.5f;
        lightResult[i] = (((int) ((sky + maxSky) * 0.5f) & 0xF0) << 16) | ((int) ((block + maxBlock) * 0.5f) & 0xF0);
    }
}
Also used : Vector3f(net.minecraft.client.util.math.Vector3f) Direction(net.minecraft.util.math.Direction)

Example 19 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project sodium-fabric by CaffeineMC.

the class MixinRebuildTask method render.

/**
 * @author JellySquid
 */
@Overwrite
private Set<BlockEntity> render(float cameraX, float cameraY, float cameraZ, ChunkBuilder.ChunkData data, BlockBufferBuilderStorage buffers) {
    ExtendedChunkData edata = (ExtendedChunkData) data;
    BlockPos from = this.parent.getOrigin().toImmutable();
    BlockPos to = from.add(15, 15, 15);
    ChunkOcclusionDataBuilder occlusion = new ChunkOcclusionDataBuilder();
    Set<BlockEntity> set = Sets.newHashSet();
    ChunkRendererRegion world = this.region;
    Vector3f translation = new Vector3f();
    if (world != null) {
        BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
        int minX = from.getX();
        int minY = from.getY();
        int minZ = from.getZ();
        int maxX = to.getX();
        int maxY = to.getY();
        int maxZ = to.getZ();
        BlockPos.Mutable pos = new BlockPos.Mutable();
        for (int z = minZ; z <= maxZ; z++) {
            for (int y = minY; y <= maxY; y++) {
                for (int x = minX; x <= maxX; x++) {
                    pos.set(x, y, z);
                    BlockState blockState = world.getBlockState(pos);
                    FluidState fluidState = blockState.getFluidState();
                    Block block = blockState.getBlock();
                    if (blockState.isFullOpaque(world, pos)) {
                        occlusion.markClosed(pos);
                    }
                    if (block.hasBlockEntity()) {
                        BlockEntity entity = world.getBlockEntity(pos, WorldChunk.CreationType.CHECK);
                        if (entity != null) {
                            this.addBlockEntity(data, set, entity);
                        }
                    }
                    if (!fluidState.isEmpty()) {
                        RenderLayer layer = RenderLayers.getFluidLayer(fluidState);
                        BufferBuilder builder = buffers.get(layer);
                        if (!builder.isBuilding()) {
                            builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                            edata.getInitializedLayers().add(layer);
                        }
                        blockRenderManager.renderFluid(pos, world, builder, fluidState);
                    }
                    if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
                        RenderLayer layer = RenderLayers.getBlockLayer(blockState);
                        BufferBuilder builder = buffers.get(layer);
                        if (!builder.isBuilding()) {
                            builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                            edata.getInitializedLayers().add(layer);
                        }
                        translation.set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15);
                        this.pipeline.renderBlock(blockState, pos, world, translation, builder, true);
                    }
                }
            }
        }
        for (RenderLayer layer : edata.getInitializedLayers()) {
            BufferBuilder builder = buffers.get(layer);
            if (layer == RenderLayer.getTranslucent()) {
                builder.sortQuads(cameraX - (float) from.getX(), cameraY - (float) from.getY(), cameraZ - (float) from.getZ());
                edata.setTranslucentBufferState(builder.popState());
            }
            builder.end();
            if (((ChunkMeshBuilder) builder).isEmpty()) {
                continue;
            }
            edata.getNonEmptyLayers().add(layer);
        }
        if (edata.getNonEmptyLayers().size() > 0) {
            edata.markNonEmpty();
        }
    }
    edata.setOcclusionData(occlusion.build());
    this.region = null;
    this.pipeline = null;
    return set;
}
Also used : ChunkRendererRegion(net.minecraft.client.render.chunk.ChunkRendererRegion) BufferBuilder(net.minecraft.client.render.BufferBuilder) RenderLayer(net.minecraft.client.render.RenderLayer) ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) BlockState(net.minecraft.block.BlockState) ChunkMeshBuilder(me.jellysquid.mods.sodium.client.render.mesh.ChunkMeshBuilder) Vector3f(net.minecraft.client.util.math.Vector3f) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager) ExtendedChunkData(me.jellysquid.mods.sodium.client.render.pipeline.ExtendedChunkData) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) FluidState(net.minecraft.fluid.FluidState) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 20 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project sodium-fabric by CaffeineMC.

the class ChunkRenderRebuildTask method generateMesh.

private ChunkMeshInfo generateMesh(VertexBufferCache buffers) {
    ChunkMeshInfo info = new ChunkMeshInfo();
    ChunkOcclusionDataBuilder occlusionDataBuilder = new ChunkOcclusionDataBuilder();
    Vector3f translation = new Vector3f();
    BlockPos from = this.render.getOrigin();
    BlockPos to = from.add(16, 16, 16);
    int minX = from.getX();
    int minY = from.getY();
    int minZ = from.getZ();
    int maxX = to.getX();
    int maxY = to.getY();
    int maxZ = to.getZ();
    BlockPos.Mutable pos = new BlockPos.Mutable();
    for (int z = minZ; z < maxZ; z++) {
        for (int y = minY; y < maxY; y++) {
            for (int x = minX; x < maxX; x++) {
                pos.set(x, y, z);
                BlockState blockState = this.region.getBlockState(pos);
                FluidState fluidState = blockState.getFluidState();
                Block block = blockState.getBlock();
                if (blockState.isFullOpaque(this.region, pos)) {
                    occlusionDataBuilder.markClosed(pos);
                }
                if (block.hasBlockEntity()) {
                    BlockEntity entity = this.region.getBlockEntity(pos, WorldChunk.CreationType.CHECK);
                    if (entity != null) {
                        BlockEntityRenderer<BlockEntity> renderer = BlockEntityRenderDispatcher.INSTANCE.get(entity);
                        if (renderer != null) {
                            info.blockEntities.add(entity);
                            if (renderer.rendersOutsideBoundingBox(entity)) {
                                info.globalEntities.add(entity);
                            }
                        }
                    }
                }
                if (!fluidState.isEmpty()) {
                    RenderLayer layer = RenderLayers.getFluidLayer(fluidState);
                    BufferBuilder builder = buffers.get(layer);
                    if (!builder.isBuilding()) {
                        builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                    }
                    this.fallbackPipeline.renderFluid(pos, this.region, builder, fluidState);
                }
                if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
                    RenderLayer layer = RenderLayers.getBlockLayer(blockState);
                    BufferBuilder builder = buffers.get(layer);
                    if (!builder.isBuilding()) {
                        builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                    }
                    translation.set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15);
                    this.pipeline.renderBlock(blockState, pos, this.region, translation, builder, true);
                }
            }
        }
    }
    BufferBuilder.State translucentBufferState = null;
    for (RenderLayer layer : RenderLayer.getBlockLayers()) {
        BufferBuilder builder = buffers.get(layer);
        if (!builder.isBuilding()) {
            continue;
        }
        if (((ChunkMeshBuilder) builder).isEmpty()) {
            continue;
        }
        if (layer == RenderLayer.getTranslucent()) {
            builder.sortQuads((float) this.camera.x - (float) from.getX(), (float) this.camera.y - (float) from.getY(), (float) this.camera.z - (float) from.getZ());
            translucentBufferState = builder.popState();
        }
        info.presentLayers.add(layer);
    }
    info.occlusionGraph = occlusionDataBuilder.build();
    info.translucentBufferState = translucentBufferState;
    return info;
}
Also used : BufferBuilder(net.minecraft.client.render.BufferBuilder) CloneableBufferBuilder(me.jellysquid.mods.sodium.client.render.chunk.CloneableBufferBuilder) RenderLayer(net.minecraft.client.render.RenderLayer) ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) BlockState(net.minecraft.block.BlockState) ChunkMeshBuilder(me.jellysquid.mods.sodium.client.render.mesh.ChunkMeshBuilder) Vector3f(net.minecraft.client.util.math.Vector3f) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) FluidState(net.minecraft.fluid.FluidState) BlockEntity(net.minecraft.block.entity.BlockEntity)

Aggregations

Vector3f (net.minecraft.client.util.math.Vector3f)23 Direction (net.minecraft.util.math.Direction)4 BlockState (net.minecraft.block.BlockState)3 ChunkOcclusionDataBuilder (net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder)3 Vector4f (net.minecraft.client.util.math.Vector4f)3 BlockPos (net.minecraft.util.math.BlockPos)3 Matrix3f (net.minecraft.util.math.Matrix3f)3 Matrix4f (net.minecraft.util.math.Matrix4f)3 ChunkMeshBuilder (me.jellysquid.mods.sodium.client.render.mesh.ChunkMeshBuilder)2 Block (net.minecraft.block.Block)2 BlockEntity (net.minecraft.block.entity.BlockEntity)2 BufferBuilder (net.minecraft.client.render.BufferBuilder)2 RenderLayer (net.minecraft.client.render.RenderLayer)2 VertexConsumer (net.minecraft.client.render.VertexConsumer)2 FluidState (net.minecraft.fluid.FluidState)2 Quaternion (net.minecraft.util.math.Quaternion)2 CuboidAccessor (net.sistr.littlemaidmodelloader.client.util.CuboidAccessor)2 ModelPartAccessor (net.sistr.littlemaidmodelloader.client.util.ModelPartAccessor)2 Lists (com.google.common.collect.Lists)1 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1