Search in sources :

Example 41 with Matrix4f

use of org.joml.Matrix4f in project chunkstories-core by Hugobros3.

the class WaterPass method render.

@Override
public void render(RenderingInterface renderer) {
    // if(true)
    // return;
    renderer.setBlendMode(BlendMode.MIX);
    renderer.setCullingMode(CullingMode.DISABLED);
    GameWindow gameWindow = pipeline.getRenderingInterface().getWindow();
    // one for computing the refracted color and putting it in shaded buffer, and another one to read it back and blend it
    for (int pass = 1; pass <= 2; pass++) {
        Shader liquidBlocksShader = renderer.useShader("blocks_liquid_pass" + pass);
        liquidBlocksShader.setUniform1f("viewDistance", world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance"));
        renderer.bindTexture2D("waterNormalDeep", renderer.textures().getTexture("./textures/water/deep.png"));
        renderer.bindTexture2D("waterNormalShallow", renderer.textures().getTexture("./textures/water/shallow.png"));
        renderer.bindTexture2D("lightColors", renderer.textures().getTexture("./textures/environement/light.png"));
        Texture2D blocksAlbedoTexture = gameWindow.getClient().getContent().voxels().textures().getDiffuseAtlasTexture();
        renderer.bindAlbedoTexture(blocksAlbedoTexture);
        liquidBlocksShader.setUniform2f("screenSize", gameWindow.getWidth(), gameWindow.getHeight());
        skyRenderer.setupShader(liquidBlocksShader);
        liquidBlocksShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
        renderer.getCamera().setupShader(liquidBlocksShader);
        // Underwater flag
        Voxel vox = world.peekSafely(renderer.getCamera().getCameraPosition()).getVoxel();
        liquidBlocksShader.setUniform1f("underwater", vox.getDefinition().isLiquid() ? 1 : 0);
        if (pass == 1) {
            renderer.getRenderTargetManager().setConfiguration(waterRefractionFbo);
            renderer.getRenderTargetManager().clearBoundRenderTargetAll();
            renderer.bindTexture2D("readbackAlbedoBufferTemp", albedoBuffer);
            renderer.bindTexture2D("readbackVoxelLightBufferTemp", voxelLightBuffer);
            renderer.bindTexture2D("readbackDepthBufferTemp", zBuffer);
            renderer.getRenderTargetManager().setDepthMask(false);
        } else if (pass == 2) {
            renderer.getRenderTargetManager().setConfiguration(fboGBuffers);
            renderer.setBlendMode(BlendMode.DISABLED);
            renderer.bindTexture2D("readbackShadedBufferTemp", waterTempTexture);
            renderer.getRenderTargetManager().setDepthMask(true);
        }
        renderer.setObjectMatrix(new Matrix4f());
        worldRenderer.getChunksRenderer().renderChunks(renderer);
    }
}
Also used : GameWindow(io.xol.chunkstories.api.rendering.GameWindow) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Matrix4f(org.joml.Matrix4f) Voxel(io.xol.chunkstories.api.voxel.Voxel) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 42 with Matrix4f

use of org.joml.Matrix4f in project chunkstories-core by Hugobros3.

the class SignRenderer method renderVoxels.

@Override
public void renderVoxels(RenderingInterface renderingContext, IterableIterator<ChunkCell> renderableEntitiesIterator) {
    setupRender(renderingContext);
    renderingContext.setObjectMatrix(null);
    for (// .getElementsInFrustrumOnly())
    ChunkCell context : // .getElementsInFrustrumOnly())
    renderableEntitiesIterator) {
        if (renderingContext.getCamera().getCameraPosition().distance(context.getLocation()) > 32)
            continue;
        Texture2D diffuse = renderingContext.textures().getTexture("./models/sign.png");
        diffuse.setLinearFiltering(false);
        renderingContext.bindAlbedoTexture(diffuse);
        renderingContext.bindNormalTexture(renderingContext.textures().getTexture("./textures/normalnormal.png"));
        renderingContext.currentShader().setUniform2f("worldLightIn", context.getBlocklight(), context.getSunlight());
        boolean isPost = context.getVoxel().getName().endsWith("_post");
        int facing = context.getMetaData();
        Matrix4f mutrix = new Matrix4f();
        mutrix.translate(new Vector3f(0.5f, 0.0f, 0.5f));
        Location loc = context.getLocation();
        mutrix.translate((float) loc.x, (float) loc.y, (float) loc.z);
        mutrix.rotate((float) Math.PI * 2.0f * (-facing) / 16f, new Vector3f(0, 1, 0));
        if (!isPost)
            mutrix.translate(new Vector3f(0.0f, 0.0f, -0.5f));
        renderingContext.setObjectMatrix(mutrix);
        if (!isPost)
            renderingContext.meshes().getRenderableMeshByName("./models/sign_post.obj").render(renderingContext);
        else
            renderingContext.meshes().getRenderableMeshByName("./models/sign.obj").render(renderingContext);
        VoxelComponentSignText signTextComponent = (VoxelComponentSignText) context.components().get("signData");
        if (signTextComponent == null)
            continue;
        // bake sign mesh
        if (signTextComponent.cachedText == null || !signTextComponent.cachedText.equals(signTextComponent.getSignText())) {
            // entitySign.renderData = new TextMeshObject(entitySign.signText.getSignText());
            signTextComponent.cachedText = signTextComponent.getSignText();
            signTextComponent.renderData = renderingContext.getFontRenderer().newTextMeshObject(renderingContext.getFontRenderer().defaultFont(), signTextComponent.cachedText);
        }
        // signTextComponent.setSignText("fuck");
        // System.out.println("cachedText:"+signTextComponent.getSignText());
        // Display it
        mutrix.translate(new Vector3f(0.0f, 1.15f, 0.055f));
        renderingContext.setObjectMatrix(mutrix);
        signTextComponent.renderData.render(renderingContext);
    }
}
Also used : VoxelComponentSignText(io.xol.chunkstories.core.voxel.components.VoxelComponentSignText) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) ChunkCell(io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell) Location(io.xol.chunkstories.api.Location)

Example 43 with Matrix4f

use of org.joml.Matrix4f in project lwjgl3-demos by LWJGL.

the class TwoRotatingTrianglesDemo method updateUbo.

private static void updateUbo(VkDevice device, UboDescriptor ubo, float angle) {
    Matrix4f m = new Matrix4f().scale(1, -1, // <- correcting viewport transformation (what Direct3D does, too)
    1).perspective((float) Math.toRadians(45.0f), (float) width / height, 0.1f, 10.0f, true).lookAt(0, 1, 3, 0, 0, 0, 0, 1, 0).rotateY(angle);
    PointerBuffer pData = memAllocPointer(1);
    int err = vkMapMemory(device, ubo.memory, 0, 16 * 4, 0, pData);
    long data = pData.get(0);
    memFree(pData);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to map UBO memory: " + translateVulkanResult(err));
    }
    ByteBuffer matrixBuffer = memByteBuffer(data, 16 * 4);
    m.get(matrixBuffer);
    vkUnmapMemory(device, ubo.memory);
}
Also used : Matrix4f(org.joml.Matrix4f) PointerBuffer(org.lwjgl.PointerBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 44 with Matrix4f

use of org.joml.Matrix4f in project lwjgl3-demos by LWJGL.

the class TwoRotatingTrianglesInvDepthDemo method updateUbo.

private static void updateUbo(VkDevice device, UboDescriptor ubo, float angle) {
    Matrix4f m = new Matrix4f().scale(1, -1, // <- correcting viewport transformation (what Direct3D does, too)
    1).perspective((float) Math.toRadians(45.0f), (float) width / height, 0.1f, 10.0f, true).lookAt(0, 1, 3, 0, 0, 0, 0, 1, 0).rotateY(angle);
    PointerBuffer pData = memAllocPointer(1);
    int err = vkMapMemory(device, ubo.memory, 0, 16 * 4, 0, pData);
    long data = pData.get(0);
    memFree(pData);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to map UBO memory: " + translateVulkanResult(err));
    }
    ByteBuffer matrixBuffer = memByteBuffer(data, 16 * 4);
    m.get(matrixBuffer);
    vkUnmapMemory(device, ubo.memory);
}
Also used : Matrix4f(org.joml.Matrix4f) PointerBuffer(org.lwjgl.PointerBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 45 with Matrix4f

use of org.joml.Matrix4f in project lwjgl3-demos by LWJGL.

the class NoVerticesProjectedGridDemo method render.

void render() {
    glClear(GL_COLOR_BUFFER_BIT);
    glUseProgram(this.program);
    long thisTime = System.nanoTime();
    float delta = (thisTime - lastTime) / 1E9f;
    alpha += delta * 2.0f;
    lastTime = thisTime;
    // Build camera view-projection matrix
    Matrix4f r = viewproj.setPerspective((float) Math.toRadians(45.0f), (float) width / height, 0.1f, 100.0f).lookAt(0, 4, 20, 0, 0, 0, 0, 1, 0).invert(// <- invert it
    invViewProj).projectedGridRange(viewproj, -MAX_HEIGHT, MAX_HEIGHT, // <- build range matrix
    range);
    if (r == null) {
        // grid not visible. We don't render anything!
        return;
    }
    // <- build final projector matrix
    invViewProj.mul(range, projector);
    // compute the intersections with the y=0 plane at the grid corners in homogeneous space
    for (int i = 0; i < 4; i++) {
        float x = (i & 1);
        float y = (i >>> 1) & 1;
        projector.transform(p0.set(x, y, -1, 1));
        projector.transform(p1.set(x, y, +1, 1));
        float t = -p0.y / (p1.y - p0.y);
        isect.set(p1).sub(p0).mul(t).add(p0);
        glUniform4f(intersectionsUniform + i, isect.x, isect.y, isect.z, isect.w);
    }
    // upload matrices to the shader
    glUniformMatrix4fv(transformUniform, false, viewproj.get(matrixBuffer));
    glUniform1f(timeUniform, alpha);
    glUniform2i(sizeUniform, sizeX, sizeY);
    glDrawArrays(GL_TRIANGLES, 0, 6 * sizeX * sizeY);
    glUseProgram(0);
}
Also used : Matrix4f(org.joml.Matrix4f)

Aggregations

Matrix4f (org.joml.Matrix4f)62 Vector3f (org.joml.Vector3f)34 Quaternionf (org.joml.Quaternionf)13 LocationComponent (org.terasology.engine.logic.location.LocationComponent)7 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)5 Vector3d (org.joml.Vector3d)5 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)5 Shader (io.xol.chunkstories.api.rendering.shader.Shader)4 AABBf (org.terasology.joml.geom.AABBf)4 com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject (com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject)3 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)3 Location (io.xol.chunkstories.api.Location)3 GameWindow (io.xol.chunkstories.api.rendering.GameWindow)3 ByteBuffer (java.nio.ByteBuffer)3 Matrix3f (org.joml.Matrix3f)3 Vector4f (org.joml.Vector4f)3 PointerBuffer (org.lwjgl.PointerBuffer)3 Camera (org.terasology.engine.rendering.cameras.Camera)3 ClosestRayResultCallback (com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback)2 TFloatList (gnu.trove.list.TFloatList)2