Sign in to follow this  

texture combines

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi., I'm tryng to speedup my render here, using multitexture when possible, however i'm facing a little problem. The scene has N dynamic lights, 1 static lightmap and 1 difuse map. For the dynamic lights, for the first light i render the scene normally, and for the rest of the lights i render them with blend (GL_SRC_ALPHA, GL_ONE). Now, to render the static lightmap and the difuse map, i add the dynamic lightmap with the static one, and modulate the difuse map, like this : glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD); glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); However it doens't look that good, i also tryed with gl_modulate in tu0, and altough it looks better, the dynamic lights are too bright. Can someone help me to setup the texture units, to get the desired result ? thanks, Bruno

Share this post


Link to post
Share on other sites
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);

It doesn't quite work like that. First, if you want to use the texturing mode GL_ADD you should do
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_ADD);

And then a few more calls to glTexEnvi to set up sources and operands (depending on exactly what you want to add.)
link
Second, using a texturing mode of GL_ADD does not make it possible to add to the pixels on screen. The texturing modes just tell how textures and vertex colors are combined.

Since this doesn't work, you can't just have the diffuse map on TU1 with GL_MODULATE, since that would mean that it gets modulated with the static lightmap and then this gets combined with the result from the previous passes depending on the blending mode.

If you can't do all lighting and the base texture in one pass, you should draw the base texture last, in TU0, with glBlendFunc(GL_ZERO,GL_SRC_COLOR) to modulate it. You can do several lights in one pass, though.

Also, for additive blending, shouldn't you just use glBlendFunc(GL_ONE,GL_ONE)? Or is the lighting encoded in the alpha channel (and if so, why don't you use it when rendering the first light)?

Here's one way to do render two lights in one pass:
//Add these lights to the previous pass
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
// Don't care about vertex color
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
// Add this light to the one in TU0
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_ADD);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT,GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_EXT,GL_SRC_COLOR);


And then finally you would do one pass with the diffuse map, with glBlendFunc(GL_ZERO,GL_SRC_ALPHA).

Hope that helps a bit [grin]

Share this post


Link to post
Share on other sites
Thanks mate , however i'm not sure that i explained correctly what i'm tryng to do :)

This is my code that renders everything in several passes.,

render_Dynamic_lights();

If there's only 1 light, no blending is enabled, and the scene is just rendered.
If more than 1 light exists, several passes are made to get them all on screen.

This next step, wich is the one i'm tryng to optimize, is also made in 2 passes.,

This pass, to blend the static lightmaps with the dynamic lightmaps.

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);
drawFaces_Lightmaps();

And the last step, to blend the difuse maps,

glBlendFunc(GL_ONE_MINUS_DST_ALPHA,GL_SRC_COLOR);
drawFaces_Difuse();


This last two steps were the ones i'm tryng to do with multitexture.
I have seen the link you posted, but still i don't get it on how the texture combiners setup work,

thanks for any help,
Bruno











Share this post


Link to post
Share on other sites
Well, the point is that you can't really do the last two passes as one multitextured pass. The problem is that what you want to do is:
(sum of all dynamic lights+static light)*diffuse texture.
You can't access what's already rendered on screen when doing multitexturing - all you can do is combine the textures first, and then combine this with what's on screen using blending.

For the light textures this will work fine, since all you want to do is add them together. For the diffuse texture this is a problem, since you want to multiply it with not only the light texture(s) in the current pass, but also the ones in the passes that have already been rendered.

Share this post


Link to post
Share on other sites
Well, if you don't have enough texture units, you'll just have to do several passes.
First do light passes with as many lights as you have texture units per pass, and then finally a pass with only the diffuse map.
If it's too slow, then I guess you'll just have to use fewer lights :)

Share this post


Link to post
Share on other sites

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this