Blender V5.0
overlay_shader_shared.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#ifndef GPU_SHADER
9
10# include "DNA_action_types.h"
11# include "DNA_view3d_types.h"
12#endif
13
22
30
31enum OVERLAY_GridBits : uint32_t {
32 SHOW_AXIS_X = (1u << 0u),
33 SHOW_AXIS_Y = (1u << 1u),
34 SHOW_AXIS_Z = (1u << 2u),
35 SHOW_GRID = (1u << 3u),
36 PLANE_XY = (1u << 4u),
37 PLANE_XZ = (1u << 5u),
38 PLANE_YZ = (1u << 6u),
39 CLIP_ZPOS = (1u << 7u),
40 CLIP_ZNEG = (1u << 8u),
41 GRID_BACK = (1u << 9u),
42 GRID_CAMERA = (1u << 10u),
43 PLANE_IMAGE = (1u << 11u),
44 CUSTOM_GRID = (1u << 12u),
45};
46#ifndef GPU_SHADER
48#endif
49
72#ifndef GPU_SHADER
74#endif
75
76enum StickBoneFlag : uint32_t {
77 COL_WIRE = (1u << 0u),
78 COL_HEAD = (1u << 1u),
79 COL_TAIL = (1u << 2u),
80 COL_BONE = (1u << 3u),
81 POS_HEAD = (1u << 4u),
82 POS_TAIL = (1u << 5u),
83 POS_BONE = (1u << 6u),
84};
85#ifndef GPU_SHADER
87#endif
88
89/* TODO(fclem): Convert into enum. */
90/* See: 'draw_cache_impl.hh' for matching includes. */
91#define VERT_GPENCIL_BEZT_HANDLE (1u << 30)
92/* data[0] (1st byte flags) */
93#define FACE_ACTIVE (1u << 0)
94#define FACE_SELECTED (1u << 1)
95#define FACE_FREESTYLE (1u << 2)
96#define VERT_UV_SELECT (1u << 3)
97#define VERT_UV_PINNED (1u << 4)
98#define EDGE_UV_SELECT (1u << 5)
99#define FACE_UV_ACTIVE (1u << 6)
100#define FACE_UV_SELECT (1u << 7)
101/* data[1] (2nd byte flags) */
102#define VERT_ACTIVE (1u << 0)
103#define VERT_SELECTED (1u << 1)
104#define VERT_SELECTED_BEZT_HANDLE (1u << 2)
105#define EDGE_ACTIVE (1u << 3)
106#define EDGE_SELECTED (1u << 4)
107#define EDGE_SEAM (1u << 5)
108#define EDGE_SHARP (1u << 6)
109#define EDGE_FREESTYLE (1u << 7)
110
111static inline uint outline_id_pack(uint outline_id, uint object_id)
112{
113 /* Replace top 2 bits (of the 16bit output) by outline_id.
114 * This leaves 16K different IDs to create outlines between objects.
115 * 18 = (32 - (16 - 2)) */
116 return (outline_id << 14u) | ((object_id << 18u) >> 18u);
117}
118
119/* Match: #SI_GRID_STEPS_LEN */
120#define OVERLAY_GRID_STEPS_LEN 8
121
122/* Due to the encoding clamping the passed in floats, the wire width needs to be scaled down. */
123#define WIRE_WIDTH_COMPRESSION 16.0
124
126 float4 steps[OVERLAY_GRID_STEPS_LEN]; /* float arrays are padded to float4 in std130. */
127 float4 size; /* float3 padded to float4. */
128 float distance;
130 float zoom_factor; /* Only for UV editor */
131 float _pad0;
132};
134
135#ifdef GPU_SHADER
136/* Keep the same values as in `draw_cache_impl_curves.cc` */
137# define EDIT_CURVES_NURBS_CONTROL_POINT (1u)
138# define EDIT_CURVES_BEZIER_HANDLE (1u << 1)
139# define EDIT_CURVES_ACTIVE_HANDLE (1u << 2)
140# define EDIT_CURVES_BEZIER_KNOT (1u << 3)
141# define EDIT_CURVES_HANDLE_TYPES_SHIFT (4u)
142/* Keep the same values as in `draw_cache_imp_curve.c` */
143# define ACTIVE_NURB (1u << 2)
144# define BEZIER_HANDLE (1u << 3)
145# define EVEN_U_BIT (1u << 4)
146# define COLOR_SHIFT 5u
147
148/* Keep the same value in `handle_display` in `DNA_view3d_types.h` */
149# define CURVE_HANDLE_SELECTED 0u
150# define CURVE_HANDLE_ALL 1u
151# define CURVE_HANDLE_NONE 2u
152
153# define GP_EDIT_POINT_SELECTED 1u /* 1 << 0 */
154# define GP_EDIT_STROKE_SELECTED 2u /* 1 << 1 */
155# define GP_EDIT_MULTIFRAME 4u /* 1 << 2 */
156# define GP_EDIT_STROKE_START 8u /* 1 << 3 */
157# define GP_EDIT_STROKE_END 16u /* 1 << 4 */
158# define GP_EDIT_POINT_DIMMED 32u /* 1 << 5 */
159
160# define MOTIONPATH_VERT_SEL (1u << 0)
161# define MOTIONPATH_VERT_KEY (1u << 1)
162
163#else
164/* TODO(fclem): Find a better way to share enums/defines from DNA files with GLSL. */
165BLI_STATIC_ASSERT(CURVE_HANDLE_SELECTED == 0u, "Ensure value is sync");
166BLI_STATIC_ASSERT(CURVE_HANDLE_ALL == 1u, "Ensure value is sync");
167BLI_STATIC_ASSERT(MOTIONPATH_VERT_SEL == (1u << 0), "Ensure value is sync");
168BLI_STATIC_ASSERT(MOTIONPATH_VERT_KEY == (1u << 1), "Ensure value is sync");
169#endif
170
171/* All colors in this struct are converted to display linear RGB color-space. */
173 /* UBOs data needs to be 16 byte aligned (size of float4) */
176 float4 active_object; /* "active" is reserved keyword in GLSL. */
177 float4 object_select; /* "select" is defined as a macro for GLSL. */
186 float4 vert; /* "vertex" is reserved keyword in MSL. */
191 float4 edge_select; /* Stands for edge selection, not edge select mode. */
192 float4 edge_mode_select; /* Stands for edge mode selection. */
200 float4 face_select; /* Stands for face selection, not face select mode. */
201 float4 face_mode_select; /* Stands for face mode selection. */
211
215
222
237
253
256
258
263
267
273
276
278};
280
281/* All values in this struct are premultiplied by U.pixelsize. */
283 float pixel; /* Equivalent to U.pixelsize. */
284
286
290
291 float vert; /* "vertex" is reserved keyword in MSL. */
292 float edge;
293 float face_dot;
294
295 float checker;
297 float _pad1, _pad2;
298};
300
316
317#ifdef GPU_SHADER
318/* The uniform_buf mostly contains theme properties.
319 * This alias has better semantic and shorter syntax. */
320# define theme uniform_buf
321#endif
322
326
327#ifndef GPU_SHADER
328 ExtraInstanceData(const float4x4 &object_to_world, const float4 &color, float draw_size)
329 {
330 this->color_ = color;
331 this->object_to_world = object_to_world;
332 this->object_to_world[3][3] = draw_size;
333 };
334
336 {
337 ExtraInstanceData copy = *this;
338 copy.color_ = color;
339 return copy;
340 }
341
342 /* For degrees of freedom. */
344 const float4 &color,
345 float angle_min_x,
346 float angle_min_z,
347 float angle_max_x,
348 float angle_max_z)
349 {
350 this->color_ = color;
351 this->object_to_world = object_to_world;
352 this->object_to_world[0][3] = angle_min_x;
353 this->object_to_world[1][3] = angle_min_z;
354 this->object_to_world[2][3] = angle_max_x;
355 this->object_to_world[3][3] = angle_max_z;
356 };
357#endif
358};
360
363 /* TODO: change to color_id. Idea expressed in #125894. */
365};
367
368/* Limited by expand_prim_len bit count. */
369#define PARTICLE_SHAPE_CIRCLE_RESOLUTION 7
370
376
379 /* Can either be velocity or acceleration. */
380 float value;
381 /* Rotation encoded as quaternion. */
383};
385
389 /* TODO(pragma37): wire width is never used in the shader. */
393
394#ifndef GPU_SHADER
395 BoneEnvelopeData() = default;
396
397 /* For bone fills. */
408
409 /* For bone outlines. */
412 float4 &color_and_wire_width,
413 float3 &x_axis)
416 bone_color_and_wire_width(color_and_wire_width),
417 x_axis(x_axis, 0.0f) {};
418
419 /* For bone distance volumes. */
422#endif
423};
425
433
434#ifndef GPU_SHADER
435 BoneStickData() = default;
436
437 /* For bone fills. */
450#endif
451};
453
454
465#define M_1_SQRTPI 0.5641895835477563f /* `1/sqrt(pi)`. */
466#define DISC_RADIUS (M_1_SQRTPI * 1.05f)
467#define LINE_SMOOTH_START (0.5f - DISC_RADIUS)
468#define LINE_SMOOTH_END (0.5f + DISC_RADIUS)
469/* Returns 0 before LINE_SMOOTH_START and 1 after LINE_SMOOTH_END. */
470#define LINE_STEP(dist) smoothstep(LINE_SMOOTH_START, LINE_SMOOTH_END, dist)
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:83
#define BLI_STATIC_ASSERT_ALIGN(st, align)
Definition BLI_assert.h:86
unsigned int uint
#define ENUM_OPERATORS(_type, _max)
@ MOTIONPATH_VERT_KEY
@ MOTIONPATH_VERT_SEL
@ CURVE_HANDLE_ALL
@ CURVE_HANDLE_SELECTED
int32_t bool32_t
#define VCLASS_LIGHT_AREA_SHAPE
Definition draw_cache.cc:45
#define VCLASS_CAMERA_DIST
Definition draw_cache.cc:52
#define VCLASS_EMPTY_AXES_NAME
Definition draw_cache.cc:60
#define VCLASS_LIGHT_SPOT_BLEND
Definition draw_cache.cc:47
#define VCLASS_EMPTY_AXES
Definition draw_cache.cc:59
#define VCLASS_EMPTY_AXES_SHADOW
Definition draw_cache.cc:61
#define VCLASS_EMPTY_SCALED
Definition draw_cache.cc:58
#define VCLASS_LIGHT_DIST
Definition draw_cache.cc:49
#define VCLASS_LIGHT_SPOT_SHAPE
Definition draw_cache.cc:46
#define VCLASS_CAMERA_FRAME
Definition draw_cache.cc:51
#define VCLASS_CAMERA_VOLUME
Definition draw_cache.cc:53
#define VCLASS_LIGHT_SPOT_CONE
Definition draw_cache.cc:48
#define VCLASS_SCREENALIGNED
Definition draw_cache.cc:56
#define VCLASS_SCREENSPACE
Definition draw_cache.cc:55
#define VCLASS_EMPTY_SIZE
Definition draw_cache.cc:62
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< float, 2 > float2
VecBase< float, 3 > float3
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)
@ PART_SHAPE_CIRCLE
static uint outline_id_pack(uint outline_id, uint object_id)
OVERLAY_BackgroundType
@ BG_SOLID_CHECKER
@ OVERLAY_UV_LINE_STYLE_DASH
@ OVERLAY_UV_LINE_STYLE_SHADOW
@ OVERLAY_UV_LINE_STYLE_WHITE
@ OVERLAY_UV_LINE_STYLE_OUTLINE
@ OVERLAY_UV_LINE_STYLE_BLACK
#define OVERLAY_GRID_STEPS_LEN
BoneEnvelopeData()=default
BoneEnvelopeData(float4 &head_sphere, float4 &tail_sphere, float3 &bone_color, float3 &state_color, float3 &x_axis)
BoneEnvelopeData(float4 &head_sphere, float4 &tail_sphere, float3 &x_axis)
BoneEnvelopeData(float4 &head_sphere, float4 &tail_sphere, float4 &color_and_wire_width, float3 &x_axis)
BoneStickData()=default
BoneStickData(const float3 &bone_start, const float3 &bone_end, const float4 &wire_color, const float4 &bone_color, const float4 &head_color, const float4 &tail_color)
ExtraInstanceData with_color(const float4 &color) const
ExtraInstanceData(const float4x4 &object_to_world, const float4 &color, float angle_min_x, float angle_min_z, float angle_max_x, float angle_max_z)
ExtraInstanceData(const float4x4 &object_to_world, const float4 &color, float draw_size)
float4 steps[OVERLAY_GRID_STEPS_LEN]