Skip to content

Commit

Permalink
Draw 3d brush cursor procedurally
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Jan 17, 2025
1 parent 042bc34 commit ce1a0f0
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 21 deletions.
2 changes: 0 additions & 2 deletions armorlab/sources/render_path_paint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f3

render_path_set_target("");
g4_set_pipeline(pipes_cursor);
let img: image_t = resource_get("cursor.k");
g4_set_tex(pipes_cursor_tex, img);
let gbuffer0: render_target_t = map_get(render_path_render_targets, "gbuffer0");
g4_set_tex_depth(pipes_cursor_gbufferd, gbuffer0._image);
g4_set_float2(pipes_cursor_mouse, mx, my);
Expand Down
4 changes: 0 additions & 4 deletions armorpaint/sources/render_path_paint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,6 @@ function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f3

render_path_set_target("");
g4_set_pipeline(pipes_cursor);
let decal: bool = context_is_decal();
let decal_mask: bool = context_is_decal_mask();
let img: image_t = (decal && !decal_mask) ? context_raw.decal_image : resource_get("cursor.k");
g4_set_tex(pipes_cursor_tex, img);
let rt: render_target_t = map_get(render_path_render_targets, "gbuffer0");
let gbuffer0: image_t = rt._image;
g4_set_tex_depth(pipes_cursor_gbufferd, gbuffer0);
Expand Down
Binary file added base/assets/cursor4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions base/shaders/cursor.frag.glsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#version 450

uniform vec3 tint;
#ifdef SPIRV
uniform sampler2D gbufferD; // vulkan unit align
#endif
uniform sampler2D tex;

in vec2 tex_coord;
out vec4 frag_color;

void main() {
vec4 col = texture(tex, tex_coord);
frag_color = vec4((col.rgb / col.a) * tint, col.a);
float radius = 0.45;
float thickness = 0.03;
float dist = distance(tex_coord, vec2(0.5, 0.5));
float ring = smoothstep(radius - thickness, radius, dist) -
smoothstep(radius, radius + thickness, dist);
frag_color = vec4(tint, min(ring, 0.6));
}
7 changes: 1 addition & 6 deletions base/shaders/cursor.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ uniform vec2 tex_step;
uniform float radius;
uniform vec3 camera_right;
uniform sampler2D gbufferD;
#ifdef HLSL
// direct3d12 unit align
uniform sampler2D texa;
#endif

#ifdef HLSL
in vec4 pos;
Expand All @@ -21,8 +17,7 @@ out vec2 tex_coord;

vec3 get_pos(vec2 uv) {
#ifdef HLSL
float keep = textureLod(texa, vec2(0.0, 0.0), 0.0).r; // direct3d12 unit align
float keep2 = pos.x + nor.x;
float keep = pos.x + nor.x;
#endif

#ifdef GLSL
Expand Down
2 changes: 0 additions & 2 deletions base/sources/pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ let pipes_cursor_tex_step: kinc_const_loc_t;
let pipes_cursor_radius: kinc_const_loc_t;
let pipes_cursor_camera_right: kinc_const_loc_t;
let pipes_cursor_tint: kinc_const_loc_t;
let pipes_cursor_tex: kinc_tex_unit_t;
let pipes_cursor_gbufferd: kinc_tex_unit_t;

function _pipes_make_merge(red: bool, green: bool, blue: bool, alpha: bool): pipeline_t {
Expand Down Expand Up @@ -287,6 +286,5 @@ function pipes_init() {
pipes_cursor_camera_right = g4_pipeline_get_const_loc(pipes_cursor, "camera_right");
pipes_cursor_tint = g4_pipeline_get_const_loc(pipes_cursor, "tint");
pipes_cursor_gbufferd = g4_pipeline_get_tex_unit(pipes_cursor, "gbufferD");
pipes_cursor_tex = g4_pipeline_get_tex_unit(pipes_cursor, "tex");
}
}
2 changes: 1 addition & 1 deletion base/sources/ui_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ function ui_base_render_cursor() {
}

let cursor_img: image_t = resource_get("cursor.k");
let psize: i32 = math_floor(cursor_img.width * (context_raw.brush_radius * context_raw.brush_nodes_radius) * ui_SCALE(ui_base_ui));
let psize: i32 = math_floor(182 * (context_raw.brush_radius * context_raw.brush_nodes_radius) * ui_SCALE(ui_base_ui));

// Clone source cursor
if (context_raw.tool == workspace_tool_t.CLONE && !keyboard_down("alt") && (mouse_down() || pen_down())) {
Expand Down

0 comments on commit ce1a0f0

Please sign in to comment.