From 37faccd014b848a6bb5214eaa9a281678fbf33e1 Mon Sep 17 00:00:00 2001
From: Geoffrey McRae <geoff@hostfission.com>
Date: Tue, 10 Aug 2021 00:54:54 +1000
Subject: [PATCH] [client] egl: allow ffxCAS sharpness configuration

---
 client/renderers/EGL/desktop.c           | 19 +++++++++++++++++++
 client/renderers/EGL/shader/ffx_cas.frag |  4 ++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/client/renderers/EGL/desktop.c b/client/renderers/EGL/desktop.c
index aa7ac0c8..f94aa737 100644
--- a/client/renderers/EGL/desktop.c
+++ b/client/renderers/EGL/desktop.c
@@ -82,6 +82,7 @@ struct EGL_Desktop
   EGL_Shader * ffxCAS;
   bool enableCAS;
   PostProcessHandle ffxCASHandle;
+  EGL_Uniform ffxUniform;
 };
 
 // forwards
@@ -176,6 +177,11 @@ bool egl_desktopInit(EGL * egl, EGL_Desktop ** desktop_, EGLDisplay * display,
       b_shader_basic_vert  , b_shader_basic_vert_size,
       b_shader_ffx_cas_frag, b_shader_ffx_cas_frag_size);
 
+  desktop->ffxUniform.type     = EGL_UNIFORM_TYPE_1F;
+  desktop->ffxUniform.location =
+    egl_shaderGetUniform(desktop->ffxCAS, "uSharpness");
+  desktop->ffxUniform.f[0]     = 0.0f;
+
   setupFilters(desktop);
 
   return true;
@@ -263,6 +269,19 @@ void egl_desktopConfigUI(EGL_Desktop * desktop)
     desktop->enableCAS = cas;
     egl_textureEnableFilter(desktop->ffxCASHandle, cas);
   }
+
+  float sharpness = desktop->ffxUniform.f[0];
+  igText("Sharpness:");
+  igSameLine(0.0f, -1.0f);
+  igPushItemWidth(igGetWindowWidth() - igGetCursorPosX() - igGetStyle()->WindowPadding.x);
+  igSliderFloat("##casSharpness", &sharpness, 0.0f, 1.0f, NULL, 0);
+  igPopItemWidth();
+
+  if (sharpness != desktop->ffxUniform.f[0])
+  {
+    desktop->ffxUniform.f[0] = sharpness;
+    egl_shaderSetUniforms(desktop->ffxCAS, &desktop->ffxUniform, 1);
+  }
 }
 
 bool egl_desktopSetup(EGL_Desktop * desktop, const LG_RendererFormat format)
diff --git a/client/renderers/EGL/shader/ffx_cas.frag b/client/renderers/EGL/shader/ffx_cas.frag
index 51c5aad2..5130151d 100644
--- a/client/renderers/EGL/shader/ffx_cas.frag
+++ b/client/renderers/EGL/shader/ffx_cas.frag
@@ -8,6 +8,7 @@ out vec4  fragColor;
 uniform sampler2D iChannel0;
 uniform uvec2     uInRes[8];
 uniform uvec2     uOutRes;
+uniform float     uSharpness;
 
 // the following are not available until verion 400 or later
 // so we implement our own versions of them
@@ -51,12 +52,11 @@ void main()
   vec4 color;
   vec2 inputResolution  = vec2(uInRes[0]);
   vec2 outputResolution = vec2(uOutRes);
-  float sharpnessTuning = 1.0f;
 
   uvec4 const0;
   uvec4 const1;
 
-  CasSetup(const0, const1, sharpnessTuning,
+  CasSetup(const0, const1, uSharpness,
     inputResolution.x, inputResolution.y, 
     outputResolution.x, outputResolution.y);