From 427b39006268104c0e89c187f3a941c1abd62937 Mon Sep 17 00:00:00 2001 From: Christoph Neuhauser Date: Mon, 6 Feb 2023 12:49:57 +0100 Subject: [PATCH] added shader compilation switch for applying opacity depending on use of premultiplied alpha --- CMakeLists.txt | 3 ++- shaders/vkvg_main.frag | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f159319..f59f756 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ OPTION(VKVG_RECORDING "enable experimental recording functions" ON) OPTION(VKVG_PREMULT_ALPHA "use premultiplied alpha for internal rendering" ON) IF (VKVG_PREMULT_ALPHA) ADD_DEFINITIONS (-DVKVG_PREMULT_ALPHA) + SET(GLSLDEFS ${GLSLDEFS} -DVKVG_PREMULT_ALPHA) ENDIF () OPTION(VKVG_DBG_STATS "record contexts statistics in the device" OFF) @@ -147,7 +148,7 @@ CMAKE_DEPENDENT_OPTION(VKVG_LCD_FONT_FILTER "enable freetype lcd font filtering" OPTION(VKVG_ENABLE_VK_SCALAR_BLOCK_LAYOUT "Enable scalar block layout support." ON) IF (VKVG_ENABLE_VK_SCALAR_BLOCK_LAYOUT) ADD_DEFINITIONS (-DVKVG_ENABLE_VK_SCALAR_BLOCK_LAYOUT) - SET(GLSLDEFS "-DVKVG_ENABLE_VK_SCALAR_BLOCK_LAYOUT") + SET(GLSLDEFS ${GLSLDEFS} -DVKVG_ENABLE_VK_SCALAR_BLOCK_LAYOUT) ENDIF () OPTION(VKVG_ENABLE_VK_TIMELINE_SEMAPHORE "Enable vulkan TimelineSemaphore support." OFF) diff --git a/shaders/vkvg_main.frag b/shaders/vkvg_main.frag index 8c1c8f5..5b43765 100644 --- a/shaders/vkvg_main.frag +++ b/shaders/vkvg_main.frag @@ -145,7 +145,12 @@ void main() if (inFontUV.z >= 0.0) c *= texture(fontMap, inFontUV).r; +#ifdef VKVG_PREMULT_ALPHA c *= inOpacity; +#else + c.a *= inOpacity; +#endif + outFragColor = c; } -- 2.47.3