use of com.gempukku.libgdx.graph.pipeline.RenderPipeline in project gdx-graph by MarcinSc.
the class PipelineRendererNodeProducer method createNodeForSingleInputs.
@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
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 Vector2 tmpVector = new Vector2();
@Override
public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
fullScreenRender = pipelineDataProvider.getFullScreenRender();
}
@Override
public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
RenderPipeline canvasPipeline = (RenderPipeline) inputs.get("input").getValue();
RenderPipeline paintPipeline = (RenderPipeline) inputs.get("pipeline").getValue();
Vector2 position = (Vector2) inputs.get("position").getValue();
final PipelineNode.FieldOutput<Vector2> sizeInput = (PipelineNode.FieldOutput<Vector2>) inputs.get("size");
RenderPipelineBuffer canvasBuffer = canvasPipeline.getDefaultBuffer();
RenderPipelineBuffer paintBuffer = paintPipeline.getDefaultBuffer();
Vector2 size = (sizeInput != null) ? sizeInput.getValue() : tmpVector.set(paintBuffer.getWidth(), paintBuffer.getHeight());
canvasPipeline.drawTexture(paintBuffer, canvasBuffer, pipelineRenderingContext, fullScreenRender, position.x, position.y, size.x, size.y);
paintPipeline.destroyDefaultBuffer();
output.setValue(canvasPipeline);
}
};
}
use of com.gempukku.libgdx.graph.pipeline.RenderPipeline in project gdx-graph by MarcinSc.
the class GaussianBlurPipelineNodeProducer 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/gaussianBlur.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> blurRadiusInput = (PipelineNode.FieldOutput<Float>) inputs.get("blurRadius");
final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
RenderPipeline renderPipeline = renderPipelineInput.getValue();
boolean enabled = processorEnabled == null || processorEnabled.getValue();
int blurRadius = MathUtils.round(blurRadiusInput != null ? blurRadiusInput.getValue() : 0f);
if (enabled && blurRadius > 0) {
float[] kernel = GaussianBlurKernel.getKernel(blurRadius);
RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
OpenGLContext renderContext = pipelineRenderingContext.getRenderContext();
renderContext.setDepthTest(0);
renderContext.setDepthMask(false);
renderContext.setBlending(false, 0, 0);
renderContext.setCullFace(GL20.GL_BACK);
shaderProgram.bind();
shaderProgram.setUniformi("u_blurRadius", blurRadius);
shaderProgram.setUniformf("u_pixelSize", 1f / currentBuffer.getWidth(), 1f / currentBuffer.getHeight());
shaderProgram.setUniform1fv("u_kernel", kernel, 0, kernel.length);
shaderProgram.setUniformi("u_vertical", 1);
RenderPipelineBuffer tempBuffer = executeBlur(shaderProgram, renderPipeline, currentBuffer, pipelineRenderingContext.getRenderContext(), fullScreenRender);
shaderProgram.setUniformi("u_vertical", 0);
RenderPipelineBuffer finalBuffer = executeBlur(shaderProgram, renderPipeline, tempBuffer, pipelineRenderingContext.getRenderContext(), fullScreenRender);
renderPipeline.returnFrameBuffer(tempBuffer);
renderPipeline.swapColorTextures(currentBuffer, finalBuffer);
renderPipeline.returnFrameBuffer(finalBuffer);
}
pipelineOutput.setValue(renderPipeline);
}
@Override
public void dispose() {
shaderProgram.dispose();
}
};
}
use of com.gempukku.libgdx.graph.pipeline.RenderPipeline 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();
}
};
}
use of com.gempukku.libgdx.graph.pipeline.RenderPipeline in project gdx-graph by MarcinSc.
the class ModelShaderRendererPipelineNodeProducer method createNodeForSingleInputs.
@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
final ShaderContextImpl shaderContext = new ShaderContextImpl(pluginPrivateDataSource);
final ObjectMap<String, ShaderGroup> shaderGroups = new ObjectMap<>();
final Array<String> allShaderTags = new Array<>();
final Array<String> depthDrawingShaderTags = new Array<>();
final JsonValue shaderDefinitions = data.get("shaders");
RenderOrder renderOrder = RenderOrder.valueOf(data.getString("renderOrder", "Shader_Unordered"));
final ModelRenderingStrategy renderingStrategy = createRenderingStrategy(renderOrder);
final RenderingStrategyCallback colorStrategyCallback = new RenderingStrategyCallback(shaderContext, new Function<String, GraphShader>() {
@Override
public GraphShader apply(String s) {
return shaderGroups.get(s).getColorShader();
}
});
final RenderingStrategyCallback depthStrategyCallback = new RenderingStrategyCallback(shaderContext, new Function<String, GraphShader>() {
@Override
public GraphShader apply(String s) {
return shaderGroups.get(s).getDepthShader();
}
});
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 GraphModelsImpl models;
private WhitePixel whitePixel;
@Override
public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
fullScreenRender = pipelineDataProvider.getFullScreenRender();
timeProvider = pipelineDataProvider.getTimeProvider();
models = pipelineDataProvider.getPrivatePluginData(GraphModelsImpl.class);
whitePixel = pipelineDataProvider.getWhitePixel();
for (JsonValue shaderDefinition : shaderDefinitions) {
ShaderGroup shaderGroup = new ShaderGroup(shaderDefinition);
shaderGroup.initialize(whitePixel);
allShaderTags.add(shaderGroup.getTag());
shaderGroups.put(shaderGroup.getTag(), shaderGroup);
if (shaderGroup.getColorShader().isDepthWriting())
depthDrawingShaderTags.add(shaderGroup.getTag());
}
for (ShaderGroup shaderGroup : shaderGroups.values()) {
GraphShader shader = shaderGroup.getColorShader();
models.registerTag(shader.getTag(), shader);
}
}
private void initializeDepthShaders() {
for (String depthDrawingShaderTag : depthDrawingShaderTags) {
shaderGroups.get(depthDrawingShaderTag).initializeDepthShader(whitePixel);
}
}
private boolean needsDepth() {
for (ShaderGroup shaderGroup : shaderGroups.values()) {
GraphShader colorShader = shaderGroup.getColorShader();
if (colorShader.isUsingDepthTexture() && models.hasModelWithTag(colorShader.getTag()))
return true;
}
return false;
}
private boolean isRequiringSceneColor() {
for (ShaderGroup shaderGroup : shaderGroups.values()) {
GraphShader colorShader = shaderGroup.getColorShader();
if (colorShader.isUsingColorTexture() && models.hasModelWithTag(colorShader.getTag()))
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");
RenderPipeline renderPipeline = renderPipelineInput.getValue();
boolean enabled = processorEnabled == null || processorEnabled.getValue();
if (enabled) {
boolean needsToDrawDepth = pipelineRequirementsCallback.getPipelineRequirements().isRequiringDepthTexture();
if (needsToDrawDepth)
initializeDepthShaders();
boolean usesDepth = needsDepth();
boolean needsSceneColor = isRequiringSceneColor();
RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
Camera camera = cameraInput.getValue();
shaderContext.setCamera(camera);
shaderContext.setTimeProvider(timeProvider);
shaderContext.setRenderWidth(currentBuffer.getWidth());
shaderContext.setRenderHeight(currentBuffer.getHeight());
if (needsToDrawDepth || usesDepth) {
renderPipeline.enrichWithDepthBuffer(currentBuffer);
shaderContext.setDepthTexture(currentBuffer.getDepthBufferTexture());
}
RenderPipelineBuffer sceneColorBuffer = null;
if (needsSceneColor)
sceneColorBuffer = setupColorTexture(renderPipeline, currentBuffer, pipelineRenderingContext);
// Drawing models on color buffer
colorStrategyCallback.prepare(pipelineRenderingContext, models);
currentBuffer.beginColor();
renderingStrategy.processModels(models, allShaderTags, camera, colorStrategyCallback);
currentBuffer.endColor();
if (needsToDrawDepth) {
// Drawing models on depth buffer
depthStrategyCallback.prepare(pipelineRenderingContext, models);
currentBuffer.beginDepth();
renderingStrategy.processModels(models, depthDrawingShaderTags, camera, depthStrategyCallback);
currentBuffer.endDepth();
}
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 (ShaderGroup shaderGroup : shaderGroups.values()) {
shaderGroup.dispose();
}
}
};
}
use of com.gempukku.libgdx.graph.pipeline.RenderPipeline in project gdx-graph by MarcinSc.
the class MapsLayersRendererPipelineNodeProducer method createNodeForSingleInputs.
@Override
public PipelineNode createNodeForSingleInputs(final JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
final String mapId = data.getString("id");
final String[] layerNames = data.getString("layers").split(",");
final int[] ids = new int[layerNames.length];
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 MapsPluginPrivateData mapsPluginData;
@Override
public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
mapsPluginData = pipelineDataProvider.getPrivatePluginData(MapsPluginPrivateData.class);
}
@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");
RenderPipeline renderPipeline = renderPipelineInput.getValue();
Camera camera = cameraInput.getValue();
boolean enabled = processorEnabled == null || processorEnabled.getValue();
Map map = mapsPluginData.getMap(mapId);
MapRenderer mapRenderer = mapsPluginData.getMapRenderer(mapId);
if (enabled && map != null) {
// Sadly need to switch off (and then on) the RenderContext
pipelineRenderingContext.getRenderContext().end();
RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
for (int i = 0; i < layerNames.length; i++) {
ids[i] = map.getLayers().getIndex(layerNames[i].trim());
}
currentBuffer.beginColor();
mapRenderer.setView((OrthographicCamera) camera);
mapRenderer.render(ids);
currentBuffer.endColor();
pipelineRenderingContext.getRenderContext().begin();
}
output.setValue(renderPipeline);
}
};
}
Aggregations