Overlay-Next: Lattice

Overlay-Next version of Lattice.

Rel #102179

Co-authored-by: Clément Foucault <foucault.clem@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/123398
This commit is contained in:
Laurynas Duburas
2024-07-17 16:49:38 +02:00
committed by Clément Foucault
parent 389b322975
commit 85f8161ef7
7 changed files with 153 additions and 0 deletions

View File

@@ -66,6 +66,7 @@ void Instance::init()
/* TODO(fclem): Remove DRW global usage. */
resources.globals_buf = G_draw.block_ubo;
resources.theme_settings = G_draw.block;
resources.weight_ramp_tx.wrap(G_draw.weight_ramp);
}
void Instance::begin_sync()
@@ -78,6 +79,7 @@ void Instance::begin_sync()
background.begin_sync(resources, state);
prepass.begin_sync(resources, state);
empties.begin_sync();
lattices.begin_sync(resources, state);
metaballs.begin_sync();
speakers.begin_sync();
grid.begin_sync(resources, state, view);
@@ -111,6 +113,7 @@ void Instance::object_sync(ObjectRef &ob_ref, Manager &manager)
case OB_SURF:
break;
case OB_LATTICE:
lattices.edit_object_sync(manager, ob_ref, resources);
break;
case OB_MBALL:
metaballs.edit_object_sync(ob_ref, resources);
@@ -129,6 +132,11 @@ void Instance::object_sync(ObjectRef &ob_ref, Manager &manager)
break;
case OB_ARMATURE:
break;
case OB_LATTICE:
if (!in_edit_mode) {
lattices.object_sync(manager, ob_ref, resources, state);
}
break;
case OB_MBALL:
if (!in_edit_mode) {
metaballs.object_sync(ob_ref, resources, state);
@@ -215,12 +223,14 @@ void Instance::draw(Manager &manager)
background.draw(resources, manager);
empties.draw(resources, manager, view);
lattices.draw(resources, manager, view);
metaballs.draw(resources, manager, view);
speakers.draw(resources, manager, view);
grid.draw(resources, manager, view);
empties.draw_in_front(resources, manager, view);
lattices.draw_in_front(resources, manager, view);
metaballs.draw_in_front(resources, manager, view);
speakers.draw_in_front(resources, manager, view);

View File

@@ -13,6 +13,7 @@
#include "overlay_next_background.hh"
#include "overlay_next_empty.hh"
#include "overlay_next_grid.hh"
#include "overlay_next_lattice.hh"
#include "overlay_next_metaball.hh"
#include "overlay_next_prepass.hh"
#include "overlay_next_speaker.hh"
@@ -42,6 +43,7 @@ class Instance {
Prepass prepass;
Metaballs metaballs = {selection_type_};
Empties empties = {selection_type_};
Lattices lattices;
Speakers speakers = {selection_type_};
Grid grid;

View File

@@ -0,0 +1,106 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup overlay
*/
#pragma once
#include "draw_cache_impl.hh"
#include "draw_common_c.hh"
#include "overlay_next_private.hh"
#include "ED_lattice.hh"
namespace blender::draw::overlay {
class Lattices {
private:
PassMain ps_ = {"Lattice"};
PassMain in_front_ps_ = {"Lattice_in_front"};
PassMain::Sub *lattice_ps_[2];
PassMain::Sub *edit_lattice_wire_ps_[2];
PassMain::Sub *edit_lattice_point_ps_[2];
public:
void begin_sync(Resources &res, const State &state)
{
const DRWState pass_state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
DRW_STATE_DEPTH_LESS_EQUAL | state.clipping_state;
auto init_pass = [&](PassMain &pass, int in_front) {
auto create_sub_pass = [&](const char *name, GPUShader *shader, bool add_weight_tex) {
PassMain::Sub &sub_pass = pass.sub(name);
sub_pass.state_set(pass_state);
sub_pass.shader_set(shader);
sub_pass.bind_ubo("globalsBlock", &res.globals_buf);
if (add_weight_tex) {
sub_pass.bind_texture("weightTex", &res.weight_ramp_tx);
}
return &sub_pass;
};
pass.init();
edit_lattice_wire_ps_[in_front] = create_sub_pass(
"edit_lattice_wire", res.shaders.lattice_wire.get(), true);
edit_lattice_point_ps_[in_front] = create_sub_pass(
"edit_lattice_points", res.shaders.lattice_points.get(), false);
lattice_ps_[in_front] = create_sub_pass(
"lattice", res.shaders.extra_wire_object.get(), false);
res.select_bind(pass);
};
init_pass(ps_, 0);
init_pass(in_front_ps_, 1);
}
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res)
{
const int in_front = (ob_ref.object->dtx & OB_DRAW_IN_FRONT) != 0 ? 1 : 0;
{
gpu::Batch *geom = DRW_cache_lattice_wire_get(ob_ref.object, true);
if (geom) {
ResourceHandle res_handle = manager.resource_handle(ob_ref);
edit_lattice_wire_ps_[in_front]->draw(geom, res_handle, res.select_id(ob_ref).get());
}
}
{
gpu::Batch *geom = DRW_cache_lattice_vert_overlay_get(ob_ref.object);
if (geom) {
ResourceHandle res_handle = manager.resource_handle(ob_ref);
edit_lattice_point_ps_[in_front]->draw(geom, res_handle, res.select_id(ob_ref).get());
}
}
}
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state)
{
gpu::Batch *geom = DRW_cache_lattice_wire_get(ob_ref.object, false);
if (geom) {
const float4 &color = res.object_wire_color(ob_ref, state);
float4x4 draw_mat(ob_ref.object->object_to_world().ptr());
for (int i : IndexRange(3)) {
draw_mat[i][3] = color[i];
}
draw_mat[3][3] = 0.0f /* No stipples. */;
ResourceHandle res_handle = manager.resource_handle(ob_ref, &draw_mat, nullptr, nullptr);
const int in_front = (ob_ref.object->dtx & OB_DRAW_IN_FRONT) != 0 ? 1 : 0;
lattice_ps_[in_front]->draw(geom, res_handle, res.select_id(ob_ref).get());
}
}
void draw(Resources &res, Manager &manager, View &view)
{
GPU_framebuffer_bind(res.overlay_line_fb);
manager.submit(ps_, view);
}
void draw_in_front(Resources &res, Manager &manager, View &view)
{
GPU_framebuffer_bind(res.overlay_line_in_front_fb);
manager.submit(in_front_ps_, view);
}
};
} // namespace blender::draw::overlay

View File

@@ -118,6 +118,9 @@ class ShaderModule {
ShaderPtr armature_sphere_outline;
ShaderPtr depth_mesh;
ShaderPtr extra_shape;
ShaderPtr extra_wire_object;
ShaderPtr lattice_points;
ShaderPtr lattice_wire;
ShaderModule(const SelectionType selection_type, const bool clipping_enabled);
@@ -159,6 +162,7 @@ struct Resources : public select::SelectMap {
TextureRef depth_in_front_tx;
TextureRef color_overlay_tx;
TextureRef color_render_tx;
TextureRef weight_ramp_tx;
Resources(const SelectionType selection_type_, ShaderModule &shader_module)
: select::SelectMap(selection_type_), shaders(shader_module){};

View File

@@ -81,6 +81,26 @@ ShaderModule::ShaderModule(const SelectionType selection_type, const bool clippi
info.vertex_inputs_.pop_last();
info.vertex_inputs_.pop_last();
});
extra_wire_object = selectable_shader(
"overlay_extra_wire", [](gpu::shader::ShaderCreateInfo &info) {
info.define("OBJECT_WIRE");
info.additional_infos_.clear();
info.additional_info(
"draw_view", "draw_modelmat_new", "draw_resource_handle_new", "draw_globals");
});
lattice_points = selectable_shader(
"overlay_edit_lattice_point", [](gpu::shader::ShaderCreateInfo &info) {
info.additional_infos_.clear();
info.additional_info(
"draw_view", "draw_modelmat_new", "draw_resource_handle_new", "draw_globals");
});
lattice_wire = selectable_shader(
"overlay_edit_lattice_wire", [](gpu::shader::ShaderCreateInfo &info) {
info.additional_infos_.clear();
info.additional_info(
"draw_view", "draw_modelmat_new", "draw_resource_handle_new", "draw_globals");
});
}
ShaderModule &ShaderModule::module_get(SelectionType selection_type, bool clipping_enabled)

View File

@@ -3,6 +3,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(select_lib.glsl)
void main()
{
@@ -23,7 +24,14 @@ void main()
fragColor.a = 1.0;
#ifndef SELECT_ENABLE
/* Discarding inside the selection will create some undefined behavior.
* This is because we force the early depth test to only output the front most fragment.
* Discarding would expose us to race condition depending on rasterization order. */
if (fract(dist / dash_width) > dash_factor) {
discard;
}
#endif
select_id_output(select_id);
}

View File

@@ -4,6 +4,7 @@
#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(select_lib.glsl)
vec2 screen_position(vec4 p)
{
@@ -12,6 +13,8 @@ vec2 screen_position(vec4 p)
void main()
{
select_id_set(drw_CustomID);
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);