Search in sources :

Example 1 with GraphParticleEffectImpl

use of com.gempukku.libgdx.graph.plugin.particles.impl.GraphParticleEffectImpl in project gdx-graph by MarcinSc.

the class ParticlesShaderRendererPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final ShaderContextImpl shaderContext = new ShaderContextImpl(pluginPrivateDataSource);
    final Array<ParticlesGraphShader> particleShaders = 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 FullScreenRender fullScreenRender;

        private TimeProvider timeProvider;

        private GraphParticleEffectsImpl particleEffects;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            fullScreenRender = pipelineDataProvider.getFullScreenRender();
            timeProvider = pipelineDataProvider.getTimeProvider();
            particleEffects = pipelineDataProvider.getPrivatePluginData(GraphParticleEffectsImpl.class);
            for (JsonValue shaderDefinition : shaderDefinitions) {
                String tag = shaderDefinition.getString("tag");
                JsonValue shaderGraph = shaderDefinition.get("shader");
                Gdx.app.debug("Shader", "Building shader with tag: " + tag);
                final ParticlesGraphShader graphShader = GraphLoader.loadGraph(shaderGraph, new ParticlesShaderLoaderCallback(tag, pipelineDataProvider.getWhitePixel().texture, configurations), PropertyLocation.Uniform);
                particleShaders.add(graphShader);
            }
            for (ParticlesGraphShader particleShader : particleShaders) {
                particleEffects.registerEffect(particleShader.getTag(), particleShader);
            }
        }

        private boolean usesDepth() {
            for (ParticlesGraphShader particleShader : particleShaders) {
                if (particleShader.isUsingDepthTexture()) {
                    return true;
                }
            }
            return false;
        }

        @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 = usesDepth();
                boolean needsSceneColor = false;
                for (ParticlesGraphShader particleShader : particleShaders) {
                    if (particleShader.isUsingColorTexture()) {
                        needsSceneColor = true;
                        break;
                    }
                }
                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 (ParticlesGraphShader particleShader : particleShaders) {
                    String tag = particleShader.getTag();
                    if (particleEffects.hasEffects(tag)) {
                        shaderContext.setGlobalPropertyContainer(particleEffects.getGlobalPropertyContainer(tag));
                        particleShader.begin(shaderContext, pipelineRenderingContext.getRenderContext());
                        for (GraphParticleEffectImpl particleEffect : particleEffects.getParticleEffects(tag)) {
                            if (particleEffect.getRenderableParticleEffect().isRendered(shaderContext.getCamera(), tag)) {
                                shaderContext.setLocalPropertyContainer(particleEffect.getPropertyContainer());
                                particleEffect.render(particleShader, shaderContext);
                            }
                        }
                        particleShader.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 (ParticlesGraphShader particleShader : particleShaders) {
                particleShader.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) GraphParticleEffectImpl(com.gempukku.libgdx.graph.plugin.particles.impl.GraphParticleEffectImpl) GraphParticleEffectsImpl(com.gempukku.libgdx.graph.plugin.particles.impl.GraphParticleEffectsImpl) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Example 2 with GraphParticleEffectImpl

use of com.gempukku.libgdx.graph.plugin.particles.impl.GraphParticleEffectImpl in project gdx-graph by MarcinSc.

the class ParticlesShaderPreviewWidget method createModel.

private void createModel() {
    renderableParticleEffect = new CommonPropertiesRenderableParticleEffect(createGenerator());
    particleEffect = new GraphParticleEffectImpl("tag", new ParticleEffectConfiguration(null, graphShader.getProperties(), graphShader.getMaxNumberOfParticles()), renderableParticleEffect, new QuadParticleModel(), false);
    if (running)
        particleEffect.start();
}
Also used : ParticleEffectConfiguration(com.gempukku.libgdx.graph.plugin.particles.ParticleEffectConfiguration) GraphParticleEffectImpl(com.gempukku.libgdx.graph.plugin.particles.impl.GraphParticleEffectImpl) QuadParticleModel(com.gempukku.libgdx.graph.plugin.particles.model.QuadParticleModel)

Aggregations

GraphParticleEffectImpl (com.gempukku.libgdx.graph.plugin.particles.impl.GraphParticleEffectImpl)2 Camera (com.badlogic.gdx.graphics.Camera)1 Array (com.badlogic.gdx.utils.Array)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 ObjectMap (com.badlogic.gdx.utils.ObjectMap)1 RenderPipeline (com.gempukku.libgdx.graph.pipeline.RenderPipeline)1 RenderPipelineBuffer (com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)1 FullScreenRender (com.gempukku.libgdx.graph.pipeline.producer.FullScreenRender)1 PipelineRenderingContext (com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext)1 ShaderContextImpl (com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.ShaderContextImpl)1 ParticleEffectConfiguration (com.gempukku.libgdx.graph.plugin.particles.ParticleEffectConfiguration)1 GraphParticleEffectsImpl (com.gempukku.libgdx.graph.plugin.particles.impl.GraphParticleEffectsImpl)1 QuadParticleModel (com.gempukku.libgdx.graph.plugin.particles.model.QuadParticleModel)1 TimeProvider (com.gempukku.libgdx.graph.time.TimeProvider)1