728x90
  1. Texturing a png so alpha channel part is transparent?

    Hello I have a PNG with an alpha channel I would like it so the transparent parts of the image
    are transparent when I texture to a quad. Right now they just show up as white. Considering the results I'm getting I'm guessing its not as easy as giving the WebGL API a png with an alpha channel. If anyone knows how to do this I would love to hear how you did it.
  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    208

    Re: Texturing a png so alpha channel part is transparent?

    Did you remember to enable blending?

    gl.enable ( gl.BLEND ) ;

    Does your shader copy the alpha channel of the texture into the alpha channel of the output?
  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    15

    Re: Texturing a png so alpha channel part is transparent?

    Thanks for the reply. I do not have blend enabled. I will do that.

    My shader looks like this:

    #ifdef GL_ES
    precision highp float;
    #endif
    varying vec2 vTextureCoord;
    uniform sampler2D uSampler;
    void main(void)
    {
    gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
    }

    Is what I'm doing here copying the alpha channel to the output?
  4. #4
    Junior Member
    Join Date
    Sep 2010
    Posts
    15

    Re: Texturing a png so alpha channel part is transparent?

    Using the above shader and adding these two lines of code got parts of my sprite to be transparent exactly as I wanted.

    gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
    gl.enable(gl.BLEND);

     That was suprisingly easy!


'WEB > WEBGL' 카테고리의 다른 글

WebGL Lesson 2 – Adding colour  (0) 2018.03.07
jQuery Ripples  (0) 2018.03.07
WebGL Lesson 1 – A triangle and a square  (0) 2018.03.03

+ Recent posts