From c4bef426c4ddc97810a992d9345c58e356210d2b Mon Sep 17 00:00:00 2001 From: hooke007 Date: Tue, 31 Oct 2023 20:11:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=8E=E6=95=B4=E5=90=88?= =?UTF-8?q?=E4=B8=8A=E6=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 核心: 同步 --watch-later-dir --sub-ass-style-overrides --screenshot-dir 修正 --dscale 脚本: osc_plus 修复 https://github.com/hooke007/MPV_lazy/issues/378 uosc 同步上游 着色器: 新增 CfL_Prediction_Lite, MemeBilateral_Lite 由 https://github.com/deus0ww 创建 --- portable_config/mpv.conf | 8 +- portable_config/script-opts.conf | 3 +- portable_config/script-opts/uosc.conf | 5 +- portable_config/scripts/osc_plus.lua | 2 +- .../scripts/uosc/elements/Menu.lua | 57 ++-- .../scripts/uosc/elements/Timeline.lua | 12 +- .../scripts/uosc/elements/Volume.lua | 2 +- portable_config/scripts/uosc/lib/menus.lua | 9 +- portable_config/scripts/uosc/main.lua | 11 +- ...ediction_next.glsl => CfL_Prediction.glsl} | 99 ++++--- ...tap_next.glsl => CfL_Prediction_Lite.glsl} | 237 ++++++++--------- .../shaders/FastBilateral_next.glsl | 59 ++++- .../shaders/JointBilateral_next.glsl | 63 +++-- portable_config/shaders/KrigBilateral.glsl | 2 +- .../shaders/MemeBilateral_Lite.glsl | 244 ++++++++++++++++++ .../shaders/MemeBilateral_next.glsl | 75 +++++- 16 files changed, 641 insertions(+), 247 deletions(-) rename portable_config/shaders/{CfL_Prediction_next.glsl => CfL_Prediction.glsl} (86%) rename portable_config/shaders/{CfL_Prediction_4tap_next.glsl => CfL_Prediction_Lite.glsl} (63%) create mode 100644 portable_config/shaders/MemeBilateral_Lite.glsl diff --git a/portable_config/mpv.conf b/portable_config/mpv.conf index 6805a352..663285f9 100644 --- a/portable_config/mpv.conf +++ b/portable_config/mpv.conf @@ -93,7 +93,7 @@ gpu-shader-cache = yes # 是否在本地存储GLSL着色器的编译缓存,可以提高启动性能,默认 yes gpu-shader-cache-dir = # 指定GLSL着色器的编译缓存目录(例值 "~~/_cache/shader"),Windows平台便携式设置下的默认实际为 "~~/cache" - watch-later-directory = + watch-later-dir = # 稍后观看功能的缓存目录,其中的文件记录 --watch-later-options 指定的项。WIN平台默认为 "~~/watch_later" @@ -179,7 +179,7 @@ cscale = # 色度还原算法。若不设定,则自动采用 --scale 的值 scale = lanczos # 放大算法,默认值 lanczos (追求最快算法可用 bilinear ) - dscale = # 缩小算法。若不设定,则自动采用 --scale 的值 + dscale = hermite # 缩小算法。默认值 hermite 。若设为空值,则自动采用 --scale 的值 ##所有可用的内置算法参见手册 [06] linear-upscaling = no # [须 --fbo-format 指定16位及以上的精度;与 --sigmoid-upscaling 不兼容] (对HDR内容无影响)默认 no @@ -286,7 +286,7 @@ sub-ass-scale-with-window = no # 字幕随窗口缩放而不是随视频缩放,默认 no embeddedfonts = yes # 是否使用mkv容器的内嵌字体,默认 yes sub-ass-force-margins = no # [当 --blend-subtitles=yes/video 时无效] 是否使ASS字幕尽可能输出在黑边上,默认 no - sub-ass-force-style = + sub-ass-style-overrides = # 使用自定义的参数以覆盖字幕文件内的预设。默认为空,例值(覆盖字幕内的所有字体) Fontname=LXGW WenKai ##⇘⇘模拟vsfilter相关 @@ -325,5 +325,5 @@ screenshot-template = "mpv-shot%n" # 截图命名模板: https://mpv.io/manual/master/#options-screenshot-template # 示例即默认值。可额外选填路径,例值 "~~desktop/MPV-%P-N%n" - screenshot-directory = + screenshot-dir = # [若已在截图命名模板中设置路径,此时无需使用该选项 ] 默认为空,例值(保存截图在桌面) "~~desktop/" diff --git a/portable_config/script-opts.conf b/portable_config/script-opts.conf index 6621fd9b..25595a20 100644 --- a/portable_config/script-opts.conf +++ b/portable_config/script-opts.conf @@ -496,6 +496,7 @@ script-opts-append = uosc-menu_item_height=36 # 上下文菜单样式,示例即默认值 script-opts-append = uosc-menu_min_width=260 + script-opts-append = uosc-menu_padding=4 script-opts-append = uosc-menu_type_to_search=yes # 是否启用菜单快速搜索(只需输入任何文本即可),否则使用按键 / 或 Ctrl+F 来激活搜索。 # 启用该项时,如果输入的是一个 Unicode 字符,就不能再使用相同的键位来关闭已打开的菜单 @@ -527,7 +528,7 @@ script-opts-append = uosc-text_border=1.2 # 控件元素的边框,默认 1.2 - script-opts-append = uosc-border_radius=2 # 界面元素中圆角矩形的弧度,默认 2 + script-opts-append = uosc-border_radius=4 # 界面元素中圆角矩形的弧度,默认 4 script-opts-append = uosc-color= # 界面元素的颜色,多个值之间用半角逗号分隔。 diff --git a/portable_config/script-opts/uosc.conf b/portable_config/script-opts/uosc.conf index 9787050a..9a69959d 100644 --- a/portable_config/script-opts/uosc.conf +++ b/portable_config/script-opts/uosc.conf @@ -45,6 +45,7 @@ speed_persistency=idle,audio # 上下文菜单样式,示例即默认值 menu_item_height=36 menu_min_width=260 +menu_padding=4 # 是否启用菜单快速搜索(只需输入任何文本即可),否则使用按键 / 或 Ctrl+F 来激活搜索。启用该项时,如果输入的是一个 Unicode 字符,就不能再使用相同的键位来关闭已打开的菜单 menu_type_to_search=yes @@ -85,8 +86,8 @@ font_scale=1 font_bold=no # 控件元素的边框,默认 1.2 text_border=1.2 -# 界面元素中圆角矩形的弧度,默认 2 -border_radius=2 +# 界面元素中圆角矩形的弧度,默认 4 +border_radius=4 # 界面元素的颜色,多个值之间用半角逗号分隔。 # 示例的默认值:foreground=ffffff,foreground_text=000000,background=000000,background_text=ffffff,curtain=000000,success=a5e075,error=ff616e color= diff --git a/portable_config/scripts/osc_plus.lua b/portable_config/scripts/osc_plus.lua index ee797630..c0dc11b2 100644 --- a/portable_config/scripts/osc_plus.lua +++ b/portable_config/scripts/osc_plus.lua @@ -2473,7 +2473,7 @@ function osc_init() local property = user_opts.remaining_playtime and "playtime-remaining" or "time-remaining" if state.tc_ms then - return return (minus..mp.get_property_osd(property .. "/full")) + return (minus..mp.get_property_osd(property .. "/full")) else return (minus..mp.get_property_osd(property)) end diff --git a/portable_config/scripts/uosc/elements/Menu.lua b/portable_config/scripts/uosc/elements/Menu.lua index 5e00686e..babd0810 100644 --- a/portable_config/scripts/uosc/elements/Menu.lua +++ b/portable_config/scripts/uosc/elements/Menu.lua @@ -119,9 +119,6 @@ function Menu:init(data, callback, opts) self.drag_last_y = nil self.is_dragging = false - if utils.shared_script_property_set then - utils.shared_script_property_set('uosc-menu-type', self.type or 'undefined') - end mp.set_property_native('user-data/uosc/menu/type', self.type or 'undefined') self:update(data) @@ -142,9 +139,6 @@ function Menu:destroy() self:disable_key_bindings() self.is_closed = true if not self.is_being_replaced then Elements:maybe('curtain', 'unregister', self.id) end - if utils.shared_script_property_set then - utils.shared_script_property_set('uosc-menu-type', nil) - end mp.set_property_native('user-data/uosc/menu/type', nil) if self.opts.on_close then self.opts.on_close() end end @@ -276,7 +270,7 @@ function Menu:update_content_dimensions() self.item_height = round(options.menu_item_height * state.scale) self.min_width = round(options.menu_min_width * state.scale) self.separator_size = round(1 * state.scale) - self.padding = round(2 * state.scale) + self.padding = round(options.menu_padding * state.scale) self.gap = round(2 * state.scale) self.font_size = round(self.item_height * 0.48 * options.font_scale) self.font_size_hint = self.font_size - 1 @@ -288,7 +282,7 @@ function Menu:update_content_dimensions() for _, menu in ipairs(self.all) do title_opts.bold, title_opts.italic = true, false - local max_width = text_width(menu.title, title_opts) + 2 * self.item_padding + local max_width = text_width(menu.title, title_opts) + 2 * self.padding + 2 * self.item_padding -- Estimate width of a widest item for _, item in ipairs(menu.items) do @@ -302,7 +296,7 @@ function Menu:update_content_dimensions() if estimated_width > max_width then max_width = estimated_width end end - menu.max_width = max_width + menu.max_width = max_width + 2 * self.padding end self:update_dimensions() @@ -320,7 +314,7 @@ function Menu:update_dimensions() for _, menu in ipairs(self.all) do local width = math.max(menu.search and menu.search.max_width or 0, menu.max_width) menu.width = round(clamp(min_width, width, width_available)) - local title_height = (menu.is_root and menu.title or menu.search) and self.scroll_step or 0 + local title_height = (menu.is_root and menu.title or menu.search) and self.scroll_step + self.padding or 0 local max_height = height_available - title_height local content_height = self.scroll_step * #menu.items menu.height = math.min(content_height - self.item_spacing, max_height) @@ -818,7 +812,7 @@ function Menu:search_backspace(event, word_mode) local word_pat, other_pat = '[^%c%s%p]+$', '[%c%s%p]+$' local init_pat = old_query:sub(#old_query):match(word_pat) and word_pat or other_pat -- First we match all same type consecutive chars at the end - local tail = old_query:match(init_pat) + local tail = old_query:match(init_pat) or '' -- If there's only one, we extend the tail with opposite type chars if tail and #tail == 1 then tail = tail .. old_query:sub(1, #old_query - #tail):match(init_pat == word_pat and other_pat or word_pat) @@ -1101,7 +1095,7 @@ function Menu:render() local end_index = math.ceil((menu.scroll_y + menu.height) / self.scroll_step) local menu_rect = { ax = ax, - ay = ay - (draw_title and self.scroll_step or 0) - self.padding, + ay = ay - (draw_title and self.scroll_step + self.padding or 0) - self.padding, bx = bx, by = by + self.padding, } @@ -1109,7 +1103,9 @@ function Menu:render() -- Background ass:rect(menu_rect.ax, menu_rect.ay, menu_rect.bx, menu_rect.by, { - color = bg, opacity = menu_opacity * config.opacity.menu, radius = state.radius + self.padding, + color = bg, + opacity = menu_opacity * config.opacity.menu, + radius = state.radius > 0 and state.radius + self.padding or 0, }) if is_parent then @@ -1135,8 +1131,8 @@ function Menu:render() local item_by = item_ay + self.item_height local item_center_y = item_ay + (self.item_height / 2) local item_clip = (item_ay < ay or item_by > by) and scroll_clip or nil - local content_ax, content_bx = ax + spacing, bx - spacing - local is_selected = menu.selected_index == index or item.active + local content_ax, content_bx = ax + self.padding + spacing, bx - self.padding - spacing + local is_selected = menu.selected_index == index -- Select hovered item if is_current and self.mouse_nav and item.selectable ~= false then @@ -1152,28 +1148,32 @@ function Menu:render() if submenu_is_hovered or get_point_to_rectangle_proximity(cursor, item_rect_hitbox) == 0 then blur_selected_index = false menu.selected_index = index + if not is_selected then request_render() end end end end + local has_background = is_selected or item.active local next_item = menu.items[index + 1] local next_is_active = next_item and next_item.active - local next_is_highlighted = menu.selected_index == index + 1 or next_is_active + local next_has_background = menu.selected_index == index + 1 or next_is_active local font_color = item.active and fgt or bgt -- Separator - local separator_ay = item.separator and item_by - 1 or item_by - local separator_by = item_by + (item.separator and 2 or 1) - if is_selected then separator_ay = item_by + 1 end - if next_is_highlighted then separator_by = item_by end - if separator_by - separator_ay > 0 and item_by < by then - ass:rect(ax + spacing / 2, separator_ay, bx - spacing / 2, separator_by, { - color = fg, opacity = menu_opacity * (item.separator and 0.08 or 0.06), + if item_by < by and ((not has_background and not next_has_background) or item.separator) then + local separator_ay, separator_by = item_by, item_by + 1 + if has_background then + separator_ay, separator_by = separator_ay + 1, separator_by + 1 + elseif next_has_background then + separator_ay, separator_by = separator_ay - 1, separator_by - 1 + end + ass:rect(ax + spacing, separator_ay, bx - spacing, separator_by, { + color = fg, opacity = menu_opacity * (item.separator and 0.13 or 0.04), }) end - -- Highlight - local highlight_opacity = 0 + (item.active and 0.8 or 0) + (menu.selected_index == index and 0.15 or 0) + -- Background + local highlight_opacity = 0 + (item.active and 0.8 or 0) + (is_selected and 0.15 or 0) if not is_submenu and highlight_opacity > 0 then ass:rect(ax + self.padding, item_ay, bx - self.padding, item_by, { radius = state.radius, @@ -1243,7 +1243,12 @@ function Menu:render() -- Menu title if draw_title then local requires_submit = menu.search_debounce == 'submit' - local rect = {ax = ax + spacing, ay = ay - self.scroll_step, bx = bx - spacing, by = math.min(by, ay - 2)} + local rect = { + ax = ax + spacing / 2 + self.padding, + ay = ay - self.scroll_step - self.padding * 2, + bx = bx - spacing / 2 - self.padding, + by = math.min(by, ay - self.padding), + } rect.cx, rect.cy = rect.ax + (rect.bx - rect.ax) / 2, rect.ay + (rect.by - rect.ay) / 2 -- centers if menu.title and not menu.ass_safe_title then diff --git a/portable_config/scripts/uosc/elements/Timeline.lua b/portable_config/scripts/uosc/elements/Timeline.lua index 629e5728..900e178a 100644 --- a/portable_config/scripts/uosc/elements/Timeline.lua +++ b/portable_config/scripts/uosc/elements/Timeline.lua @@ -118,7 +118,10 @@ function Timeline:on_prop_fullormaxed() self:update_dimensions() end function Timeline:on_display() self:update_dimensions() end -function Timeline:on_options() self:update_dimensions() end +function Timeline:on_options() + self:decide_progress_size() + self:update_dimensions() +end function Timeline:handle_cursor_up() if self.pressed then mp.set_property_native('pause', self.pressed.pause) @@ -350,11 +353,12 @@ function Timeline:render() -- Time values if text_opacity > 0 then - local time_opts = {size = self.font_size, opacity = text_opacity, border = 2} + local time_opts = {size = self.font_size, opacity = text_opacity, border = 2 * state.scale} -- Upcoming cache time if buffered_playtime and options.buffered_time_threshold > 0 and buffered_playtime < options.buffered_time_threshold then - local x, align = fbx + 5, 4 + local margin = 5 * state.scale + local x, align = fbx + margin, 4 local cache_opts = { size = self.font_size * 0.8, opacity = text_opacity * 0.6, border = options.text_border * state.scale, } @@ -362,7 +366,7 @@ function Timeline:render() local width = text_width(human, cache_opts) local time_width = timestamp_width(state.time_human, time_opts) local time_width_end = timestamp_width(state.destination_time_human, time_opts) - local min_x, max_x = bax + spacing + 5 + time_width, bbx - spacing - 5 - time_width_end + local min_x, max_x = bax + spacing + margin + time_width, bbx - spacing - margin - time_width_end if x < min_x then x = min_x elseif x + width > max_x then x, align = max_x, 6 end draw_timeline_text(x, fcy, align, human, cache_opts) end diff --git a/portable_config/scripts/uosc/elements/Volume.lua b/portable_config/scripts/uosc/elements/Volume.lua index f9593f93..ff65f4cd 100644 --- a/portable_config/scripts/uosc/elements/Volume.lua +++ b/portable_config/scripts/uosc/elements/Volume.lua @@ -18,7 +18,7 @@ function VolumeSlider:init(props) end function VolumeSlider:update_dimensions() - self.border_size = math.max(1, round(options.volume_border * state.scale)) + self.border_size = math.max(0, round(options.volume_border * state.scale)) end function VolumeSlider:get_visibility() return Elements.volume:get_visibility(self) end diff --git a/portable_config/scripts/uosc/lib/menus.lua b/portable_config/scripts/uosc/lib/menus.lua index c0ec1f6b..02e45bdd 100644 --- a/portable_config/scripts/uosc/lib/menus.lua +++ b/portable_config/scripts/uosc/lib/menus.lua @@ -512,9 +512,14 @@ function open_open_file_menu() ) end ----@param opts {name: string; prop: string; allowed_types: string[]} +---@param opts {name: 'subtitles'|'audio'|'video'; prop: string; allowed_types: string[]} function create_track_loader_menu_opener(opts) local menu_type = 'load-' .. opts.name + local title = ({ + subtitles = lang._import_id_menu .. lang._sid_menu, + audio = lang._import_id_menu .. lang._aid_menu, + video = lang._import_id_menu .. lang._vid_menu, + })[opts.name] return function() if Menu:is_open(menu_type) then @@ -537,7 +542,7 @@ function create_track_loader_menu_opener(opts) open_file_navigation_menu( path, function(path) mp.commandv(opts.prop .. '-add', path) end, - {type = menu_type, title = lang._import_id_menu .. opts.name, allowed_types = opts.allowed_types} + {type = menu_type, title = title, allowed_types = opts.allowed_types} ) end end diff --git a/portable_config/scripts/uosc/main.lua b/portable_config/scripts/uosc/main.lua index 708b9bfd..30a274fc 100644 --- a/portable_config/scripts/uosc/main.lua +++ b/portable_config/scripts/uosc/main.lua @@ -1,6 +1,6 @@ --[[ -SOURCE_ https://github.com/tomasklaen/uosc/tree/main/scripts/uosc -COMMIT_ 6e19bee95591e3c7653ba1d887d09e7708544eac +SOURCE_ https://github.com/tomasklaen/uosc/tree/main/dist/scripts/uosc +COMMIT_ bf7f97029544f01c7a2c5447e41c357402a5e1fe 文档_ https://github.com/hooke007/MPV_lazy/discussions/186 极简主义设计驱动的多功能界面脚本群组,兼容 thumbfast 新缩略图引擎 @@ -52,6 +52,7 @@ defaults = { menu_item_height = 36, menu_min_width = 260, + menu_padding = 4, menu_type_to_search = true, top_bar = 'no-border', @@ -74,7 +75,7 @@ defaults = { font_scale = 1, font_bold = false, text_border = 1.2, - border_radius = 2, + border_radius = 4, color = '', opacity = '', animation_duration = 100, @@ -495,9 +496,6 @@ function update_margins() state.margin_left = left state.margin_right = right - if utils.shared_script_property_set then - utils.shared_script_property_set('osc-margins', string.format('%f,%f,%f,%f', 0, 0, top, bottom)) - end mp.set_property_native('user-data/osc/margins', {l = left, r = right, t = top, b = bottom}) if not options.adjust_osd_margins then return end @@ -1124,7 +1122,6 @@ if options.idlescreen then mp.register_script_message('osc-idlescreen', function(mode, no_osd) if mode == 'cycle' then mode = state.idlescreen and 'no' or 'yes' end set_state('idlescreen', mode == 'yes') - utils.shared_script_property_set('osc-idlescreen', mode) mp.set_property_native('user-data/osc', { idlescreen = state.idlescreen }) if not no_osd and mp.get_property_number('osd-level', 1) >= 1 then diff --git a/portable_config/shaders/CfL_Prediction_next.glsl b/portable_config/shaders/CfL_Prediction.glsl similarity index 86% rename from portable_config/shaders/CfL_Prediction_next.glsl rename to portable_config/shaders/CfL_Prediction.glsl index aadf34e0..e8e93642 100644 --- a/portable_config/shaders/CfL_Prediction_next.glsl +++ b/portable_config/shaders/CfL_Prediction.glsl @@ -37,11 +37,11 @@ vec4 hook() { float output_luma = 0.0; int wt = 0; for (int dx = start; dx <= end; dx++) { - output_luma += linearize(LUMA_texOff(vec2(dx + 0.5, 0.0))).x; + output_luma += LUMA_texOff(vec2(dx + 0.5, 0.0)).x; wt++; } vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); - return delinearize(output_pix); + return output_pix; } //!HOOK CHROMA @@ -61,11 +61,11 @@ vec4 hook() { float output_luma = 0.0; int wt = 0; for (int dy = start; dy <= end; dy++) { - output_luma += linearize(LUMA_LOWRES_texOff(vec2(0.0, dy + 0.5))).x; + output_luma += LUMA_LOWRES_texOff(vec2(0.0, dy + 0.5)).x; wt++; } vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); - return delinearize(output_pix); + return output_pix; } //!HOOK CHROMA @@ -78,7 +78,8 @@ vec4 hook() { //!OFFSET ALIGN //!DESC Chroma From Luma Prediction (Upscaling Chroma) -#define USE_4_TAP_REGRESSION 1 +#define USE_12_TAP_REGRESSION 1 +#define USE_4_TAP_REGRESSION 0 float comp_wd(vec2 distance) { float d2 = min(pow(length(distance), 2.0), 4.0); @@ -86,8 +87,7 @@ float comp_wd(vec2 distance) { } vec4 hook() { - float ar_strength = 0.75; - float division_limit = 1e-4; + float ar_strength = 0.6666666667; vec4 output_pix = vec4(0.0, 0.0, 0.0, 1.0); float luma_zero = LUMA_texOff(0.0).x; @@ -107,17 +107,11 @@ vec4 hook() { chroma_quads[2][1] = HOOKED_gather(vec2((fp + vec2(0.0, 2.0)) * HOOKED_pt), 1); chroma_quads[3][1] = HOOKED_gather(vec2((fp + vec2(2.0, 2.0)) * HOOKED_pt), 1); - vec4 luma_quads[4]; - luma_quads[0] = LUMA_LOWRES_gather(vec2((fp + vec2(0.0, 0.0)) * HOOKED_pt), 0); - luma_quads[1] = LUMA_LOWRES_gather(vec2((fp + vec2(2.0, 0.0)) * HOOKED_pt), 0); - luma_quads[2] = LUMA_LOWRES_gather(vec2((fp + vec2(0.0, 2.0)) * HOOKED_pt), 0); - luma_quads[3] = LUMA_LOWRES_gather(vec2((fp + vec2(2.0, 2.0)) * HOOKED_pt), 0); - vec2 chroma_pixels[12]; chroma_pixels[0] = vec2(chroma_quads[0][0].z, chroma_quads[0][1].z); chroma_pixels[1] = vec2(chroma_quads[1][0].w, chroma_quads[1][1].w); chroma_pixels[2] = vec2(chroma_quads[0][0].x, chroma_quads[0][1].x); - chroma_pixels[3] = vec2(chroma_quads[0][0].y, chroma_quads[0][1].y); + chroma_pixels[3] = vec2(chroma_quads[0][0].y, chroma_quads[0][1].y); chroma_pixels[4] = vec2(chroma_quads[1][0].x, chroma_quads[1][1].x); chroma_pixels[5] = vec2(chroma_quads[1][0].y, chroma_quads[1][1].y); chroma_pixels[6] = vec2(chroma_quads[2][0].w, chroma_quads[2][1].w); @@ -126,6 +120,12 @@ vec4 hook() { chroma_pixels[9] = vec2(chroma_quads[3][0].z, chroma_quads[3][1].z); chroma_pixels[10] = vec2(chroma_quads[2][0].y, chroma_quads[2][1].y); chroma_pixels[11] = vec2(chroma_quads[3][0].x, chroma_quads[3][1].x); +#if (USE_12_TAP_REGRESSION == 1 || USE_4_TAP_REGRESSION == 1) + vec4 luma_quads[4]; + luma_quads[0] = LUMA_LOWRES_gather(vec2((fp + vec2(0.0, 0.0)) * HOOKED_pt), 0); + luma_quads[1] = LUMA_LOWRES_gather(vec2((fp + vec2(2.0, 0.0)) * HOOKED_pt), 0); + luma_quads[2] = LUMA_LOWRES_gather(vec2((fp + vec2(0.0, 2.0)) * HOOKED_pt), 0); + luma_quads[3] = LUMA_LOWRES_gather(vec2((fp + vec2(2.0, 2.0)) * HOOKED_pt), 0); float luma_pixels[12]; luma_pixels[0] = luma_quads[0].z; @@ -140,6 +140,7 @@ vec4 hook() { luma_pixels[9] = luma_quads[3].z; luma_pixels[10] = luma_quads[2].y; luma_pixels[11] = luma_quads[3].x; +#endif #else vec2 chroma_pixels[12]; chroma_pixels[0] = HOOKED_tex(vec2((fp + vec2(0.5, -0.5)) * HOOKED_pt)).xy; @@ -154,7 +155,7 @@ vec4 hook() { chroma_pixels[9] = HOOKED_tex(vec2((fp + vec2( 2.5, 1.5)) * HOOKED_pt)).xy; chroma_pixels[10] = HOOKED_tex(vec2((fp + vec2( 0.5, 2.5)) * HOOKED_pt)).xy; chroma_pixels[11] = HOOKED_tex(vec2((fp + vec2( 1.5, 2.5)) * HOOKED_pt)).xy; - +#if (USE_12_TAP_REGRESSION == 1 || USE_4_TAP_REGRESSION == 1) float luma_pixels[12]; luma_pixels[0] = LUMA_LOWRES_tex(vec2((fp + vec2(0.5, -0.5)) * HOOKED_pt)).x; luma_pixels[1] = LUMA_LOWRES_tex(vec2((fp + vec2(1.5, -0.5)) * HOOKED_pt)).x; @@ -169,13 +170,13 @@ vec4 hook() { luma_pixels[10] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 2.5)) * HOOKED_pt)).x; luma_pixels[11] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 2.5)) * HOOKED_pt)).x; #endif - +#endif vec2 chroma_min = vec2(1e8); chroma_min = min(chroma_min, chroma_pixels[3]); chroma_min = min(chroma_min, chroma_pixels[4]); chroma_min = min(chroma_min, chroma_pixels[7]); chroma_min = min(chroma_min, chroma_pixels[8]); - + vec2 chroma_max = vec2(1e-8); chroma_max = max(chroma_max, chroma_pixels[3]); chroma_max = max(chroma_max, chroma_pixels[4]); @@ -209,43 +210,58 @@ vec4 hook() { vec2 chroma_spatial = ct / wt; chroma_spatial = mix(chroma_spatial, clamp(chroma_spatial, chroma_min, chroma_max), ar_strength); +#if (USE_12_TAP_REGRESSION == 1 || USE_4_TAP_REGRESSION == 1) float luma_avg_12 = 0.0; for(int i = 0; i < 12; i++) { luma_avg_12 += luma_pixels[i]; } luma_avg_12 /= 12.0; - + float luma_var_12 = 0.0; for(int i = 0; i < 12; i++) { luma_var_12 += pow(luma_pixels[i] - luma_avg_12, 2.0); } - + vec2 chroma_avg_12 = vec2(0.0); for(int i = 0; i < 12; i++) { chroma_avg_12 += chroma_pixels[i]; } chroma_avg_12 /= 12.0; - + vec2 chroma_var_12 = vec2(0.0); for(int i = 0; i < 12; i++) { chroma_var_12 += pow(chroma_pixels[i] - chroma_avg_12, vec2(2.0)); } - + vec2 luma_chroma_cov_12 = vec2(0.0); for(int i = 0; i < 12; i++) { luma_chroma_cov_12 += (luma_pixels[i] - luma_avg_12) * (chroma_pixels[i] - chroma_avg_12); } - - vec2 corr = abs(luma_chroma_cov_12 / max(sqrt(luma_var_12 * chroma_var_12), division_limit)); - corr = clamp(corr, 0.0, 1.0); - vec2 alpha_12 = luma_chroma_cov_12 / max(luma_var_12, division_limit); + vec2 corr = abs(luma_chroma_cov_12 / max(sqrt(luma_var_12 * chroma_var_12), 1e-6)); + corr = clamp(corr, 0.0, 1.0); +#endif +#if (USE_12_TAP_REGRESSION == 1) + vec2 alpha_12 = luma_chroma_cov_12 / max(luma_var_12, 1e-6); vec2 beta_12 = chroma_avg_12 - alpha_12 * luma_avg_12; vec2 chroma_pred_12 = alpha_12 * luma_zero + beta_12; - chroma_pred_12 = clamp(chroma_pred_12, 0.0, 1.0); - chroma_pred_12 = mix(chroma_spatial, chroma_pred_12, pow(corr, vec2(2.0)) / 2.0); + if (chroma_min.x > 0.5) { + chroma_pred_12.x = clamp(chroma_pred_12.x, 0.5, 1.0); + } + if (chroma_min.y > 0.5) { + chroma_pred_12.y = clamp(chroma_pred_12.y, 0.5, 1.0); + } + if (chroma_max.x < 0.5) { + chroma_pred_12.x = clamp(chroma_pred_12.x, 0.0, 0.5); + } + if (chroma_max.y < 0.5) { + chroma_pred_12.y = clamp(chroma_pred_12.y, 0.0, 0.5); + } + + chroma_pred_12 = mix(chroma_spatial, chroma_pred_12, pow(corr, vec2(2.0)) / 2.0); +#endif #if (USE_4_TAP_REGRESSION == 1) float luma_avg_4 = 0.0; luma_avg_4 += luma_pixels[3]; @@ -273,18 +289,35 @@ vec4 hook() { luma_chroma_cov_4 += (luma_pixels[7] - luma_avg_4) * (chroma_pixels[7] - chroma_avg_4); luma_chroma_cov_4 += (luma_pixels[8] - luma_avg_4) * (chroma_pixels[8] - chroma_avg_4); - vec2 alpha_4 = luma_chroma_cov_4 / max(luma_var_4, division_limit); + vec2 alpha_4 = luma_chroma_cov_4 / max(luma_var_4, 1e-4); vec2 beta_4 = chroma_avg_4 - alpha_4 * luma_avg_4; vec2 chroma_pred_4 = alpha_4 * luma_zero + beta_4; - chroma_pred_4 = clamp(chroma_pred_4, 0.0, 1.0); - chroma_pred_4 = mix(chroma_spatial, chroma_pred_4, pow(corr, vec2(2.0)) / 2.0); + if (chroma_min.x > 0.5) { + chroma_pred_4.x = clamp(chroma_pred_4.x, 0.5, 1.0); + } + if (chroma_min.y > 0.5) { + chroma_pred_4.y = clamp(chroma_pred_4.y, 0.5, 1.0); + } + if (chroma_max.x < 0.5) { + chroma_pred_4.x = clamp(chroma_pred_4.x, 0.0, 0.5); + } + if (chroma_max.y < 0.5) { + chroma_pred_4.y = clamp(chroma_pred_4.y, 0.0, 0.5); + } + + chroma_pred_4 = mix(chroma_spatial, chroma_pred_4, pow(corr, vec2(2.0)) / 2.0); +#endif +#if (USE_12_TAP_REGRESSION == 1 && USE_4_TAP_REGRESSION == 1) output_pix.xy = mix(chroma_pred_4, chroma_pred_12, 0.5); -#else +#elif (USE_12_TAP_REGRESSION == 1 && USE_4_TAP_REGRESSION == 0) output_pix.xy = chroma_pred_12; +#elif (USE_12_TAP_REGRESSION == 0 && USE_4_TAP_REGRESSION == 1) + output_pix.xy = chroma_pred_4; +#else + output_pix.xy = chroma_spatial; #endif - // output_pix.xy = mix(output_pix.xy, clamp(output_pix.xy, chroma_min, chroma_max), ar_strength); output_pix.xy = clamp(output_pix.xy, 0.0, 1.0); return output_pix; -} \ No newline at end of file +} diff --git a/portable_config/shaders/CfL_Prediction_4tap_next.glsl b/portable_config/shaders/CfL_Prediction_Lite.glsl similarity index 63% rename from portable_config/shaders/CfL_Prediction_4tap_next.glsl rename to portable_config/shaders/CfL_Prediction_Lite.glsl index 44b81a3b..72e491c6 100644 --- a/portable_config/shaders/CfL_Prediction_4tap_next.glsl +++ b/portable_config/shaders/CfL_Prediction_Lite.glsl @@ -23,60 +23,14 @@ //!HOOK CHROMA //!BIND HOOKED //!BIND LUMA -//!SAVE LUMA_LOWRES -//!WIDTH CHROMA.w -//!HEIGHT LUMA.h -//!WHEN CHROMA.w LUMA.w < -//!DESC Chroma From Luma Prediction (Downscaling Luma 1st Step) - -vec4 hook() { - float factor = ceil(LUMA_size.x / HOOKED_size.x); - int start = int(ceil(-factor / 2.0 - 0.5)); - int end = int(floor(factor / 2.0 - 0.5)); - - float output_luma = 0.0; - int wt = 0; - for (int dx = start; dx <= end; dx++) { - output_luma += linearize(LUMA_texOff(vec2(dx + 0.5, 0.0))).x; - wt++; - } - vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); - return delinearize(output_pix); -} - -//!HOOK CHROMA -//!BIND HOOKED -//!BIND LUMA_LOWRES -//!SAVE LUMA_LOWRES -//!WIDTH CHROMA.w -//!HEIGHT CHROMA.h -//!WHEN CHROMA.w LUMA.w < -//!DESC Chroma From Luma Prediction (Downscaling Luma 2nd Step) - -vec4 hook() { - float factor = ceil(LUMA_LOWRES_size.y / HOOKED_size.y); - int start = int(ceil(-factor / 2.0 - 0.5)); - int end = int(floor(factor / 2.0 - 0.5)); - - float output_luma = 0.0; - int wt = 0; - for (int dy = start; dy <= end; dy++) { - output_luma += linearize(LUMA_LOWRES_texOff(vec2(0.0, dy + 0.5))).x; - wt++; - } - vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); - return delinearize(output_pix); -} - -//!HOOK CHROMA -//!BIND HOOKED -//!BIND LUMA -//!BIND LUMA_LOWRES //!WHEN CHROMA.w LUMA.w < //!WIDTH LUMA.w //!HEIGHT LUMA.h //!OFFSET ALIGN -//!DESC Chroma From Luma Prediction (4-tap, Upscaling Chroma) +//!DESC CfL Prediction Lite + +#define USE_12_TAP_REGRESSION 1 +#define USE_4_TAP_REGRESSION 0 float comp_wd(vec2 distance) { float d2 = min(pow(length(distance), 2.0), 4.0); @@ -84,8 +38,7 @@ float comp_wd(vec2 distance) { } vec4 hook() { - float ar_strength = 0.75; - float division_limit = 1e-4; + float ar_strength = 0.8; vec4 output_pix = vec4(0.0, 0.0, 0.0, 1.0); float luma_zero = LUMA_texOff(0.0).x; @@ -95,35 +48,38 @@ vec4 hook() { pp -= fp; #ifdef HOOKED_gather - vec4 chroma_quads[4][2]; - chroma_quads[0][0] = HOOKED_gather(vec2((fp + vec2(0.0, 0.0)) * HOOKED_pt), 0); - chroma_quads[1][0] = HOOKED_gather(vec2((fp + vec2(2.0, 0.0)) * HOOKED_pt), 0); - chroma_quads[2][0] = HOOKED_gather(vec2((fp + vec2(0.0, 2.0)) * HOOKED_pt), 0); - chroma_quads[3][0] = HOOKED_gather(vec2((fp + vec2(2.0, 2.0)) * HOOKED_pt), 0); - chroma_quads[0][1] = HOOKED_gather(vec2((fp + vec2(0.0, 0.0)) * HOOKED_pt), 1); - chroma_quads[1][1] = HOOKED_gather(vec2((fp + vec2(2.0, 0.0)) * HOOKED_pt), 1); - chroma_quads[2][1] = HOOKED_gather(vec2((fp + vec2(0.0, 2.0)) * HOOKED_pt), 1); - chroma_quads[3][1] = HOOKED_gather(vec2((fp + vec2(2.0, 2.0)) * HOOKED_pt), 1); - - vec4 luma_quads[4]; - luma_quads[0] = LUMA_LOWRES_gather(vec2((fp + vec2(0.0, 0.0)) * HOOKED_pt), 0); - luma_quads[1] = LUMA_LOWRES_gather(vec2((fp + vec2(2.0, 0.0)) * HOOKED_pt), 0); - luma_quads[2] = LUMA_LOWRES_gather(vec2((fp + vec2(0.0, 2.0)) * HOOKED_pt), 0); - luma_quads[3] = LUMA_LOWRES_gather(vec2((fp + vec2(2.0, 2.0)) * HOOKED_pt), 0); + const ivec2 gatherOffsets[4] = ivec2[](ivec2( 0, 0), ivec2( 2, 0), ivec2( 0, 2), ivec2( 2, 2)); + + vec4 chroma_u_quads[4]; + vec4 chroma_v_quads[4]; + chroma_u_quads[0] = HOOKED_gather(vec2((fp + gatherOffsets[0]) * HOOKED_pt), 0); + chroma_u_quads[1] = HOOKED_gather(vec2((fp + gatherOffsets[1]) * HOOKED_pt), 0); + chroma_u_quads[2] = HOOKED_gather(vec2((fp + gatherOffsets[2]) * HOOKED_pt), 0); + chroma_u_quads[3] = HOOKED_gather(vec2((fp + gatherOffsets[3]) * HOOKED_pt), 0); + chroma_v_quads[0] = HOOKED_gather(vec2((fp + gatherOffsets[0]) * HOOKED_pt), 1); + chroma_v_quads[1] = HOOKED_gather(vec2((fp + gatherOffsets[1]) * HOOKED_pt), 1); + chroma_v_quads[2] = HOOKED_gather(vec2((fp + gatherOffsets[2]) * HOOKED_pt), 1); + chroma_v_quads[3] = HOOKED_gather(vec2((fp + gatherOffsets[3]) * HOOKED_pt), 1); vec2 chroma_pixels[12]; - chroma_pixels[0] = vec2(chroma_quads[0][0].z, chroma_quads[0][1].z); - chroma_pixels[1] = vec2(chroma_quads[1][0].w, chroma_quads[1][1].w); - chroma_pixels[2] = vec2(chroma_quads[0][0].x, chroma_quads[0][1].x); - chroma_pixels[3] = vec2(chroma_quads[0][0].y, chroma_quads[0][1].y); - chroma_pixels[4] = vec2(chroma_quads[1][0].x, chroma_quads[1][1].x); - chroma_pixels[5] = vec2(chroma_quads[1][0].y, chroma_quads[1][1].y); - chroma_pixels[6] = vec2(chroma_quads[2][0].w, chroma_quads[2][1].w); - chroma_pixels[7] = vec2(chroma_quads[2][0].z, chroma_quads[2][1].z); - chroma_pixels[8] = vec2(chroma_quads[3][0].w, chroma_quads[3][1].w); - chroma_pixels[9] = vec2(chroma_quads[3][0].z, chroma_quads[3][1].z); - chroma_pixels[10] = vec2(chroma_quads[2][0].y, chroma_quads[2][1].y); - chroma_pixels[11] = vec2(chroma_quads[3][0].x, chroma_quads[3][1].x); + chroma_pixels[0] = vec2(chroma_u_quads[0].z, chroma_v_quads[0].z); + chroma_pixels[1] = vec2(chroma_u_quads[1].w, chroma_v_quads[1].w); + chroma_pixels[2] = vec2(chroma_u_quads[0].x, chroma_v_quads[0].x); + chroma_pixels[3] = vec2(chroma_u_quads[0].y, chroma_v_quads[0].y); + chroma_pixels[4] = vec2(chroma_u_quads[1].x, chroma_v_quads[1].x); + chroma_pixels[5] = vec2(chroma_u_quads[1].y, chroma_v_quads[1].y); + chroma_pixels[6] = vec2(chroma_u_quads[2].w, chroma_v_quads[2].w); + chroma_pixels[7] = vec2(chroma_u_quads[2].z, chroma_v_quads[2].z); + chroma_pixels[8] = vec2(chroma_u_quads[3].w, chroma_v_quads[3].w); + chroma_pixels[9] = vec2(chroma_u_quads[3].z, chroma_v_quads[3].z); + chroma_pixels[10] = vec2(chroma_u_quads[2].y, chroma_v_quads[2].y); + chroma_pixels[11] = vec2(chroma_u_quads[3].x, chroma_v_quads[3].x); +#if (USE_12_TAP_REGRESSION == 1 || USE_4_TAP_REGRESSION == 1) + vec4 luma_quads[4]; + luma_quads[0] = LUMA_gather(vec2((fp + gatherOffsets[0]) * HOOKED_pt), 0); + luma_quads[1] = LUMA_gather(vec2((fp + gatherOffsets[1]) * HOOKED_pt), 0); + luma_quads[2] = LUMA_gather(vec2((fp + gatherOffsets[2]) * HOOKED_pt), 0); + luma_quads[3] = LUMA_gather(vec2((fp + gatherOffsets[3]) * HOOKED_pt), 0); float luma_pixels[12]; luma_pixels[0] = luma_quads[0].z; @@ -138,6 +94,7 @@ vec4 hook() { luma_pixels[9] = luma_quads[3].z; luma_pixels[10] = luma_quads[2].y; luma_pixels[11] = luma_quads[3].x; +#endif #else vec2 chroma_pixels[12]; chroma_pixels[0] = HOOKED_tex(vec2((fp + vec2(0.5, -0.5)) * HOOKED_pt)).xy; @@ -152,7 +109,7 @@ vec4 hook() { chroma_pixels[9] = HOOKED_tex(vec2((fp + vec2( 2.5, 1.5)) * HOOKED_pt)).xy; chroma_pixels[10] = HOOKED_tex(vec2((fp + vec2( 0.5, 2.5)) * HOOKED_pt)).xy; chroma_pixels[11] = HOOKED_tex(vec2((fp + vec2( 1.5, 2.5)) * HOOKED_pt)).xy; - +#if (USE_12_TAP_REGRESSION == 1 || USE_4_TAP_REGRESSION == 1) float luma_pixels[12]; luma_pixels[0] = LUMA_LOWRES_tex(vec2((fp + vec2(0.5, -0.5)) * HOOKED_pt)).x; luma_pixels[1] = LUMA_LOWRES_tex(vec2((fp + vec2(1.5, -0.5)) * HOOKED_pt)).x; @@ -167,18 +124,9 @@ vec4 hook() { luma_pixels[10] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 2.5)) * HOOKED_pt)).x; luma_pixels[11] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 2.5)) * HOOKED_pt)).x; #endif - - vec2 chroma_min = vec2(1e8); - chroma_min = min(chroma_min, chroma_pixels[3]); - chroma_min = min(chroma_min, chroma_pixels[4]); - chroma_min = min(chroma_min, chroma_pixels[7]); - chroma_min = min(chroma_min, chroma_pixels[8]); - - vec2 chroma_max = vec2(1e-8); - chroma_max = max(chroma_max, chroma_pixels[3]); - chroma_max = max(chroma_max, chroma_pixels[4]); - chroma_max = max(chroma_max, chroma_pixels[7]); - chroma_max = max(chroma_max, chroma_pixels[8]); +#endif + vec2 chroma_min = min(min(min(min(vec2(1e8 ), chroma_pixels[3]), chroma_pixels[4]), chroma_pixels[7]), chroma_pixels[8]); + vec2 chroma_max = max(max(max(max(vec2(1e-8), chroma_pixels[3]), chroma_pixels[4]), chroma_pixels[7]), chroma_pixels[8]); float wd[12]; wd[0] = comp_wd(vec2( 0.0,-1.0) - pp); @@ -207,6 +155,59 @@ vec4 hook() { vec2 chroma_spatial = ct / wt; chroma_spatial = mix(chroma_spatial, clamp(chroma_spatial, chroma_min, chroma_max), ar_strength); +#if (USE_12_TAP_REGRESSION == 1 || USE_4_TAP_REGRESSION == 1) + float luma_avg_12 = 0.0; + for(int i = 0; i < 12; i++) { + luma_avg_12 += luma_pixels[i]; + } + luma_avg_12 /= 12.0; + + float luma_var_12 = 0.0; + for(int i = 0; i < 12; i++) { + luma_var_12 += pow(luma_pixels[i] - luma_avg_12, 2.0); + } + + vec2 chroma_avg_12 = vec2(0.0); + for(int i = 0; i < 12; i++) { + chroma_avg_12 += chroma_pixels[i]; + } + chroma_avg_12 /= 12.0; + + vec2 chroma_var_12 = vec2(0.0); + for(int i = 0; i < 12; i++) { + chroma_var_12 += pow(chroma_pixels[i] - chroma_avg_12, vec2(2.0)); + } + + vec2 luma_chroma_cov_12 = vec2(0.0); + for(int i = 0; i < 12; i++) { + luma_chroma_cov_12 += (luma_pixels[i] - luma_avg_12) * (chroma_pixels[i] - chroma_avg_12); + } + + vec2 corr = abs(luma_chroma_cov_12 / max(sqrt(luma_var_12 * chroma_var_12), 1e-6)); + corr = clamp(corr, 0.0, 1.0); +#endif +#if (USE_12_TAP_REGRESSION == 1) + vec2 alpha_12 = luma_chroma_cov_12 / max(luma_var_12, 1e-6); + vec2 beta_12 = chroma_avg_12 - alpha_12 * luma_avg_12; + + vec2 chroma_pred_12 = alpha_12 * luma_zero + beta_12; + + if (chroma_min.x > 0.5) { + chroma_pred_12.x = clamp(chroma_pred_12.x, 0.5, 1.0); + } + if (chroma_min.y > 0.5) { + chroma_pred_12.y = clamp(chroma_pred_12.y, 0.5, 1.0); + } + if (chroma_max.x < 0.5) { + chroma_pred_12.x = clamp(chroma_pred_12.x, 0.0, 0.5); + } + if (chroma_max.y < 0.5) { + chroma_pred_12.y = clamp(chroma_pred_12.y, 0.0, 0.5); + } + + chroma_pred_12 = mix(chroma_spatial, chroma_pred_12, pow(corr, vec2(2.0)) / 2.0); +#endif +#if (USE_4_TAP_REGRESSION == 1) float luma_avg_4 = 0.0; luma_avg_4 += luma_pixels[3]; luma_avg_4 += luma_pixels[4]; @@ -233,45 +234,35 @@ vec4 hook() { luma_chroma_cov_4 += (luma_pixels[7] - luma_avg_4) * (chroma_pixels[7] - chroma_avg_4); luma_chroma_cov_4 += (luma_pixels[8] - luma_avg_4) * (chroma_pixels[8] - chroma_avg_4); - vec2 alpha_4 = luma_chroma_cov_4 / max(luma_var_4, division_limit); + vec2 alpha_4 = luma_chroma_cov_4 / max(luma_var_4, 1e-4); vec2 beta_4 = chroma_avg_4 - alpha_4 * luma_avg_4; vec2 chroma_pred_4 = alpha_4 * luma_zero + beta_4; - chroma_pred_4 = clamp(chroma_pred_4, 0.0, 1.0); - float luma_avg_12 = 0.0; - for(int i = 0; i < 12; i++) { - luma_avg_12 += luma_pixels[i]; + if (chroma_min.x > 0.5) { + chroma_pred_4.x = clamp(chroma_pred_4.x, 0.5, 1.0); } - luma_avg_12 /= 12.0; - - float luma_var_12 = 0.0; - for(int i = 0; i < 12; i++) { - luma_var_12 += pow(luma_pixels[i] - luma_avg_12, 2.0); + if (chroma_min.y > 0.5) { + chroma_pred_4.y = clamp(chroma_pred_4.y, 0.5, 1.0); } - - vec2 chroma_avg_12 = vec2(0.0); - for(int i = 0; i < 12; i++) { - chroma_avg_12 += chroma_pixels[i]; + if (chroma_max.x < 0.5) { + chroma_pred_4.x = clamp(chroma_pred_4.x, 0.0, 0.5); } - chroma_avg_12 /= 12.0; - - vec2 chroma_var_12 = vec2(0.0); - for(int i = 0; i < 12; i++) { - chroma_var_12 += pow(chroma_pixels[i] - chroma_avg_12, vec2(2.0)); + if (chroma_max.y < 0.5) { + chroma_pred_4.y = clamp(chroma_pred_4.y, 0.0, 0.5); } - - vec2 luma_chroma_cov_12 = vec2(0.0); - for(int i = 0; i < 12; i++) { - luma_chroma_cov_12 += (luma_pixels[i] - luma_avg_12) * (chroma_pixels[i] - chroma_avg_12); - } - - vec2 corr = abs(luma_chroma_cov_12 / max(sqrt(luma_var_12 * chroma_var_12), division_limit)); - corr = clamp(corr, 0.0, 1.0); - output_pix.xy = mix(chroma_spatial, chroma_pred_4, pow(corr, vec2(2.0)) / 2.0); - - // output_pix.xy = mix(output_pix.xy, clamp(output_pix.xy, chroma_min, chroma_max), ar_strength); + chroma_pred_4 = mix(chroma_spatial, chroma_pred_4, pow(corr, vec2(2.0)) / 2.0); +#endif +#if (USE_12_TAP_REGRESSION == 1 && USE_4_TAP_REGRESSION == 1) + output_pix.xy = mix(chroma_pred_4, chroma_pred_12, 0.5); +#elif (USE_12_TAP_REGRESSION == 1 && USE_4_TAP_REGRESSION == 0) + output_pix.xy = chroma_pred_12; +#elif (USE_12_TAP_REGRESSION == 0 && USE_4_TAP_REGRESSION == 1) + output_pix.xy = chroma_pred_4; +#else + output_pix.xy = chroma_spatial; +#endif output_pix.xy = clamp(output_pix.xy, 0.0, 1.0); return output_pix; -} \ No newline at end of file +} diff --git a/portable_config/shaders/FastBilateral_next.glsl b/portable_config/shaders/FastBilateral_next.glsl index 5b0becce..9e814f51 100644 --- a/portable_config/shaders/FastBilateral_next.glsl +++ b/portable_config/shaders/FastBilateral_next.glsl @@ -20,14 +20,63 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +//!HOOK CHROMA +//!BIND HOOKED +//!BIND LUMA +//!SAVE LUMA_LOWRES +//!WIDTH CHROMA.w +//!HEIGHT LUMA.h +//!WHEN CHROMA.w LUMA.w < +//!DESC Fast Bilateral (Downscaling Luma 1st Step) + +vec4 hook() { + float factor = ceil(LUMA_size.x / HOOKED_size.x); + int start = int(ceil(-factor / 2.0 - 0.5)); + int end = int(floor(factor / 2.0 - 0.5)); + + float output_luma = 0.0; + int wt = 0; + for (int dx = start; dx <= end; dx++) { + output_luma += LUMA_texOff(vec2(dx + 0.5, 0.0)).x; + wt++; + } + vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); + return output_pix; +} + +//!HOOK CHROMA +//!BIND HOOKED +//!BIND LUMA_LOWRES +//!SAVE LUMA_LOWRES +//!WIDTH CHROMA.w +//!HEIGHT CHROMA.h +//!WHEN CHROMA.w LUMA.w < +//!DESC Fast Bilateral (Downscaling Luma 2nd Step) + +vec4 hook() { + float factor = ceil(LUMA_LOWRES_size.y / HOOKED_size.y); + int start = int(ceil(-factor / 2.0 - 0.5)); + int end = int(floor(factor / 2.0 - 0.5)); + + float output_luma = 0.0; + int wt = 0; + for (int dy = start; dy <= end; dy++) { + output_luma += LUMA_LOWRES_texOff(vec2(0.0, dy + 0.5)).x; + wt++; + } + vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); + return output_pix; +} + //!PARAM intensity_coeff //!TYPE float //!MINIMUM 0.0 -256.0 +512.0 //!HOOK CHROMA //!BIND CHROMA //!BIND LUMA +//!BIND LUMA_LOWRES //!WIDTH LUMA.w //!HEIGHT LUMA.h //!WHEN CHROMA.w LUMA.w < @@ -50,10 +99,10 @@ vec4 hook() { vec2 chroma_21 = CHROMA_tex(vec2(fp + vec2(1.5, 0.5)) * CHROMA_pt).xy; vec2 chroma_22 = CHROMA_tex(vec2(fp + vec2(1.5, 1.5)) * CHROMA_pt).xy; - float luma_11 = LUMA_tex(vec2(fp + vec2(0.5)) * CHROMA_pt).x; - float luma_12 = LUMA_tex(vec2(fp + vec2(0.5, 1.5)) * CHROMA_pt).x; - float luma_21 = LUMA_tex(vec2(fp + vec2(1.5, 0.5)) * CHROMA_pt).x; - float luma_22 = LUMA_tex(vec2(fp + vec2(1.5, 1.5)) * CHROMA_pt).x; + float luma_11 = LUMA_LOWRES_tex(vec2(fp + vec2(0.5)) * CHROMA_pt).x; + float luma_12 = LUMA_LOWRES_tex(vec2(fp + vec2(0.5, 1.5)) * CHROMA_pt).x; + float luma_21 = LUMA_LOWRES_tex(vec2(fp + vec2(1.5, 0.5)) * CHROMA_pt).x; + float luma_22 = LUMA_LOWRES_tex(vec2(fp + vec2(1.5, 1.5)) * CHROMA_pt).x; float wd11 = (1 - pp.y) * (1 - pp.x); float wd12 = pp.y * (1 - pp.x); diff --git a/portable_config/shaders/JointBilateral_next.glsl b/portable_config/shaders/JointBilateral_next.glsl index 68272a4f..b972c53f 100644 --- a/portable_config/shaders/JointBilateral_next.glsl +++ b/portable_config/shaders/JointBilateral_next.glsl @@ -21,47 +21,62 @@ // SOFTWARE. //!HOOK CHROMA -//!BIND LUMA //!BIND HOOKED +//!BIND LUMA //!SAVE LUMA_LOWRES +//!WIDTH CHROMA.w +//!HEIGHT LUMA.h //!WHEN CHROMA.w LUMA.w < -//!DESC Joint Bilateral (Downscaling Luma) +//!DESC Joint Bilateral (Downscaling Luma 1st Step) vec4 hook() { - vec2 start = ceil((LUMA_pos - CHROMA_pt) * LUMA_size - 0.5); - vec2 end = floor((LUMA_pos + CHROMA_pt) * LUMA_size - 0.5); - - float luma_pix = 0.0; - float w = 0.0; - float d = 0.0; - float wt = 0.0; - float val = 0.0; - vec2 pos = LUMA_pos; - - for (float dx = start.x; dx <= end.x; dx++) { - for (float dy = start.y; dy <= end.y; dy++) { - pos = LUMA_pt * vec2(dx + 0.5, dy + 0.5); - d = length((pos - LUMA_pos) * CHROMA_size); - w = exp(-2.0 * pow(d, 2.0)); - luma_pix = LUMA_tex(pos).x; - val += w * luma_pix; - wt += w; - } + float factor = ceil(LUMA_size.x / HOOKED_size.x); + int start = int(ceil(-factor / 2.0 - 0.5)); + int end = int(floor(factor / 2.0 - 0.5)); + + float output_luma = 0.0; + int wt = 0; + for (int dx = start; dx <= end; dx++) { + output_luma += LUMA_texOff(vec2(dx + 0.5, 0.0)).x; + wt++; } + vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); + return output_pix; +} - vec4 output_pix = vec4(val / wt, 0.0, 0.0, 1.0); +//!HOOK CHROMA +//!BIND HOOKED +//!BIND LUMA_LOWRES +//!SAVE LUMA_LOWRES +//!WIDTH CHROMA.w +//!HEIGHT CHROMA.h +//!WHEN CHROMA.w LUMA.w < +//!DESC Joint Bilateral (Downscaling Luma 2nd Step) + +vec4 hook() { + float factor = ceil(LUMA_LOWRES_size.y / HOOKED_size.y); + int start = int(ceil(-factor / 2.0 - 0.5)); + int end = int(floor(factor / 2.0 - 0.5)); + + float output_luma = 0.0; + int wt = 0; + for (int dy = start; dy <= end; dy++) { + output_luma += LUMA_LOWRES_texOff(vec2(0.0, dy + 0.5)).x; + wt++; + } + vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); return output_pix; } //!PARAM distance_coeff //!TYPE float //!MINIMUM 0.0 -4.0 +2.5 //!PARAM intensity_coeff //!TYPE float //!MINIMUM 0.0 -256.0 +512.0 //!HOOK CHROMA //!BIND CHROMA diff --git a/portable_config/shaders/KrigBilateral.glsl b/portable_config/shaders/KrigBilateral.glsl index 50052db1..d7f39734 100644 --- a/portable_config/shaders/KrigBilateral.glsl +++ b/portable_config/shaders/KrigBilateral.glsl @@ -134,7 +134,7 @@ vec4 hook() { total.xyz /= total.w; float localVar = abs(total.y - total.x * total.x) + sigma_nsq; float Var = localVar + total.z; - float radius = mix(1.0, 2.0, sigma_nsq / Var); + float radius = 1.5; // mix(1.5, 1.0, sigma_nsq / Var); float y = LUMA_texOff(0).x; float Mx[(N*(N+1))/2]; diff --git a/portable_config/shaders/MemeBilateral_Lite.glsl b/portable_config/shaders/MemeBilateral_Lite.glsl new file mode 100644 index 00000000..5f4de519 --- /dev/null +++ b/portable_config/shaders/MemeBilateral_Lite.glsl @@ -0,0 +1,244 @@ +// MIT License + +// Copyright (c) 2023 João Chrisóstomo + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +//!HOOK CHROMA +//!BIND HOOKED +//!BIND LUMA +//!WIDTH LUMA.w +//!HEIGHT LUMA.h +//!WHEN CHROMA.w LUMA.w < +//!OFFSET ALIGN +//!DESC MemeBilateral Lite + +#define distance_coeff 0.5 +#define intensity_coeff 512.0 + +float comp_wd1(vec2 distance) { + float d2 = min(pow(length(distance), 2.0), 4.0); + return (25.0 / 16.0 * pow(2.0 / 5.0 * d2 - 1.0, 2.0) - (25.0 / 16.0 - 1.0)) * pow(1.0 / 4.0 * d2 - 1.0, 2.0); +} + +float comp_wd2(vec2 distance) { + return exp(-distance_coeff * pow(length(distance), 2.0)); +} + +float comp_wi(float distance) { + return exp(-intensity_coeff * pow(distance, 2.0)); +} + +float comp_w(float wd, float wi) { + float w = wd * wi; + // return clamp(w, 1e-32, 1.0); + return w; +} + +vec4 hook() { + float ar_strength = 0.8; + float division_limit = 1e-4; + + float luma_zero = LUMA_texOff(0.0).x; + vec4 output_pix = vec4(0.0, 0.0, 0.0, 1.0); + + vec2 pp = HOOKED_pos * HOOKED_size - vec2(0.5); + vec2 fp = floor(pp); + pp -= fp; + +#ifdef HOOKED_gather + const ivec2 gatherOffsets[4] = ivec2[](ivec2( 0, 0), ivec2( 2, 0), ivec2( 0, 2), ivec2( 2, 2)); + + vec4 chroma_u_quads[4]; + vec4 chroma_v_quads[4]; + chroma_u_quads[0] = HOOKED_gather(vec2((fp + gatherOffsets[0]) * HOOKED_pt), 0); + chroma_u_quads[1] = HOOKED_gather(vec2((fp + gatherOffsets[1]) * HOOKED_pt), 0); + chroma_u_quads[2] = HOOKED_gather(vec2((fp + gatherOffsets[2]) * HOOKED_pt), 0); + chroma_u_quads[3] = HOOKED_gather(vec2((fp + gatherOffsets[3]) * HOOKED_pt), 0); + chroma_v_quads[0] = HOOKED_gather(vec2((fp + gatherOffsets[0]) * HOOKED_pt), 1); + chroma_v_quads[1] = HOOKED_gather(vec2((fp + gatherOffsets[1]) * HOOKED_pt), 1); + chroma_v_quads[2] = HOOKED_gather(vec2((fp + gatherOffsets[2]) * HOOKED_pt), 1); + chroma_v_quads[3] = HOOKED_gather(vec2((fp + gatherOffsets[3]) * HOOKED_pt), 1); + + vec2 chroma_pixels[12]; + chroma_pixels[0] = vec2(chroma_u_quads[0].z, chroma_v_quads[0].z); + chroma_pixels[1] = vec2(chroma_u_quads[1].w, chroma_v_quads[1].w); + chroma_pixels[2] = vec2(chroma_u_quads[0].x, chroma_v_quads[0].x); + chroma_pixels[3] = vec2(chroma_u_quads[0].y, chroma_v_quads[0].y); + chroma_pixels[4] = vec2(chroma_u_quads[1].x, chroma_v_quads[1].x); + chroma_pixels[5] = vec2(chroma_u_quads[1].y, chroma_v_quads[1].y); + chroma_pixels[6] = vec2(chroma_u_quads[2].w, chroma_v_quads[2].w); + chroma_pixels[7] = vec2(chroma_u_quads[2].z, chroma_v_quads[2].z); + chroma_pixels[8] = vec2(chroma_u_quads[3].w, chroma_v_quads[3].w); + chroma_pixels[9] = vec2(chroma_u_quads[3].z, chroma_v_quads[3].z); + chroma_pixels[10] = vec2(chroma_u_quads[2].y, chroma_v_quads[2].y); + chroma_pixels[11] = vec2(chroma_u_quads[3].x, chroma_v_quads[3].x); + + vec4 luma_quads[4]; + luma_quads[0] = LUMA_gather(vec2((fp + gatherOffsets[0]) * HOOKED_pt), 0); + luma_quads[1] = LUMA_gather(vec2((fp + gatherOffsets[1]) * HOOKED_pt), 0); + luma_quads[2] = LUMA_gather(vec2((fp + gatherOffsets[2]) * HOOKED_pt), 0); + luma_quads[3] = LUMA_gather(vec2((fp + gatherOffsets[3]) * HOOKED_pt), 0); + + float luma_pixels[12]; + luma_pixels[0] = luma_quads[0].z; + luma_pixels[1] = luma_quads[1].w; + luma_pixels[2] = luma_quads[0].x; + luma_pixels[3] = luma_quads[0].y; + luma_pixels[4] = luma_quads[1].x; + luma_pixels[5] = luma_quads[1].y; + luma_pixels[6] = luma_quads[2].w; + luma_pixels[7] = luma_quads[2].z; + luma_pixels[8] = luma_quads[3].w; + luma_pixels[9] = luma_quads[3].z; + luma_pixels[10] = luma_quads[2].y; + luma_pixels[11] = luma_quads[3].x; +#else + vec2 chroma_pixels[12]; + chroma_pixels[0] = HOOKED_tex(vec2((fp + vec2(0.5, -0.5)) * HOOKED_pt)).xy; + chroma_pixels[1] = HOOKED_tex(vec2((fp + vec2(1.5, -0.5)) * HOOKED_pt)).xy; + chroma_pixels[2] = HOOKED_tex(vec2((fp + vec2(-0.5, 0.5)) * HOOKED_pt)).xy; + chroma_pixels[3] = HOOKED_tex(vec2((fp + vec2( 0.5, 0.5)) * HOOKED_pt)).xy; + chroma_pixels[4] = HOOKED_tex(vec2((fp + vec2( 1.5, 0.5)) * HOOKED_pt)).xy; + chroma_pixels[5] = HOOKED_tex(vec2((fp + vec2( 2.5, 0.5)) * HOOKED_pt)).xy; + chroma_pixels[6] = HOOKED_tex(vec2((fp + vec2(-0.5, 1.5)) * HOOKED_pt)).xy; + chroma_pixels[7] = HOOKED_tex(vec2((fp + vec2( 0.5, 1.5)) * HOOKED_pt)).xy; + chroma_pixels[8] = HOOKED_tex(vec2((fp + vec2( 1.5, 1.5)) * HOOKED_pt)).xy; + chroma_pixels[9] = HOOKED_tex(vec2((fp + vec2( 2.5, 1.5)) * HOOKED_pt)).xy; + chroma_pixels[10] = HOOKED_tex(vec2((fp + vec2( 0.5, 2.5)) * HOOKED_pt)).xy; + chroma_pixels[11] = HOOKED_tex(vec2((fp + vec2( 1.5, 2.5)) * HOOKED_pt)).xy; + + float luma_pixels[12]; + luma_pixels[0] = LUMA_LOWRES_tex(vec2((fp + vec2(0.5, -0.5)) * HOOKED_pt)).x; + luma_pixels[1] = LUMA_LOWRES_tex(vec2((fp + vec2(1.5, -0.5)) * HOOKED_pt)).x; + luma_pixels[2] = LUMA_LOWRES_tex(vec2((fp + vec2(-0.5, 0.5)) * HOOKED_pt)).x; + luma_pixels[3] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 0.5)) * HOOKED_pt)).x; + luma_pixels[4] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 0.5)) * HOOKED_pt)).x; + luma_pixels[5] = LUMA_LOWRES_tex(vec2((fp + vec2( 2.5, 0.5)) * HOOKED_pt)).x; + luma_pixels[6] = LUMA_LOWRES_tex(vec2((fp + vec2(-0.5, 1.5)) * HOOKED_pt)).x; + luma_pixels[7] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 1.5)) * HOOKED_pt)).x; + luma_pixels[8] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 1.5)) * HOOKED_pt)).x; + luma_pixels[9] = LUMA_LOWRES_tex(vec2((fp + vec2( 2.5, 1.5)) * HOOKED_pt)).x; + luma_pixels[10] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 2.5)) * HOOKED_pt)).x; + luma_pixels[11] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 2.5)) * HOOKED_pt)).x; +#endif + + vec2 chroma_min = min(min(min(min(vec2(1e8 ), chroma_pixels[3]), chroma_pixels[4]), chroma_pixels[7]), chroma_pixels[8]); + vec2 chroma_max = max(max(max(max(vec2(1e-8), chroma_pixels[3]), chroma_pixels[4]), chroma_pixels[7]), chroma_pixels[8]); + +// Sharp spatial filter + float wd1[12]; + wd1[0] = comp_wd1(vec2( 0.0,-1.0) - pp); + wd1[1] = comp_wd1(vec2( 1.0,-1.0) - pp); + wd1[2] = comp_wd1(vec2(-1.0, 0.0) - pp); + wd1[3] = comp_wd1(vec2( 0.0, 0.0) - pp); + wd1[4] = comp_wd1(vec2( 1.0, 0.0) - pp); + wd1[5] = comp_wd1(vec2( 2.0, 0.0) - pp); + wd1[6] = comp_wd1(vec2(-1.0, 1.0) - pp); + wd1[7] = comp_wd1(vec2( 0.0, 1.0) - pp); + wd1[8] = comp_wd1(vec2( 1.0, 1.0) - pp); + wd1[9] = comp_wd1(vec2( 2.0, 1.0) - pp); + wd1[10] = comp_wd1(vec2( 0.0, 2.0) - pp); + wd1[11] = comp_wd1(vec2( 1.0, 2.0) - pp); + + float wt1 = 0.0; + for (int i = 0; i < 12; i++) { + wt1 += wd1[i]; + } + + vec2 ct1 = vec2(0.0); + for (int i = 0; i < 12; i++) { + ct1 += wd1[i] * chroma_pixels[i]; + } + + vec2 chroma_spatial = ct1 / wt1; + chroma_spatial = mix(chroma_spatial, clamp(chroma_spatial, chroma_min, chroma_max), ar_strength); + +// Bilateral filter + float wd2[12]; + wd2[0] = comp_wd2(vec2( 0.0,-1.0) - pp); + wd2[1] = comp_wd2(vec2( 1.0,-1.0) - pp); + wd2[2] = comp_wd2(vec2(-1.0, 0.0) - pp); + wd2[3] = comp_wd2(vec2( 0.0, 0.0) - pp); + wd2[4] = comp_wd2(vec2( 1.0, 0.0) - pp); + wd2[5] = comp_wd2(vec2( 2.0, 0.0) - pp); + wd2[6] = comp_wd2(vec2(-1.0, 1.0) - pp); + wd2[7] = comp_wd2(vec2( 0.0, 1.0) - pp); + wd2[8] = comp_wd2(vec2( 1.0, 1.0) - pp); + wd2[9] = comp_wd2(vec2( 2.0, 1.0) - pp); + wd2[10] = comp_wd2(vec2( 0.0, 2.0) - pp); + wd2[11] = comp_wd2(vec2( 1.0, 2.0) - pp); + + float wi[12]; + for (int i = 0; i < 12; i++) { + wi[i] = comp_wi(luma_zero - luma_pixels[i]); + } + + float w[12]; + for (int i = 0; i < 12; i++) { + w[i] = comp_w(wd2[i], wi[i]); + } + + float wt2 = 0.0; + for (int i = 0; i < 12; i++) { + wt2 += w[i]; + } + + vec2 ct2 = vec2(0.0); + for (int i = 0; i < 12; i++) { + ct2 += w[i] * chroma_pixels[i]; + } + + vec2 chroma_bilat = ct2 / wt2; + +// Coefficient of determination + float luma_avg_12 = 0.0; + for(int i = 0; i < 12; i++) { + luma_avg_12 += luma_pixels[i]; + } + luma_avg_12 /= 12.0; + + float luma_var_12 = 0.0; + for(int i = 0; i < 12; i++) { + luma_var_12 += pow(luma_pixels[i] - luma_avg_12, 2.0); + } + + vec2 chroma_avg_12 = vec2(0.0); + for(int i = 0; i < 12; i++) { + chroma_avg_12 += chroma_pixels[i]; + } + chroma_avg_12 /= 12.0; + + vec2 chroma_var_12 = vec2(0.0); + for(int i = 0; i < 12; i++) { + chroma_var_12 += pow(chroma_pixels[i] - chroma_avg_12, vec2(2.0)); + } + + vec2 luma_chroma_cov_12 = vec2(0.0); + for(int i = 0; i < 12; i++) { + luma_chroma_cov_12 += (luma_pixels[i] - luma_avg_12) * (chroma_pixels[i] - chroma_avg_12); + } + + vec2 corr = abs(luma_chroma_cov_12 / max(sqrt(luma_var_12 * chroma_var_12), division_limit)); + corr = clamp(corr, 0.0, 1.0); + + output_pix.xy = mix(chroma_spatial, chroma_bilat, pow(corr, vec2(2.0)) / 2.0); + output_pix.xy = clamp(output_pix.xy, 0.0, 1.0); + return output_pix; +} diff --git a/portable_config/shaders/MemeBilateral_next.glsl b/portable_config/shaders/MemeBilateral_next.glsl index 5baa773d..2b33f8ed 100644 --- a/portable_config/shaders/MemeBilateral_next.glsl +++ b/portable_config/shaders/MemeBilateral_next.glsl @@ -20,6 +20,54 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +//!HOOK CHROMA +//!BIND HOOKED +//!BIND LUMA +//!SAVE LUMA_LOWRES +//!WIDTH CHROMA.w +//!HEIGHT LUMA.h +//!WHEN CHROMA.w LUMA.w < +//!DESC Meme Bilateral (Downscaling Luma 1st Step) + +vec4 hook() { + float factor = ceil(LUMA_size.x / HOOKED_size.x); + int start = int(ceil(-factor / 2.0 - 0.5)); + int end = int(floor(factor / 2.0 - 0.5)); + + float output_luma = 0.0; + int wt = 0; + for (int dx = start; dx <= end; dx++) { + output_luma += LUMA_texOff(vec2(dx + 0.5, 0.0)).x; + wt++; + } + vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); + return output_pix; +} + +//!HOOK CHROMA +//!BIND HOOKED +//!BIND LUMA_LOWRES +//!SAVE LUMA_LOWRES +//!WIDTH CHROMA.w +//!HEIGHT CHROMA.h +//!WHEN CHROMA.w LUMA.w < +//!DESC Meme Bilateral (Downscaling Luma 2nd Step) + +vec4 hook() { + float factor = ceil(LUMA_LOWRES_size.y / HOOKED_size.y); + int start = int(ceil(-factor / 2.0 - 0.5)); + int end = int(floor(factor / 2.0 - 0.5)); + + float output_luma = 0.0; + int wt = 0; + for (int dy = start; dy <= end; dy++) { + output_luma += LUMA_LOWRES_texOff(vec2(0.0, dy + 0.5)).x; + wt++; + } + vec4 output_pix = vec4(output_luma / float(wt), 0.0, 0.0, 1.0); + return output_pix; +} + //!PARAM distance_coeff //!TYPE float //!MINIMUM 0.0 @@ -33,6 +81,7 @@ //!HOOK CHROMA //!BIND HOOKED //!BIND LUMA +//!BIND LUMA_LOWRES //!WIDTH LUMA.w //!HEIGHT LUMA.h //!WHEN CHROMA.w LUMA.w < @@ -59,7 +108,7 @@ float comp_w(float wd, float wi) { } vec4 hook() { - float ar_strength = 0.75; + float ar_strength = 0.5; float division_limit = 1e-4; float luma_zero = LUMA_texOff(0.0).x; @@ -84,18 +133,18 @@ vec4 hook() { chroma_pixels[11] = HOOKED_tex(vec2((fp + vec2( 1.5, 2.5)) * HOOKED_pt)).xy; float luma_pixels[12]; - luma_pixels[0] = LUMA_tex(vec2((fp + vec2(0.5, -0.5)) * HOOKED_pt)).x; - luma_pixels[1] = LUMA_tex(vec2((fp + vec2(1.5, -0.5)) * HOOKED_pt)).x; - luma_pixels[2] = LUMA_tex(vec2((fp + vec2(-0.5, 0.5)) * HOOKED_pt)).x; - luma_pixels[3] = LUMA_tex(vec2((fp + vec2( 0.5, 0.5)) * HOOKED_pt)).x; - luma_pixels[4] = LUMA_tex(vec2((fp + vec2( 1.5, 0.5)) * HOOKED_pt)).x; - luma_pixels[5] = LUMA_tex(vec2((fp + vec2( 2.5, 0.5)) * HOOKED_pt)).x; - luma_pixels[6] = LUMA_tex(vec2((fp + vec2(-0.5, 1.5)) * HOOKED_pt)).x; - luma_pixels[7] = LUMA_tex(vec2((fp + vec2( 0.5, 1.5)) * HOOKED_pt)).x; - luma_pixels[8] = LUMA_tex(vec2((fp + vec2( 1.5, 1.5)) * HOOKED_pt)).x; - luma_pixels[9] = LUMA_tex(vec2((fp + vec2( 2.5, 1.5)) * HOOKED_pt)).x; - luma_pixels[10] = LUMA_tex(vec2((fp + vec2( 0.5, 2.5)) * HOOKED_pt)).x; - luma_pixels[11] = LUMA_tex(vec2((fp + vec2( 1.5, 2.5)) * HOOKED_pt)).x; + luma_pixels[0] = LUMA_LOWRES_tex(vec2((fp + vec2(0.5, -0.5)) * HOOKED_pt)).x; + luma_pixels[1] = LUMA_LOWRES_tex(vec2((fp + vec2(1.5, -0.5)) * HOOKED_pt)).x; + luma_pixels[2] = LUMA_LOWRES_tex(vec2((fp + vec2(-0.5, 0.5)) * HOOKED_pt)).x; + luma_pixels[3] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 0.5)) * HOOKED_pt)).x; + luma_pixels[4] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 0.5)) * HOOKED_pt)).x; + luma_pixels[5] = LUMA_LOWRES_tex(vec2((fp + vec2( 2.5, 0.5)) * HOOKED_pt)).x; + luma_pixels[6] = LUMA_LOWRES_tex(vec2((fp + vec2(-0.5, 1.5)) * HOOKED_pt)).x; + luma_pixels[7] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 1.5)) * HOOKED_pt)).x; + luma_pixels[8] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 1.5)) * HOOKED_pt)).x; + luma_pixels[9] = LUMA_LOWRES_tex(vec2((fp + vec2( 2.5, 1.5)) * HOOKED_pt)).x; + luma_pixels[10] = LUMA_LOWRES_tex(vec2((fp + vec2( 0.5, 2.5)) * HOOKED_pt)).x; + luma_pixels[11] = LUMA_LOWRES_tex(vec2((fp + vec2( 1.5, 2.5)) * HOOKED_pt)).x; vec2 chroma_min = vec2(1e8); chroma_min = min(chroma_min, chroma_pixels[3]);