Skip to content

Render Stages

tobspr edited this page Nov 12, 2015 · 10 revisions

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 stage 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 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 """

Specifying the Stage order

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.