Texture Blending

Started by
4 comments, last by mrrolf810p 21 years, 7 months ago
I''m drawing a textured quad. I want the texture''s alpla to be a gaussian distrobution, but it is impossible for me to do this with the original texture, and there are too many textures to edit and create. So I''m trying to draw the quad using 2 textures, one is the original texture, and the other is a black and white gaussian distrobution. I''m not sure that I''m setting the glBlendFunc() correctly. I''ve try many combinations and nothing is doing what I want. Anyone with some ideas on how to blend the images correctly(so the first texture''s alpha is the second texture''s color)? Thanks
Advertisement
I''m not sure what effect you want to achieve.

Though, if you want to redirect first texture''s alpha channel to the second texture''s color, you can use the ARB_texture_env_combine extension (which is part of the OpenGL kernel since OpenGL1.3)
Hopefully this will be a better explanation.

I''m trying to take these two textures:
http://www.prism.gatech.edu/~gte810p/1.jpg
http://www.prism.gatech.edu/~gte810p/2.jpg

blend then and end up with this on the quad:
http://www.prism.gatech.edu/~gte810p/3.jpg

I need the black areas to be transparent.
Sorry about the second post, it''s gone now.

Thanks
That''s really a ''better'' explanation. thanks !

Are they two different textures ?
Or is it one texture with the ''wall'' into the texture''s RGB components and ''mask'' into the texture''s Alpha component ?
They are two different textures.

The wall is one big texture(I cropped the full image for the pictures I posted). I''m drawing ~100k quads using this texture. It is only RGB.

The second texture is one that I created in PSP. It also only has RGB.

The ''or'' part of your responce sounds like what I need. I need the wall texture to have an alpha component that is like the rgb of the second image.

I''m trying to draw splats using this texture. As of right now I''m just drawing normal textured quads for each splat. I would like to have each splat have a high alpha value in the middle, and fade off going away from the center. The second image is how I would like the alphas, high in the middle and more transparent the further from the middle. The final texture should resemble the third picture I posted.

I''ve been trying to do this by blending the two textures(first and second one) when I draw the quad, but have had no luck.
Ok then I see 4 solutions :


Solution 1 : alpha buffer
Render the ''gaussian mask'' into the alpha buffer without enabling rgb writes, and then render (in a second pass) the ''wall texture'' with the blending glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA).

Advantages :
- works on all OpenGL implementations (at least in theory)

Disadvantages :
- your driver have to be able to allocate an alpha buffer (some old cards can''t)
- you can''t use the alpha buffer for other tricks
- you have to clear the alpha buffer if many of those gaussian objects may overlap (and obviously this operation wastes some fillrate)
- since it''s done in two passes, it wastes fillrate
- you need to load your ''gaussian mask'' with GL_INSTENSITY or GL_ALPHA (or GL_RGBA) but not GL_RGB because you write into the alpha buffer


Solution 2 : multitexturing with combine
Activate multitexturing and set the ''wall texture'' in the first texture unit, an set the ''gaussian mask'' in the second texture unit, and combine the textures with a little trick.

Advantages :
- do it in one pass (saves fillrate)
- don''t need to resize the texture(s) and/or merge them

Disadvantages :
- need at least OpenGL1.3, or need OpenGL1.1 with ARB_multitexture and ARB_texture_env_combine extensions supported
- you need to load your ''gaussian mask'' with GL_INSTENSITY or GL_ALPHA (or GL_RGBA) but not GL_RGB because you use the gaussian mask as an alpha component


Solution 3 : single texturing with colors
If your wall quad is splitten into several quads, then you can just use the ''wall texture'' and for each vertex you call glColor4f(1, 1, 1, alpha_component) where alpha_component is a variable that is zero when the vertex is close to the border, and that is one when the vertex is close to the center.

Advantages :
- works on all OpenGL implementations for sure
- you need a single texture
- don''t need to resize the texture(s) and/or merge them

Disadvantages :
- you have to tesselate you quad with a significant number of miniquads otherwise it will look crap
- you can''t use the glColor for some other effect
- you have to force glShadeModel(GL_SMOOTH), ie Gouraud shading (but is it really a problem?)


Solution 4 : build an RGBA texture
Build your own texture so that the ''wall texture'' fill the RGB components of the texture and so that the ''gaussian mask'' fills the Alpha component

Advantages :
- works on all OpenGL implementations
- you need a single texture

Disadvantages :
- you need some pre-processing when the texture is loaded
- you may have to resize one of the two textures because they must have the same dimensions when you merge them



Choose whatever you want, or maybe choose another !
Anyway, please ask for implementation details when you feel like you''re going to use one (or more) of these methods.


Personaly I would use solution #2, and at runtime I would test if the OpenGL features are supported (eg test if OpenGL version is greater or equal than 1.3), and if the features are not supported I would use solution #4 as a backdoor.

This topic is closed to new replies.

Advertisement