Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does alpha blending gradient textures yield unexpected results in OpenGL ES 2.0?
    primarykey
    data
    text
    <p>I have a radial gradient texture (RGBA) that goes from a black fully opaque color in the center to fully transparent one at the edges:</p> <p><img src="https://i.stack.imgur.com/94jHH.png" alt="ball.png"></p> <p>I've set up an iOS project using the recent OpenGL template, which uses GLKit. I added texture capability and have the following code set in the setupGL method:</p> <pre><code>glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); </code></pre> <p>When I overlap two of these textures (each has a separate z) in an ortho projection on a white background, I expect something like this:</p> <p><img src="https://i.stack.imgur.com/NrkCI.png" alt="right.png"></p> <p>But instead I get this:</p> <p><img src="https://i.stack.imgur.com/TgQp5.png" alt="wrong.png"></p> <p>My question is simply: why? Can OpenGL ES 2.0's blending not achieve this effect? (I've gotten it to work before in OpenGL ES 1.1) Is there a common thing I'm missing? Is it maybe a premultiplied alpha problem with my texture? If so could it be something strange with my PNG or the way I'm loading it? I'm loading textures using GLKTextureLoader.</p> <p>It's very possible I'm wrong, but I understand that it couldn't be a shader problem as alpha blending happens before it gets to the fragment shader. My shaders do little more than pass the information directly through. (Maybe that's a problem?)</p> <p>Vertex Shader:</p> <pre><code>attribute vec4 position; attribute vec2 texCoordIn; varying vec2 texCoordOut; uniform mat4 modelViewProjectionMatrix; void main() { gl_Position = modelViewProjectionMatrix * position; texCoordOut = texCoordIn; } </code></pre> <p>Fragment Shader:</p> <pre><code>varying lowp vec2 texCoordOut; uniform sampler2D texture; void main() { gl_FragColor = texture2D(texture, texCoordOut); } </code></pre> <p>I've also tried setting the glBendFunc as follows, but I get the same results:</p> <pre><code>glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); </code></pre> <p>Any tips or common hangups are welcome. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload