diff --git a/client/renderers/EGL/filter_ffx_cas.c b/client/renderers/EGL/filter_ffx_cas.c index bb89832f..9a653685 100644 --- a/client/renderers/EGL/filter_ffx_cas.c +++ b/client/renderers/EGL/filter_ffx_cas.c @@ -21,9 +21,11 @@ #include "filter.h" #include "framebuffer.h" +#include "common/countedbuffer.h" #include "common/debug.h" #include "common/option.h" #include "cimgui.h" +#include "ffx.h" #include "basic.vert.h" #include "ffx_cas.frag.h" @@ -34,10 +36,11 @@ typedef struct EGL_FilterFFXCAS EGL_Shader * shader; bool enable; - EGL_Uniform uniform; enum EGL_PixelFormat pixFmt; unsigned int width, height; + float sharpness; + CountedBuffer * consts; bool prepared; EGL_Framebuffer * fb; @@ -69,6 +72,12 @@ static void egl_filterFFXCASEarlyInit(void) option_register(options); } +static void casUpdateConsts(EGL_FilterFFXCAS * this) +{ + ffxCasConst((uint32_t *) this->consts->data, this->sharpness, this->width, this->height, + this->width, this->height); +} + static bool egl_filterFFXCASInit(EGL_Filter ** filter) { EGL_FilterFFXCAS * this = calloc(1, sizeof(*this)); @@ -93,12 +102,15 @@ static bool egl_filterFFXCASInit(EGL_Filter ** filter) goto error_shader; } - this->enable = option_get_bool("eglFilter", "ffxCAS"); - this->uniform.type = EGL_UNIFORM_TYPE_1F; - this->uniform.location = - egl_shaderGetUniform(this->shader, "uSharpness"); - this->uniform.f[0] = - option_get_float("eglFilter", "ffxCASSharpness"); + this->consts = countedBufferNew(8 * sizeof(GLuint)); + egl_shaderSetUniforms(this->shader, &(EGL_Uniform) { + .type = EGL_UNIFORM_TYPE_4UIV, + .location = egl_shaderGetUniform(this->shader, "uConsts"), + .v = this->consts, + }, 1); + + this->enable = option_get_bool("eglFilter", "ffxCAS"); + this->sharpness = option_get_float("eglFilter", "ffxCASSharpness"); if (!egl_framebufferInit(&this->fb)) { @@ -139,7 +151,7 @@ static bool egl_filterFFXCASImguiConfig(EGL_Filter * filter) bool redraw = false; bool cas = this->enable; - float casSharpness = this->uniform.f[0]; + float casSharpness = this->sharpness; igCheckbox("AMD FidelityFX CAS", &cas); if (cas != this->enable) @@ -156,7 +168,7 @@ static bool egl_filterFFXCASImguiConfig(EGL_Filter * filter) igSliderFloat("##casSharpness", &casSharpness, 0.0f, 1.0f, NULL, 0); igPopItemWidth(); - if (casSharpness != this->uniform.f[0]) + if (casSharpness != this->sharpness) { // enable CAS if the sharpness was changed if (!cas) @@ -165,7 +177,8 @@ static bool egl_filterFFXCASImguiConfig(EGL_Filter * filter) this->enable = true; } - this->uniform.f[0] = casSharpness; + this->sharpness = casSharpness; + casUpdateConsts(this); redraw = true; } @@ -190,6 +203,7 @@ static bool egl_filterFFXCASSetup(EGL_Filter * filter, this->width = width; this->height = height; this->prepared = false; + casUpdateConsts(this); return true; } @@ -212,7 +226,6 @@ static bool egl_filterFFXCASPrepare(EGL_Filter * filter) if (this->prepared) return true; - egl_shaderSetUniforms(this->shader, &this->uniform, 1); this->prepared = true; return true; diff --git a/client/renderers/EGL/shader/ffx_cas.frag b/client/renderers/EGL/shader/ffx_cas.frag index 3105d101..4312bf21 100644 --- a/client/renderers/EGL/shader/ffx_cas.frag +++ b/client/renderers/EGL/shader/ffx_cas.frag @@ -7,7 +7,7 @@ in vec2 fragCoord; out vec4 fragColor; uniform sampler2D texture; -uniform float uSharpness; +uniform uvec4 uConsts[2]; #define A_GPU 1 #define A_GLSL 1 @@ -32,17 +32,8 @@ void main() { vec2 res = vec2(textureSize(texture, 0)); uvec2 point = uvec2(fragCoord * res); - - vec4 color; - uvec4 const0; - uvec4 const1; - - CasSetup(const0, const1, uSharpness, - res.x, res.y, res.x, res.y); CasFilter( fragColor.r, fragColor.g, fragColor.b, - point, - const0, const1, - true); + point, uConsts[0], uConsts[1], true); }