Reputation: 21
I am have a problem figuring out how to get my fragmentshader to load 3 images properly. The objective is : Load three texture images IMAGE1, IMAGE2, and IMAGE3. IMAGE3 should be a black and white image. Use IMAGE3 as a filter. For any given pixel P, if the corresponding texture pixel color in IMAGE3 is white, then use IMAGE1 to texture map pixel P. If the corresponding pixel color in MAGE3 is black, then use IMAGE2 to texture map pixel P. If the corresponding pixel color in MAGE3 is neither black or white, then use a mixture of IMAGE1 and IMAGE2 to texture map pixel P.
Now I can get it working with IMAGE1 displaying in the white shaded area of IMAGE3 but I am having a hard time getting IMAGE2 to display in the Black area of IMAGE3 without overlapping IMAGE1 in the HEXAGON. Any help would be appreciated.
#version 330
in vec2 textureCoord;
uniform sampler2D textureMap0;
uniform sampler2D textureMap1;
uniform sampler2D textureMap2;
out vec4 fragColor;
void main() {
// retrieve color from each texture
vec4 textureColor1 = texture2D(textureMap0, textureCoord);
vec4 textureColor2 = texture2D(textureMap1, textureCoord);
vec4 textureColor3 = texture2D(textureMap2, textureCoord);
//vec4 finalColor = textureColor1 + textureColor2 + textureColor3;
// Combine the two texture colors
// Depending on the texture colors, you may multiply, add,
// or mix the two colors.
#if __VERSION__ >= 130
if ((textureColor1.r == 0.0f) && (textureColor1.g == 0.0f)
&& (textureColor1.b == 0.0f)) {
textureColor1.r = 1.0f;
}
//fragColor = mix(fragColor,finalColor,0.5);
fragColor = textureColor1 * textureColor3 ;//* textureColor3;
#else
gl_FragColor = textureColor1 * textureColor2;// * textureColor3;
#endif
}
Upvotes: 1
Views: 60
Reputation: 160
I think this should do what you describe:
vec4 textureColor4 = vec4(vec3(1.0, 1.0, 1.0) - textureColor3.rgb, 1.0)
//...
fragColor = textureColor3 * textureColor1 + textureColor 4 * textureColor2;
Which is essentially a linear interpolation.
Upvotes: 1