Skip to content

Commit 3e3a7be

Browse files
committed
Fixed blend mode and alpha issues when drawing bitmaps that use textures
1 parent 6766616 commit 3e3a7be

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

flixel/graphics/tile/FlxDrawQuadsItem.hx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem<FlxDrawQuadsItem>
118118
// TODO: catch this error when the dev actually messes up, not in the draw phase
119119
if (shader == null && graphics.isDestroyed)
120120
throw 'Attempted to render an invalid FlxDrawItem, did you destroy a cached sprite?';
121-
121+
122122
final shader = shader != null ? shader : graphics.shader;
123123
shader.bitmap.input = graphics.bitmap;
124124
shader.bitmap.filter = (camera.antialiasing || antialiasing) ? LINEAR : NEAREST;
125125
shader.alpha.value = alphas;
126+
final isTexture:Bool = !graphics.bitmap.readable;
127+
shader.isTexture.value = [isTexture];
126128

127129
if (colored || hasColorOffsets)
128130
{
@@ -146,4 +148,4 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem<FlxDrawQuadsItem>
146148
parameter.value[0] = value;
147149
}
148150
#end
149-
}
151+
}

flixel/graphics/tile/FlxGraphicsShader.hx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class FlxGraphicsShader extends GraphicsShader
1212
", true)
1313
@:glVertexBody("
1414
openfl_Alphav = openfl_Alpha * alpha;
15-
15+
1616
if (hasColorTransform)
1717
{
1818
if (openfl_HasColorTransform)
@@ -30,27 +30,32 @@ class FlxGraphicsShader extends GraphicsShader
3030
@:glFragmentHeader("
3131
uniform bool hasTransform; // TODO: Is this still needed? Apparently, yes!
3232
uniform bool hasColorTransform;
33+
uniform bool isTexture;
3334
vec4 flixel_texture2D(sampler2D bitmap, vec2 coord)
3435
{
3536
vec4 color = texture2D(bitmap, coord);
37+
38+
if (isTexture)
39+
color.rgb *= color.a;
40+
3641
if (!(hasTransform || openfl_HasColorTransform))
3742
return color;
38-
43+
3944
if (color.a == 0.0)
4045
return vec4(0.0, 0.0, 0.0, 0.0);
41-
46+
4247
if (openfl_HasColorTransform || hasColorTransform)
4348
{
4449
color = vec4 (color.rgb / color.a, color.a);
4550
vec4 mult = vec4 (openfl_ColorMultiplierv.rgb, 1.0);
4651
color = clamp (openfl_ColorOffsetv + (color * mult), 0.0, 1.0);
47-
52+
4853
if (color.a == 0.0)
4954
return vec4 (0.0, 0.0, 0.0, 0.0);
50-
55+
5156
return vec4 (color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav);
5257
}
53-
58+
5459
return color * openfl_Alphav;
5560
}
5661
", true)

0 commit comments

Comments
 (0)