Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

skow

Multitexturing alpha based blending?

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

I''m making some terrain, at a higher y value I want there to be snow and at a lower heights rock. In between the rock and the snow I want there to be a blending of both. The rock I have bound under GL_TEXTURE1_ARB and the snow under GL_TEXTURE0_ARB. I set the alpha values for the snow per vertex using glColor4f(). How do I set up the glTexEnvi to draw the snow over the rock depending on its alpha value? Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Well after a LOT of searching I found this which is supposed to do the trick, but it looks the same GL_DECAL.


// Init texture unit 0

glActiveTexture( GL_TEXTURE0 );
// Set up texture function for RGB and alpha channel

glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE );
// Modulate the RGB components of the primary color and texture

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 );
// Replace the alpha component

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PREVIOUS_EXT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA );

// Init texture unit 1

glActiveTexture( GL_TEXTURE1 );
// Set up texture function for RGB and alpha channel

glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE );
// Interpolate the RGB components of the first and second texture

// using the alpha primary color

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_ZERO );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_ONE_MINUS_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PREVIOUS_EXT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE3_RGB_NV, GL_TEXTURE );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND3_RGB_NV, GL_SRC_COLOR );
// Replace the alpha component

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PREVIOUS_EXT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA );


This doesn't work. I would really like to be able to do this without doing second poly pass, any suggestions?

[edited by - skow on February 29, 2004 6:15:18 PM]

Share this post


Link to post
Share on other sites
If you only have 2 textures, use GL_COMBINE with GL_INTERPOLATE.
This will smoothly blend between 2 textures based on the supplied alpha value. look for the specs here: http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt

Good luck.



Waramp.

"Before you insult a man, walk a mile in his shoes.
That way, when you do insult him, you''ll be a mile away, and you''ll have his shoes."

Share this post


Link to post
Share on other sites

  • 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!