Pixel testing in effects
In OpenGL, and thus in FlightGear's effect files, one can define several tests for each pixel. The tests are executed for every pixel to-be-rendered on screen, and if all tests pass, the shaders (if defined) are executed and pixel ends up on screen.
Test queue
Incoming pixel --> | Alpha test --> | Stencil test --> | Shaders/colouring --> | Color mask --> | Screen | |
V | V | V | ||||
Discard | Discard | Discard |
In every pass, a pixel can be discarded, and no other tests will be executed. If all tests pass, pixel will be drawn on screen.
Alpha test
With alpha test you can check if the pixel to be written is transparent or not. It can be used to discard or only draw opaque geometry instead of transparent or vice versa. Note! I'm not sure how this works if shader writes to alpha channel!
Alpha test can be enabled by specifying <alpha-test> in effect <pass>. Possible attributes are:
- <comparison>
- less: Pass if pixel's alpha is less than <value>
- lequal: Pass if pixel's alpha is less or equal to <value>
- equal: Pass if pixel's alpha is equal to <value>
- gequal: Pass if pixel's alpha is greater or equal to <value>
- greater: Pass if pixel's alpha is greater than <value>
- <value>
- Floating point value against which the pixel's alpha is tested
- Is it possible to use properties?
Stencil test
Stencil test can do several things. First, it can discard pixels depending on what is already in the stencil buffer. Second, it can update stencil buffer depending on whether pixel passes z-test or not (i.e. is behind other pixels or not).
Incoming pixel --> | Stencil test --> (update s-buffer) | Z-test --> (update s-buffer) | Pass --> (update s-buffer) |
V | V | ||
Discard (update s-buffer) | Discard (update s-buffer) |
Stencil test can be enabled by adding <stencil> tags to <pass> in effect.
- <function>: How the stencil-test is done
- never: Pixel is always discarded
- less: Pixel passes if s-buffer contains value less than <value>
- equal: Pixel passes if s-buffer contains value equal to <value>
- less-or-equal: Pixel passes if s-buffer contains value less or equal to <value>
- greater: Pixel passes if s-buffer contains value greater than <value>
- not-equal: Pixel passes if s-buffer contains value not equal to <value>
- greater-or-equal: Pixel passes if s-buffer contains value greater or equal to <value>
- always: Pixel always passes
- <value>
- <stencil-fail>
- keep: Keep the old value currently in s-buffer
- zero: Zero the s-buffer value
- replace: Replace s-buffer value with <value>
- increase: Increase s-buffer value with 1 or <value>?
- decrease: Decrease s-buffer value ---"---
- increase-wrap: Increase and wrap to zero if overflows
- decrease-wrap: Decrease and wrap to maximum if goes below zero
- invert: Bitwise invert the value in s-buffer
- <z-fail>
- <pass>
- <mask>