Skip to content

Commit

Permalink
Simplify FlxGraphicsShader
Browse files Browse the repository at this point in the history
  • Loading branch information
Geokureli committed Dec 26, 2024
1 parent 609003b commit dfa6630
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
1 change: 0 additions & 1 deletion flixel/graphics/tile/FlxDrawQuadsItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem<FlxDrawQuadsItem>
shader.colorOffset.value = colorOffsets;
}

setParameterValue(shader.hasTransform, true);
setParameterValue(shader.hasColorTransform, colored || hasColorOffsets);

#if (openfl > "8.7.0")
Expand Down
50 changes: 11 additions & 39 deletions flixel/graphics/tile/FlxGraphicsShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,26 @@ import openfl.display.GraphicsShader;

class FlxGraphicsShader extends GraphicsShader
{
@:glVertexHeader("
attribute float alpha;
attribute vec4 colorMultiplier;
attribute vec4 colorOffset;
@:glFragmentHeader("
uniform float alpha;
uniform vec4 colorMultiplier;
uniform vec4 colorOffset;
uniform bool hasColorTransform;
")
@:glVertexBody("
openfl_Alphav = openfl_Alpha * alpha;
if (hasColorTransform)
vec4 transform(bool has, vec4 color, vec4 mult, vec4 offset)
{
if (openfl_HasColorTransform)
{
openfl_ColorOffsetv = (openfl_ColorOffsetv * colorMultiplier) + (colorOffset / 255.0);
openfl_ColorMultiplierv *= colorMultiplier;
}
else
{
openfl_ColorOffsetv = colorOffset / 255.0;
openfl_ColorMultiplierv = colorMultiplier;
}
return mix(color, clamp(offset + (color * mult), 0.0, 1.0), float(has));
}
")
@:glFragmentHeader("
uniform bool hasTransform; // TODO: Is this still needed?
uniform bool hasColorTransform;
vec4 flixel_texture2D(sampler2D bitmap, vec2 coord)
{
vec4 color = texture2D(bitmap, coord);
if (!(hasTransform || openfl_HasColorTransform))
return color;
if (color.a == 0.0)
return vec4(0.0, 0.0, 0.0, 0.0);
if (openfl_HasColorTransform || hasColorTransform)
{
color = vec4 (color.rgb / color.a, color.a);
vec4 mult = vec4 (openfl_ColorMultiplierv.rgb, 1.0);
color = clamp (openfl_ColorOffsetv + (color * mult), 0.0, 1.0);
if (color.a == 0.0)
return vec4 (0.0, 0.0, 0.0, 0.0);
return vec4 (color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav);
}
color = transform(openfl_HasColorTransform, color, openfl_ColorMultiplierv, openfl_ColorOffsetv);
color = transform(hasColorTransform, color, colorMultiplier, colorOffset / 255.0);
return color * openfl_Alphav;
float _alpha = color.a * openfl_Alphav * alpha;
return vec4 (color.rgb * _alpha, _alpha);
}
")
@:glFragmentBody("
Expand Down

0 comments on commit dfa6630

Please sign in to comment.