Graphics Reference
In-Depth Information
float3 texture_decode ( float2 data , float3 bc1 , float3 bc2 )
{ float3 color = lerp ( bc1 , bc2 , data . y );
float color_lum = dot ( color , float3 (0.2126 ,0.7152 ,0.0722) );
float target_lum = data . x ￿ data . x ;
color ￿ = target_lum / color_lum ;
return color ;
}
Listing 2.1. Two-channel texture decoding algorithm.
passing through the origin and the point on the plane being encoded. This gives
us the following line-line intersection equation:
A + t ( B
A )= sP.
Solving this linear equation for t gives us the result—the base color blend
factor resulting in a hue most closely matching the hue of the encoded point. This
blend factor is then simply stored directly in the second channel, completing the
2-channel encoding process.
2.3 Decoding Algorithm
The decoding algorithm is simple and best described by the actual decoding
shader code in Listing 2.1.
First, the base colors bc1 and bc2 , which are passed as constant data, are
blended with a blend factor coming from the second channel of data , resulting in
a color having the desired hue, but wrong luminance. This luminance is computed
as color_lum . Next, we compute the desired luminance target_lum as a value of
first channel of data squared (because we stored the luminance with gamma 2).
As the resulting color is in a linear color space, we can adjust the luminance by
simply dividing the color by the current luminance and then multiplying it by
the desired one. If needed, we can of course convert the computed color to a
nonlinear color space for presentation purposes.
2.4 Encoded Image Quality
Figures 2.4, 2.5, and 2.6 show examples of the encoding and decoding process.
The example textures are taken from the CGTextures texture library and were
selected because of their relatively rich content and variety.
Figure 2.4 presents a 2-channel approximation result of a dirt texture with
grass patches. Both dirt and grass are reproduced with slight, but mostly unno-
ticeable differences in color. As the method is designed with limited-color material
Search WWH ::




Custom Search