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

Fix camera.color #3326

Merged
merged 2 commits into from
Dec 30, 2024
Merged
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
71 changes: 32 additions & 39 deletions flixel/graphics/tile/FlxGraphicsShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,59 @@ import openfl.display.GraphicsShader;

class FlxGraphicsShader extends GraphicsShader
{
@:glVertexSource("
#pragma header

@:glVertexHeader("
attribute float alpha;
attribute vec4 colorMultiplier;
attribute vec4 colorOffset;
uniform bool hasColorTransform;

void main(void)
")
@:glVertexBody("
openfl_Alphav = openfl_Alpha * alpha;

if (hasColorTransform)
{
#pragma body

openfl_Alphav = openfl_Alpha * alpha;

if (hasColorTransform)
if (openfl_HasColorTransform)
{
openfl_ColorOffsetv = (openfl_ColorOffsetv * colorMultiplier) + (colorOffset / 255.0);
openfl_ColorMultiplierv *= colorMultiplier;
}
else
{
openfl_ColorOffsetv = colorOffset / 255.0;
openfl_ColorMultiplierv = colorMultiplier;
}
}")
}
")
@:glFragmentHeader("
uniform bool hasTransform;
uniform bool hasTransform; // TODO: Is this still needed? Apparently, yes!
uniform bool hasColorTransform;

vec4 flixel_texture2D(sampler2D bitmap, vec2 coord)
{
vec4 color = texture2D(bitmap, coord);
if (!hasTransform)
{
if (!(hasTransform || openfl_HasColorTransform))
return color;
}


if (color.a == 0.0)
{
return vec4(0.0, 0.0, 0.0, 0.0);
}

if (!hasColorTransform)
{
return color * openfl_Alphav;
}

color = vec4(color.rgb / color.a, color.a);

color = clamp(openfl_ColorOffsetv + (color * openfl_ColorMultiplierv), 0.0, 1.0);

if (color.a > 0.0)

if (openfl_HasColorTransform || hasColorTransform)
{
return vec4(color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav);
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);
}
return vec4(0.0, 0.0, 0.0, 0.0);

return color * openfl_Alphav;
}
")
@:glFragmentSource("
#pragma header

void main(void)
{
gl_FragColor = flixel_texture2D(bitmap, openfl_TextureCoordv);
}")
@:glFragmentBody("
gl_FragColor = flixel_texture2D(bitmap, openfl_TextureCoordv);
")
public function new()
{
super();
Expand Down
Loading