-
Notifications
You must be signed in to change notification settings - Fork 134
Render Stages
Render Stages are a core mechanism of the pipeline. The pipeline collects all render stages, forms a pipe out of them, and executes them in order, to get the final result.
TODO: Add graphic
Each render stage can specify which pipes and inputs it needs, and also which pipes and inputs it produces. Render stages can also modify a pipe, by simply specifying the same pipe as input and output pipe.
A simple render which takes as input SomePipe1 and SomePipe2, and produces SomePipe3 looks like this:
class MyStage(RenderStage):
""" Specify all required pipes here. They will be made available as
a shader input to all contained targets """
required_pipes = ["SomePipe1", "SomePipe2"]
""" Specify all required inputs here. They will be made available
as a shader input aswell. """
required_inputs = ["some_input", "another_input"]
def __init__(self, pipeline):
RenderStage.__init__(self, pipeline)
def create(self):
""" This method gets called when the stage actually gets created.
You should setup all RenderTargets here. """
# Construct a single Render Target, see the RenderTarget API
self._target = self._create_target("My Target")
self._target.add_color_texture(bits=16)
self._target.prepare_offscreen_buffer()
def get_produced_pipes(self):
""" This method tells the pipeline which pipes are produced / modified
by this stage. The key is the name of the pipe, and the value should be
a texture handle """
return {"SomePipe3": self._target["color"]}
def set_shaders(self):
""" This method gets called after the create method, aswell as on
manual shader reload. It should set all required shaders on the
render targets """
# MyStage.frag.glsl should be located in the Plugin directory at
# Shader/Stages/MyStage.frag.glsl
self._target.set_shader(self.load_plugin_shader("MyStage.frag.glsl"))
def resize(self):
""" This method gets called when the window got resized. """
def cleanup(self):
""" This method gets called when the stage got removed, you should
remove all targets here """
The pipeline somehow has to know at which point of the rendering process your stage belongs to. Notice: This is subject to change
Right now, you have to edit Code/StageManager.py
and insert your pipe name at the _STAGE_ORDER
definition.
Writing shaders for your stages is pretty straightforward. Assuming you created a RenderStage like the example above, which takes SomePipe1 and SomePipe2 to produce SomePipe3 (e.g. by adding both), then your shader could look like this:
"""glsl #version 400
// Input from the vertex shader, range 0 .. 1 in vec4 texcoord;
// Fragment output out vec4 output;
// Pipe inputs uniform sampler2D SomePipe1; uniform sampler2D SomePipe2;
void main() { vec4 pipe1_value = textureLod(SomePipe1, texcoord, 0); vec4 pipe2_value = textureLod(SomePipe2, texcoord, 0); output = pipe1_value + pipe2_value; }
"""
Rendering Pipeline by tobspr (c) 2014 - 2016
For developers: