El-Cheapo Fullbrights
Posted: Sun Aug 14, 2011 9:13 pm
This one ain't a copy and paste tutorial.
So, here's a way of using the same texture object for fullbrights as you use for the main texture. Neat for saving on texture memory, faster loading times, and may run faster if your hardware is able to figure out that it can cache the result of a texture lookup and reuse it rather than needing to do a second texture lookup.
I'm assuming that you've got multitexture and a minimum of 3 TMUs available. If neither of these apply you can still get the texture memory saving but you'll need to figure out the blend modes for yourself.
You'll also need to do more work yourself if you've got external textures or a legit use for BSP or MDL textures with an alpha channel.
On to the info.
First thing is that we build a second copy of d_8to24table; this one has an alpha channel of 0 for entries below 224 but it keeps the same r, g and b. Entries 224 and above are the same as your regular d_8to24table.
Then we use that as the palette when uploading a texture that has fullbright colours in it.
Finally when rendering, we set up our texture environment for these textures like so:
Now we just bind the regular texture to both TMU 0 and 2, the lightmap to TMU1, and draw. That's it. The GL_DECAL environment will give you the following result:
Which is exactly what we need for fullbrights - areas covered by fullbright pixels are replaced by them, areas not so covered are left alone. Result.
So, here's a way of using the same texture object for fullbrights as you use for the main texture. Neat for saving on texture memory, faster loading times, and may run faster if your hardware is able to figure out that it can cache the result of a texture lookup and reuse it rather than needing to do a second texture lookup.
I'm assuming that you've got multitexture and a minimum of 3 TMUs available. If neither of these apply you can still get the texture memory saving but you'll need to figure out the blend modes for yourself.
You'll also need to do more work yourself if you've got external textures or a legit use for BSP or MDL textures with an alpha channel.
On to the info.
First thing is that we build a second copy of d_8to24table; this one has an alpha channel of 0 for entries below 224 but it keeps the same r, g and b. Entries 224 and above are the same as your regular d_8to24table.
Then we use that as the palette when uploading a texture that has fullbright colours in it.
Finally when rendering, we set up our texture environment for these textures like so:
Code: Select all
// diffuse - regular texture
glActiveTexture (GL_TEXTURE0);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
// lightmap - optionally use GL_RGB_SCALE for overbrighting
glActiveTexture (GL_TEXTURE1);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// fullbright
glActiveTexture (GL_TEXTURE2);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);Code: Select all
(tex * lm) * (1.0f - tex.a) + (fb.a * tex.rgb)
