Search code examples
openglglslshaderfragment-shader

Trying to blend diffuse texture with cubemap makes object invisible


I'm following the learnopengl website and I'm trying to combine the diffuse texture I have on the object with the calculated reflection/refraction vectors but it makes the object invisible. When I set gl_FragColor = environmentColor; it works fine but the moment I try to multipliy, add, or mix the diffuse texture the object becomes invisible. Here is the code I have:

vec3 norm = normalize(Normal);

vec3 viewVector = normalize(worldPosition.xyz - cameraPosition);
vec3 reflectedVector = reflect(viewVector, norm);
vec3 refractedVector = refract(viewVector, norm, 0.68047f);
vec4 reflectedColor = texture(skybox, reflectedVector);
vec4 refractedColor = texture(skybox, refractedVector);
vec4 environmentColor = mix(reflectedColor, refractedColor, 0.5f);

gl_FragColor = mix(texture(texture_diffuse1, TexCoords), environmentColor, 0.5f);

Solution

  • I found my mistake for anyone else that might have this same issue: I was setting the location of the cubemap textures to be the same as my sampler2D textures. I simply modified the glActiveTexture for the cubemap textures to be using GL_TEXTURE1 instead of GL_TEXTURE0 and initialized the uniforms to point to 1 and everything works now.