glslmaskmultitexturing

GLSL dark seams between masks


Texturing follows:

gl_FragColor=texture2D(my_main_texture, vUv);

gl_FragColor= mix(gl_FragColor,texture2D(texture[1], 32.0*vUv),texture2D(mask[0], vUv).r);
gl_FragColor= mix(gl_FragColor,texture2D(texture[2], 32.0*vUv),texture2D(mask[0], vUv).b);

For example, using a mask:

http://i.imgur.com/Y0p9ilH.png

But for some reason on the border between the red and blue masks do not produce a texture value, although the number of channels for each pixel between the blue and red mask is 255

For example, the following code having:

gl_FragColor=vec4(0.0);

gl_FragColor= mix(gl_FragColor,vec4(1.0),texture2D(mask[0], vUv).r);
gl_FragColor= mix(gl_FragColor,vec4(1.0),texture2D(mask[0], vUv).b);

I get:

http://i.imgur.com/hCMqbAm.png

The shaded circle - this is the border between the red and blue mask, it should not be

How to get rid of it? Perhaps the reason to use mix (), and there are other ways to achieve the desired result?


Solution

  • This is because of linear interpolation of texels. You get "in beetween values" which are half blue and half red. Thus resulting in grey. you may switch off texture interpolation. Or try:

    vec4 m0=texture2D(mask[0], vUv);
    gl_FragColor= gl_FragColor*(1.0-m0.r-m0.b)+texture2D(texture[1], 32.0*vUv)*m0.r+texture2D(texture[3], 32.0*vUv)*m0.b;