Anim: Per bone wire width for custom shapes #120176

Merged
Christoph Lendenfeld merged 48 commits from ChrisLend/blender:bone_wire_width into main 2024-05-30 15:51:42 +02:00
3 changed files with 6 additions and 4 deletions
Showing only changes of commit cf8442b0f7 - Show all commits

View File

@ -465,10 +465,10 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_float_copy(grp, "alpha", 1.0f);
DRW_shgroup_uniform_bool_copy(grp, "do_smooth_wire", do_smooth_wire);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
Jeroen-Bakker marked this conversation as resolved Outdated

Not sure what compression means or does by reading the name.

Currently the line width doesn't take into account the user preference resolution scale. When this will be added this 'constant' might become a variable. In this case using a uniform is good. If it is still a constant this uniform should be replaced with a define in overlay_armature_info.hh

Not sure what compression means or does by reading the name. Currently the line width doesn't take into account the user preference resolution scale. When this will be added this 'constant' might become a variable. In this case using a uniform is good. If it is still a constant this uniform should be replaced with a define in `overlay_armature_info.hh`

Because the value is passed in packed next to the color it has to be in a range of 0-2 (Though I am only using 0-1 here)
See overlay_armature.cc/892.
To achieve this range I am dividing by the max wire width allowed by RNA and then multiplying by that same number in the shader, essentially packing and unpacking. The precision loss doesn't matter in this case.

Given that this is heavily linked to the RNA range, @dr.sybren suggested using a constexpr which can be found in DNA_action_types.h/274

Insofar it could be a define, if I can use WIRE_WIDTH_COMPRESSION converted to a string passed into the shader.

There is already a comment in the shader when the value is unpacked, I've added one for the no_geom version as well

Because the value is passed in packed next to the color it has to be in a range of 0-2 (Though I am only using 0-1 here) See `overlay_armature.cc/892`. To achieve this range I am dividing by the max wire width allowed by RNA and then multiplying by that same number in the shader, essentially packing and unpacking. The precision loss doesn't matter in this case. Given that this is heavily linked to the RNA range, @dr.sybren suggested using a `constexpr` which can be found in `DNA_action_types.h/274` Insofar it could be a define, if I can use `WIRE_WIDTH_COMPRESSION` converted to a string passed into the shader. There is already a comment in the shader when the value is unpacked, I've added one for the no_geom version as well
DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
if (use_wire_alpha) {
cb->transp.custom_wire = grp = DRW_shgroup_create(sh, armature_ps);
DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_float_copy(grp, "alpha", wire_alpha);
}

View File

@ -166,6 +166,7 @@ GPU_SHADER_CREATE_INFO(overlay_armature_shape_wire)
.geometry_source("overlay_armature_shape_wire_geom.glsl")
.fragment_source("overlay_armature_shape_wire_frag.glsl")
.fragment_out(0, Type::VEC4, "fragColor")
.fragment_out(1, Type::VEC4, "lineOutput")
.additional_info("overlay_armature_common", "draw_globals");
GPU_SHADER_CREATE_INFO(overlay_armature_shape_wire_clipped)

View File

@ -36,11 +36,12 @@ float edge_step(float dist)
void main()
{
const float dist = abs(geometry_noperspective_out.edgeCoord) - max(geometry_out.wire_width/2.0 - 0.5, 0.0);
const float mix_w = edge_step(dist);
const float dist = abs(geometry_noperspective_out.edgeCoord) - geometry_out.wire_width / 2.0;
const float mix_w = clamp(edge_step(dist), 0.0, 1.0);
fragColor = mix(vec4(0), vec4(geometry_out.finalColor.rgb, alpha), 1.0 - mix_w);
fragColor = mix(vec4(geometry_out.finalColor.rgb, alpha), vec4(0), mix_w);
fragColor.a *= 1.0 - mix_w;
fragColor.a *= test_occlusion() ? alpha : 1.0;
select_id_output(select_id);
lineOutput = vec4(0);
}