From 0729aa5d46aff4db930419b3140691ef670d923e Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 5 Jul 2023 19:20:17 +0200 Subject: [PATCH] Postshader - New version of bloom --- UWP/UWP.vcxproj | 3 +++ UWP/UWP.vcxproj.filters | 3 +++ assets/shaders/bloomnoblur.fsh | 43 +++++++++++++++++++++++++++++++ assets/shaders/defaultshaders.ini | 12 +++++++++ 4 files changed, 61 insertions(+) create mode 100644 assets/shaders/bloomnoblur.fsh diff --git a/UWP/UWP.vcxproj b/UWP/UWP.vcxproj index 58dc54ec1b..fc372eb945 100644 --- a/UWP/UWP.vcxproj +++ b/UWP/UWP.vcxproj @@ -820,6 +820,9 @@ true + + true + true diff --git a/UWP/UWP.vcxproj.filters b/UWP/UWP.vcxproj.filters index 5b018c1498..afdce13957 100644 --- a/UWP/UWP.vcxproj.filters +++ b/UWP/UWP.vcxproj.filters @@ -292,6 +292,9 @@ Content\shaders + + Content\shaders + Content\shaders diff --git a/assets/shaders/bloomnoblur.fsh b/assets/shaders/bloomnoblur.fsh new file mode 100644 index 0000000000..812af8bfff --- /dev/null +++ b/assets/shaders/bloomnoblur.fsh @@ -0,0 +1,43 @@ +// Simple Bloom shader; created to use in PPSSPP. +// Without excessive samples and complex nested loops +// (to make it compatible with low-end GPUs and to ensure ps_2_0 compatibility). + +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif + +uniform sampler2D sampler0; +varying vec2 v_texcoord0; + +uniform vec4 u_setting; + +void main() +{ + //get the pixel color + vec3 color = texture2D(sampler0, v_texcoord0.xy).xyz; + gl_FragColor.rgb = color; + float gray = (color.r + color.g + color.b) / 3.0; + float saturation = (abs(color.r - gray) + abs(color.g - gray) + abs(color.b - gray)) / 3.0; + + //show the effect mainly on bright parts of the screen + float step = 0.001 * gray / max(saturation, 0.25) * u_setting.x; + + //sum the neightbor pixels + vec3 sum = vec3(0); + for (int x = -3; x <= 3; x += 2) + { + for (int y = -3; y <= 3; y += 2) + { + color = texture2D(sampler0, v_texcoord0 + vec2(x, y)*step).xyz; + gray = (color.r + color.g + color.b) / 3.0; + saturation = (abs(color.r - gray) + abs(color.g - gray) + abs(color.b - gray)) / 3.0; + sum += color * gray * gray / max(saturation, 0.25); + } + } + sum /= 16.0; + + //mix the color + gl_FragColor.rgb += sum * u_setting.y; + gl_FragColor.a = 1.0; +} diff --git a/assets/shaders/defaultshaders.ini b/assets/shaders/defaultshaders.ini index b7cd268733..ee197eaf38 100644 --- a/assets/shaders/defaultshaders.ini +++ b/assets/shaders/defaultshaders.ini @@ -50,6 +50,18 @@ SettingName2=Power SettingDefaultValue2=0.5 SettingMaxValue2=1.0 SettingMinValue2=0.0 +[BloomNoBlur] +Name=Bloom (no blur)r +Fragment=bloomnoblur.fsh +Vertex=fxaa.vsh +SettingName1=Amount +SettingDefaultValue1=0.6 +SettingMaxValue1=1.0 +SettingMinValue1=0.0 +SettingName2=Power +SettingDefaultValue2=0.5 +SettingMaxValue2=1.0 +SettingMinValue2=0.0 [Sharpen] Name=Sharpen Fragment=sharpen.fsh