Search in sources :

Example 6 with RenderPass

use of io.xol.chunkstories.api.rendering.pass.RenderPass in project chunkstories by Hugobros3.

the class RenderingGraph method resolveInputs.

/**
 * Passes the output buffers of the early passes to the inputs of the later ones
 */
private void resolveInputs() {
    if (executionOrder != null) {
        for (int i = 0; i < executionOrder.length; i++) {
            RenderPass pass = executionOrder[i];
            Map<String, Texture> inputs = new HashMap<>();
            // For each buffer we depend on
            for (String requirement : pass.requires) {
                // System.out.println("resolving requirement "+requirement+" for pass "+pass.name);
                // parse pass and buffer name
                String[] s = requirement.split("\\.");
                String requiredPassName = s[0];
                String requiredBufferName = s.length > 0 ? s[1] : "invalid";
                boolean forward = requiredBufferName.endsWith("!");
                requiredBufferName = requiredBufferName.replace("!", "");
                // System.out.println(requiredPassName+"."+requiredBufferName+" forward:"+forward);
                RenderPass requiredPass = this.getRenderPass(requiredPassName);
                // assumes all previous passes were resolved ok
                Texture requiredBuffer = requiredPass == null ? null : requiredPass.resolvedOutputs.get(requiredBufferName);
                if (forward) {
                    // System.out.println("auto-forwarding buffer:"+requiredBufferName);
                    pass.resolvedOutputs.put(requiredBufferName, requiredBuffer);
                }
                // return it the buffer he asked under multiple names
                inputs.put(requiredPassName + "." + requiredBufferName, requiredBuffer);
                inputs.put(requiredBufferName, requiredBuffer);
                // may alias !
                inputs.put(requirement, requiredBuffer);
            }
            // notify the pass we found it's buffers
            pass.resolvedInputs.clear();
            pass.resolvedInputs.putAll(inputs);
            pass.onResolvedInputs();
        }
    }
}
Also used : HashMap(java.util.HashMap) RenderPass(io.xol.chunkstories.api.rendering.pass.RenderPass) Texture(io.xol.chunkstories.api.rendering.textures.Texture)

Example 7 with RenderPass

use of io.xol.chunkstories.api.rendering.pass.RenderPass in project chunkstories by Hugobros3.

the class RenderingGraph method recursivelyAddNodes.

private Node recursivelyAddNodes(RenderPass pass, Node parent) throws CycleException {
    Node node = nodes.get(pass.name);
    if (node == null) {
        node = new Node();
        node.pass = pass;
        nodes.put(pass.name, node);
    }
    // Ensure we can't find this node by going up
    cycleCheck(node, parent);
    node.parents.add(parent);
    for (String requirement : pass.requires) {
        String passName = requirement.indexOf(".") == -1 ? "invalid" : requirement.split("\\.")[0];
        // System.out.println("this requires pass: "+passName + " (from "+requirement+")");
        RenderPass requiredPass = getRenderPass(passName);
        if (requiredPass != null) {
            Node childNode = recursivelyAddNodes(requiredPass, node);
            node.children.add(childNode);
        } else
            logger.error("pass" + passName + " missing");
    }
    return node;
}
Also used : RenderPass(io.xol.chunkstories.api.rendering.pass.RenderPass)

Example 8 with RenderPass

use of io.xol.chunkstories.api.rendering.pass.RenderPass 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

RenderPass (io.xol.chunkstories.api.rendering.pass.RenderPass)8 RenderPassesInitEvent (io.xol.chunkstories.api.events.rendering.RenderPassesInitEvent)1 Shader (io.xol.chunkstories.api.rendering.shader.Shader)1 Texture (io.xol.chunkstories.api.rendering.textures.Texture)1 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)1 ShadingType (io.xol.chunkstories.api.rendering.world.chunk.ChunkMeshDataSubtypes.ShadingType)1 GiPass (io.xol.chunkstories.core.rendering.passes.gi.GiPass)1 RenderLodLevel (io.xol.chunkstories.renderer.chunks.ChunkRenderDataHolder.RenderLodLevel)1 ClientChunk (io.xol.chunkstories.world.chunk.ClientChunk)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Matrix4f (org.joml.Matrix4f)1 Vector3d (org.joml.Vector3d)1 Vector3f (org.joml.Vector3f)1