OpenGL transparent images have black in them

后端 未结 4 554
醉酒成梦
醉酒成梦 2021-01-13 03:31

I am working on a game for Android and I was wondering why whenever I draw images with transparency there seems to always be some black added to the transparent parts. This

4条回答
  •  伪装坚强ぢ
    2021-01-13 04:26

    You can also divide by alpha, because, the problem is, when you export your textures, Image processing software may pre-multiply your Alpha channel. I ended up with alpha division into my fragment shader. The following code is HLSL, but you can easily convert it to GLSL:

    float4 main(float4 tc: TEXCOORD0): COLOR0
    {
        float4 ts = tex2D(Tex0,tc);
    
        //Divide out this pre-multiplied alpha
        float3 outColor = ts.rgb / ts.a;
    
        return float4(outColor, ts.a);
    }
    

    Note that this operation is lossy, very lossy and even if it will most likely suffice in cases such as these, it's not a general solution. In your case you can totally ignore the COLOR and serve original alpha AND white in your fragment shader, e.g. return float4(1,1,1,ts.a); (convert to GLSL)

提交回复
热议问题