Search in sources :

Example 16 with RenderPipelineBuffer

use of com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer in project gdx-graph by MarcinSc.

the class GammaCorrectionPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final ShaderProgram shaderProgram = new ShaderProgram(Gdx.files.classpath("shader/viewToScreenCoords.vert"), Gdx.files.classpath("shader/gamma.frag"));
    if (!shaderProgram.isCompiled())
        throw new IllegalArgumentException("Error compiling shader: " + shaderProgram.getLog());
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput<RenderPipeline> pipelineOutput = new DefaultFieldOutput<>(PipelineFieldType.RenderPipeline);
    result.put("output", pipelineOutput);
    return new SingleInputsPipelineNode(result) {

        private FullScreenRender fullScreenRender;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            fullScreenRender = pipelineDataProvider.getFullScreenRender();
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            final PipelineNode.FieldOutput<Boolean> processorEnabled = (PipelineNode.FieldOutput<Boolean>) inputs.get("enabled");
            PipelineNode.FieldOutput<Float> gammaInput = (PipelineNode.FieldOutput<Float>) inputs.get("gamma");
            final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            float gamma = gammaInput != null ? gammaInput.getValue() : 0f;
            if (enabled && gamma != 1) {
                RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
                RenderPipelineBuffer newBuffer = renderPipeline.getNewFrameBuffer(currentBuffer, Color.BLACK);
                OpenGLContext renderContext = pipelineRenderingContext.getRenderContext();
                renderContext.setDepthTest(0);
                renderContext.setDepthMask(false);
                renderContext.setBlending(false, 0, 0);
                renderContext.setCullFace(GL20.GL_BACK);
                newBuffer.beginColor();
                shaderProgram.bind();
                shaderProgram.setUniformi("u_sourceTexture", renderContext.bindTexture(currentBuffer.getColorBufferTexture()));
                shaderProgram.setUniformf("u_gamma", gamma);
                fullScreenRender.renderFullScreen(shaderProgram);
                newBuffer.endColor();
                renderPipeline.swapColorTextures(currentBuffer, newBuffer);
                renderPipeline.returnFrameBuffer(newBuffer);
            }
            pipelineOutput.setValue(renderPipeline);
        }

        @Override
        public void dispose() {
            shaderProgram.dispose();
        }
    };
}
Also used : FullScreenRender(com.gempukku.libgdx.graph.pipeline.producer.FullScreenRender) RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) OpenGLContext(com.gempukku.libgdx.graph.libgdx.context.OpenGLContext) ObjectMap(com.badlogic.gdx.utils.ObjectMap) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Example 17 with RenderPipelineBuffer

use of com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer in project gdx-graph by MarcinSc.

the class StartPipelineNode method executeNode.

@Override
public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
    FieldOutput<Vector2> sizeInput = (FieldOutput<Vector2>) inputs.get("size");
    FieldOutput<Color> backgroundInput = (FieldOutput<Color>) inputs.get("background");
    float bufferX = (sizeInput != null) ? sizeInput.getValue().x : pipelineRenderingContext.getRenderWidth();
    float bufferY = (sizeInput != null) ? sizeInput.getValue().y : pipelineRenderingContext.getRenderHeight();
    Color backgroundColor = (backgroundInput != null) ? backgroundInput.getValue() : Color.BLACK;
    int width = MathUtils.round(bufferX);
    int height = MathUtils.round(bufferY);
    RenderPipelineBuffer frameBuffer = renderPipeline.initializeDefaultBuffer(width, height, Pixmap.Format.RGB888, backgroundColor);
    // Dummy call to make sure frame buffer is drawn
    frameBuffer.beginColor();
    frameBuffer.endColor();
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) Color(com.badlogic.gdx.graphics.Color)

Example 18 with RenderPipelineBuffer

use of com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer in project gdx-graph by MarcinSc.

the class BloomPipelineNodeProducer method applyGaussianBlur.

private RenderPipelineBuffer applyGaussianBlur(int bloomRadius, RenderPipeline renderPipeline, RenderPipelineBuffer sourceBuffer, ShaderProgram blurProgram, OpenGLContext renderContext, FullScreenRender fullScreenRender) {
    float[] kernel = GaussianBlurKernel.getKernel(MathUtils.round(bloomRadius));
    blurProgram.bind();
    blurProgram.setUniformi("u_blurRadius", bloomRadius);
    blurProgram.setUniformf("u_pixelSize", 1f / sourceBuffer.getWidth(), 1f / sourceBuffer.getHeight());
    blurProgram.setUniform1fv("u_kernel", kernel, 0, kernel.length);
    blurProgram.setUniformi("u_vertical", 1);
    RenderPipelineBuffer tempBuffer = executeBlur(blurProgram, renderPipeline, sourceBuffer, renderContext, fullScreenRender);
    blurProgram.setUniformi("u_vertical", 0);
    RenderPipelineBuffer blurredBuffer = executeBlur(blurProgram, renderPipeline, tempBuffer, renderContext, fullScreenRender);
    renderPipeline.returnFrameBuffer(tempBuffer);
    return blurredBuffer;
}
Also used : RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)

Example 19 with RenderPipelineBuffer

use of com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer in project gdx-graph by MarcinSc.

the class BloomPipelineNodeProducer method applyTheBloom.

private RenderPipelineBuffer applyTheBloom(float bloomStrength, RenderPipeline renderPipeline, RenderPipelineBuffer sourceBuffer, RenderPipelineBuffer gaussianBlur, ShaderProgram bloomSumProgram, OpenGLContext renderContext, FullScreenRender fullScreenRender) {
    RenderPipelineBuffer result = renderPipeline.getNewFrameBuffer(sourceBuffer, Color.BLACK);
    result.beginColor();
    bloomSumProgram.bind();
    bloomSumProgram.setUniformi("u_brightnessTexture", renderContext.bindTexture(gaussianBlur.getColorBufferTexture()));
    bloomSumProgram.setUniformi("u_sourceTexture", renderContext.bindTexture(sourceBuffer.getColorBufferTexture()));
    bloomSumProgram.setUniformf("u_bloomStrength", bloomStrength);
    fullScreenRender.renderFullScreen(bloomSumProgram);
    result.endColor();
    return result;
}
Also used : RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)

Example 20 with RenderPipelineBuffer

use of com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer in project gdx-graph by MarcinSc.

the class ScreenShaderRendererPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final ShaderContextImpl shaderContext = new ShaderContextImpl(pluginPrivateDataSource);
    final Array<ScreenGraphShader> shaderArray = new Array<>();
    final JsonValue shaderDefinitions = data.get("shaders");
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput<RenderPipeline> output = new DefaultFieldOutput<>(PipelineFieldType.RenderPipeline);
    result.put("output", output);
    return new SingleInputsPipelineNode(result) {

        private TimeProvider timeProvider;

        private FullScreenRender fullScreenRender;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            fullScreenRender = pipelineDataProvider.getFullScreenRender();
            timeProvider = pipelineDataProvider.getTimeProvider();
            GraphScreenShadersImpl graphScreenShaders = pipelineDataProvider.getPrivatePluginData(GraphScreenShadersImpl.class);
            for (JsonValue shaderDefinition : shaderDefinitions) {
                JsonValue shaderGraph = shaderDefinition.get("shader");
                String tag = shaderDefinition.getString("tag");
                Gdx.app.debug("Shader", "Building shader with tag: " + tag);
                final ScreenGraphShader shader = GraphLoader.loadGraph(shaderGraph, new ScreenShaderLoaderCallback(tag, pipelineDataProvider.getWhitePixel().texture, configurations), PropertyLocation.Global_Uniform);
                shaderArray.add(shader);
            }
            for (ScreenGraphShader shader : shaderArray) {
                graphScreenShaders.registerTag(shader.getTag(), shader);
            }
        }

        private boolean needsDepth() {
            for (ScreenGraphShader shader : shaderArray) {
                if (shader.isUsingDepthTexture())
                    return true;
            }
            return false;
        }

        private boolean isRequiringSceneColor() {
            for (ScreenGraphShader shader : shaderArray) {
                if (shader.isUsingColorTexture())
                    return true;
            }
            return false;
        }

        @Override
        public void processPipelineRequirements(PipelineRequirements pipelineRequirements) {
            if (needsDepth())
                pipelineRequirements.setRequiringDepthTexture();
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            final PipelineNode.FieldOutput<Boolean> processorEnabled = (PipelineNode.FieldOutput<Boolean>) inputs.get("enabled");
            final PipelineNode.FieldOutput<Camera> cameraInput = (PipelineNode.FieldOutput<Camera>) inputs.get("camera");
            final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            if (enabled) {
                boolean usesDepth = needsDepth();
                boolean needsSceneColor = isRequiringSceneColor();
                RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
                if (usesDepth) {
                    renderPipeline.enrichWithDepthBuffer(currentBuffer);
                }
                if (cameraInput != null) {
                    Camera camera = cameraInput.getValue();
                    shaderContext.setCamera(camera);
                }
                shaderContext.setTimeProvider(timeProvider);
                shaderContext.setRenderWidth(currentBuffer.getWidth());
                shaderContext.setRenderHeight(currentBuffer.getHeight());
                RenderPipelineBuffer sceneColorBuffer = null;
                if (needsSceneColor) {
                    sceneColorBuffer = setupColorTexture(renderPipeline, currentBuffer, pipelineRenderingContext);
                }
                currentBuffer.beginColor();
                for (ScreenGraphShader shader : shaderArray) {
                    shaderContext.setGlobalPropertyContainer(shader.getPropertyContainer());
                    shader.begin(shaderContext, pipelineRenderingContext.getRenderContext());
                    shader.render(shaderContext, fullScreenRender);
                    shader.end();
                }
                currentBuffer.endColor();
                if (sceneColorBuffer != null)
                    renderPipeline.returnFrameBuffer(sceneColorBuffer);
            }
            output.setValue(renderPipeline);
        }

        private RenderPipelineBuffer setupColorTexture(final RenderPipeline renderPipeline, final RenderPipelineBuffer currentBuffer, PipelineRenderingContext pipelineRenderingContext) {
            RenderPipelineBuffer sceneColorBuffer = renderPipeline.getNewFrameBuffer(currentBuffer, Color.BLACK);
            shaderContext.setColorTexture(sceneColorBuffer.getColorBufferTexture());
            renderPipeline.drawTexture(currentBuffer, sceneColorBuffer, pipelineRenderingContext, fullScreenRender);
            return sceneColorBuffer;
        }

        @Override
        public void dispose() {
            for (ScreenGraphShader shader : shaderArray) {
                shader.dispose();
            }
        }
    };
}
Also used : ShaderContextImpl(com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.ShaderContextImpl) FullScreenRender(com.gempukku.libgdx.graph.pipeline.producer.FullScreenRender) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Camera(com.badlogic.gdx.graphics.Camera) TimeProvider(com.gempukku.libgdx.graph.time.TimeProvider) RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) JsonValue(com.badlogic.gdx.utils.JsonValue) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) Array(com.badlogic.gdx.utils.Array) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Aggregations

RenderPipelineBuffer (com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)21 ObjectMap (com.badlogic.gdx.utils.ObjectMap)14 RenderPipeline (com.gempukku.libgdx.graph.pipeline.RenderPipeline)13 PipelineRenderingContext (com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext)13 Camera (com.badlogic.gdx.graphics.Camera)8 FullScreenRender (com.gempukku.libgdx.graph.pipeline.producer.FullScreenRender)8 Array (com.badlogic.gdx.utils.Array)5 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)4 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)4 Vector2 (com.badlogic.gdx.math.Vector2)4 JsonValue (com.badlogic.gdx.utils.JsonValue)4 OpenGLContext (com.gempukku.libgdx.graph.libgdx.context.OpenGLContext)4 ShaderContextImpl (com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.ShaderContextImpl)4 TimeProvider (com.gempukku.libgdx.graph.time.TimeProvider)4 Map (com.badlogic.gdx.maps.Map)3 MapRenderer (com.badlogic.gdx.maps.MapRenderer)3 MapsPluginPrivateData (com.gempukku.libgdx.graph.plugin.maps.MapsPluginPrivateData)3 RenderOrder (com.gempukku.libgdx.graph.pipeline.RenderOrder)2 Lighting3DEnvironment (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment)2 GraphModelsImpl (com.gempukku.libgdx.graph.plugin.models.impl.GraphModelsImpl)2