Blending Question

Started by
3 comments, last by Lord_Evil 15 years, 3 months ago
Hi, I'm trying to blend two images, where one image is like a mask, and represents what I want to be drawn on the screen, and the other image represents a pattern of what I want to be drawn as the texture for the mask. For example. The mask will keep it's position and coordinates on the screen, but the pattern texture will move it's texture coordinates around so it looks like the image is flowing. Here is an example of what I'm talking about: Mask - Pattern - Result- ( I want it so I can change the tex coords on just the pattern like this ) Thanks in advance.
Advertisement
Oh, and the black part of the image should be completely transparent.
Use shaders
This site and many others talk about GLSL shaders
http://lumina.sourceforge.net
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Well, you need multitexturing (or atleast 2 texture coords), one for your mask and one for your animated texture. Then you need to calculate your final output color in a shader so that final_color.rgb=color_texture(1. texture coord) and final_color.a=mask(2. texture coord). Now you could either use blending (more expensive) or alpha testing (better in this case) to mask your animated texture.

blending:
blend_source_mode = source_alpha
blend_dest_mode = inverse_source_alpha

alpha testing:
enable alpha testing, set your reference alpha value to 0.5 and the comparision operation to greater_equal.

--
Ashaman
Well, you don't need shaders.

Just provide two texture coordinates per vertex and assign each texture unit the corresponding coordinate set.

You could also employ a texture matrix to transform the texture coordinates for a specific texture unit (e.g. scaling/translating).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

This topic is closed to new replies.

Advertisement