Compositor

From FlightGear wiki
Revision as of 21:46, 26 February 2018 by Icecode (talk | contribs) (Created page with "{{infobox subsystem |image = Canvas-view-element-prototype-by-icecode gl.png |name = Compositor Subsystem |started = 01/2018 |description = Dynamic rendering...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Compositor Subsystem
Canvas-view-element-prototype-by-icecode gl.png
Started in 01/2018
Description Dynamic rendering pipeline configured via the property tree
Maintainer(s) none
Contributor(s) Icecode
Status experimental as of 02/2018

A Compositor is a rendering pipeline configured by the Property Tree. Every configurable element of the pipeline wraps a OpenGL/OSG object and exposes its parameters to the property tree.

Elements

Buffers

A buffer represents a texture or, more generically, a region of GPU memory. Textures can be of any type allowed by OpenGL: 1D, 2D, rectangle, 2Darray, 3D or cubemap.

A typical property tree structure describing a buffer may be as follows:

      <buffer>
            <name>buffer-name</name>
	    <type>2d</type>
	    <width>512</width>
	    <height>512</height>
	    <scale-factor>1.0</scale-factor>
	    <internal-format>rgba8</internal-format>
	    <source-format>rgba</source-format>
            <source-type>ubyte</source-type>
      </buffer>

Passes

A pass wraps around a osg::Camera. As of February 2018 there are two types of passes:

  • scene. Renders a scene. The scene can be an already loaded scene graph node (terrain, aircraft etc.) or a path to a custom model.
  • quad. Renders a fullscreen quad with an optional effect applied. Useful for screen space shaders (like SSAO, Screen Space Reflections or bloom) and deferred rendering.

Passes can render to a buffer (Render to Texture), to several buffers (Multiple Render Targets) or directly to the OSG context. This allows chaining of multiple passes, sharing buffers between them.

Example XML for a quad type pass:

      <pass>
          <type>quad</type>
          <name>pass-name</name>

          <effect>Effects/test.eff</effect>
    
          <output-buffer>
              <buffer>buffer-name</buffer>
              <component>color</component>
          </output-buffer>
      </pass>

Canvas integration

A fullscreen quad with a shader that colors everything magenta is rendered to a buffer, which is displayed by a Canvas Image.

Apart from serving as a debugging tool for visualizing the contents of a buffer, integrating the Compositor with Canvas allows aircraft developers to access RTT capabilities. Compositor buffers can be accessed within Canvas via the Canvas Image protocol buffer://. For example, the path buffer://test-compositor/test-buffer displays the buffer test-buffer declared in test-compositor.

var (width,height) = (612,612);
var title = 'Compositor&Canvas test';
var window = canvas.Window.new([width,height],"dialog")
 .set('title',title);
var myCanvas = window.createCanvas().set("background", canvas.style.getColor("bg_color"));
var root = myCanvas.createGroup();
var path = "buffer://test-compositor/test-buffer";
var child = root.createChild("image")
    .setTranslation(50, 50)
    .setSize(512, 512)
    .setFile(path);