Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
gl_FragColor alpha issue — Gideros Forum

gl_FragColor alpha issue

keszeghkeszegh Member
edited January 2020 in Bugs and issues
I'm trying to make a shader which changes the color of every pixel to some fixed color while preserving the alpha value.
It should be as simple as this (to set it to green e.g.):
lowp vec4 col=texture2D(fTexture,fTexCoord);
gl_FragColor = vec4(0.0,1.0,0.0,col.a)
However, the alpha value does not seem to be used, so the whole thing becomes homogenously colored to (0.0,1.0,0.0,1.0).
Is this a bug in gideros or am i doing something wrong? i spent an hour trying to understand what i'm doing wrong, and it seems that maybe nothing.
even the simpler example
gl_FragColor = vec4(0.0,1.0,0.0,0.1)
outputs all pixels (0.0,1.0,0.0,1.0).

i'm tring it on a windows pc. please help.


  • keszeghkeszegh Member
    edited January 2020
    lowp vec4 col=texture2D(fTexture,fTexCoord);
    vec3 colTo=vec3(0.0,1.0,0.0)
    gl_FragColor = vec4(colTo*col.a,col.a);
    does seem to do what i want. but i don't understand why. can you explain?
  • hgy29hgy29 Maintainer
    OpenGL blends the shader output with the on-screen color using one of the blending operations available. In Gideros the shader output is supposed to be 'premultiplied alpha' and blending is set accordingly. So what you experience is correct, you have to premultiply the color with the alpha channel before outputting it.
    Note that if you lookup a texture you'll also get an alpha premultiplied sample, since Gideros converts image to that format before uploading them to the GPU.

    I can't tell why Gideros uses premultiplied alpha output, but it seems to be a common convention in OpenGL programs.
  • thanks, i mostly understand what you say. it's very useful info when working with shaders.
    it is very confusing though for me as it is different from how gideros/lua handles colors.
Sign In or Register to comment.