From f83e60243e6efd930f6c5e18019e6f98cfa9e278 Mon Sep 17 00:00:00 2001 From: KojoZero Date: Fri, 24 Apr 2026 13:27:49 -0700 Subject: [PATCH] added cursor to vulkan --- .../host_shaders/vulkan_present.frag | 42 ++++++++++++++++++- .../host_shaders/vulkan_present.vert | 4 +- .../renderer_vulkan/renderer_vulkan.cpp | 3 +- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/video_core/host_shaders/vulkan_present.frag b/src/video_core/host_shaders/vulkan_present.frag index 01b158732..54d61ea8d 100644 --- a/src/video_core/host_shaders/vulkan_present.frag +++ b/src/video_core/host_shaders/vulkan_present.frag @@ -7,7 +7,7 @@ layout (location = 0) in vec2 frag_tex_coord; layout (location = 0) out vec4 color; - +layout (location = 1) in vec2 pixelUnit; layout (push_constant, std140) uniform DrawInfo { mat4 modelview_matrix; vec4 i_resolution; @@ -22,6 +22,7 @@ layout (push_constant, std140) uniform DrawInfo { layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; + vec4 GetScreen(int screen_id) { #ifdef ARRAY_DYNAMIC_INDEX return texture(screen_textures[screen_id], frag_tex_coord); @@ -38,5 +39,42 @@ vec4 GetScreen(int screen_id) { } void main() { - color = GetScreen(screen_id_l); + vec4 pixel = GetScreen(screen_id_l); + vec2 rfrag_tex_coord = vec2(frag_tex_coord.y, 1.0 - frag_tex_coord.x); + //Cursor + if (cursor_enable == 1){ + //Black Outline + if (rfrag_tex_coord.x <= (cursor_pos.x + (2.0*pixelUnit.x)) && + rfrag_tex_coord.x >= (cursor_pos.x - (1.0*pixelUnit.x))) { + if (rfrag_tex_coord.y <= (cursor_pos.y + (5.0*pixelUnit.y)) && + rfrag_tex_coord.y >= (cursor_pos.y - (4.0*pixelUnit.y))) { + pixel = vec4(0.0, 0.0, 0.0, 1.0); + } + } + + if (rfrag_tex_coord.y <= (cursor_pos.y + (2.0*pixelUnit.y)) && + rfrag_tex_coord.y >= (cursor_pos.y - (1.0*pixelUnit.y))) { + if (rfrag_tex_coord.x <= (cursor_pos.x + (5.0*pixelUnit.x)) && + rfrag_tex_coord.x >= (cursor_pos.x - (4.0*pixelUnit.x))) { + pixel = vec4(0.0, 0.0, 0.0, 1.0); + } + } + //White Cross + if (rfrag_tex_coord.x <= (cursor_pos.x + (1.0*pixelUnit.x)) && + rfrag_tex_coord.x >= (cursor_pos.x - (0.0*pixelUnit.x))) { + if (rfrag_tex_coord.y <= (cursor_pos.y + (4.0*pixelUnit.y)) && + rfrag_tex_coord.y >= (cursor_pos.y - (3.0*pixelUnit.y))) { + pixel = vec4(1.0, 1.0, 1.0, 1.0); + } + } + + if (rfrag_tex_coord.y <= (cursor_pos.y + (1.0*pixelUnit.y)) && + rfrag_tex_coord.y >= (cursor_pos.y - (0.0*pixelUnit.y))) { + if (rfrag_tex_coord.x <= (cursor_pos.x + (4.0*pixelUnit.x)) && + rfrag_tex_coord.x >= (cursor_pos.x - (3.0*pixelUnit.x))) { + pixel = vec4(1.0, 1.0, 1.0, 1.0); + } + } + } + color = vec4(pixel.rgb, 1.0); } diff --git a/src/video_core/host_shaders/vulkan_present.vert b/src/video_core/host_shaders/vulkan_present.vert index 2844fdafc..96ede7ec1 100644 --- a/src/video_core/host_shaders/vulkan_present.vert +++ b/src/video_core/host_shaders/vulkan_present.vert @@ -8,7 +8,7 @@ layout (location = 0) in vec2 vert_position; layout (location = 1) in vec2 vert_tex_coord; layout (location = 0) out vec2 frag_tex_coord; - +layout (location = 1) out vec2 pixelUnit; layout (push_constant, std140) uniform DrawInfo { mat4 modelview_matrix; vec4 i_resolution; @@ -24,4 +24,6 @@ void main() { vec4 position = vec4(vert_position, 0.0, 1.0) * modelview_matrix; gl_Position = vec4(position.x, position.y, 0.0, 1.0); frag_tex_coord = vert_tex_coord; + pixelUnit.x = 1/320.0; + pixelUnit.y = 1/240.0; } diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 7a00ed342..4233eed5e 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp @@ -1020,7 +1020,8 @@ void RendererVulkan::DrawScreens(Frame* frame, const Layout::FramebufferLayout& if (settings.shader_update_requested.exchange(false)) { ReloadPipeline(layout.render_3d_mode); } - + cursor_pos[0] += 1; + cursor_pos[1] += 1; PrepareDraw(frame, layout); const auto& top_screen = layout.top_screen;