blending textures using a mask

Hi,

I want to be able to blend two textures according to a gray scale mask. The first texture should show up in the white area of the mask. The second texture should show up in the black area of the mask. And both textures should be blended accordingly in the gray areas.

I had no problem doing this using a fragment program, but I would like to implement this without using any shaders.

I figured I would have to render the object multiple times and use glBlendFunc to blend the textures. I’m able get the first texture blended correctly but I can’t figure out how to blend in the second texture. Here’s what I have so far:

glDisable(GL_BLEND);
//Draw object with gray scale mask texture

glEnable(GL_BLEND);

glBlendFunc(GL_ZERO,GL_SRC_COLOR);
//Draw object with first blended texture
//This will fill in the white areas

What should I do next in order to blend in the second texture so that it fills in the black area of the original mask? Is possible to do with the technique I’m using? Should I use an alpha mask instead of a gray scale mask? Any help is greatly appreciated.

If your target hardware supports fragment programs, it supports texture combining. Check out the spec on ARB_texture_env_combine at the SGI site.

It should be doable without any extension, just with 2 passes :

<draw with first texture without blending>

<enable blending>

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

<draw with second texture with RGBA, A having the ‘greyscale values’ of transparency>

And maybe the same way with ARB_multitexture.

Thanks for the tips. The texture_env_combine extension looks like it should do the trick.