From 0283d8ef4f2675488d4e872dd9e2ec66e8d9cc23 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Thu, 26 Dec 2024 13:33:33 -0600 Subject: [PATCH] Revert "Fix camera.color (#3321)" (#3324) This reverts commit 593f04ff6612652cbf413f06f2a791dda6e0a58c. --- flixel/graphics/tile/FlxDrawQuadsItem.hx | 1 + flixel/graphics/tile/FlxDrawTrianglesItem.hx | 1 + flixel/graphics/tile/FlxGraphicsShader.hx | 71 +++++++++++++++----- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/flixel/graphics/tile/FlxDrawQuadsItem.hx b/flixel/graphics/tile/FlxDrawQuadsItem.hx index adfa2bf6ed..bd73f8b346 100644 --- a/flixel/graphics/tile/FlxDrawQuadsItem.hx +++ b/flixel/graphics/tile/FlxDrawQuadsItem.hx @@ -130,6 +130,7 @@ 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 b1d4a64880..c1af4b6438 100644 --- a/flixel/graphics/tile/FlxDrawTrianglesItem.hx +++ b/flixel/graphics/tile/FlxDrawTrianglesItem.hx @@ -76,6 +76,7 @@ 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 bd17b3e3e8..e433b45a86 100644 --- a/flixel/graphics/tile/FlxGraphicsShader.hx +++ b/flixel/graphics/tile/FlxGraphicsShader.hx @@ -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();