Search in sources :

Example 1 with RenderPasses

use of io.xol.chunkstories.api.rendering.pass.RenderPasses in project chunkstories-core by Hugobros3.

the class RenderingEventsListener method onRenderPassesInitialization.

@EventHandler
public void onRenderPassesInitialization(RenderPassesInitEvent event) {
    RenderPasses pipeline = event.getPasses();
    WorldRenderer worldRenderer = pipeline.getWorldRenderer();
    SkyRenderer sky = new DefaultSkyRenderer(event.getPasses().getRenderingInterface().getWorldRenderer());
    worldRenderer.setSkyRenderer(sky);
    SkyPass skyPass = new SkyPass(pipeline, "sky", worldRenderer.getSkyRenderer());
    pipeline.registerRenderPass(skyPass);
    // gbuffer uses the zBuffer and outputs albedo/normal/materials
    GBuffersOpaquePass gBuffers = new GBuffersOpaquePass(pipeline, "gBuffers", new String[] { "sky.zBuffer!" }, new String[] { "albedoBuffer", "normalBuffer", "voxelLightBuffer", "specularityBuffer", "materialsBuffer" /*"zBuffer"*/
    });
    pipeline.registerRenderPass(gBuffers);
    DecalsPass decals = new DecalsPass(pipeline, "decals", new String[] { "gBuffers.albedoBuffer!", "gBuffers.zBuffer" }, new String[] {});
    pipeline.registerRenderPass(decals);
    WaterPass waterPass = new WaterPass(pipeline, "water", new String[] { "decals.albedoBuffer", "gBuffers.normalBuffer", "gBuffers.voxelLightBuffer", "gBuffers.specularityBuffer", "gBuffers.materialsBuffer", "gBuffers.zBuffer" }, new String[] {/*"albedoBuffer", "normalBuffer", "voxelLightBuffer", "specularityBuffer", "materialsBuffer", "zBuffer"*/
    }, sky);
    pipeline.registerRenderPass(waterPass);
    boolean shadows = client.getConfiguration().getBooleanOption("client.rendering.shadows");
    // a shadowmap pass requires no previous buffer and just outputs a shadowmap
    ShadowPass sunShadowPass = null;
    if (shadows) {
        sunShadowPass = new ShadowPass(pipeline, "shadowsSun", new String[] {}, new String[] { "shadowMap" }, sky);
        // note we could generalize the shadowmappass to not only the sun but also the moon, point and spotlights
        pipeline.registerRenderPass(sunShadowPass);
    }
    // aka shadows_apply in the current code, it takes the gbuffers and applies the shadowmapping to them, then outputs to the shaded pixels buffers already filled with the far terrain pixels
    ApplySunlightPass applySunlight = new ApplySunlightPass(pipeline, "applySunlight", new String[] { "water.albedoBuffer", "water.normalBuffer", "water.voxelLightBuffer", "water.specularityBuffer", "water.materialsBuffer", "water.zBuffer", "sky.shadedBuffer!" }, new String[] {/*"shadedBuffer"*/
    }, sunShadowPass);
    if (shadows)
        applySunlight.requires.add("shadowsSun.shadowMap");
    pipeline.registerRenderPass(applySunlight);
    boolean gi = client.getConfiguration().getBooleanOption("client.rendering.globalIllumination") && shadows;
    if (gi) {
        GiPass giPass = new GiPass(pipeline, "gi", new String[] { "water.albedoBuffer", "water.normalBuffer", "water.zBuffer" }, new String[] { "giBuffer" }, sunShadowPass);
        pipeline.registerRenderPass(giPass);
    }
    DefferedLightsPass lightsPass = new DefferedLightsPass(pipeline, "lights", new String[] { "applySunlight.shadedBuffer!", "water.albedoBuffer", "water.normalBuffer", "water.zBuffer" }, new String[] {});
    pipeline.registerRenderPass(lightsPass);
    // far terrain needs the shaded buffer from sky and outputs it, as well with a zbuffer
    FarTerrainPass farTerrain = new FarTerrainPass(pipeline, "farTerrain", new String[] { "lights.shadedBuffer!", "gBuffers.specularityBuffer!", "gBuffers.zBuffer!" }, new String[] {/*"shadedBuffer", "zBuffer", "specularityBuffer"*/
    });
    pipeline.registerRenderPass(farTerrain);
    BloomPass bloomPass = new BloomPass(pipeline, "bloom", new String[] { "farTerrain.shadedBuffer" }, new String[] { "bloomBuffer" });
    pipeline.registerRenderPass(bloomPass);
    ForwardPass forward = new ForwardPass(pipeline, "forward", new String[] { "farTerrain.shadedBuffer!", "farTerrain.zBuffer!" }, new String[] {});
    pipeline.registerRenderPass(forward);
    ReflectionsPass reflections = new ReflectionsPass(pipeline, "reflections", new String[] { "farTerrain.shadedBuffer", "gBuffers.normalBuffer", "gBuffers.voxelLightBuffer", "farTerrain.specularityBuffer", "farTerrain.zBuffer" }, new String[] { "reflectionsBuffer" }, sky);
    pipeline.registerRenderPass(reflections);
    // the pass declared as 'final' is considered the last one and it's outputs are shown to the screen
    PostProcessPass postprocess = new PostProcessPass(pipeline, "final", new String[] { "water.albedoBuffer", "forward.shadedBuffer", "farTerrain.zBuffer", "bloom.bloomBuffer", "reflections.reflectionsBuffer", "farTerrain.specularityBuffer" }, sunShadowPass);
    if (gi)
        postprocess.requires.add("gi.giBuffer");
    pipeline.registerRenderPass(postprocess);
}
Also used : WaterPass(io.xol.chunkstories.core.rendering.passes.WaterPass) ForwardPass(io.xol.chunkstories.core.rendering.passes.ForwardPass) GiPass(io.xol.chunkstories.core.rendering.passes.gi.GiPass) DefaultSkyRenderer(io.xol.chunkstories.core.rendering.sky.DefaultSkyRenderer) SkyRenderer(io.xol.chunkstories.api.rendering.world.SkyRenderer) FarTerrainPass(io.xol.chunkstories.core.rendering.passes.FarTerrainPass) ReflectionsPass(io.xol.chunkstories.core.rendering.passes.ReflectionsPass) ShadowPass(io.xol.chunkstories.core.rendering.passes.ShadowPass) RenderPasses(io.xol.chunkstories.api.rendering.pass.RenderPasses) WorldRenderer(io.xol.chunkstories.api.rendering.world.WorldRenderer) DecalsPass(io.xol.chunkstories.core.rendering.passes.DecalsPass) ApplySunlightPass(io.xol.chunkstories.core.rendering.passes.ApplySunlightPass) PostProcessPass(io.xol.chunkstories.core.rendering.passes.PostProcessPass) BloomPass(io.xol.chunkstories.core.rendering.passes.BloomPass) DefaultSkyRenderer(io.xol.chunkstories.core.rendering.sky.DefaultSkyRenderer) GBuffersOpaquePass(io.xol.chunkstories.core.rendering.passes.GBuffersOpaquePass) SkyPass(io.xol.chunkstories.core.rendering.passes.SkyPass) DefferedLightsPass(io.xol.chunkstories.core.rendering.passes.DefferedLightsPass) EventHandler(io.xol.chunkstories.api.events.EventHandler)

Aggregations

EventHandler (io.xol.chunkstories.api.events.EventHandler)1 RenderPasses (io.xol.chunkstories.api.rendering.pass.RenderPasses)1 SkyRenderer (io.xol.chunkstories.api.rendering.world.SkyRenderer)1 WorldRenderer (io.xol.chunkstories.api.rendering.world.WorldRenderer)1 ApplySunlightPass (io.xol.chunkstories.core.rendering.passes.ApplySunlightPass)1 BloomPass (io.xol.chunkstories.core.rendering.passes.BloomPass)1 DecalsPass (io.xol.chunkstories.core.rendering.passes.DecalsPass)1 DefferedLightsPass (io.xol.chunkstories.core.rendering.passes.DefferedLightsPass)1 FarTerrainPass (io.xol.chunkstories.core.rendering.passes.FarTerrainPass)1 ForwardPass (io.xol.chunkstories.core.rendering.passes.ForwardPass)1 GBuffersOpaquePass (io.xol.chunkstories.core.rendering.passes.GBuffersOpaquePass)1 PostProcessPass (io.xol.chunkstories.core.rendering.passes.PostProcessPass)1 ReflectionsPass (io.xol.chunkstories.core.rendering.passes.ReflectionsPass)1 ShadowPass (io.xol.chunkstories.core.rendering.passes.ShadowPass)1 SkyPass (io.xol.chunkstories.core.rendering.passes.SkyPass)1 WaterPass (io.xol.chunkstories.core.rendering.passes.WaterPass)1 GiPass (io.xol.chunkstories.core.rendering.passes.gi.GiPass)1 DefaultSkyRenderer (io.xol.chunkstories.core.rendering.sky.DefaultSkyRenderer)1