Reputation: 489
How can I blend two texture so the texture are side by side, With 50 % of texture A on the left, and 50% of texture B on the right.
for example
----------------
| | |
| 50% A | 50% B|
| | |
----------------
I want the region to be changeable, so might be 25% A 75% B.
Now I can blend two textures fully on the Rect, with each being translucent.
this is my frag shader
uniform sampler2D tex;
uniform sampler2D texx;
uniform float alpha;
in vec2 textureCoord;
out vec4 finalColor;
void main() {
vec4 first_sample = texture(tex, textureCoord);
vec4 second_sample = texture(texx, textureCoord);
finalColor = first_sample * alpha + second_sample * (1-alpha);
}
Do I need to create an alpha mask texture in my C++ program? Thank you.
Upvotes: 1
Views: 7012
Reputation: 18399
Alpha mask (1D texture would be enough) is one of possible solutions, but in this particular case it isn't necessary
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform float t; // e.g. 0.4
in vec2 texcoord;
out vec4 outColor;
void main(void)
{
vec4 t0 = texture2D(tex0, texcoord);
vec4 t1 = texture2D(tex1, texcoord);
outColor = mix(t0, t1, step(t, texcoord.x));
}
By the way, it isn't called 'blending'. Rather 'threshold' or 'step'.
Upvotes: 3