0
votes

I am trying to apply a texture (128x128 with a black arrow in the middle and the rest of the texture is transparent). My model contains vertices that also have color data. Before I apply the texture the model looks correct with each vertex containing the correct color information. Once I apply the texture, it shows up correctly with the arrows everywhere with the portions that should be transparent are transparent yet the model is also transparent. I want the texture to lay "on top" of the model and you should be able to see through the transparent portion of the texture and see the colors of the model underneath. See below for what I'm talking about. I have glEnable(GL_BLEND) and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) added as well.

As you can see below, the first image is with the texture and the second image is without the texture. I want to be able to see the color data of the second image on the first image. What is the issue?

with texturewithout texture

2
Post your shader code, assuming you are using ES 2 or 3. Are you using GLKit?Ben Pious
I'm using GLKit, yes.kschins
Are you using back face culling?rickster
No, I don't believe so.kschins

2 Answers

0
votes

The Blend Function is generally used for overlapping semi-transparent polygons. From your description, I do not think it is relevant.

It sounds like you are asking to derive the output color from the alpha-weighted average of the vertex color and texture color. In a shader that would look something like this:

gl_FragColor = vec4(
  vertexColor.a * vertexColor.rgb + textureColor.a * textureColor.rgb, 1.0);

Using GLKit you may be able to achieve the desired effect with GLKBaseEffect but I have not tried it. Documentation points out you must enable GLKVertexAttribColor in addition to setting up texture coordinates. Given your images it seems you've done that, so you may need to write your own shader.

0
votes

The ability to set the fragment color using GLKit relies on using the envMode property on GLKEffectPropertyTexture. This was a comment I posted earlier but am going to mark it as the answer now.