From 53c77466f5a09ce89913f38aec1859bd44dfb10a Mon Sep 17 00:00:00 2001 From: Ne_Eo Date: Mon, 16 Sep 2024 00:59:41 +0200 Subject: [PATCH] Added util function for shaders --- source/funkin/backend/shaders/FunkinShader.hx | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/source/funkin/backend/shaders/FunkinShader.hx b/source/funkin/backend/shaders/FunkinShader.hx index b676ae45..451afecd 100644 --- a/source/funkin/backend/shaders/FunkinShader.hx +++ b/source/funkin/backend/shaders/FunkinShader.hx @@ -438,29 +438,46 @@ uniform sampler2D bitmap; uniform bool hasTransform; uniform bool hasColorTransform; -vec4 flixel_texture2D(sampler2D bitmap, vec2 coord) -{ +vec4 flixel_texture2D(sampler2D bitmap, vec2 coord) { vec4 color = texture2D(bitmap, coord); - if (!hasTransform) - { + if (!hasTransform) { return color; } - if (color.a == 0.0) - { + if (color.a == 0.0) { return vec4(0.0, 0.0, 0.0, 0.0); } - if (!hasColorTransform) - { + 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 (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); +} + +vec4 applyFlixelEffects(vec4 color) { + 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);