Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify FlxGraphicShader #3327

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions flixel/graphics/tile/FlxGraphicsShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,44 @@ class FlxGraphicsShader extends GraphicsShader
{
if (openfl_HasColorTransform)
{
// concat transforms
openfl_ColorOffsetv = (openfl_ColorOffsetv * colorMultiplier) + (colorOffset / 255.0);
openfl_ColorMultiplierv *= colorMultiplier;
}
else
{
// overwrite openfl's transform
openfl_ColorOffsetv = colorOffset / 255.0;
openfl_ColorMultiplierv = colorMultiplier;
}
}
")
@:glFragmentHeader("
uniform bool hasTransform; // TODO: Is this still needed? Apparently, yes!
// Note: this is being set to false somewhere!
uniform bool hasTransform;
uniform bool hasColorTransform;

vec4 transform(vec4 color, vec4 mult, vec4 offset, float alpha)
{
color = clamp(offset + (color * mult), 0.0, 1.0);
return vec4 (color.rgb, 1.0) * color.a * alpha;
}

vec4 transformIf(bool hasTransform, vec4 color, vec4 mult, vec4 offset, float alpha)
{
return mix(color * alpha, transform(color, mult, offset, alpha), float(hasTransform));
}

vec4 flixel_texture2D(sampler2D bitmap, vec2 coord)
{
vec4 color = texture2D(bitmap, coord);
if (!(hasTransform || openfl_HasColorTransform))
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 = mix(color, vec4(0.0), float(color.a == 0.0));

return color * openfl_Alphav;
bool _hasTransform = openfl_HasColorTransform || hasColorTransform;
return transformIf(_hasTransform, color, openfl_ColorMultiplierv, openfl_ColorOffsetv, openfl_Alphav);
}
")
@:glFragmentBody("
Expand Down
Loading