Compositor: Difference between revisions

Jump to navigation Jump to search
2,743 bytes added ,  27 March 2020
m
no edit summary
mNo edit summary
mNo edit summary
(3 intermediate revisions by the same user not shown)
Line 77: Line 77:
== How to enable the Compositor ==
== How to enable the Compositor ==


Currently the Compositor can only be enabled at compile time via the <code>-DENABLE_COMPOSITOR=ON</code> CMake flag in FlightGear. SimGear doesn't require any extra parameters. Once you have a binary with the Compositor enabled and you run it, you will be presented with the default rendering pipeline. At the time of writing, this is the low spec rendering pipeline. If you want to try the [[#ALS|ALS pipeline]], start FlightGear with the command line argument: <code>--compositor=Compositor/ALS/als</code>
Currently the Compositor can only be enabled at compile time via the <code>-DENABLE_COMPOSITOR=ON</code> CMake flag in FlightGear. SimGear doesn't require any extra parameters. Once you have a binary with the Compositor enabled and you run it, you will be presented with the default rendering pipeline. At the time of writing, this is the low spec rendering pipeline. If you want to try the [[#ALS|ALS pipeline]], start FlightGear with the command line argument: <code>--compositor=Compositor/als</code>


If you want to enable shadows on all objects in the ALS pipeline use these options as a startup parameters (in QT GUI or in the commandline) <code>--prop:bool:/sim/rendering/als/shadows/enabled=true</code> and <code>--prop:int:/sim/rendering/als/shadows/sun-atlas-size=2048</code>. If you feel like the shadows are too low-quality (specially in the cockpit), increase the shadow resolution to 4096 or 8192 instead of 2048.
If you want to enable shadows on all objects in the ALS pipeline use these options as a startup parameters (in QT GUI or in the commandline) <code>--prop:bool:/sim/rendering/als/shadows/enabled=true</code> and <code>--prop:int:/sim/rendering/als/shadows/sun-atlas-size=2048</code>. If you feel like the shadows are too low-quality (specially in the cockpit), increase the shadow resolution to 4096 or 8192 instead of 2048.
Line 185: Line 185:
* Unlike in Rembrandt, polygons facing the Sun are the ones used to generate the shadow map, so single sided surfaces and non-closed objects should be rendered correctly.
* Unlike in Rembrandt, polygons facing the Sun are the ones used to generate the shadow map, so single sided surfaces and non-closed objects should be rendered correctly.


== Pipelines ==
== Porting and developing Effects/Shaders ==


=== Low-Spec pipeline ===
Effects can now have different implementations depending on the Compositor pipeline being used. For example, a grass Effect implemented in the ALS pipeline might have much more detail than the one in the low-spec pipeline. Still, they both implement the "look" of grass, so they share the same Effect file (grass.eff).
 
The Compositor chooses which implementation of an Effect to render based on the <tt><scheme></tt> of the techniques.
<syntaxhighlight lang="xml">
<technique n="15">
  <scheme>als-lighting</scheme>
  [...]
</technique>
</syntaxhighlight>
 
In this case the technique will be chosen if the Compositor pipeline <tt><scene></tt> pass uses the <tt>als-lighting</tt> Effect scheme. Consequently, porting an Effect to a pipeline will require knowing which Effect schemes it uses and writing a technique for each one. The only exception to this is the Default (Low-Spec) pipeline, which uses techniques with no scheme.
 
Generally porting legacy Effects will require these steps:
* Remove <tt>/sim/rendering/shaders/skydome</tt> from the ALS techniques and add the <tt>als-lighting</tt> scheme.
* Remove Rembrandt techniques.
* Use technique numbers from 0 to 9 for the Default pipeline techniques and 10 to 19 for the ALS pipeline.
* Move the shaders to their correct directory. Now the <tt>$FG_ROOT/Shaders</tt> directory is subdivided into different folders for each pipeline. For example, shaders related to the ALS pipeline are located in <tt>$FG_ROOT/Shaders/ALS</tt>.
 
To add features specific to a particular pipeline (like shadows in the ALS pipeline), see each pipeline's documentation below.
 
=== ALS ===
 
==== Adding shadows ====
 
==== Rendering correct depth ====
 
The ALS pipeline uses a logarithmic depth buffer. This is accomplished by writing to <tt>gl_FragDepth</tt> in the fragment shader or by modifying <tt>gl_Position.z</tt> in the vertex shader. The 2nd option is faster but doesn't work for very large polygons (like the terrain), so you should use it by default unless visual bugs appear.
 
* '''1st option'''.
Add the following to the vertex shader:
<syntaxhighlight lang="cplusplus">
uniform float fg_Fcoef;
[...]
gl_Position = ...
gl_Position.z = (log2(max(1e-6, 1.0 + gl_Position.w)) * fg_Fcoef - 1.0) * gl_Position.w;
</syntaxhighlight>
 
* '''2nd option'''.
Add the following to the vertex shader:
<syntaxhighlight lang="cplusplus">
varying float flogz;
[...]
gl_Position = ...
flogz = 1.0 + gl_Position.w;
</syntaxhighlight>
And the following to the fragment shader:
<syntaxhighlight lang="cplusplus">
uniform float fg_Fcoef;
varying float flogz;
[...]
gl_FragColor = ...
gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5;
</syntaxhighlight>
 
== Technical notes of each pipeline ==
 
=== Default (Low-Spec) ===


A fixed function forward rendering pipeline mainly targeted to low spec systems. It imitates the classic forward pipeline used before multi-pass rendering was introduced by using two near/far cameras rendering directly to the screen.
A fixed function forward rendering pipeline mainly targeted to low spec systems. It imitates the classic forward pipeline used before multi-pass rendering was introduced by using two near/far cameras rendering directly to the screen.
342

edits

Navigation menu