View Full Version : blending textures using a mask

04-23-2004, 01:56 PM

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:

//Draw object with gray scale mask texture


//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.

04-23-2004, 04:56 PM
If your target hardware supports fragment programs, it supports texture combining. Check out the spec on ARB_texture_env_combine at the SGI (http://oss.sgi.com/projects/ogl-sample/registry/) site.

04-24-2004, 01:34 AM
It should be doable without any extension, just with 2 passes :

<draw with first texture without blending>

<enable blending>


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

And maybe the same way with ARB_multitexture.

04-26-2004, 10:51 PM
Thanks for the tips. The texture_env_combine extension looks like it should do the trick.