Search in sources :

Example 1 with Shader

use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories-core by Hugobros3.

the class BreakingBlockDecal method render.

public void render(RenderingInterface renderingInterface) {
    Shader decalsShader = renderingInterface.useShader("decal_cracking");
    renderingInterface.getCamera().setupShader(decalsShader);
    renderingInterface.setCullingMode(CullingMode.DISABLED);
    renderingInterface.setBlendMode(BlendMode.MIX);
    renderingInterface.getRenderTargetManager().setDepthMask(false);
    int phases = 6;
    int phase = (int) (phases * miningProgress.progress);
    decalsShader.setUniform1f("textureScale", 1f / 6);
    decalsShader.setUniform1f("textureStart", 1f / 6 * phase);
    // decalType.getTexture();
    Texture2D diffuseTexture = renderingInterface.textures().getTexture("./textures/voxel_cracking.png");
    diffuseTexture.setTextureWrapping(true);
    diffuseTexture.setLinearFiltering(false);
    renderingInterface.bindAlbedoTexture(diffuseTexture);
    renderingInterface.bindAttribute("vertexIn", vertexBuffer.asAttributeSource(VertexFormat.FLOAT, 3, 4 * (3 + 2), 0));
    renderingInterface.bindAttribute("texCoordIn", vertexBuffer.asAttributeSource(VertexFormat.FLOAT, 2, 4 * (3 + 2), 4 * 3));
    renderingInterface.draw(Primitive.TRIANGLE, 0, size);
    renderingInterface.getRenderTargetManager().setDepthMask(true);
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 2 with Shader

use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories-core by Hugobros3.

the class GBuffersOpaquePass method render.

@Override
public void render(RenderingInterface renderingInterface) {
    if (fbo != null) {
        GameWindow gameWindow = pipeline.getRenderingInterface().getWindow();
        renderingInterface.getRenderTargetManager().setConfiguration(fbo);
        renderingInterface.getRenderTargetManager().clearBoundRenderTargetAll();
        // Set fixed-function parameters
        renderingInterface.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
        renderingInterface.setBlendMode(BlendMode.DISABLED);
        renderingInterface.setCullingMode(CullingMode.COUNTERCLOCKWISE);
        Shader opaqueBlocksShader = renderingInterface.useShader("blocks_opaque");
        Texture2D blocksAlbedoTexture = gameWindow.getClient().getContent().voxels().textures().getDiffuseAtlasTexture();
        Texture2D blocksNormalTexture = gameWindow.getClient().getContent().voxels().textures().getNormalAtlasTexture();
        Texture2D blocksMaterialTexture = gameWindow.getClient().getContent().voxels().textures().getMaterialAtlasTexture();
        renderingInterface.bindAlbedoTexture(blocksAlbedoTexture);
        renderingInterface.bindNormalTexture(blocksNormalTexture);
        renderingInterface.bindMaterialTexture(blocksMaterialTexture);
        renderingInterface.bindTexture2D("lightColors", renderingInterface.textures().getTexture("./textures/environement/light.png"));
        renderingInterface.bindTexture2D("vegetationColorTexture", worldRenderer.getWorld().getGenerator().getEnvironment().getGrassTexture(renderingInterface));
        // renderingInterface.bindTexture2D("vegetationColorTexture", getGrassTexture());
        // Set texturing arguments
        blocksAlbedoTexture.setTextureWrapping(false);
        blocksAlbedoTexture.setLinearFiltering(false);
        blocksAlbedoTexture.setMipMapping(false);
        blocksAlbedoTexture.setMipmapLevelsRange(0, 4);
        blocksNormalTexture.setTextureWrapping(false);
        blocksNormalTexture.setLinearFiltering(false);
        blocksNormalTexture.setMipMapping(false);
        blocksNormalTexture.setMipmapLevelsRange(0, 4);
        blocksMaterialTexture.setTextureWrapping(false);
        blocksMaterialTexture.setLinearFiltering(false);
        blocksMaterialTexture.setMipMapping(false);
        blocksMaterialTexture.setMipmapLevelsRange(0, 4);
        // World stuff
        opaqueBlocksShader.setUniform1f("mapSize", world.getSizeInChunks() * 32);
        opaqueBlocksShader.setUniform1f("overcastFactor", world.getWeather());
        opaqueBlocksShader.setUniform1f("wetness", world.getGenerator().getEnvironment().getWorldWetness(renderingInterface.getCamera().getCameraPosition()));
        opaqueBlocksShader.setUniform1f("time", worldRenderer.getAnimationTimer());
        opaqueBlocksShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
        opaqueBlocksShader.setUniform2f("screenSize", gameWindow.getWidth(), gameWindow.getHeight());
        renderingInterface.getCamera().setupShader(opaqueBlocksShader);
        renderingInterface.setObjectMatrix(new Matrix4f());
        worldRenderer.getChunksRenderer().renderChunks(renderingInterface);
        worldRenderer.getChunksRenderer().renderChunksExtras(renderingInterface);
        worldRenderer.getEntitiesRenderer().renderEntities(renderingInterface);
        worldRenderer.getParticlesRenderer().renderParticles(renderingInterface);
    }
}
Also used : GameWindow(io.xol.chunkstories.api.rendering.GameWindow) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Matrix4f(org.joml.Matrix4f) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 3 with Shader

use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories-core by Hugobros3.

the class GiPass method render.

public void render(RenderingInterface renderer) {
    cameraPosition.set(renderer.getCamera().getCameraPosition());
    cameraDirection.set(renderer.getCamera().getViewDirection());
    Shader giShader = renderer.useShader("gi");
    renderer.getRenderTargetManager().setConfiguration(renderingToA ? fboAccumulationA : fboAccumulationB);
    renderer.setDepthTestMode(DepthTestMode.ALWAYS);
    renderer.setBlendMode(BlendMode.DISABLED);
    if (shadowPass != null) {
        renderer.bindTexture2D("shadowMap", (Texture2D) shadowPass.resolvedOutputs.get("shadowMap"));
        giShader.setUniform1f("shadowMapResolution", ((Texture2D) shadowPass.resolvedOutputs.get("shadowMap")).getWidth());
        giShader.setUniform1f("shadowVisiblity", shadowPass.getShadowVisibility());
        giShader.setUniformMatrix4f("shadowMatrix", shadowPass.getShadowMatrix());
    }
    renderer.getRenderTargetManager().clearBoundRenderTargetAll();
    renderer.getRenderTargetManager().setDepthMask(true);
    renderer.bindTexture2D("previousBuffer", !renderingToA ? accumulationA : accumulationB);
    renderer.bindTexture2D("previousConfidence", !renderingToA ? confidenceA : confidenceB);
    renderer.bindTexture2D("previousZ", !renderingToA ? zBufferA : zBufferB);
    giShader.setUniformMatrix4f("previousProjectionMatrix", previousProjectionMatrix);
    giShader.setUniformMatrix4f("previousModelViewMatrix", previousModelViewMatrix);
    giShader.setUniformMatrix4f("previousProjectionMatrixInv", previousProjectionMatrixInv);
    giShader.setUniformMatrix4f("previousModelViewMatrixInv", previousModelViewMatrixInv);
    if (cameraPosition.distance(oldCameraPosition) != 0.0f || cameraDirection.distance(oldCameraDirection) != 0.0f) {
        // System.out.println("moved! : " + cameraPosition.distance(oldCameraPosition) + "or " + cameraDirection.distance(oldCameraDirection));
        giShader.setUniform1i("keepPreviousData", 0);
        accumulatedSamples = 0;
    } else {
        giShader.setUniform1i("keepPreviousData", 1);
    }
    accumulatedSamples++;
    voxels4gi.update(renderer);
    voxels4gi.setupForRendering(renderer);
    boolean lf = true;
    accumulationA.setLinearFiltering(lf);
    accumulationB.setLinearFiltering(lf);
    confidenceA.setLinearFiltering(lf);
    confidenceB.setLinearFiltering(lf);
    giShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer() + accumulatedSamples);
    giShader.setUniform1f("overcastFactor", worldRenderer.getWorld().getWeather());
    giShader.setUniform1f("wetness", worldRenderer.getWorld().getGenerator().getEnvironment().getWorldWetness(cameraPosition));
    worldRenderer.getSkyRenderer().setupShader(giShader);
    renderer.getCamera().setupShader(giShader);
    renderer.drawFSQuad();
    previousProjectionMatrix.set(renderer.getCamera().getProjectionMatrix4f());
    previousModelViewMatrix.set(renderer.getCamera().getModelViewMatrix4f());
    previousProjectionMatrixInv.set(renderer.getCamera().getProjectionMatrix4fInverted());
    previousModelViewMatrixInv.set(renderer.getCamera().getModelViewMatrix4fInverted());
    renderingToA = !renderingToA;
    oldCameraPosition.set(cameraPosition);
    oldCameraDirection.set(cameraDirection);
}
Also used : Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 4 with Shader

use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories-core by Hugobros3.

the class NearbyVoxelsVolumeTexture method setupForRendering.

public void setupForRendering(RenderingInterface renderingContext) {
    renderingContext.bindTexture3D("currentChunk", test);
    Shader shader = renderingContext.currentShader();
    shader.setUniform1i("voxel_size", size);
    shader.setUniform1f("voxel_sizef", 0.0f + size);
    shader.setUniform3f("voxelOffset", offsetX * 32, offsetY * 32, offsetZ * 32);
}
Also used : Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 5 with Shader

use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories-core by Hugobros3.

the class CloudsRenderer method renderClouds.

public void renderClouds(RenderingInterface renderingContext) {
    bake(renderingContext);
    if (baked <= 0)
        return;
    // ShaderProgram cloudsShader = ShadersLibrary.getShaderProgram("clouds");
    renderingContext.useShader("clouds");
    // renderingContext.setCurrentShader(cloudsShader);
    renderingContext.getCamera().setupShader(renderingContext.currentShader());
    skyRenderer.setupShader(renderingContext.currentShader());
    renderingContext.currentShader().setUniform3f("sunPos", skyRenderer.getSunPosition());
    Shader cloudsShader = renderingContext.currentShader();
    cloudsShader.setUniform1f("time", (world.getTime() % 10000) / 10000f);
    cloudsShader.setUniform1f("overcastFactor", world.getWeather());
    renderingContext.setCullingMode(CullingMode.DISABLED);
    // glDisable(GL_CULL_FACE);
    // cloudsMesh.bind();
    renderingContext.bindAttribute("vertexIn", cloudsMesh.asAttributeSource(VertexFormat.FLOAT, 3, (4 * 3 + 4 * 3 + 4), 0));
    renderingContext.bindAttribute("normalIn", cloudsMesh.asAttributeSource(VertexFormat.FLOAT, 3, (4 * 3 + 4 * 3 + 4), 4 * 3));
    renderingContext.bindAttribute("alphaIn", cloudsMesh.asAttributeSource(VertexFormat.FLOAT, 1, (4 * 3 + 4 * 3 + 4), 4 * 6));
    // renderingContext.setVertexAttributePointerLocation("vertexIn", 3, GL_FLOAT, false, (4 * 3 + 4 * 3 + 4), 0);
    // renderingContext.setVertexAttributePointerLocation("normalIn", 3, GL_FLOAT, false, (4 * 3 + 4 * 3 + 4), (4 * 3));
    // renderingContext.setVertexAttributePointerLocation("alphaIn", 1, GL_FLOAT, false, (4 * 3 + 4 * 3 + 4), (4 * 3 + 4 * 3));
    renderingContext.draw(Primitive.TRIANGLE, 0, baked);
// cloudsMesh.drawElementsTriangles(baked);
}
Also used : Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Aggregations

Shader (io.xol.chunkstories.api.rendering.shader.Shader)27 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)9 Vector4f (org.joml.Vector4f)5 ByteBuffer (java.nio.ByteBuffer)4 Matrix4f (org.joml.Matrix4f)4 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)3 GameWindow (io.xol.chunkstories.api.rendering.GameWindow)3 Vector3f (org.joml.Vector3f)3 Location (io.xol.chunkstories.api.Location)2 Player (io.xol.chunkstories.api.player.Player)2 Voxel (io.xol.chunkstories.api.voxel.Voxel)2 CellData (io.xol.chunkstories.api.world.cell.CellData)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 Layer (io.xol.chunkstories.api.gui.Layer)1 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)1 RenderPass (io.xol.chunkstories.api.rendering.pass.RenderPass)1 DummyCell (io.xol.chunkstories.api.world.cell.DummyCell)1