Jump to content
  • Advertisement
Sign in to follow this  
O-san

Shimmering effect on texture

This topic is 2658 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

Hello, I am trying to apply shimmer to a blended/alpha-tested texture (I got both kinds) in fixed function. The problem is I want to use the same shimmer texture on every object that should have shimmer. The object's texture alpha channel should mask the shimmer texture.
tn_gallery_119664_44_5287.png
Maybe with some kind of multi-pass technique? Thank you for any help.

Share this post


Link to post
Share on other sites
Advertisement
You should probably look at texture combiners, e.g. start here. it allows to blend textures before the result is blended with the frame buffer.

Share this post


Link to post
Share on other sites
Thanks for the reply, I haven't used texture combiners before and I can't quite figure them out. This is what I have tried now...

glActiveTexture(GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);

// RGB
glActiveTexture(GL_TEXTURE2);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);

// Alpha
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);

But it gives weird results:

gallery_119664_44_381624.png

Only the red pixel in the bottom right of texture#2 is added to the base texture. I use the same texture coordinates for both units:

glActiveTexture(GL_TEXTURE0);
glTexCoordPointer(2,GL_FLOAT,sizeof(Vector2D),&uv[0]);
glActiveTexture(GL_TEXTURE2);
glTexCoordPointer(2,GL_FLOAT,sizeof(Vector2D),&uv[0]);

Share this post


Link to post
Share on other sites
Combining textures means that the very first texture is used "as is", and the sub-sequent textures are combined. Hence the 1st texture (of unit 0 in your case ?) must be set to mode DECAL:

glActiveTexture(GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);


[font="sans-serif"]Effects like light, fire, laser beam, lightning bolt, ... are usually blended using additive translucency; no alpha weighting in use. Perhaps you want to do so also for shimmering. If so then add the shimmering texture (pre-multiplied RGB) onto the object texture (pre-multiplied RGBA), and let the object texture's alpha passthrough for blending with the framebuffer.[/font] [font="sans-serif"]Notice please that the textures should be pre-multiplied to avoid spatial interpolation artifacts. This means later that the fragment weight should be GL_ONE and those of the framebuffer GL_ONE_MINUS_SRC_ALPHA for blending.[/font]
[font="sans-serif"] [/font]
[font="sans-serif"] [/font]
[font="sans-serif"]EDIT: I'm not sure about, but perhaps something like[/font]
[font="sans-serif"]

// texture0: RGBA w/ object
// texture1: RGB w/ shimmering

glActiveTexture(GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);

would do the job!?
[/font]

Share this post


Link to post
Share on other sites
I got it working now. I hadn't my texture coords sent right.. needed to call glClientActiveTextureARB (GL_TEXTURE2);

But I can't use decal as the base GL_TEXTURE_ENV_MODE. Then I loose my alpha testing and lighting. :P it works fine if I use

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DECAL);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!