Search in sources :

Example 11 with Texture2D

use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories by Hugobros3.

the class VoxelTexturesStoreAndAtlaser method getDiffuseAtlasTexture.

public Texture2D getDiffuseAtlasTexture() {
    Texture2D diffuseTexture = this.diffuseTexture;
    if (diffuseTexture == null) {
        diffuseTexture = getTextureFromBufferedImage(diffuseTextureImage);
        this.diffuseTexture = diffuseTexture;
    }
    return diffuseTexture;
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D)

Example 12 with Texture2D

use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories by Hugobros3.

the class WorldRendererImplementation method blitFinalImage.

public void blitFinalImage(RenderingInterface renderingContext, boolean hideGui) {
    Texture finalBuffer = this.renderingGraph.getRenderPass("final").resolvedOutputs.get("finalBuffer");
    if (finalBuffer != null && finalBuffer instanceof Texture2D) {
        final Texture2D finalTexture = (Texture2D) (finalBuffer);
        // We render to the screen.
        renderingContext.getRenderTargetManager().setConfiguration(null);
        renderingContext.setDepthTestMode(DepthTestMode.DISABLED);
        renderingContext.setBlendMode(BlendMode.DISABLED);
        renderingContext.useShader("blit");
        renderingContext.bindTexture2D("diffuseTexture", finalTexture);
        renderingContext.drawFSQuad();
        if (!hideGui) {
            world.entitiesLock.readLock().lock();
            Iterator<Entity> ei = world.getAllLoadedEntities();
            Entity e;
            while (ei.hasNext()) {
                e = ei.next();
                if (e instanceof EntityOverlay) {
                    ((EntityOverlay) e).drawEntityOverlay(renderingContext);
                }
            }
            world.entitiesLock.readLock().unlock();
        }
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Texture(io.xol.chunkstories.api.rendering.textures.Texture) HeightmapArrayTexture(io.xol.chunkstories.renderer.terrain.HeightmapArrayTexture) EntityOverlay(io.xol.chunkstories.api.entity.interfaces.EntityOverlay)

Example 13 with Texture2D

use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories-api by Hugobros3.

the class VoxelItemRenderer method renderItemInWorld.

@Override
public void renderItemInWorld(RenderingInterface renderer, ItemPile pile, World world, Location location, Matrix4f handTransformation) {
    /*if (((ItemVoxel) pile.getItem()).getVoxel() instanceof VoxelCustomIcon) {
			fallbackRenderer.renderItemInWorld(renderer, pile, world, location, handTransformation);
			return;
		}*/
    Voxel voxel = ((ItemVoxel) pile.getItem()).getVoxel();
    if (voxel == null)
        return;
    CellData fakeCell = new DummyCell(0, 0, 0, voxel, 0, 0, 0) {

        CellData air = new DummyCell(0, 1, 0, voxel.store().air(), 0, 0, 0);

        @Override
        public int getBlocklight() {
            return voxel.getEmittedLightLevel(this);
        }

        @Override
        public CellData getNeightbor(int side) {
            return air;
        }

        @Override
        public int getMetaData() {
            return ((ItemVoxel) pile.getItem()).getVoxelMeta();
        }
    };
    float s = 0.45f;
    handTransformation.scale(new Vector3f(s, s, s));
    handTransformation.translate(new Vector3f(-0.25f, -0.5f, -0.5f));
    renderer.setObjectMatrix(handTransformation);
    // Add a light only on the opaque pass
    if (fakeCell.getBlocklight() > 0 && renderer.getCurrentPass().name.contains("gBuffers")) {
        Vector4f lightposition = new Vector4f(0.0f, 0.0f, 0.0f, 1.0f);
        handTransformation.transform(lightposition);
        Light heldBlockLight = new Light(new Vector3f(0.6f, 0.50f, 0.4f).mul(0.5f), new Vector3f(lightposition.x(), lightposition.y(), lightposition.z()), 15f);
        renderer.getLightsRenderer().queueLight(heldBlockLight);
        // If we hold a light source, prepare the shader accordingly
        renderer.currentShader().setUniform2f("worldLightIn", Math.max(world.peekSafely(location).getBlocklight(), fakeCell.getBlocklight()), world.peekSafely(location).getSunlight());
    }
    Texture2D texture = content.voxels().textures().getDiffuseAtlasTexture();
    texture.setLinearFiltering(false);
    renderer.bindAlbedoTexture(texture);
    Texture2D normalTexture = content.voxels().textures().getNormalAtlasTexture();
    normalTexture.setLinearFiltering(false);
    renderer.bindNormalTexture(normalTexture);
    Texture2D materialTexture = content.voxels().textures().getMaterialAtlasTexture();
    materialTexture.setLinearFiltering(false);
    renderer.bindMaterialTexture(materialTexture);
    renderFakeVoxel(renderer, fakeCell);
}
Also used : ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Vector4f(org.joml.Vector4f) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) Light(io.xol.chunkstories.api.rendering.lightning.Light) Vector3f(org.joml.Vector3f) CellData(io.xol.chunkstories.api.world.cell.CellData) DummyCell(io.xol.chunkstories.api.world.cell.DummyCell)

Example 14 with Texture2D

use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories-api by Hugobros3.

the class VoxelItemRenderer method renderItemInInventory.

@Override
public void renderItemInInventory(RenderingInterface renderer, ItemPile pile, float screenPositionX, float screenPositionY, int scaling) {
    /*if (((ItemVoxel) pile.getItem()).getVoxel() instanceof VoxelCustomIcon) {
			fallbackRenderer.renderItemInInventory(renderer, pile, screenPositionX, screenPositionY, scaling);
			return;
		}*/
    int slotSize = 24 * scaling;
    Shader program = renderer.useShader("inventory_blockmodel");
    renderer.setCullingMode(CullingMode.COUNTERCLOCKWISE);
    renderer.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
    program.setUniform2f("screenSize", renderer.getWindow().getWidth(), renderer.getWindow().getHeight());
    program.setUniform2f("dekal", screenPositionX + pile.getItem().getDefinition().getSlotsWidth() * slotSize / 2, screenPositionY + pile.getItem().getDefinition().getSlotsHeight() * slotSize / 2);
    program.setUniform1f("scaling", slotSize / 1.65f);
    transformation.identity();
    transformation.scale(new Vector3f(-1f, 1f, 1f));
    transformation.rotate(toRad(-22.5f), new Vector3f(1.0f, 0.0f, 0.0f));
    transformation.rotate(toRad(45f), new Vector3f(0.0f, 1.0f, 0.0f));
    transformation.translate(new Vector3f(-0.5f, -0.5f, -0.5f));
    program.setUniformMatrix4f("transformation", transformation);
    Voxel voxel = ((ItemVoxel) pile.getItem()).getVoxel();
    if (voxel == null) {
        int width = slotSize * pile.getItem().getDefinition().getSlotsWidth();
        int height = slotSize * pile.getItem().getDefinition().getSlotsHeight();
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(screenPositionX, screenPositionY, width, height, 0, 1, 1, 0, content.textures().getTexture("./items/icons/notex.png"), true, true, null);
        return;
    }
    Texture2D texture = content.voxels().textures().getDiffuseAtlasTexture();
    texture.setLinearFiltering(false);
    renderer.bindAlbedoTexture(texture);
    Texture2D normalTexture = content.voxels().textures().getNormalAtlasTexture();
    normalTexture.setLinearFiltering(false);
    renderer.bindNormalTexture(normalTexture);
    Texture2D materialTexture = content.voxels().textures().getMaterialAtlasTexture();
    materialTexture.setLinearFiltering(false);
    renderer.bindMaterialTexture(materialTexture);
    CellData fakeCell = new DummyCell(0, 0, 0, voxel, 0, 0, 0) {

        CellData air = new DummyCell(0, 1, 0, voxel.store().air(), 0, 0, 0);

        @Override
        public int getBlocklight() {
            return voxel.getEmittedLightLevel(this);
        }

        @Override
        public CellData getNeightbor(int side) {
            return air;
        }

        @Override
        public int getMetaData() {
            return ((ItemVoxel) pile.getItem()).getVoxelMeta();
        }
    };
    renderFakeVoxel(renderer, fakeCell);
}
Also used : ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) Vector3f(org.joml.Vector3f) Shader(io.xol.chunkstories.api.rendering.shader.Shader) CellData(io.xol.chunkstories.api.world.cell.CellData) DummyCell(io.xol.chunkstories.api.world.cell.DummyCell)

Example 15 with Texture2D

use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories-api by Hugobros3.

the class LargeButton method render.

@Override
public void render(RenderingInterface renderer) {
    String localizedText = layer.getGameWindow().getClient().getContent().localization().localize(text);
    Texture2D buttonTexture = renderer.textures().getTexture("./textures/gui/mainMenu.png");
    if (isFocused() || isMouseOver())
        buttonTexture = renderer.textures().getTexture("./textures/gui/mainMenuOver.png");
    buttonTexture.setLinearFiltering(false);
    renderer.getGuiRenderer().drawCorneredBoxTiled(xPosition, yPosition, getWidth(), getHeight(), 4 * scale(), buttonTexture, 32, scale());
    Font font = layer.getGameWindow().getRenderingInterface().getFontRenderer().getFont("LiberationSansNarrow-Bold__aa", 16f * scale());
    float a = 1f / scale();
    float yPositionText = yPosition + 2.5f * scale();
    float centering = getWidth() / 2 - font.getWidth(localizedText) * a * scale() / 2;
    renderer.getFontRenderer().drawString(font, xPosition + centering + scale(), yPositionText - scale(), localizedText, a * scale(), new Vector4f(161 / 255f, 161 / 255f, 161 / 255f, 1));
    renderer.getFontRenderer().drawString(font, xPosition + centering, yPositionText, localizedText, a * scale(), new Vector4f(38 / 255f, 38 / 255f, 38 / 255f, 1));
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Vector4f(org.joml.Vector4f) Font(io.xol.chunkstories.api.rendering.text.FontRenderer.Font)

Aggregations

Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)27 Shader (io.xol.chunkstories.api.rendering.shader.Shader)9 Vector4f (org.joml.Vector4f)6 Matrix4f (org.joml.Matrix4f)5 Vector3f (org.joml.Vector3f)5 Location (io.xol.chunkstories.api.Location)3 GameWindow (io.xol.chunkstories.api.rendering.GameWindow)3 Voxel (io.xol.chunkstories.api.voxel.Voxel)3 ByteBuffer (java.nio.ByteBuffer)3 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)2 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)2 Player (io.xol.chunkstories.api.player.Player)2 Font (io.xol.chunkstories.api.rendering.text.FontRenderer.Font)2 CellData (io.xol.chunkstories.api.world.cell.CellData)2 DummyCell (io.xol.chunkstories.api.world.cell.DummyCell)2 MemFreeByteBuffer (io.xol.chunkstories.client.util.MemFreeByteBuffer)2 HeightmapImplementation (io.xol.chunkstories.world.summary.HeightmapImplementation)2 Vector2d (org.joml.Vector2d)2 Vector3dc (org.joml.Vector3dc)2 Entity (io.xol.chunkstories.api.entity.Entity)1