Cleanup: Overlay: Share vertex enum values

This commit is contained in:
Clément Foucault
2025-04-17 18:25:14 +02:00
committed by Clément Foucault
parent d2373cf5d5
commit 77ed9359dc
7 changed files with 111 additions and 125 deletions

View File

@@ -262,13 +262,13 @@ class Particles : Overlay {
case PART_DRAW_AXIS:
geom = DRW_cache_particles_get_dots(ob, psys);
set_color(*shape_ps_);
shape_ps_->push_constant("shape_type", PART_SHAPE_AXIS);
shape_ps_->push_constant("shape_type", int(PART_SHAPE_AXIS));
shape_ps_->draw_expand(geom, GPU_PRIM_LINES, 3, 1, handle, res.select_id(ob_ref).get());
break;
case PART_DRAW_CIRC:
geom = DRW_cache_particles_get_dots(ob, psys);
set_color(*shape_ps_);
shape_ps_->push_constant("shape_type", PART_SHAPE_CIRCLE);
shape_ps_->push_constant("shape_type", int(PART_SHAPE_CIRCLE));
shape_ps_->draw_expand(geom,
GPU_PRIM_LINES,
PARTICLE_SHAPE_CIRCLE_RESOLUTION,
@@ -279,7 +279,7 @@ class Particles : Overlay {
case PART_DRAW_CROSS:
geom = DRW_cache_particles_get_dots(ob, psys);
set_color(*shape_ps_);
shape_ps_->push_constant("shape_type", PART_SHAPE_CROSS);
shape_ps_->push_constant("shape_type", int(PART_SHAPE_CROSS));
shape_ps_->draw_expand(geom, GPU_PRIM_LINES, 3, 1, handle, res.select_id(ob_ref).get());
break;
}

View File

@@ -274,7 +274,12 @@ struct State {
/* Matches Vertex Format. */
struct Vertex {
float3 pos;
int vclass;
VertexClass vclass;
};
struct VertexBone {
float3 pos;
StickBoneFlag vclass;
};
struct VertexWithColor {
@@ -284,7 +289,7 @@ struct VertexWithColor {
struct VertShaded {
float3 pos;
int v_class;
VertexClass v_class;
float3 nor;
};
@@ -400,6 +405,17 @@ class ShapeCache {
return format;
}
const GPUVertFormat &get_format(VertexBone /*unused*/)
{
GPUVertFormat &format = format_vert;
if (format.attr_len != 0) {
return format;
}
GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
GPU_vertformat_attr_add(&format, "vclass", GPU_COMP_I32, 1, GPU_FETCH_INT);
return format;
}
const GPUVertFormat &get_format(VertexWithColor /*unused*/)
{
GPUVertFormat &format = format_vert_with_color;

View File

@@ -47,6 +47,45 @@ enum OVERLAY_GridBits : uint32_t {
ENUM_OPERATORS(OVERLAY_GridBits, CUSTOM_GRID)
#endif
enum VertexClass : uint32_t {
VCLASS_NONE = 0,
VCLASS_LIGHT_AREA_SHAPE = 1 << 0,
VCLASS_LIGHT_SPOT_SHAPE = 1 << 1,
VCLASS_LIGHT_SPOT_BLEND = 1 << 2,
VCLASS_LIGHT_SPOT_CONE = 1 << 3,
VCLASS_LIGHT_DIST = 1 << 4,
VCLASS_CAMERA_FRAME = 1 << 5,
VCLASS_CAMERA_DIST = 1 << 6,
VCLASS_CAMERA_VOLUME = 1 << 7,
VCLASS_SCREENSPACE = 1 << 8,
VCLASS_SCREENALIGNED = 1 << 9,
VCLASS_EMPTY_SCALED = 1 << 10,
VCLASS_EMPTY_AXES = 1 << 11,
VCLASS_EMPTY_AXES_NAME = 1 << 12,
VCLASS_EMPTY_AXES_SHADOW = 1 << 13,
VCLASS_EMPTY_SIZE = 1 << 14,
};
#ifndef GPU_SHADER
ENUM_OPERATORS(VertexClass, VCLASS_EMPTY_SIZE)
#endif
enum StickBoneFlag {
COL_WIRE = (1u << 0u),
COL_HEAD = (1u << 1u),
COL_TAIL = (1u << 2u),
COL_BONE = (1u << 3u),
POS_HEAD = (1u << 4u),
POS_TAIL = (1u << 5u),
POS_BONE = (1u << 6u),
};
#ifndef GPU_SHADER
ENUM_OPERATORS(StickBoneFlag, POS_BONE)
#endif
static inline uint outline_id_pack(uint outline_id, uint object_id)
{
/* Replace top 2 bits (of the 16bit output) by outline_id.
@@ -265,10 +304,11 @@ BLI_STATIC_ASSERT_ALIGN(VertexData, 16)
/* Limited by expand_prim_len bit count. */
#define PARTICLE_SHAPE_CIRCLE_RESOLUTION 7
/* TODO(fclem): This should be a enum, but it breaks compilation on Metal for some reason. */
#define PART_SHAPE_AXIS 1
#define PART_SHAPE_CIRCLE 2
#define PART_SHAPE_CROSS 3
enum OVERLAY_ParticleShape : uint32_t {
PART_SHAPE_AXIS = 1,
PART_SHAPE_CIRCLE = 2,
PART_SHAPE_CROSS = 3,
};
struct ParticlePointData {
packed_float3 position;
@@ -319,17 +359,6 @@ struct BoneEnvelopeData {
};
BLI_STATIC_ASSERT_ALIGN(BoneEnvelopeData, 16)
/* Keep in sync with armature_stick_vert.glsl. */
enum StickBoneFlag {
COL_WIRE = (1u << 0u),
COL_HEAD = (1u << 1u),
COL_TAIL = (1u << 2u),
COL_BONE = (1u << 3u),
POS_HEAD = (1u << 4u),
POS_TAIL = (1u << 5u),
POS_BONE = (1u << 6u),
};
struct BoneStickData {
float4 bone_start;
float4 bone_end;

View File

@@ -13,29 +13,6 @@
namespace blender::draw::overlay {
enum VertexClass {
VCLASS_NONE = 0,
VCLASS_LIGHT_AREA_SHAPE = 1 << 0,
VCLASS_LIGHT_SPOT_SHAPE = 1 << 1,
VCLASS_LIGHT_SPOT_BLEND = 1 << 2,
VCLASS_LIGHT_SPOT_CONE = 1 << 3,
VCLASS_LIGHT_DIST = 1 << 4,
VCLASS_CAMERA_FRAME = 1 << 5,
VCLASS_CAMERA_DIST = 1 << 6,
VCLASS_CAMERA_VOLUME = 1 << 7,
VCLASS_SCREENSPACE = 1 << 8,
VCLASS_SCREENALIGNED = 1 << 9,
VCLASS_EMPTY_SCALED = 1 << 10,
VCLASS_EMPTY_AXES = 1 << 11,
VCLASS_EMPTY_AXES_NAME = 1 << 12,
VCLASS_EMPTY_AXES_SHADOW = 1 << 13,
VCLASS_EMPTY_SIZE = 1 << 14,
};
static constexpr int diamond_nsegments = 4;
static constexpr int inner_nsegments = 8;
static constexpr int outer_nsegments = 10;
@@ -207,7 +184,7 @@ static const float bone_octahedral_solid_normals[8][3] = {
};
static void append_line_loop(
Vector<Vertex> &dest, Span<float2> verts, float z, int flag, bool dashed = false)
Vector<Vertex> &dest, Span<float2> verts, float z, VertexClass flag, bool dashed = false)
{
const int step = dashed ? 2 : 1;
for (const int i : IndexRange(verts.size() / step)) {
@@ -402,16 +379,17 @@ ShapeCache::ShapeCache()
/* Armature Stick. */
{
const StickBoneFlag bone = StickBoneFlag(COL_BONE | POS_BONE);
/* Gather as a strip and add to main buffer as a list of triangles. */
Vector<Vertex> vert_strip;
vert_strip.append({{0.0f, 1.0f, 0.0f}, COL_BONE | POS_BONE | POS_HEAD | COL_HEAD | COL_WIRE});
vert_strip.append({{0.0f, 1.0f, 0.0f}, COL_BONE | POS_BONE | POS_TAIL | COL_TAIL | COL_WIRE});
vert_strip.append({{0.0f, 0.0f, 0.0f}, COL_BONE | POS_BONE | POS_HEAD | COL_HEAD});
vert_strip.append({{0.0f, 0.0f, 0.0f}, COL_BONE | POS_BONE | POS_TAIL | COL_TAIL});
vert_strip.append({{0.0f, -1.0f, 0.0f}, COL_BONE | POS_BONE | POS_HEAD | COL_HEAD | COL_WIRE});
vert_strip.append({{0.0f, -1.0f, 0.0f}, COL_BONE | POS_BONE | POS_TAIL | COL_TAIL | COL_WIRE});
Vector<VertexBone> vert_strip;
vert_strip.append({{0.0f, 1.0f, 0.0f}, StickBoneFlag(bone | POS_HEAD | COL_HEAD | COL_WIRE)});
vert_strip.append({{0.0f, 1.0f, 0.0f}, StickBoneFlag(bone | POS_TAIL | COL_TAIL | COL_WIRE)});
vert_strip.append({{0.0f, 0.0f, 0.0f}, StickBoneFlag(bone | POS_HEAD | COL_HEAD)});
vert_strip.append({{0.0f, 0.0f, 0.0f}, StickBoneFlag(bone | POS_TAIL | COL_TAIL)});
vert_strip.append({{0.0f, -1.0f, 0.0f}, StickBoneFlag(bone | POS_HEAD | COL_HEAD | COL_WIRE)});
vert_strip.append({{0.0f, -1.0f, 0.0f}, StickBoneFlag(bone | POS_TAIL | COL_TAIL | COL_WIRE)});
Vector<Vertex> verts;
Vector<VertexBone> verts;
/* Bone rectangle */
for (int t : IndexRange(vert_strip.size() - 2)) {
/* NOTE: Don't care about winding.
@@ -427,13 +405,13 @@ ShapeCache::ShapeCache()
float2 cv1 = ring[a % resolution];
float2 cv2 = ring[(a + 1) % resolution];
/* Head point. */
verts.append({{0.0f, 0.0f, 0.0f}, int(POS_HEAD | COL_HEAD)});
verts.append({{cv1.x, cv1.y, 0.0f}, int(POS_HEAD | COL_HEAD | COL_WIRE)});
verts.append({{cv2.x, cv2.y, 0.0f}, int(POS_HEAD | COL_HEAD | COL_WIRE)});
verts.append({{0.0f, 0.0f, 0.0f}, StickBoneFlag(POS_HEAD | COL_HEAD)});
verts.append({{cv1.x, cv1.y, 0.0f}, StickBoneFlag(POS_HEAD | COL_HEAD | COL_WIRE)});
verts.append({{cv2.x, cv2.y, 0.0f}, StickBoneFlag(POS_HEAD | COL_HEAD | COL_WIRE)});
/* Tail point. */
verts.append({{0.0f, 0.0f, 0.0f}, int(POS_TAIL | COL_TAIL)});
verts.append({{cv1.x, cv1.y, 0.0f}, int(POS_TAIL | COL_TAIL | COL_WIRE)});
verts.append({{cv2.x, cv2.y, 0.0f}, int(POS_TAIL | COL_TAIL | COL_WIRE)});
verts.append({{0.0f, 0.0f, 0.0f}, StickBoneFlag(POS_TAIL | COL_TAIL)});
verts.append({{cv1.x, cv1.y, 0.0f}, StickBoneFlag(POS_TAIL | COL_TAIL | COL_WIRE)});
verts.append({{cv2.x, cv2.y, 0.0f}, StickBoneFlag(POS_TAIL | COL_TAIL | COL_WIRE)});
}
bone_stick = BatchPtr(
@@ -807,12 +785,12 @@ ShapeCache::ShapeCache()
for (int axis : IndexRange(3)) {
/* Vertex layout is XY screen position and axis in Z.
* Fractional part of Z is a positive offset at axis unit position. */
int flag = VCLASS_EMPTY_AXES | VCLASS_SCREENALIGNED;
VertexClass flag = VCLASS_EMPTY_AXES | VCLASS_SCREENALIGNED;
/* Center to axis line. */
/* NOTE: overlay_armature_shape_wire_vert.glsl expects the axis verts at the origin to be the
* only ones with this coordinates (it derives the VCLASS from it). */
float pos_on_axis = float(axis) + 1e-8f;
verts.append({{0.0f, 0.0f, 0.0f}, 0});
verts.append({{0.0f, 0.0f, 0.0f}, VCLASS_NONE});
verts.append({{0.0f, 0.0f, pos_on_axis}, flag});
/* Axis end marker. */
constexpr int marker_fill_layer = 6;
@@ -824,7 +802,7 @@ ShapeCache::ShapeCache()
/* Axis name. */
const Vector<float2> *axis_names[3] = {&x_axis_name, &y_axis_name, &z_axis_name};
for (float2 axis_name_vert : *(axis_names[axis])) {
int flag = VCLASS_EMPTY_AXES | VCLASS_EMPTY_AXES_NAME | VCLASS_SCREENALIGNED;
VertexClass flag = VCLASS_EMPTY_AXES | VCLASS_EMPTY_AXES_NAME | VCLASS_SCREENALIGNED;
verts.append({{axis_name_vert * 4.0f, pos_on_axis + 0.25f}, flag});
}
}
@@ -966,10 +944,10 @@ ShapeCache::ShapeCache()
Vector<Vertex> verts;
/* Ground Point */
append_line_loop(verts, ring, 0.0f, 0);
append_line_loop(verts, ring, 0.0f, VCLASS_NONE);
/* Ground Line */
verts.append({{0.0, 0.0, 1.0}, 0});
verts.append({{0.0, 0.0, 0.0}, 0});
verts.append({{0.0, 0.0, 1.0}, VCLASS_NONE});
verts.append({{0.0, 0.0, 0.0}, VCLASS_NONE});
ground_line = BatchPtr(
GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
@@ -989,7 +967,7 @@ ShapeCache::ShapeCache()
Vector<Vertex> verts;
/* Cone apex */
verts.append({{0.0f, 0.0f, 0.0f}, 0});
verts.append({{0.0f, 0.0f, 0.0f}, VCLASS_NONE});
/* Cone silhouette */
for (const int angle_i : IndexRange(circle_nsegments + 1)) {
const float angle = (2.0f * math::numbers::pi * angle_i) / circle_nsegments;
@@ -1053,8 +1031,8 @@ ShapeCache::ShapeCache()
{
Vector<Vertex> verts;
/* Direction Line */
verts.append({{0.0, 0.0, 0.0}, 0});
verts.append({{0.0, 0.0, -20.0}, 0}); /* Good default. */
verts.append({{0.0, 0.0, 0.0}, VCLASS_NONE});
verts.append({{0.0, 0.0, -20.0}, VCLASS_NONE}); /* Good default. */
light_sun_lines = BatchPtr(
GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
}
@@ -1070,7 +1048,7 @@ ShapeCache::ShapeCache()
append_line_loop(verts, ring, 0.0f, VCLASS_LIGHT_SPOT_SHAPE | VCLASS_LIGHT_SPOT_BLEND);
/* Cone silhouette */
for (const float2 &point : ring) {
verts.append({{0.0f, 0.0f, 0.0f}, 0});
verts.append({{0.0f, 0.0f, 0.0f}, VCLASS_NONE});
verts.append({{point.x, point.y, -1.0f}, VCLASS_LIGHT_SPOT_SHAPE | VCLASS_LIGHT_SPOT_CONE});
}
@@ -1108,7 +1086,7 @@ ShapeCache::ShapeCache()
/* field_force */
{
constexpr int circle_resol = 32;
constexpr int flag = VCLASS_EMPTY_SIZE | VCLASS_SCREENALIGNED;
constexpr VertexClass flag = VCLASS_EMPTY_SIZE | VCLASS_SCREENALIGNED;
constexpr std::array<float, 2> scales{2.0f, 0.75};
Vector<float2> ring = ring_vertices(1.0f, circle_resol);
@@ -1235,7 +1213,7 @@ ShapeCache::ShapeCache()
/* lightprobe_cube */
{
constexpr float r = 14.0f;
constexpr int flag = VCLASS_SCREENSPACE;
constexpr VertexClass flag = VCLASS_SCREENSPACE;
/* Icon */
constexpr float sin_pi_3 = 0.86602540378f;
constexpr float cos_pi_3 = 0.5f;
@@ -1288,7 +1266,7 @@ ShapeCache::ShapeCache()
/* lightprobe_grid */
{
constexpr float r = 14.0f;
constexpr int flag = VCLASS_SCREENSPACE;
constexpr VertexClass flag = VCLASS_SCREENSPACE;
/* Icon */
constexpr float sin_pi_3 = 0.86602540378f;
constexpr float cos_pi_3 = 0.5f;

View File

@@ -11,11 +11,6 @@
#define V3D_SHADING_OBJECT_COLOR 4
#define V3D_SHADING_RANDOM_COLOR 1
#define DRW_BASE_SELECTED (1 << 1)
#define DRW_BASE_FROM_DUPLI (1 << 2)
#define DRW_BASE_FROM_SET (1 << 3)
#define DRW_BASE_ACTIVE (1 << 4)
float4x4 extract_matrix_packed_data(float4x4 mat, out float4 dataA, out float4 dataB)
{
constexpr float div = 1.0f / 255.0f;

View File

@@ -6,18 +6,6 @@
FRAGMENT_SHADER_CREATE_INFO(overlay_edit_uv_edges)
/**
* We want to know how much a pixel is covered by a line.
* We replace the square pixel with a circle of the same area and try to find the intersection
* area. The area we search is the circular segment. https://en.wikipedia.org/wiki/Circular_segment
* The formula for the area uses inverse trig function and is quite complex. Instead,
* we approximate it by using the smooth-step function and a 1.05 factor to the disc radius.
*/
#define M_1_SQRTPI 0.5641895835477563f /* `1/sqrt(pi)`. */
#define DISC_RADIUS (M_1_SQRTPI * 1.05f)
#define GRID_LINE_SMOOTH_START (0.5f - DISC_RADIUS)
#define GRID_LINE_SMOOTH_END (0.5f + DISC_RADIUS)
#include "draw_object_infos_lib.glsl"
#include "gpu_shader_utildefines_lib.glsl"
#include "overlay_common_lib.glsl"

View File

@@ -11,43 +11,6 @@ VERTEX_SHADER_CREATE_INFO(overlay_extra_spot_cone)
#include "overlay_common_lib.glsl"
#include "select_lib.glsl"
#define lamp_area_size inst_data.xy
#define lamp_clip_sta inst_data.z
#define lamp_clip_end inst_data.w
#define lamp_spot_cosine inst_data.x
#define lamp_spot_blend inst_data.y
#define camera_corner inst_data.xy
#define camera_center inst_data.zw
#define camera_dist color.a
#define camera_dist_sta inst_data.z
#define camera_dist_end inst_data.w
#define camera_distance_color inst_data.x
#define empty_size inst_data.xyz
#define empty_scale inst_data.w
/* TODO(fclem): Share with C code. */
#define VCLASS_LIGHT_AREA_SHAPE (1 << 0)
#define VCLASS_LIGHT_SPOT_SHAPE (1 << 1)
#define VCLASS_LIGHT_SPOT_BLEND (1 << 2)
#define VCLASS_LIGHT_SPOT_CONE (1 << 3)
#define VCLASS_LIGHT_DIST (1 << 4)
#define VCLASS_CAMERA_FRAME (1 << 5)
#define VCLASS_CAMERA_DIST (1 << 6)
#define VCLASS_CAMERA_VOLUME (1 << 7)
#define VCLASS_SCREENSPACE (1 << 8)
#define VCLASS_SCREENALIGNED (1 << 9)
#define VCLASS_EMPTY_SCALED (1 << 10)
#define VCLASS_EMPTY_AXES (1 << 11)
#define VCLASS_EMPTY_AXES_NAME (1 << 12)
#define VCLASS_EMPTY_AXES_SHADOW (1 << 13)
#define VCLASS_EMPTY_SIZE (1 << 14)
void main()
{
select_id_set(in_select_buf[gl_InstanceID]);
@@ -70,6 +33,23 @@ void main()
final_color.a = 1.0f;
}
float2 lamp_area_size = inst_data.xy;
float lamp_clip_sta = inst_data.z;
float lamp_clip_end = inst_data.w;
float lamp_spot_cosine = inst_data.x;
float lamp_spot_blend = inst_data.y;
float2 camera_corner = inst_data.xy;
float2 camera_center = inst_data.zw;
float camera_dist = color.a;
float camera_dist_sta = inst_data.z;
float camera_dist_end = inst_data.w;
float camera_distance_color = inst_data.x;
float3 empty_size = inst_data.xyz;
float empty_scale = inst_data.w;
float lamp_spot_sine;
float3 vpos = pos;
float3 vofs = float3(0.0f);