PDA

View Full Version : How to set the alpha of multitexture?



blender
03-14-2002, 09:38 AM
I'm using ARB_multitexture extension for lightmapping, but the lightmap shadows are just too dark. How could I change the alpha value of specific multitexture.
I tried GL_TEXTURE_ENV_COLOR, but I couldn't get it work.

Tom Nuydens
03-15-2002, 02:25 AM
Lightmapping has nothing to do with alpha blending. If you have a texture T and a lightmap L, what you're calculating is simply L*T. Alpha is never considered.

I don't think you can make it look brighter on-the-fly without using an extra texture unit or resorting to pixel shaders. The easiest solution is to do it off-line: just add an ambient lighting term to your lightmaps.

-- Tom

blender
03-15-2002, 01:55 PM
Ok. I made some pretty good invention http://www.opengl.org/discussion_boards/ubb/smile.gif.
I put one "brightmap" for each level, which is blitted on every lightmap durring their loading progress. This makes possible things like lighting the whole level and setting a cool color (at nigh blue color looks awsome).

zed
03-15-2002, 10:25 PM
>>I'm using ARB_multitexture extension for lightmapping, but the lightmap shadows are just too dark<<

youre using modulate i take it?
try add_signed_arb or modulate+scale*2

blender
03-16-2002, 03:52 AM
add_signed_arb definition is not included in gl.h, where can I get that?
For the second question I would ask:
How to do overbrighting with lightmaps?

zeckensack
03-16-2002, 04:43 AM
Originally posted by blender:
add_signed_arb definition is not included in gl.h, where can I get that?
Get glext.h here (http://oss.sgi.com/projects/ogl-sample/sdk.html) and also read the rest of that page.

For the second question I would ask:
How to do overbrighting with lightmaps? Not sure what you mean. In ARB_texture_env_combine and basic ARB_multitexture modes, you can't get any brighter than 1.0 because results are clamped to the range [0...1] in between texturing stages. Not that your monitor could display anything brighter than 1.0 anyway ...

zeckensack
03-16-2002, 05:55 AM
An addition for the overbright stuff:
You need to avoid the clamping in between texture environments. To do that you must either use some sort of pixel shader (or possibly other extension http://www.opengl.org/discussion_boards/ubb/confused.gif ) that allows passing values beyond the [0...1] range. Or you can simply first multiply with the lightmap, and then do the additive operations.

blender
03-16-2002, 08:46 AM
I thought I could do overbrighting by using extra multitexture, but my voodoo3 seems to be able to handle only two multitextures.

blender
03-18-2002, 07:31 AM
When MODULATE allows using shadows by doing Arg0 * Arg1, it doesn't let lightmap colors go over the main texture colors, so no overbrighting (or whatever it's called).

I can't add 3rd multitexture for ADD becouse some (my) cards doesn't support it.

Humus
03-18-2002, 08:13 AM
Use GL_RGB_SCALE_ARB, and set the scaling to for instance 2. Now you'll have something like a [0,2] range, sort of.

blender
03-18-2002, 09:47 PM
What do you mean about scaling? glPixelTransferf(GL_ALPHA_SCALE, 2.0f); (or whatever) ?

richardve
03-18-2002, 09:57 PM
Originally posted by blender:
What do you mean about scaling? glPixelTransferf(GL_ALPHA_SCALE, 2.0f); (or whatever) ?

This: GL_ARB_texture_env_combine (http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt)

blender
03-18-2002, 10:43 PM
Could you explain to me (I am a little new to extensions), is GL_ARB_texture_env_combine a whole new extension, or can I use it if my card just supports ARB_multitexture?

If I can, can I just directly use it's definitions in glTexEnvi(...); or do I need some other function?

Humus
03-18-2002, 11:35 PM
To use it your card must of course support the extension, there is an GL_EXT_texture_env_combine that works too, it only lacks a subtract option but is otherwise identical.

Do something like this:

glActiveTexture(GL_TEXTURE0_ARB);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);


glActiveTexture(GL_TEXTURE1_ARB);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);

blender
03-19-2002, 09:49 AM
I tried following code and results were that lightmaps weren't drawn.




for(n=0; n<numFaces; n++)
{
pFace = &amp;face[n];
pTextr = &amp;texture[pFace->id];
pLmap = &amp;lightmap[pFace->lid];

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, pTextr->texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
//glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, pLmap->texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glEnable(GL_TEXTURE_2D);

glBegin(GL_TRIANGLE_FAN);
for(m=pFace->start; m<pFace->start+pFace->num; m++)
{
if(pFace->flags != SKY)
{
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, verts[m].tv.x, verts[m].tv.y);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, verts[m].lv.x, verts[m].lv.y);
glVertex3f(verts[m].pos.x, verts[m].pos.y, verts[m].pos.z);
}
}
glEnd();
}
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);

blender
03-19-2002, 10:13 AM
My graphics card doesn't seem to support either ARB_texture_env_combine or EXT_texture_env_combine.

Still I can see overbrighting in some games like quake3 and blood2.

Humus
03-19-2002, 10:28 AM
Hmm, what card do you have? EXT_texture_env_combine should be supported by at least TNT and up AFAIK.

Another possibility is to use multipass. First draw the base texture, then the lightmap with blending glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR). This will also be a scale by 2 (src * dest + dest * src = 2 * src * dest).

blender
03-20-2002, 06:11 AM
I have this damn Voodoo3 3000, which supports nothing. I'm planning to buy GeForce 2 this week.

How for example quake3 renders lightmaps with overbrighting on my machine? Multipass?

Do you mean that I should render first all the polygons with base texture, and then draw all the polygons with lightmaps. Fps will surely drop down badly.

If I can't do overbrighting well with Voodoo, I'll maybe just have to put It off from voodoo users.

blender
03-20-2002, 10:49 AM
If I'll do as following:

If the graphics card supports only two multitextures, it uses them for regular lightmapping, and then uses also at the same time multipass for overbrighting.

If the card supports more than two textures, it uses 3rd for overbrighting.

I'm just wondering how does other games do overbrighting.

zeckensack
03-20-2002, 11:01 AM
Originally posted by blender:
If I'll do as following:

If the graphics card supports only two multitextures, it uses them for regular lightmapping, and then uses also at the same time multipass for overbrighting.

If the card supports more than two textures, it uses 3rd for overbrighting.

I'm just wondering how does other games do overbrighting.

Howdy,

having seen the versatility of the color/texture combine operations in glide, the Voodoos must be able to support advanced texture environments which are needed for what you want to do.

Get your extension string, look for everything with texture_env in it. Then cross-check with the Extension Registry (http://oss.sgi.com/projects/ogl-sample/registry/) and see if some blending equations are useful to you. I know that the hardware can do that, and it would puzzle me if it wasn't exposed somehow.

zeckensack
03-20-2002, 11:03 AM
PS: the easy way would be to just fire up Quake, it displays all the extensions it found in the console and in setup->system->driver info. If you want to post your list of texture env extensions here, be my guest. http://www.opengl.org/discussion_boards/ubb/smile.gif

Tom Nuydens
03-20-2002, 01:37 PM
Originally posted by zeckensack:
I know that the hardware can do that, and it would puzzle me if it wasn't exposed somehow.

Unfortunately, 3dfx wasn't exactly famous for the quality of their OpenGL drivers http://www.opengl.org/discussion_boards/ubb/smile.gif


PS: the easy way would be to just fire up Quake, it displays all the extensions it found in the console and in setup->system->driver info. If you want to post your list of texture env extensions here, be my guest. http://www.opengl.org/discussion_boards/ubb/smile.gif

Why bother? http://www.delphi3d.net/hardware http://www.opengl.org/discussion_boards/ubb/smile.gif

They had EXT_texture_env_add from the Voodoo3 upwards. Looks like EXT_texture_env_combine was only supported on the Voodoo4/5.

-- Tom

blender
03-21-2002, 05:24 AM
I have this Nehe tutorial which shows my cards extensions:

GL_ARB_multitexture
GL_EXT_abgr
GL_EXT_bgra
GL_EXT_clip_volume_hint
GL_EXT_compiled_vertex_array
GL_EXT_packed_pixels
GL_EXT_point_parameters
GL_EXT_stencil_warp
GL_EXT_texture_env_add
GL_EXT_vertex_array
GL_SGIS_texture_edge_clamp
GL_EXT_paletted_texture
GL_EXT_shared_texture_palette
GL_SGIS_multitexture
WGL_EXT_extensions_string
WGL_3DFX_gamma_control
WGL_EXT_swap_control
WGL_ARB_extensions_string

(I hand typed those)

davepermen
03-21-2002, 07:46 AM
try texture-env-add, its not as good as signed add but you get nice overbrighting anyways..

blender
03-21-2002, 09:45 AM
I have tried GL_REPLACE and GL_ADD (base - lightmap) and the result is exactly the overbrighting I want, the big bad thing is that the important shadows are gone, becouse by adding I can't get black colors from lightmaps.

blender
03-21-2002, 10:18 AM
I have been searcing some info how others render lightmaps, and figured out that many uses multipass rendering. They say it's more flexible and doesn't drop fps that much if you use a powerful visibility determination.

zeckensack
03-21-2002, 11:18 AM
The exact equation is for you to decide. As a starting point, I suggest doing something like this:

Render light*base map in first pass.
Set blend equation to (GL_SRC_ALPHA,GL_ONE) <- requires alpha in lightmaps, maybe not optimal http://www.opengl.org/discussion_boards/ubb/confused.gif
Render light*light map in second pass.

This will add the cube of the light map to the general base*light pass. This way, when the lightmap is very bright, it'll add almost one to the framebuffer, for extreme overbrighting. If the lightmap is relatively dark, it won't change much.

blender
03-22-2002, 06:41 AM
If I use multipass and multitexture in the first, fps will go down (at least at this point).
I'v also had some color problems with alpha blended lightmaps: too much green and pink or something, even when the light color is white. That may be just a voodoo color thing, becouse I think it don't support big color depths (maybe just 16).

zeckensack
03-22-2002, 10:31 AM
You can simplify the second pass (and throw out alpha again) if you set your blend equation to (GL_ONE,GL_ONE). This will only add whatever you compute in the second pass (would be the square of the light intensity in my example).

The whole idea of taking the cube was to not overly influence the base pass where light intensity is low. You'll have to experiment a bit with that and you can also try to change your lightmap computations a bit.

However, multipassing will always cost you some performance. You have to resend geometry and it eats fill. Activated blending eats additional bandwith. You can minimize the fill overhead by using the GL_EQUAL depth function for your second pass. And you should simply skip the second pass altogether for objects where you don't need or want overbrighting at all.