Skip to content

Instantly share code, notes, and snippets.

@hooke007
Created February 12, 2026 08:19
Show Gist options
  • Select an option

  • Save hooke007/0ea3f634217b73a00bdaf9844bcd1e50 to your computer and use it in GitHub Desktop.

Select an option

Save hooke007/0ea3f634217b73a00bdaf9844bcd1e50 to your computer and use it in GitHub Desktop.
mpv光标同步绘制测试
// 在鼠标光标位置绘制一个圆形
//!PARAM mouse_x
//!TYPE DYNAMIC float
//!MINIMUM 0
//!MAXIMUM 99999
0.0
//!PARAM mouse_y
//!TYPE DYNAMIC float
//!MINIMUM 0
//!MAXIMUM 99999
0.0
//!PARAM circle_rad
//!TYPE float
//!MINIMUM 1
//!MAXIMUM 500
50.0
//!PARAM circle_tk
//!TYPE float
//!MINIMUM 0
//!MAXIMUM 50
10.0
//!PARAM circle_r
//!TYPE float
//!MINIMUM 0.0
//!MAXIMUM 1.0
0.5
//!PARAM circle_g
//!TYPE float
//!MINIMUM 0.0
//!MAXIMUM 1.0
0.5
//!PARAM circle_b
//!TYPE float
//!MINIMUM 0.0
//!MAXIMUM 1.0
0.5
//!PARAM circle_a
//!TYPE float
//!MINIMUM 0.0
//!MAXIMUM 1.0
0.5
//!PARAM enabled
//!TYPE DEFINE
//!MINIMUM 0
//!MAXIMUM 1
1
//!HOOK OUTPUT
//!BIND HOOKED
//!DESC Cursor Circle example
//!WHEN enabled
vec4 hook() {
vec4 color = HOOKED_texOff(0);
vec2 frag_pos = HOOKED_pos * target_size;
vec2 center = vec2(mouse_x, mouse_y);
float dist = length(frag_pos - center);
vec3 circle_color = vec3(circle_r, circle_g, circle_b);
float alpha = 0.0;
if (circle_tk <= 0.0) {
alpha = 1.0 - smoothstep(circle_rad - 1.0, circle_rad + 1.0, dist);
} else {
float inner = circle_rad - circle_tk * 0.5;
float outer = circle_rad + circle_tk * 0.5;
float outer_alpha = 1.0 - smoothstep(outer - 1.0, outer + 1.0, dist);
float inner_alpha = smoothstep(inner - 1.0, inner + 1.0, dist);
alpha = outer_alpha * inner_alpha;
}
alpha *= circle_a;
color.rgb = mix(color.rgb, circle_color, alpha);
return color;
}
-- 此脚本可用于同步光标位置给着色器
local function on_mouse_pos_change(_, pos)
if pos == nil then return end
if not pos.hover then return end
local x = pos.x or 0
local y = pos.y or 0
mp.commandv("change-list", "glsl-shader-opts", "append", string.format("mouse_x=%f", x))
mp.commandv("change-list", "glsl-shader-opts", "append", string.format("mouse_y=%f", y))
end
mp.observe_property("mouse-pos", "native", on_mouse_pos_change)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment