Overlay-Next: Initial implementation #107045

Closed
Clément Foucault wants to merge 28 commits from fclem/blender:overlay-next into main

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

View File

@ -36,7 +36,7 @@ template<typename SelectEngineT> class Prepass {
init_pass(prepass_in_front_ps_); init_pass(prepass_in_front_ps_);
} }
void object_sync(Manager &manager, const ObjectRef &ob_ref, ResourcesT & /*res*/) void object_sync(Manager &manager, const ObjectRef &ob_ref, ResourcesT &res)
{ {
PassMain &pass = (ob_ref.object->dtx & OB_DRAW_IN_FRONT) != 0 ? prepass_in_front_ps_ : PassMain &pass = (ob_ref.object->dtx & OB_DRAW_IN_FRONT) != 0 ? prepass_in_front_ps_ :
prepass_ps_; prepass_ps_;
@ -46,11 +46,7 @@ template<typename SelectEngineT> class Prepass {
GPUBatch *geom = DRW_cache_object_surface_get(ob_ref.object); GPUBatch *geom = DRW_cache_object_surface_get(ob_ref.object);
if (geom) { if (geom) {
ResourceHandle res_handle = manager.resource_handle(ob_ref); ResourceHandle res_handle = manager.resource_handle(ob_ref);
pass.draw(geom, res_handle); pass.draw(geom, res_handle, res.select_id(ob_ref).value);
/* TODO */
// const SelectID radius_id = res.select_id(ob_ref);
// pass.draw(geom, res_handle, radius_id.value);
} }
} }

View File

@ -1,12 +1,15 @@
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) #pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl) #pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(select_lib.glsl)
/* Sphere radius */ /* Sphere radius */
const float rad = 0.05; const float rad = 0.05;
void main() void main()
{ {
select_id_set(in_select_buf[gl_InstanceID]);
vec4 bone_color, state_color; vec4 bone_color, state_color;
mat4 model_mat = extract_matrix_packed_data(inst_obmat, state_color, bone_color); mat4 model_mat = extract_matrix_packed_data(inst_obmat, state_color, bone_color);

View File

@ -1,8 +1,10 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl) #pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(select_lib.glsl)
void main() void main()
{ {
lineOutput = pack_line_data(gl_FragCoord.xy, edgeStart, edgePos); lineOutput = pack_line_data(gl_FragCoord.xy, edgeStart, edgePos);
fragColor = vec4(finalColor.rgb, finalColor.a * alpha); fragColor = vec4(finalColor.rgb, finalColor.a * alpha);
select_id_output(select_id);
} }

View File

@ -7,7 +7,7 @@ void main()
{ {
GPU_INTEL_VERTEX_SHADER_WORKAROUND GPU_INTEL_VERTEX_SHADER_WORKAROUND
select_id_set(in_select_buf[resource_id]); select_id_set(drw_CustomID);
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);

View File

@ -25,22 +25,18 @@ struct EngineObject {
/* Add type safety to selection ID. Only the select engine should provide them. */ /* Add type safety to selection ID. Only the select engine should provide them. */
struct ID { struct ID {
uint32_t value; uint32_t value;
friend constexpr bool operator==(ID a, ID b)
{
return a.value == b.value;
}
uint64_t hash() const
{
return BLI_ghashutil_uinthash(value);
}
}; };
struct SelectShader { struct SelectShader {
static void patch(gpu::shader::ShaderCreateInfo &info) static void patch(gpu::shader::ShaderCreateInfo &info)
{ {
info.define("SELECT_UNORDERED"); info.define("SELECT_UNORDERED");
/* Replace additional info. */
for (StringRefNull &str : info.additional_infos_) {
if (str == "draw_modelmat_new") {
str = "draw_modelmat_new_with_custom_id";
}
}
info.additional_info("select_id_patch"); info.additional_info("select_id_patch");
}; };
}; };
@ -100,11 +96,8 @@ struct EngineObject {
void begin_sync() void begin_sync()
{ {
select_id_map.clear(); select_id_map.clear();
/* Index 0 is the invalid selection ID. */
select_id_map.append(uint(-1));
#ifdef DEBUG #ifdef DEBUG
map_names.clear(); map_names.clear();
map_names.append("Invalid Index");
#endif #endif
} }
@ -115,6 +108,7 @@ struct EngineObject {
void select_bind(PassMain &pass) void select_bind(PassMain &pass)
{ {
pass.use_custom_ids = true;
/* IMPORTANT: This binds a dummy buffer `in_select_buf` but it is not supposed to be used. */ /* IMPORTANT: This binds a dummy buffer `in_select_buf` but it is not supposed to be used. */
pass.bind_ssbo(SELECT_ID_IN, &dummy_select_buf); pass.bind_ssbo(SELECT_ID_IN, &dummy_select_buf);
pass.bind_ssbo(SELECT_ID_OUT, &select_output_buf); pass.bind_ssbo(SELECT_ID_OUT, &select_output_buf);
@ -138,7 +132,8 @@ struct EngineObject {
uint32_t word = select_output_buf[i]; uint32_t word = select_output_buf[i];
for (auto bit : IndexRange(32)) { for (auto bit : IndexRange(32)) {
if ((word & 1) != 0) { if ((word & 1) != 0) {
std::cout << map_names[i * 32 + bit] << std::endl; uint index = i * 32 + bit;
std::cout << index << map_names[index] << std::endl;
} }
word >>= 1; word >>= 1;
} }