Post-processing
9 listopada 2009
When I finished adding support of subtractive shaders to FSO engine (described in my previous post) I decided to implement post-processing. It usually doesn't require many changes in existing code. That was good since I wasn't familiar with the majority of FSO source code at that time. The other reason was that it is easy to achieve satisfactory results adding a few very simple post-processing effects. However, most of them will be used only in cutscenes rendered by the engine.
How does it work?
The main idea of post-processing is really simple. The scene has to be rendered to a texture first and then drawn to the back buffer. During the second step various additional effects may be applied, hence the name - these computations are performed when the scene is already rendered. It allows to implement a wide range of effects from the completely useless ones like ASCII-art rendering to things like HDR, depth of field, motion blur, light shafts, etc.
Simple effects
Initially my patch introduced only a few simple effects, that were implemented entirely in shaders code. To work properly they needed nothing but the scene texture and intensity values. Currently four simple effects are supported:
- contrast
- saturation
- film grain
- distortion noise
These effects are similar to the filters that can be found in many graphics editors. In fact, they work in exactly the same way - apply appropriate computations to the static 2D image. Exposure, gamma, contrast, hue, saturation and many other properties can be applied without any problems as well as different types of noises, blurs and many other things. However, blur is usually implemented in a bit more complicated way in order to minimize the performance loss.
Effects management
All these effects enlisted above have their entries in post_processing.tbl file in order to give the engine the information it needs to apply and control them. The following is an example entry:
$Name: saturation $Uniform: saturation $Define: FLAG_SATURATION $AlwaysOn: false $Default: 1.0 $Div: 100 $Add: 0
- Name - general name of the effect used for identification purposes. It is mostly used in FRED. If there are more than one effect with the same name the behaviour is undefined.
- Uniform - name of the uniform variable in the shader, that specifies the intensity of the effect.
- Define - name of the preprocessor definition that allows disabling and enabling the effect when needed.
- AlwaysOn - determines if the effect is always active or applied only when current intensity differs from the default intensity.
- Default - the default effect intensity.
- Div - divisor
- Add - adder
The value of current intensity that is passed to the shader is counted using the equation:
intensity = given_intensity / divisor + adder
When given_intensity is the value set by user in mission code or additional scripts.
In the following posts I'm going to describe other, more advanced effects that are achieved using post-processing. There also will be (already promised) description of the new shaders manager.
Komentarze do wpisu "Post-processing":
Jeszcze nie ma żadnych komentarzy. Twój może być pierwszy.
Dodaj komentarz: