Search in sources :

Example 11 with PipelineRenderingContext

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

the class RenderSizePipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final Vector2 size = new Vector2();
    final DefaultFieldOutput<Vector2> sizeOutput = new DefaultFieldOutput<>(PipelineFieldType.Vector2);
    sizeOutput.setValue(size);
    final DefaultFieldOutput<Float> widthOutput = new DefaultFieldOutput<>(PipelineFieldType.Float);
    final DefaultFieldOutput<Float> heightOutput = new DefaultFieldOutput<>(PipelineFieldType.Float);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    result.put("size", sizeOutput);
    result.put("width", widthOutput);
    result.put("height", heightOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            int width = pipelineRenderingContext.getRenderWidth();
            int height = pipelineRenderingContext.getRenderHeight();
            size.set(width, height);
            widthOutput.setValue(width * 1f);
            heightOutput.setValue(height * 1f);
        }
    };
}
Also used : PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) Vector2(com.badlogic.gdx.math.Vector2) ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode)

Example 12 with PipelineRenderingContext

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

the class MultiplyPipelineNodeProducer method createNode.

@Override
public PipelineNode createNode(JsonValue data, ObjectMap<String, Array<String>> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = outputTypes.get("output");
    final Object resultValue = createDefaultValue(resultType);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(resultType);
    result.put("output", resultOutput);
    return new AbstractPipelineNode(result) {

        private Array<FieldOutput<?>> inputs;

        @Override
        public void setInputs(ObjectMap<String, Array<FieldOutput<?>>> inputs) {
            this.inputs = inputs.get("inputs");
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            Object returnValue = resetDefaultValue(resultType, resultValue);
            for (FieldOutput<?> input : inputs) {
                Object value = input.getValue();
                returnValue = multiply(returnValue, value);
            }
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : Array(com.badlogic.gdx.utils.Array) AbstractPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.AbstractPipelineNode) ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)

Example 13 with PipelineRenderingContext

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

the class BloomPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final ShaderProgram brightnessFilterPassProgram = new ShaderProgram(Gdx.files.classpath("shader/viewToScreenCoords.vert"), Gdx.files.classpath("shader/brightnessFilter.frag"));
    if (!brightnessFilterPassProgram.isCompiled())
        throw new IllegalArgumentException("Error compiling shader: " + brightnessFilterPassProgram.getLog());
    final ShaderProgram gaussianBlurPassProgram = new ShaderProgram(Gdx.files.classpath("shader/viewToScreenCoords.vert"), Gdx.files.classpath("shader/gaussianBlur.frag"));
    if (!gaussianBlurPassProgram.isCompiled())
        throw new IllegalArgumentException("Error compiling shader: " + gaussianBlurPassProgram.getLog());
    final ShaderProgram bloomSumProgram = new ShaderProgram(Gdx.files.classpath("shader/viewToScreenCoords.vert"), Gdx.files.classpath("shader/bloomSum.frag"));
    if (!bloomSumProgram.isCompiled())
        throw new IllegalArgumentException("Error compiling shader: " + bloomSumProgram.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) {
            PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
            PipelineNode.FieldOutput<Boolean> processorEnabled = (PipelineNode.FieldOutput<Boolean>) inputs.get("enabled");
            PipelineNode.FieldOutput<Float> minimalBrightness = (PipelineNode.FieldOutput<Float>) inputs.get("minimalBrightness");
            PipelineNode.FieldOutput<Float> bloomRadius = (PipelineNode.FieldOutput<Float>) inputs.get("bloomRadius");
            PipelineNode.FieldOutput<Float> bloomStrength = (PipelineNode.FieldOutput<Float>) inputs.get("bloomStrength");
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            float bloomStrengthValue = bloomStrength != null ? bloomStrength.getValue() : 0f;
            int bloomRadiusValue = MathUtils.round(bloomRadius != null ? bloomRadius.getValue() : 1f);
            if (enabled && bloomStrengthValue > 0 && bloomRadiusValue > 0) {
                float minimalBrightnessValue = minimalBrightness != null ? minimalBrightness.getValue() : 0.7f;
                RenderPipelineBuffer originalBuffer = renderPipeline.getDefaultBuffer();
                OpenGLContext renderContext = pipelineRenderingContext.getRenderContext();
                renderContext.setDepthTest(0);
                renderContext.setDepthMask(false);
                renderContext.setBlending(false, 0, 0);
                renderContext.setCullFace(GL20.GL_BACK);
                RenderPipelineBuffer brightnessFilterBuffer = runBrightnessPass(minimalBrightnessValue, renderPipeline, originalBuffer, brightnessFilterPassProgram, pipelineRenderingContext.getRenderContext(), fullScreenRender);
                RenderPipelineBuffer gaussianBlur = applyGaussianBlur(bloomRadiusValue, renderPipeline, brightnessFilterBuffer, gaussianBlurPassProgram, pipelineRenderingContext.getRenderContext(), fullScreenRender);
                renderPipeline.returnFrameBuffer(brightnessFilterBuffer);
                RenderPipelineBuffer result = applyTheBloom(bloomStrengthValue, renderPipeline, originalBuffer, gaussianBlur, bloomSumProgram, pipelineRenderingContext.getRenderContext(), fullScreenRender);
                renderPipeline.returnFrameBuffer(gaussianBlur);
                renderPipeline.swapColorTextures(originalBuffer, result);
                renderPipeline.returnFrameBuffer(result);
            }
            pipelineOutput.setValue(renderPipeline);
        }

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

Example 14 with PipelineRenderingContext

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

the class CrossProductPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final Vector3 tmpVector = new Vector3();
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(PipelineFieldType.Vector3);
    result.put("output", resultOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            FieldOutput<?> aFunction = inputs.get("a");
            FieldOutput<?> bFunction = inputs.get("b");
            Vector3 a = (Vector3) aFunction.getValue();
            Vector3 b = (Vector3) bFunction.getValue();
            Vector3 returnValue = tmpVector.set(a).crs(b);
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode) Vector3(com.badlogic.gdx.math.Vector3) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)

Example 15 with PipelineRenderingContext

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

the class NormalizePipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = inputTypes.get("input");
    final Object resultValue = createResult(resultType);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(resultType);
    result.put("output", resultOutput);
    return new SingleInputsPipelineNode(result) {

        private FieldOutput<?> aFunction;

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            aFunction = inputs.get("input");
            Object a = aFunction.getValue();
            Object returnValue;
            if (a instanceof Float) {
                returnValue = Math.signum((float) a);
            } else if (a instanceof Vector2) {
                returnValue = ((Vector2) resultValue).set((Vector2) a).nor();
            } else if (a instanceof Vector3) {
                returnValue = ((Vector3) resultValue).set((Vector3) a).nor();
            } else {
                Color aColor = (Color) a;
                float length = (float) Math.sqrt(aColor.r * aColor.r + aColor.g * aColor.g + aColor.b * aColor.b + aColor.a * aColor.a);
                returnValue = ((Color) resultValue).set(aColor.r / length, aColor.b / length, aColor.b / length, aColor.a / length);
            }
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : Color(com.badlogic.gdx.graphics.Color) Vector3(com.badlogic.gdx.math.Vector3) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Vector2(com.badlogic.gdx.math.Vector2) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode)

Aggregations

PipelineRenderingContext (com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext)29 ObjectMap (com.badlogic.gdx.utils.ObjectMap)26 RenderPipeline (com.gempukku.libgdx.graph.pipeline.RenderPipeline)14 RenderPipelineBuffer (com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)13 Vector2 (com.badlogic.gdx.math.Vector2)12 DefaultFieldOutput (com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)12 SingleInputsPipelineNode (com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode)10 Camera (com.badlogic.gdx.graphics.Camera)8 FullScreenRender (com.gempukku.libgdx.graph.pipeline.producer.FullScreenRender)8 Vector3 (com.badlogic.gdx.math.Vector3)6 Array (com.badlogic.gdx.utils.Array)6 Color (com.badlogic.gdx.graphics.Color)5 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)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 RenderCallback (com.gempukku.libgdx.graph.plugin.callback.RenderCallback)4 TimeProvider (com.gempukku.libgdx.graph.time.TimeProvider)4 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)3 Map (com.badlogic.gdx.maps.Map)3