Skip to content

Commit

Permalink
Revert "Fix camera.color (#3321)" (#3324)
Browse files Browse the repository at this point in the history
This reverts commit 593f04f.
  • Loading branch information
Geokureli authored Dec 26, 2024
1 parent 593f04f commit 0283d8e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 18 deletions.
1 change: 1 addition & 0 deletions flixel/graphics/tile/FlxDrawQuadsItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ 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: 1 addition & 0 deletions flixel/graphics/tile/FlxDrawTrianglesItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ 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: 53 additions & 18 deletions flixel/graphics/tile/FlxGraphicsShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,66 @@ import openfl.display.GraphicsShader;

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

0 comments on commit 0283d8e

Please sign in to comment.