Game Development Community

dev|Pro Game Development Curriculum

Torque Lighting Kit - Scene Exposure and Filter Control

by John Kabus (BobTheCBuilder) · 07/03/2006 (11:26 am) · 4 comments

Download Code File

(this resource is designed for TLK 1.4, but should work with TLK 1.3.x)

What does it do?

This resource adds the sgGuiExposureControl gui control to the Torque Lighting Kit. This control allows gamma-style per-client exposure adjustments. The exposure level is handled per-color component, which means it also performs color filtering, and can also use a mask texture to perform per-pixel filtering. Because it's a gui control, exposure and filtering can affect the entire screen or a smaller sub-region, and other gui controls as well as the scene.


How to install it?

Unzip the resource zip file into the TLK source file directory ('engine/synapseGaming/contentPacks/lightingPack/'), add the unzipped file 'sgGuiExposureControl.cc' to your Visual Studio and/or Xcode projects, and then perform a clean build of Torque.


How to use it?

Add the sgGuiExposureControl gui control over any screen region you want to adjust the exposure or filter the color of. Then set the control exposure level and/or mask texture to the desired effect. Selecting Filter Children also filters the control's children.

The exposure level is adjusted per-color component, which allows color filtering as well as exposure changes. Each color component can range from 0.0 - 2.0, with 0.5 allowing the color to remain unchanged. The following is a chart of a few color component values and the resulting exposure:

Color Component Value | Exposure
-----------------------------------------
0.0                   | 0   (color removed)
0.25                  | 0.5 (half intensity)
0.5                   | 1   (unchanged)
1.0                   | 2   (double intensity)
2.0                   | 4   (quad intensity)


The color component range of 0.0 - 1.0 was chosen to represent the exposure range 0.0 - 2.0 in order to play nicely with the new Torque gui editor color picker, which can only create colors up to 1.0, 1.0, 1.0.

Each color component supports a value up to 2.0 (extending the exposure range up to 4.0), however this value must be hand entered into the control's exposure member because of the color picker's limited range. There is also an additional rendering overhead involved in using this extended range.

The mask texture color components adjust the amount that the exposure member will affect the screen on a per-pixel level based on the following formula:

output_intensity = input_intensity * exposure_member_exposure * mask_texture_exposure

The following is a chart of a few mask texture color component values and the resulting exposure:

Color Component Value | Exposure
-----------------------------------------
0   (0.0)             | 0   (color removed)
63  (0.25)            | 0.25(quarter intensity)
127 (0.5)             | 0.5 (half intensity)
255 (1.0)             | 1   (unchanged)


As an example; if the control's red exposure component is 1.0 (which doubles intensity) the screen's red color will be doubled. If the mask texture is used and its red color component is 0.5 (which halves intensity) the total intensity will remain unchanged (intensity * 2 * 0.5 = intensity * 1). If the mask texture red color component is 1.0 (which leaves the exposure component intensity unchanged) the total intensity is doubled (intensity * 2 * 1 = intensity * 2).

If any of the exposure member color components exceed 1.0 (putting them in the extended range) the above formula does not entirely apply - some experimentation is needed in this case.


Enjoy!

-John Kabus

#1
07/03/2006 (1:22 pm)
I just glanced through the code, looks nice.

For those of you using DRL, don't worry. You can just drop this in right on top of DRL and it'll work fine with no modifications. I think this would be perfect for doing, say, a night vision style effect by almost zeroing out the red and blue channels while keeping (and/or amplifying) the green. Or just doing some nice stylized rendering in general.
#2
07/05/2006 (9:01 pm)
Thanks for doing & posting this, John.
Will give it a try ASAP.
#3
07/25/2006 (11:38 am)
This is great, thanks John. Already putting it to some good use in my project
#4
07/28/2006 (10:45 am)
John - have confirmed this works like a beaut under TLK 1.3.5.

it only needs a trivial change to get it to compile:
change this:
#include "gui/core/guiControl.h"
to this:
#include "gui/guiControl.h"

thanks again!