WIP: uv-simple-select #1

Closed
Chris Blackbourn wants to merge 182 commits from uv-simple-select into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
5 changed files with 42 additions and 40 deletions
Showing only changes of commit d6e95c5801 - Show all commits

View File

@ -496,7 +496,7 @@ GPU_SHADER_CREATE_INFO(overlay_edit_lattice_wire_clipped)
GPU_SHADER_CREATE_INFO(overlay_edit_particle_strand) GPU_SHADER_CREATE_INFO(overlay_edit_particle_strand)
.do_static_compilation(true) .do_static_compilation(true)
.vertex_in(0, Type::VEC3, "pos") .vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::FLOAT, "color") .vertex_in(1, Type::FLOAT, "selection")
.sampler(0, ImageType::FLOAT_1D, "weightTex") .sampler(0, ImageType::FLOAT_1D, "weightTex")
.push_constant(Type::BOOL, "useWeight") .push_constant(Type::BOOL, "useWeight")
.vertex_out(overlay_edit_smooth_color_iface) .vertex_out(overlay_edit_smooth_color_iface)
@ -512,7 +512,7 @@ GPU_SHADER_CREATE_INFO(overlay_edit_particle_strand_clipped)
GPU_SHADER_CREATE_INFO(overlay_edit_particle_point) GPU_SHADER_CREATE_INFO(overlay_edit_particle_point)
.do_static_compilation(true) .do_static_compilation(true)
.vertex_in(0, Type::VEC3, "pos") .vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::FLOAT, "color") .vertex_in(1, Type::FLOAT, "selection")
.vertex_out(overlay_edit_flat_color_iface) .vertex_out(overlay_edit_flat_color_iface)
.fragment_out(0, Type::VEC4, "fragColor") .fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("overlay_edit_particle_point_vert.glsl") .vertex_source("overlay_edit_particle_point_vert.glsl")

View File

@ -7,7 +7,7 @@ void main()
vec3 world_pos = point_object_to_world(pos); vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos); gl_Position = point_world_to_ndc(world_pos);
finalColor = mix(colorWire, colorVertexSelect, color); finalColor = mix(colorWire, colorVertexSelect, selection);
gl_PointSize = sizeVertex * 2.0; gl_PointSize = sizeVertex * 2.0;

View File

@ -25,10 +25,10 @@ void main()
gl_Position = point_world_to_ndc(world_pos); gl_Position = point_world_to_ndc(world_pos);
if (useWeight) { if (useWeight) {
finalColor = vec4(weight_to_rgb(color), 1.0); finalColor = vec4(weight_to_rgb(selection), 1.0);
} }
else { else {
finalColor = mix(colorWire, colorVertexSelect, color); finalColor = mix(colorWire, colorVertexSelect, selection);
} }
view_clipping_distances(world_pos); view_clipping_distances(world_pos);

View File

@ -54,11 +54,11 @@ struct CurvesBatchCache {
GPUBatch *edit_points; GPUBatch *edit_points;
GPUBatch *edit_lines; GPUBatch *edit_lines;
/* Editmode (original) point positions. */ /* Crazy-space point positions for original points. */
GPUVertBuf *edit_points_pos; GPUVertBuf *edit_points_pos;
/* Editmode data (such as selection). */ /* Selection of original points. */
GPUVertBuf *edit_points_data; GPUVertBuf *edit_points_selection;
GPUIndexBuf *edit_lines_ibo; GPUIndexBuf *edit_lines_ibo;
@ -113,7 +113,7 @@ static void curves_batch_cache_clear_edit_data(CurvesBatchCache *cache)
{ {
/* TODO: more granular update tagging. */ /* TODO: more granular update tagging. */
GPU_VERTBUF_DISCARD_SAFE(cache->edit_points_pos); GPU_VERTBUF_DISCARD_SAFE(cache->edit_points_pos);
GPU_VERTBUF_DISCARD_SAFE(cache->edit_points_data); GPU_VERTBUF_DISCARD_SAFE(cache->edit_points_selection);
GPU_INDEXBUF_DISCARD_SAFE(cache->edit_lines_ibo); GPU_INDEXBUF_DISCARD_SAFE(cache->edit_lines_ibo);
GPU_BATCH_DISCARD_SAFE(cache->edit_points); GPU_BATCH_DISCARD_SAFE(cache->edit_points);
@ -255,18 +255,19 @@ static void curves_batch_cache_ensure_edit_points_pos(const bke::CurvesGeometry
GPU_vertbuf_attr_fill(cache.edit_points_pos, pos, deformed_positions.data()); GPU_vertbuf_attr_fill(cache.edit_points_pos, pos, deformed_positions.data());
} }
static void curves_batch_cache_ensure_edit_points_data(const bke::CurvesGeometry &curves, static void curves_batch_cache_ensure_edit_points_selection(const bke::CurvesGeometry &curves,
const eAttrDomain selection_domain, const eAttrDomain selection_domain,
CurvesBatchCache &cache) CurvesBatchCache &cache)
{ {
static GPUVertFormat format_data = {0}; static GPUVertFormat format_data = {0};
static uint color; static uint selection_id;
if (format_data.attr_len == 0) { if (format_data.attr_len == 0) {
color = GPU_vertformat_attr_add(&format_data, "color", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); selection_id = GPU_vertformat_attr_add(
&format_data, "selection", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
} }
GPU_vertbuf_init_with_format(cache.edit_points_data, &format_data); GPU_vertbuf_init_with_format(cache.edit_points_selection, &format_data);
GPU_vertbuf_data_alloc(cache.edit_points_data, curves.points_num()); GPU_vertbuf_data_alloc(cache.edit_points_selection, curves.points_num());
const OffsetIndices points_by_curve = curves.points_by_curve(); const OffsetIndices points_by_curve = curves.points_by_curve();
@ -276,7 +277,7 @@ static void curves_batch_cache_ensure_edit_points_data(const bke::CurvesGeometry
case ATTR_DOMAIN_POINT: case ATTR_DOMAIN_POINT:
for (const int point_i : selection.index_range()) { for (const int point_i : selection.index_range()) {
const float point_selection = selection[point_i] ? 1.0f : 0.0f; const float point_selection = selection[point_i] ? 1.0f : 0.0f;
GPU_vertbuf_attr_set(cache.edit_points_data, color, point_i, &point_selection); GPU_vertbuf_attr_set(cache.edit_points_selection, selection_id, point_i, &point_selection);
} }
break; break;
case ATTR_DOMAIN_CURVE: case ATTR_DOMAIN_CURVE:
@ -284,7 +285,8 @@ static void curves_batch_cache_ensure_edit_points_data(const bke::CurvesGeometry
const float curve_selection = selection[curve_i] ? 1.0f : 0.0f; const float curve_selection = selection[curve_i] ? 1.0f : 0.0f;
const IndexRange points = points_by_curve[curve_i]; const IndexRange points = points_by_curve[curve_i];
for (const int point_i : points) { for (const int point_i : points) {
GPU_vertbuf_attr_set(cache.edit_points_data, color, point_i, &curve_selection); GPU_vertbuf_attr_set(
cache.edit_points_selection, selection_id, point_i, &curve_selection);
} }
} }
break; break;
@ -760,18 +762,18 @@ void DRW_curves_batch_cache_create_requested(Object *ob)
if (DRW_batch_requested(cache.edit_points, GPU_PRIM_POINTS)) { if (DRW_batch_requested(cache.edit_points, GPU_PRIM_POINTS)) {
DRW_vbo_request(cache.edit_points, &cache.edit_points_pos); DRW_vbo_request(cache.edit_points, &cache.edit_points_pos);
DRW_vbo_request(cache.edit_points, &cache.edit_points_data); DRW_vbo_request(cache.edit_points, &cache.edit_points_selection);
} }
if (DRW_batch_requested(cache.edit_lines, GPU_PRIM_LINE_STRIP)) { if (DRW_batch_requested(cache.edit_lines, GPU_PRIM_LINE_STRIP)) {
DRW_ibo_request(cache.edit_lines, &cache.edit_lines_ibo); DRW_ibo_request(cache.edit_lines, &cache.edit_lines_ibo);
DRW_vbo_request(cache.edit_lines, &cache.edit_points_pos); DRW_vbo_request(cache.edit_lines, &cache.edit_points_pos);
DRW_vbo_request(cache.edit_lines, &cache.edit_points_data); DRW_vbo_request(cache.edit_lines, &cache.edit_points_selection);
} }
if (DRW_vbo_requested(cache.edit_points_pos)) { if (DRW_vbo_requested(cache.edit_points_pos)) {
curves_batch_cache_ensure_edit_points_pos(curves_orig, deformation.positions, cache); curves_batch_cache_ensure_edit_points_pos(curves_orig, deformation.positions, cache);
} }
if (DRW_vbo_requested(cache.edit_points_data)) { if (DRW_vbo_requested(cache.edit_points_selection)) {
curves_batch_cache_ensure_edit_points_data( curves_batch_cache_ensure_edit_points_selection(
curves_orig, eAttrDomain(curves_id->selection_domain), cache); curves_orig, eAttrDomain(curves_id->selection_domain), cache);
} }
if (DRW_ibo_requested(cache.edit_lines_ibo)) { if (DRW_ibo_requested(cache.edit_lines_ibo)) {

View File

@ -89,21 +89,21 @@ typedef struct HairAttributeID {
typedef struct EditStrandData { typedef struct EditStrandData {
float pos[3]; float pos[3];
float color; float selection;
} EditStrandData; } EditStrandData;
static GPUVertFormat *edit_points_vert_format_get(uint *r_pos_id, uint *r_color_id) static GPUVertFormat *edit_points_vert_format_get(uint *r_pos_id, uint *r_selection_id)
{ {
static GPUVertFormat edit_point_format = {0}; static GPUVertFormat edit_point_format = {0};
static uint pos_id, color_id; static uint pos_id, selection_id;
if (edit_point_format.attr_len == 0) { if (edit_point_format.attr_len == 0) {
/* Keep in sync with EditStrandData */ /* Keep in sync with EditStrandData */
pos_id = GPU_vertformat_attr_add(&edit_point_format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); pos_id = GPU_vertformat_attr_add(&edit_point_format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
color_id = GPU_vertformat_attr_add( selection_id = GPU_vertformat_attr_add(
&edit_point_format, "color", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); &edit_point_format, "selection", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
} }
*r_pos_id = pos_id; *r_pos_id = pos_id;
*r_color_id = color_id; *r_selection_id = selection_id;
return &edit_point_format; return &edit_point_format;
} }
@ -697,11 +697,11 @@ static int particle_batch_cache_fill_segments_edit(
if (particle) { if (particle) {
float weight = particle_key_weight(particle, i, strand_t); float weight = particle_key_weight(particle, i, strand_t);
/* NaN or unclamped become 1.0f */ /* NaN or unclamped become 1.0f */
seg_data->color = (weight < 1.0f) ? weight : 1.0f; seg_data->selection = (weight < 1.0f) ? weight : 1.0f;
} }
else { else {
/* Computed in psys_cache_edit_paths_iter(). */ /* Computed in psys_cache_edit_paths_iter(). */
seg_data->color = path[j].col[0]; seg_data->selection = path[j].col[0];
} }
GPU_indexbuf_add_generic_vert(elb, curr_point); GPU_indexbuf_add_generic_vert(elb, curr_point);
curr_point++; curr_point++;
@ -1530,8 +1530,8 @@ static void particle_batch_cache_ensure_edit_pos_and_seg(PTCacheEdit *edit,
GPUVertBufRaw data_step; GPUVertBufRaw data_step;
GPUIndexBufBuilder elb; GPUIndexBufBuilder elb;
uint pos_id, color_id; uint pos_id, selection_id;
GPUVertFormat *edit_point_format = edit_points_vert_format_get(&pos_id, &color_id); GPUVertFormat *edit_point_format = edit_points_vert_format_get(&pos_id, &selection_id);
hair_cache->pos = GPU_vertbuf_create_with_format(edit_point_format); hair_cache->pos = GPU_vertbuf_create_with_format(edit_point_format);
GPU_vertbuf_data_alloc(hair_cache->pos, hair_cache->point_len); GPU_vertbuf_data_alloc(hair_cache->pos, hair_cache->point_len);
@ -1594,8 +1594,8 @@ static void particle_batch_cache_ensure_edit_inner_pos(PTCacheEdit *edit,
return; return;
} }
uint pos_id, color_id; uint pos_id, selection_id;
GPUVertFormat *edit_point_format = edit_points_vert_format_get(&pos_id, &color_id); GPUVertFormat *edit_point_format = edit_points_vert_format_get(&pos_id, &selection_id);
cache->edit_inner_pos = GPU_vertbuf_create_with_format(edit_point_format); cache->edit_inner_pos = GPU_vertbuf_create_with_format(edit_point_format);
GPU_vertbuf_data_alloc(cache->edit_inner_pos, cache->edit_inner_point_len); GPU_vertbuf_data_alloc(cache->edit_inner_pos, cache->edit_inner_point_len);
@ -1608,9 +1608,9 @@ static void particle_batch_cache_ensure_edit_inner_pos(PTCacheEdit *edit,
} }
for (int key_index = 0; key_index < point->totkey - 1; key_index++) { for (int key_index = 0; key_index < point->totkey - 1; key_index++) {
PTCacheEditKey *key = &point->keys[key_index]; PTCacheEditKey *key = &point->keys[key_index];
float color = (key->flag & PEK_SELECT) ? 1.0f : 0.0f; float selection = (key->flag & PEK_SELECT) ? 1.0f : 0.0f;
GPU_vertbuf_attr_set(cache->edit_inner_pos, pos_id, global_key_index, key->world_co); GPU_vertbuf_attr_set(cache->edit_inner_pos, pos_id, global_key_index, key->world_co);
GPU_vertbuf_attr_set(cache->edit_inner_pos, color_id, global_key_index, &color); GPU_vertbuf_attr_set(cache->edit_inner_pos, selection_id, global_key_index, &selection);
global_key_index++; global_key_index++;
} }
} }
@ -1652,8 +1652,8 @@ static void particle_batch_cache_ensure_edit_tip_pos(PTCacheEdit *edit, Particle
return; return;
} }
uint pos_id, color_id; uint pos_id, selection_id;
GPUVertFormat *edit_point_format = edit_points_vert_format_get(&pos_id, &color_id); GPUVertFormat *edit_point_format = edit_points_vert_format_get(&pos_id, &selection_id);
cache->edit_tip_pos = GPU_vertbuf_create_with_format(edit_point_format); cache->edit_tip_pos = GPU_vertbuf_create_with_format(edit_point_format);
GPU_vertbuf_data_alloc(cache->edit_tip_pos, cache->edit_tip_point_len); GPU_vertbuf_data_alloc(cache->edit_tip_pos, cache->edit_tip_point_len);
@ -1665,10 +1665,10 @@ static void particle_batch_cache_ensure_edit_tip_pos(PTCacheEdit *edit, Particle
continue; continue;
} }
PTCacheEditKey *key = &point->keys[point->totkey - 1]; PTCacheEditKey *key = &point->keys[point->totkey - 1];
float color = (key->flag & PEK_SELECT) ? 1.0f : 0.0f; float selection = (key->flag & PEK_SELECT) ? 1.0f : 0.0f;
GPU_vertbuf_attr_set(cache->edit_tip_pos, pos_id, global_point_index, key->world_co); GPU_vertbuf_attr_set(cache->edit_tip_pos, pos_id, global_point_index, key->world_co);
GPU_vertbuf_attr_set(cache->edit_tip_pos, color_id, global_point_index, &color); GPU_vertbuf_attr_set(cache->edit_tip_pos, selection_id, global_point_index, &selection);
global_point_index++; global_point_index++;
} }
} }