Opengl Framebuffer Object patch for IoQuake3
published on: July 6, 2009
IoQuake 3 is a Free Software game engine that was originaly developed by ID Software for the commercial video game Quake 3 Arena. IoQuake 3 was set up by the community to maintain and improve this code-base.
IoQuake 3 was developed in the late 90's and thus does not feature many advanced OpenGL technique's, Thus I set about developing a patch which would enable framebuffer objects and screen space post processing effects.
This patch works by hooking into the quake 3 rendering main loop just after a frame is drawn, the code then unbinds the current framebuffer, draws it to the screen and binds a new one. This process allows all of the quake 3 graphical data to be rendered to the framebuffer instead of to the screen.
An example of this patch running in game with a veriety of post processing effects
Screen Space Post Processing
Once the graphical data is stored in a framebuffer you can then access it via a texture, Thus you can then re-draw the image to the screen, applying filters and effects using glsl shaders. There are two post processing effects distributed with this patch and three main processes.
GLSL Blurring
An example of two pass blurring
Blurring is the process of taking multiple samples of data from an image and combining them together to create one averaged sample, applying this process to an entire image creates a blurred image.
Traditionally you can blur an image by taking a 'kernel' of samples, this normally comes in the form of a box around our target texel, This is however very slow and quickly eats up all your gpu's texture cache. Thus I opted to use a two-pass gaussian blur approach.
Essentially. the image is blurred twice. First a horizontal blur is performed on the image, this requires 9 texel lookups. Then we do a vertical blur on the already horizontally blurred image (requiring another 9 texel lookups). the result of this is that we get a fully mathematically sound gaussian blur with a fraction of the texel lookups. A normal box blur requiring a kernel would take n² samples, this technique however only requires n2 samples, Obviously much quicker.
GLSL Bloom
An example of bloom running ingame.
It can be difficult to present to the end user the idea of 'brightness' in an image, After all you can only display graphics as bright as the computer monitor can produce. It was this problem that gave rise to the bloom effect, Essentially the bright parts of an image are blurred and screened back on to the original image, This process makes the human eye belive that the part you have selected is indeed "bright". I used the following code in order to use the bloom effect.
uniform sampler2D srcSampler;
uniform sampler2D blurSampler;
uniform float sharpness;
uniform float brightness;
#define SIGMOIDAL_BASE 2.0
#define SIGMOIDAL_RANGE 20.0
void main()
{
vec4 blurcolor = texture2D( blurSampler, gl_TexCoord[0].xy);
vec4 basecolor = texture2D( srcSampler, gl_TexCoord[0].xy);
vec4 val = -(SIGMOIDAL_BASE + (sharpness * SIGMOIDAL_RANGE)) * (blurcolor - 0.5);
val = 1.0 + pow(vec4(2.718281828459045), val);
val = 1.0 / val;
val = val * brightness;
gl_FragColor = 1.0 - ((1.0 - basecolor) * (1.0 - val));
}
GLSL Rotoscoping
glsl rotoscoping, edge detection and colour convultion in game.
I also provided a glsl based rotoscoping effect, This is the process of taking live action and producing a cartoonish appearance.
I performed this by using a sobel edge detection filter on the image and combined that with a colour convultion filter.
Article Tags opengl, C, quake3, games, glsl, graphics, code, patch
This patch has been used to enhance Smokin'Guns since v1.1b3 with few improvements (Bloom & rotoscope effects are not modified).
A lot of players enjoyed it since the beginning.
Thanks again for your work.
Tequila
Smokin'Guns Team
Outstanding work, but how do I use it with my existing ioQuake3 installation?