From dfa6630d717e14f1a4df5ed4c9c16ca1f05396b7 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 26 Dec 2024 00:15:27 -0600 Subject: [PATCH] Simplify FlxGraphicsShader --- flixel/graphics/tile/FlxDrawQuadsItem.hx | 1 - flixel/graphics/tile/FlxGraphicsShader.hx | 50 +++++------------------ 2 files changed, 11 insertions(+), 40 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/FlxGraphicsShader.hx b/flixel/graphics/tile/FlxGraphicsShader.hx index 478d9671d1..bd17b3e3e8 100644 --- a/flixel/graphics/tile/FlxGraphicsShader.hx +++ b/flixel/graphics/tile/FlxGraphicsShader.hx @@ -4,54 +4,26 @@ import openfl.display.GraphicsShader; class FlxGraphicsShader extends GraphicsShader { - @:glVertexHeader(" - attribute float alpha; - attribute vec4 colorMultiplier; - attribute vec4 colorOffset; + @:glFragmentHeader(" + uniform float alpha; + uniform vec4 colorMultiplier; + uniform vec4 colorOffset; uniform bool hasColorTransform; - ") - @:glVertexBody(" - openfl_Alphav = openfl_Alpha * alpha; - if (hasColorTransform) + vec4 transform(bool has, vec4 color, vec4 mult, vec4 offset) { - if (openfl_HasColorTransform) - { - openfl_ColorOffsetv = (openfl_ColorOffsetv * colorMultiplier) + (colorOffset / 255.0); - openfl_ColorMultiplierv *= colorMultiplier; - } - else - { - openfl_ColorOffsetv = colorOffset / 255.0; - openfl_ColorMultiplierv = colorMultiplier; - } + return mix(color, clamp(offset + (color * mult), 0.0, 1.0), float(has)); } - ") - @:glFragmentHeader(" - 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 || openfl_HasColorTransform)) - return color; - - if (color.a == 0.0) - return vec4(0.0, 0.0, 0.0, 0.0); - if (openfl_HasColorTransform || hasColorTransform) - { - 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); - } + color = transform(openfl_HasColorTransform, color, openfl_ColorMultiplierv, openfl_ColorOffsetv); + color = transform(hasColorTransform, color, colorMultiplier, colorOffset / 255.0); - return color * openfl_Alphav; + float _alpha = color.a * openfl_Alphav * alpha; + return vec4 (color.rgb * _alpha, _alpha); } ") @:glFragmentBody("