0
\$\begingroup\$

I have a terrain in OpenGL, and two textures which I am combining using GLSL mix() function. Here are the textures I am using. enter image description here

Now I am able to combine and mix these two textures, but for some reason, when I render the textures on the terrain, the terrain becomes transparent. I render the LHS texture first, and then I render the RHS texture with alpha channel, I don't understand why it is transparent.

enter image description here Here is an interesting fact, in the screenshot, you can see the result of the terrain when rendered on Nvidia GPU, when I render the same thing on interl HD 3k, I get different result. This result is how it is supposed to be, nothing is transparent in this following screenshot.

enter image description here

Here is my fragment shader code..

void main() 
{
vec4 dryTex   = texture( u_dryTex, vs_texCoord *1 );
vec4 grassTex = texture( u_grassTex, vs_texCoord *1 );
vec4 texColor1= mix(dryTex, grassTex , grassTex.a);   
out_fragColor = texColor1;
}
\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

There might be multiple problems with your code.

In your fragment shader you mix in a color which is transparent, this causes the end result to be partially transparent too. For this you could do the following:

out_fragColor = vec4( texColor1.rgb, 1.0 );

This forces fully opaque alpha, and keeps the color the same. This might not be enough, based on the setting of glBlendFunc, as it might blend based on the background alpha or something else. See the reference for details.

Another problem is that you are rendering your terrain using blending. Generally it is better to turn blending off when it is not needed, this might improve performance as well.

You can do this by glDisable(GL_BLEND); , and when you need it again turn it on by glEnable(GL_BLEND);

The resulting image vary on different graphics cards because of the different driver implementations. The default value of glBlendFunc might be different, hence the difference in the pictures.

\$\endgroup\$
1
  • \$\begingroup\$ Yes, that was an issue, i was interpolating alpha channel from grassTex as well. I should be more careful while working with interpolating function. Thanks a lot :) \$\endgroup\$
    – 2am
    Feb 1, 2014 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .