Skip to content

Commit

Permalink
Fix camera.color (#3321)
Browse files Browse the repository at this point in the history
* fix camera.color

* fix edge cases

* Simplify FlxGraphicsShader

* fix triangles
  • Loading branch information
Geokureli authored Dec 26, 2024
1 parent ab51c0c commit 593f04f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 55 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
1 change: 0 additions & 1 deletion flixel/graphics/tile/FlxDrawTrianglesItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem<FlxDrawTrianglesItem>
shader.colorOffset.value = null;
}

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

#if (openfl > "8.7.0")
Expand Down
71 changes: 18 additions & 53 deletions flixel/graphics/tile/FlxGraphicsShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,31 @@ import openfl.display.GraphicsShader;

class FlxGraphicsShader extends GraphicsShader
{
@:glVertexSource("
#pragma header
attribute float alpha;
attribute vec4 colorMultiplier;
attribute vec4 colorOffset;
uniform bool hasColorTransform;
void main(void)
{
#pragma body
openfl_Alphav = openfl_Alpha * alpha;
if (hasColorTransform)
{
openfl_ColorOffsetv = colorOffset / 255.0;
openfl_ColorMultiplierv = colorMultiplier;
}
}")
@:glFragmentHeader("
uniform bool hasTransform;
uniform float alpha;
uniform vec4 colorMultiplier;
uniform vec4 colorOffset;
uniform bool hasColorTransform;
vec4 transform(bool has, vec4 color, vec4 mult, vec4 offset)
{
return mix(color, clamp(offset + (color * mult), 0.0, 1.0), float(has));
}
vec4 flixel_texture2D(sampler2D bitmap, vec2 coord)
{
vec4 color = texture2D(bitmap, coord);
if (!hasTransform)
{
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)
{
return vec4(color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav);
}
return vec4(0.0, 0.0, 0.0, 0.0);
color = transform(openfl_HasColorTransform, color, openfl_ColorMultiplierv, openfl_ColorOffsetv);
color = transform(hasColorTransform, color, colorMultiplier, colorOffset / 255.0);
float _alpha = color.a * openfl_Alphav * alpha;
return vec4 (color.rgb * _alpha, _alpha);
}
")
@: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

0 comments on commit 593f04f

Please sign in to comment.