use of com.gempukku.libgdx.graph.pipeline.RenderPipeline in project gdx-graph by MarcinSc.
the class ShadowShaderRendererPipelineNodeProducer 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, GraphShader> shaders = new ObjectMap<>();
final Array<String> allShaderTags = new Array<>();
final JsonValue shaderDefinitions = data.get("shaders");
RenderOrder renderOrder = RenderOrder.valueOf(data.getString("renderOrder", "Shader_Unordered"));
final ModelRenderingStrategy renderingStrategy = createRenderingStrategy(renderOrder);
final String environmentId = data.getString("id", "");
final RenderingStrategyCallback depthStrategyCallback = new RenderingStrategyCallback(shaderContext, new Function<String, GraphShader>() {
@Override
public GraphShader apply(String s) {
return shaders.get(s);
}
});
final Array<RenderPipelineBuffer> createdPipelineBuffers = new Array<>();
final Array<Directional3DLight> shadowDirectionalLights = new Array<>();
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 Lighting3DPrivateData lighting;
private TimeProvider timeProvider;
private GraphModelsImpl models;
private RenderPipeline pipeline;
@Override
public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
lighting = pipelineDataProvider.getPrivatePluginData(Lighting3DPrivateData.class);
timeProvider = pipelineDataProvider.getTimeProvider();
models = pipelineDataProvider.getPrivatePluginData(GraphModelsImpl.class);
for (JsonValue shaderDefinition : shaderDefinitions) {
GraphShader depthGraphShader = ShadowShaderRendererPipelineNodeProducer.createDepthShader(shaderDefinition, pipelineDataProvider.getWhitePixel().texture);
allShaderTags.add(depthGraphShader.getTag());
shaders.put(depthGraphShader.getTag(), depthGraphShader);
}
for (ObjectMap.Entry<String, GraphShader> shaderEntry : shaders.entries()) {
models.registerTag(shaderEntry.key, shaderEntry.value);
}
}
private boolean needsDepth() {
for (GraphShader shader : shaders.values()) {
if (shader.isUsingDepthTexture() && models.hasModelWithTag(shader.getTag()))
return true;
}
return false;
}
private boolean isRequiringSceneColor() {
for (GraphShader shader : shaders.values()) {
if (shader.isUsingColorTexture() && models.hasModelWithTag(shader.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<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
boolean enabled = processorEnabled == null || processorEnabled.getValue();
boolean usesDepth = enabled && needsDepth();
RenderPipeline renderPipeline = renderPipelineInput.getValue();
this.pipeline = renderPipeline;
if (enabled) {
boolean needsDrawing = false;
Lighting3DEnvironment environment = lighting.getEnvironment(environmentId);
// Initialize directional light cameras and textures
for (Directional3DLight directionalLight : environment.getDirectionalLights()) {
if (directionalLight.isShadowsEnabled()) {
needsDrawing = true;
directionalLight.updateCamera(environment.getSceneCenter(), environment.getSceneDiameter());
if (directionalLight.getShadowFrameBuffer() == null) {
RenderPipelineBuffer shadowFrameBuffer = renderPipeline.getNewFrameBuffer(directionalLight.getShadowBufferSize(), directionalLight.getShadowBufferSize(), Pixmap.Format.RGB888, Color.WHITE);
directionalLight.setShadowFrameBuffer(shadowFrameBuffer);
createdPipelineBuffers.add(shadowFrameBuffer);
shadowDirectionalLights.add(directionalLight);
}
}
}
if (needsDrawing) {
boolean needsSceneColor = isRequiringSceneColor();
RenderPipelineBuffer drawBuffer = renderPipeline.getDefaultBuffer();
for (Directional3DLight directionalLight : environment.getDirectionalLights()) {
if (directionalLight.isShadowsEnabled()) {
RenderPipelineBuffer shadowBuffer = directionalLight.getShadowFrameBuffer();
Camera camera = directionalLight.getShadowCamera();
shaderContext.setCamera(camera);
shaderContext.setTimeProvider(timeProvider);
shaderContext.setRenderWidth(shadowBuffer.getWidth());
shaderContext.setRenderHeight(shadowBuffer.getHeight());
if (usesDepth) {
renderPipeline.enrichWithDepthBuffer(drawBuffer);
shaderContext.setDepthTexture(drawBuffer.getDepthBufferTexture());
}
if (needsSceneColor)
shaderContext.setColorTexture(drawBuffer.getColorBufferTexture());
// Drawing models on color buffer
depthStrategyCallback.prepare(pipelineRenderingContext, models);
shadowBuffer.beginColor();
renderingStrategy.processModels(models, allShaderTags, camera, depthStrategyCallback);
shadowBuffer.endColor();
}
}
}
}
output.setValue(renderPipeline);
}
@Override
public void endFrame() {
for (RenderPipelineBuffer createdPipelineBuffer : createdPipelineBuffers) {
pipeline.returnFrameBuffer(createdPipelineBuffer);
}
createdPipelineBuffers.clear();
for (Directional3DLight shadowDirectionalLight : shadowDirectionalLights) {
shadowDirectionalLight.setShadowFrameBuffer(null);
}
shadowDirectionalLights.clear();
}
@Override
public void dispose() {
for (GraphShader shader : shaders.values()) {
shader.dispose();
}
}
};
}
use of com.gempukku.libgdx.graph.pipeline.RenderPipeline in project gdx-graph by MarcinSc.
the class MapsLayerIdsRendererPipelineNodeProducer 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[] layerIds = data.getString("layers").split(",");
final int[] ids = new int[layerIds.length];
for (int i = 0; i < layerIds.length; i++) {
ids[i] = Integer.parseInt(layerIds[i]);
}
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();
currentBuffer.beginColor();
mapRenderer.setView((OrthographicCamera) camera);
mapRenderer.render(ids);
currentBuffer.endColor();
pipelineRenderingContext.getRenderContext().begin();
}
output.setValue(renderPipeline);
}
};
}
use of com.gempukku.libgdx.graph.pipeline.RenderPipeline in project gdx-graph by MarcinSc.
the class RenderCallbackPipelineNodeProducer method createNodeForSingleInputs.
@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
final String callbackId = data.getString("callbackId", null);
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 PipelineDataProvider pipelineDataProvider;
private RenderCallbackPrivateData renderCallbackData;
@Override
public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
renderCallbackData = pipelineDataProvider.getPrivatePluginData(RenderCallbackPrivateData.class);
this.pipelineDataProvider = pipelineDataProvider;
}
@Override
public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
final PipelineNode.FieldOutput<Boolean> processorEnabled = (PipelineNode.FieldOutput<Boolean>) inputs.get("enabled");
final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
RenderPipeline renderPipeline = renderPipelineInput.getValue();
boolean enabled = processorEnabled == null || processorEnabled.getValue();
if (enabled) {
RenderCallback callback = renderCallbackData.getRenderCallback(callbackId);
callback.renderCallback(renderPipeline, pipelineDataProvider, pipelineRenderingContext, pipelineRequirementsCallback);
}
output.setValue(renderPipeline);
}
};
}
use of com.gempukku.libgdx.graph.pipeline.RenderPipeline 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();
}
}
};
}
use of com.gempukku.libgdx.graph.pipeline.RenderPipeline in project gdx-graph by MarcinSc.
the class DepthOfFieldPipelineNodeProducer method createNodeForSingleInputs.
@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
float maxBlurFloat = data.getFloat("maxBlur");
final int maxBlur = MathUtils.round(maxBlurFloat);
boolean blurBackground = data.getBoolean("blurBackground", false);
String viewToScreenCoords = getShader("viewToScreenCoords.vert");
String depthOfField = getShader("depthOfField.frag");
depthOfField = depthOfField.replaceAll("MAX_BLUR", String.valueOf(maxBlur));
depthOfField = depthOfField.replaceAll("UNPACK_FUNCTION;", GLSLFragmentReader.getFragment("unpackVec3ToFloat"));
depthOfField = depthOfField.replaceAll("BLUR_BACKGROUND", String.valueOf(blurBackground));
final ShaderProgram shaderProgram = new ShaderProgram(viewToScreenCoords, depthOfField);
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 processPipelineRequirements(PipelineRequirements pipelineRequirements) {
if (maxBlur > 0)
pipelineRequirements.setRequiringDepthTexture();
}
@Override
public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
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<Vector2> focusDistanceInput = (PipelineNode.FieldOutput<Vector2>) inputs.get("focusDistance");
final PipelineNode.FieldOutput<Float> nearDistanceBlurInput = (PipelineNode.FieldOutput<Float>) inputs.get("nearDistanceBlur");
final PipelineNode.FieldOutput<Float> farDistanceBlurInput = (PipelineNode.FieldOutput<Float>) inputs.get("farDistanceBlur");
RenderPipeline renderPipeline = renderPipelineInput.getValue();
boolean enabled = processorEnabled == null || processorEnabled.getValue();
if (enabled && maxBlur > 0) {
Camera camera = cameraInput.getValue();
Vector2 focusDistance = focusDistanceInput.getValue();
float nearDistanceBlur = nearDistanceBlurInput != null ? nearDistanceBlurInput.getValue() : 10f;
float farDistanceBlur = farDistanceBlurInput != null ? farDistanceBlurInput.getValue() : 10f;
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.setUniformf("u_pixelSize", 1f / currentBuffer.getWidth(), 1f / currentBuffer.getHeight());
shaderProgram.setUniformf("u_cameraClipping", camera.near, camera.far);
shaderProgram.setUniformf("u_focusDistance", focusDistance);
shaderProgram.setUniformf("u_nearDistanceBlur", nearDistanceBlur);
shaderProgram.setUniformf("u_farDistanceBlur", farDistanceBlur);
shaderProgram.setUniformi("u_vertical", 1);
RenderPipelineBuffer tempBuffer = executeBlur(shaderProgram, renderPipeline, currentBuffer, currentBuffer, pipelineRenderingContext.getRenderContext(), fullScreenRender);
shaderProgram.setUniformi("u_vertical", 0);
RenderPipelineBuffer finalBuffer = executeBlur(shaderProgram, renderPipeline, currentBuffer, tempBuffer, pipelineRenderingContext.getRenderContext(), fullScreenRender);
renderPipeline.returnFrameBuffer(tempBuffer);
renderPipeline.swapColorTextures(currentBuffer, finalBuffer);
renderPipeline.returnFrameBuffer(finalBuffer);
}
pipelineOutput.setValue(renderPipeline);
}
@Override
public void dispose() {
shaderProgram.dispose();
}
};
}
Aggregations