From d4d42e8ba9eb697cc91468d024005e65c59c3276 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Sun, 29 Dec 2024 23:51:55 -0500 Subject: [PATCH 1/2] fix camera.color --- flixel/graphics/tile/FlxGraphicsShader.hx | 71 ++++++++++------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/flixel/graphics/tile/FlxGraphicsShader.hx b/flixel/graphics/tile/FlxGraphicsShader.hx index e433b45a86..478d9671d1 100644 --- a/flixel/graphics/tile/FlxGraphicsShader.hx +++ b/flixel/graphics/tile/FlxGraphicsShader.hx @@ -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? 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(); From a72419075c08939d7e40f57f8d0989ea1492e26d Mon Sep 17 00:00:00 2001 From: George FunBook Date: Sun, 29 Dec 2024 23:53:43 -0500 Subject: [PATCH 2/2] doc --- flixel/graphics/tile/FlxGraphicsShader.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/graphics/tile/FlxGraphicsShader.hx b/flixel/graphics/tile/FlxGraphicsShader.hx index 478d9671d1..5e1e01d0f2 100644 --- a/flixel/graphics/tile/FlxGraphicsShader.hx +++ b/flixel/graphics/tile/FlxGraphicsShader.hx @@ -28,7 +28,7 @@ class FlxGraphicsShader extends GraphicsShader } ") @:glFragmentHeader(" - uniform bool hasTransform; // TODO: Is this still needed? + uniform bool hasTransform; // TODO: Is this still needed? Apparently, yes! uniform bool hasColorTransform; vec4 flixel_texture2D(sampler2D bitmap, vec2 coord) {