From 593f04ff6612652cbf413f06f2a791dda6e0a58c Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Thu, 26 Dec 2024 10:25:17 -0600 Subject: [PATCH] Fix camera.color (#3321) * fix camera.color * fix edge cases * Simplify FlxGraphicsShader * fix triangles --- flixel/graphics/tile/FlxDrawQuadsItem.hx | 1 - flixel/graphics/tile/FlxDrawTrianglesItem.hx | 1 - flixel/graphics/tile/FlxGraphicsShader.hx | 71 +++++--------------- 3 files changed, 18 insertions(+), 55 deletions(-) diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index bd73f8b346..adfa2bf6ed 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -130,7 +130,6 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem shader.colorOffset.value = colorOffsets; } - setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); #if (openfl > "8.7.0") diff --git a/flixel/graphics/tile/FlxDrawTrianglesItem.hx b/flixel/graphics/tile/FlxDrawTrianglesItem.hx index c1af4b6438..b1d4a64880 100644 --- a/flixel/graphics/tile/FlxDrawTrianglesItem.hx +++ b/flixel/graphics/tile/FlxDrawTrianglesItem.hx @@ -76,7 +76,6 @@ class FlxDrawTrianglesItem extends FlxDrawBaseItem shader.colorOffset.value = null; } - setParameterValue(shader.hasTransform, true); setParameterValue(shader.hasColorTransform, colored || hasColorOffsets); #if (openfl > "8.7.0") diff --git a/flixel/graphics/tile/FlxGraphicsShader.hx b/flixel/graphics/tile/FlxGraphicsShader.hx index e433b45a86..bd17b3e3e8 100644 --- a/flixel/graphics/tile/FlxGraphicsShader.hx +++ b/flixel/graphics/tile/FlxGraphicsShader.hx @@ -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();