@@ -87,11 +87,18 @@ const vec2 kCenter = vec2(0.5, 0.5);
87
87
88
88
void main()
89
89
{
90
- vec4 texColor = texture2D (u_skin, v_texCoord);
90
+ vec2 texcoord0 = v_texCoord;
91
+
92
+ gl_FragColor = texture2D (u_skin, texcoord0);
93
+
94
+ #if defined(ENABLE_color) || defined(ENABLE_brightness)
95
+ // Divide premultiplied alpha values for proper color processing
96
+ // Add epsilon to avoid dividing by 0 for fully transparent pixels
97
+ gl_FragColor .rgb = clamp (gl_FragColor .rgb / (gl_FragColor .a + epsilon), 0.0 , 1.0 );
91
98
92
99
#ifdef ENABLE_color
93
100
{
94
- vec3 hsv = convertRGB2HSV(texColor .rgb);
101
+ vec3 hsv = convertRGB2HSV(gl_FragColor .rgb);
95
102
96
103
// Force grayscale values to be slightly saturated
97
104
const float minLightness = 0.11 / 2.0 ;
@@ -102,22 +109,20 @@ void main()
102
109
hsv.x = mod (hsv.x + u_color, 1.0 );
103
110
if (hsv.x < 0.0 ) hsv.x += 1.0 ;
104
111
105
- texColor .rgb = convertHSV2RGB(hsv);
112
+ gl_FragColor .rgb = convertHSV2RGB(hsv);
106
113
}
107
114
#endif // ENABLE_color
108
115
109
116
#ifdef ENABLE_brightness
110
- texColor .rgb = clamp (texColor .rgb + vec3 (u_brightness), vec3 (0 ), vec3 (1 ));
117
+ gl_FragColor .rgb = clamp (gl_FragColor .rgb + vec3 (u_brightness), vec3 (0 ), vec3 (1 ));
111
118
#endif // ENABLE_brightness
112
119
120
+ // Re-multiply color values
121
+ gl_FragColor .rgb *= gl_FragColor .a + epsilon;
122
+
123
+ #endif // defined(ENABLE_color) || defined(ENABLE_brightness)
124
+
113
125
#ifdef ENABLE_ghost
114
- texColor *= u_ghost;
126
+ gl_FragColor *= u_ghost;
115
127
#endif // ENABLE_ghost
116
-
117
- // Set RGB components to zero if the color is fully transparent
118
- // This is a workaround for rendering issues when alpha is zero
119
- if (texColor.a == 0.0 )
120
- gl_FragColor = vec4 (0.0 , 0.0 , 0.0 , 0.0 );
121
- else
122
- gl_FragColor = texColor;
123
128
}
0 commit comments