Archive for June, 2009

Black & White Textures

June/4 2009 by Ralf

Sometimes it is necessary to render textures in black & white. Doing this with an entire scene rendered to a texture before, can result in nice visual effects.
A few months ago I was asked to explain how that can be done in Ventuz. After playing around with the texture shading options, I found a solution for it.

bw_texture

I used four textures stages to get a cross-fade between the original texture and the bw version. The four stages do the following math operations:

  • First we modulate (mix) the original texture color/alpha with the current diffuse (material)
  • The 2nd stage multiplies all values by 0.5 and adds an offset of 0.5 (please note that the internal RGBA values are always interpreted as values from 0.0 to 1.0). The result of this stage is stored in the temp register to transfer it to the 3rd stage, where all values (RGB) are in the range from 0.5 to 1.0 now
  • Stage 3 uses the Dot-Product to add the three RGB values together, multiplied by a constant weight value. The DotProduct operation interprets the RGB values (0.5-1.0) from the previous stage as signed values (-1.0 to +1.0). The unsigned values of stage 2 are converted that way:
    0.0 -> 1.0 are mapped/clipped to -1.0 -> +1.0, so our incoming values are interpreted as positive values from 0.0 to 1.0 now!
    The actual operation of the DotProduct is:   x = R*w + G*w + B*w, where the weight w is coming from the constant alpha. The result x is a scalar value stored in all three components (R, G and B) of the Temp register for further usage in stage 4
  • The last stage (4) does a simple linear interpolation between the current register (result of stage 1) and the temp register (result of stage 2+3)
    The constant alpha is used as the interpolation pregress.

A simplified version of it (only 2 stages) can be used if you only need the BW version without cross-fading the colored and the bw texture:

bw_texture_simple

Just remove stage 1 and connect the texture source (image loader) to stage 2, change the “Current” register to “TextureColor”, remove stage 4 and store the result of stage 3 in “Current” instead of “temp”

The 4-stage-scene can be downloaded here.

Ralf

Comment2 Comments »