Search in sources :

Example 21 with Texture2D

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

the class VoxelTexturesStoreAndAtlaser method getTextureFromBufferedImage.

private Texture2D getTextureFromBufferedImage(BufferedImage image) {
    int[] data = new int[image.getWidth() * image.getHeight()];
    image.getRGB(0, 0, image.getWidth(), image.getHeight(), data, 0, image.getWidth());
    // BufferUtils.createByteBuffer(4 * image.getWidth() * image.getHeight());
    ByteBuffer buffer = ByteBuffer.allocateDirect(4 * image.getWidth() * image.getHeight());
    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            int pixel = data[y * image.getWidth() + x];
            buffer.put((byte) ((pixel >> 16) & 0xFF));
            buffer.put((byte) ((pixel >> 8) & 0xFF));
            buffer.put((byte) (pixel & 0xFF));
            buffer.put((byte) ((pixel >> 24) & 0xFF));
        }
    }
    buffer.flip();
    Texture2D texture = ((ClientContent) parent().parent()).textures().newTexture2D(TextureFormat.RGBA_8BPP, image.getWidth(), image.getHeight());
    texture.uploadTextureData(image.getWidth(), image.getHeight(), buffer);
    return texture;
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) ByteBuffer(java.nio.ByteBuffer)

Example 22 with Texture2D

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

the class VoxelTexturesStoreAndAtlaser method getNormalAtlasTexture.

public Texture2D getNormalAtlasTexture() {
    Texture2D normalTexture = this.normalTexture;
    if (normalTexture == null) {
        normalTexture = getTextureFromBufferedImage(normalTextureImage);
        this.normalTexture = normalTexture;
    }
    return normalTexture;
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D)

Example 23 with Texture2D

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

the class ShadowPass method render.

public void render(RenderingInterface renderingContext) {
    if (this.getShadowVisibility() == 0f)
        // No shadows at night :)
        return;
    GameWindow gameWindow = pipeline.getRenderingInterface().getWindow();
    // Resize the texture if needed
    int shadowMapTextureSize = renderingContext.getClient().getConfiguration().getIntOption("client.rendering.shadowsResolution");
    if (shadowDepthTexture.getWidth() != shadowMapTextureSize) {
        fbo.resize(shadowMapTextureSize, shadowMapTextureSize);
    }
    // The size of the shadow range depends on the shadowmap resolution
    int shadowRange = 128;
    if (shadowMapTextureSize > 1024)
        shadowRange = 192;
    else if (shadowMapTextureSize > 2048)
        shadowRange = 256;
    int shadowDepthRange = 200;
    // Builds the shadow matrix
    // MatrixHelper.getOrthographicMatrix(-shadowRange, shadowRange, -shadowRange, shadowRange, -shadowDepthRange, shadowDepthRange);
    Matrix4f depthProjectionMatrix = new Matrix4f().ortho(-shadowRange, shadowRange, -shadowRange, shadowRange, -shadowDepthRange, shadowDepthRange);
    Matrix4f depthViewMatrix = new Matrix4f().lookAt(skyRenderer.getSunPosition(), new Vector3f(0, 0, 0), new Vector3f(0, 1, 0));
    Matrix4f shadowMVP = new Matrix4f();
    depthProjectionMatrix.mul(depthViewMatrix, shadowMVP);
    // Matrix4f.mul(depthProjectionMatrix, depthViewMatrix, shadowMVP);
    shadowMatrix = new Matrix4f(shadowMVP);
    Vector3dc posd = renderingContext.getCamera().getCameraPosition();
    Vector3f pos = new Vector3f((float) posd.x(), (float) posd.y(), (float) posd.z());
    pos.negate();
    shadowMVP.translate(pos);
    // Set appropriate fixed function stuff
    renderingContext.setCullingMode(CullingMode.COUNTERCLOCKWISE);
    renderingContext.setBlendMode(BlendMode.DISABLED);
    renderingContext.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
    // Bind relevant FBO and clear it
    renderingContext.getRenderTargetManager().setConfiguration(fbo);
    renderingContext.getRenderTargetManager().clearBoundRenderTargetZ(1.0f);
    Shader shadowsPassShader = renderingContext.useShader("shadows");
    shadowsPassShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
    shadowsPassShader.setUniformMatrix4f("depthMVP", shadowMVP);
    shadowsPassShader.setUniform1f("isUsingInstancedData", 0f);
    shadowsPassShader.setUniform1f("useVoxelCoordinates", 1f);
    Texture2D blocksAlbedoTexture = gameWindow.getClient().getContent().voxels().textures().getDiffuseAtlasTexture();
    renderingContext.bindAlbedoTexture(blocksAlbedoTexture);
    renderingContext.setObjectMatrix(null);
    // We render the world from that perspective
    // Hackish way of enabling the shader input for the fake "wind" effect vegetation can have
    shadowsPassShader.setUniform1f("allowForWavyStuff", 1);
    worldRenderer.getChunksRenderer().renderChunks(renderingContext);
    // In turn, disabling it while we do the entities
    shadowsPassShader.setUniform1f("allowForWavyStuff", 0);
    worldRenderer.getEntitiesRenderer().renderEntities(renderingContext);
}
Also used : GameWindow(io.xol.chunkstories.api.rendering.GameWindow) Vector3dc(org.joml.Vector3dc) Matrix4f(org.joml.Matrix4f) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Vector3f(org.joml.Vector3f) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 24 with Texture2D

use of io.xol.chunkstories.api.rendering.textures.Texture2D 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 25 with Texture2D

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

the class ApplySunlightPass method render.

@Override
public void render(RenderingInterface renderer) {
    Shader applyShadowsShader = renderer.useShader("shadows_apply");
    world.getGenerator().getEnvironment().setupShadowColors(renderer, applyShadowsShader);
    applyShadowsShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
    applyShadowsShader.setUniform1f("overcastFactor", world.getWeather());
    applyShadowsShader.setUniform1f("wetness", world.getGenerator().getEnvironment().getWorldWetness(renderer.getCamera().getCameraPosition()));
    renderer.setDepthTestMode(DepthTestMode.DISABLED);
    renderer.setBlendMode(BlendMode.DISABLED);
    renderer.getRenderTargetManager().setConfiguration(fbo);
    float lightMultiplier = 1.0f;
    applyShadowsShader.setUniform1f("brightnessMultiplier", lightMultiplier);
    RenderPass giPass = this.pipeline.getRenderPass("gi");
    if (giPass != null && giPass instanceof GiPass) {
        GiPass gi = (GiPass) giPass;
        renderer.bindTexture2D("giBuffer", gi.giTexture());
        renderer.bindTexture2D("giConfidence", gi.confidenceTexture());
        applyShadowsShader.setUniform1f("accumulatedSamples", gi.accumulatedSamples);
    // System.out.println("samples:"+gi.accumulatedSamples );
    }
    /*if(albedoBuffer == normalBuffer || albedoBuffer == zBuffer)
			System.out.println("well fuck"+normalBuffer);
		
		renderer.bindTexture2D("albedoBuffer", albedoBuffer);
		renderer.bindTexture2D("depthBuffer", zBuffer);
		renderer.bindTexture2D("normalBuffer", normalBuffer);
		//TODO materials
		//renderingContext.bindTexture2D("specularityBuffer", renderBuffers.rbSpecularity);
		renderer.bindTexture2D("voxelLightBuffer", voxelLightBuffer);*/
    renderer.textures().getTexture("./textures/environement/light.png").setTextureWrapping(false);
    renderer.bindTexture2D("blockLightmap", renderer.textures().getTexture("./textures/environement/light.png"));
    Texture2D lightColors = renderer.textures().getTexture("./textures/environement/lightcolors.png");
    renderer.textures().getTexture("./textures/environement/lightcolors.png").setTextureWrapping(false);
    renderer.bindTexture2D("lightColors", lightColors);
    if (shadowPass != null) {
        renderer.bindTexture2D("shadowMap", (Texture2D) shadowPass.resolvedOutputs.get("shadowMap"));
        applyShadowsShader.setUniform1f("shadowMapResolution", ((Texture2D) shadowPass.resolvedOutputs.get("shadowMap")).getWidth());
        applyShadowsShader.setUniform1f("shadowVisiblity", shadowPass.getShadowVisibility());
        applyShadowsShader.setUniformMatrix4f("shadowMatrix", shadowPass.getShadowMatrix());
    }
    // Matrices for screen-space transformations
    renderer.getCamera().setupShader(applyShadowsShader);
    worldRenderer.getSkyRenderer().setupShader(applyShadowsShader);
    renderer.getRenderTargetManager().setDepthMask(false);
    renderer.drawFSQuad();
    renderer.getRenderTargetManager().setDepthMask(true);
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) GiPass(io.xol.chunkstories.core.rendering.passes.gi.GiPass) RenderPass(io.xol.chunkstories.api.rendering.pass.RenderPass) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

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