Blender V5.3
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
8
9#pragma once
10
12
13#ifndef GPU_SHADER
14# include "DNA_action_types.h"
15# include "DNA_view3d_types.h"
16#endif
17
26
34
35enum [[host_shared]] OVERLAY_GridBits : uint32_t {
36 SHOW_GRID = (1u << 0u),
37 SHOW_AXES = (1u << 1u),
38
39 /* Axis * is shown if `SHOW_AXES` is set. */
40 AXIS_X = (1u << 2u),
41 AXIS_Y = (1u << 3u),
42 AXIS_Z = (1u << 4u),
43
44 /* Grid is placed on * plane if `SHOW_GRID` is set. */
45 PLANE_XY = (1u << 5u),
46 PLANE_XZ = (1u << 6u),
47 PLANE_YZ = (1u << 7u),
48
49 GRID_ALIGNED = (1u << 8u), /* Grid is in an axis-aligned view (PLANE_XY, ...). */
50 GRID_SIMA = (1u << 9u), /* Grid is in SpaceImage view. */
51 GRID_CAMERA = (1u << 10u), /* Grid is shown in selected camera. */
52 GRID_OVER_IMAGE = (1u << 11u), /* Grid is shown in front of SpaceImage, not behind. */
53 GRID_BEHIND_GEOMETRY = (1u << 12u) /* Grid is shown behind geometry, on the far plane. */
54};
55#ifndef GPU_SHADER
57#endif
58
81#ifndef GPU_SHADER
83#endif
84
85enum [[host_shared]] StickBoneFlag : uint32_t {
86 COL_WIRE = (1u << 0u),
87 COL_HEAD = (1u << 1u),
88 COL_TAIL = (1u << 2u),
89 COL_BONE = (1u << 3u),
90 POS_HEAD = (1u << 4u),
91 POS_TAIL = (1u << 5u),
92 POS_BONE = (1u << 6u),
93};
94#ifndef GPU_SHADER
96#endif
97
98/* TODO(fclem): Convert into enum. */
99/* See: 'draw_cache_impl.hh' for matching includes. */
100#define VERT_GPENCIL_BEZT_HANDLE (1u << 30)
101/* data[0] (1st byte flags) */
102#define FACE_ACTIVE (1u << 0)
103#define FACE_SELECTED (1u << 1)
104#define FACE_FREESTYLE (1u << 2)
105#define VERT_UV_SELECT (1u << 3)
106#define VERT_UV_PINNED (1u << 4)
107#define EDGE_UV_SELECT (1u << 5)
108#define FACE_UV_ACTIVE (1u << 6)
109#define FACE_UV_SELECT (1u << 7)
110/* data[1] (2nd byte flags) */
111#define VERT_ACTIVE (1u << 0)
112#define VERT_SELECTED (1u << 1)
113#define VERT_SELECTED_BEZT_HANDLE (1u << 2)
114#define EDGE_ACTIVE (1u << 3)
115#define EDGE_SELECTED (1u << 4)
116#define EDGE_SEAM (1u << 5)
117#define EDGE_SHARP (1u << 6)
118#define EDGE_FREESTYLE (1u << 7)
119
120static inline uint outline_id_pack(uint outline_id, uint object_id)
121{
122 /* Replace top 2 bits (of the 16bit output) by outline_id.
123 * This leaves 16K different IDs to create outlines between objects.
124 * 18 = (32 - (16 - 2)) */
125 return (outline_id << 14u) | ((object_id << 18u) >> 18u);
126}
127
129#define OVERLAY_GRID_STEPS_LEN 8
131#define OVERLAY_GRID_STEPS_DRAW 3
133#define OVERLAY_GRID_ITER_LEN 4
134
135/* Due to the encoding clamping the passed in floats, the wire width needs to be scaled down. */
136#define WIRE_WIDTH_COMPRESSION 16.0f
137
139 /* Per level step size, based on selected units/subdivision. */
140 float4 steps[OVERLAY_GRID_STEPS_LEN]; /* float3 array padded to float4 (std140). */
141 /* XY/YZ/XZ camera offset of grid. */
143 /* Clipping rectangle for UV/Image editor. */
145 /* Fractional grid-level, dependent on current camera position/distance/zoom. */
146 float level;
147 /* Per-level line count. */
149 uint _pad0;
150 uint _pad1;
151};
152
153#ifdef GPU_SHADER
154/* Keep the same values as in `draw_cache_impl_curves.cc` */
155# define EDIT_CURVES_NURBS_CONTROL_POINT (1u)
156# define EDIT_CURVES_BEZIER_HANDLE (1u << 1)
157# define EDIT_CURVES_ACTIVE_HANDLE (1u << 2)
158# define EDIT_CURVES_BEZIER_KNOT (1u << 3)
159# define EDIT_CURVES_HANDLE_TYPES_SHIFT (4u)
160/* Keep the same values as in `draw_cache_imp_curve.c` */
161# define ACTIVE_NURB (1u << 2)
162# define BEZIER_HANDLE (1u << 3)
163# define EVEN_U_BIT (1u << 4)
164# define COLOR_SHIFT 5u
165
166/* Keep the same value in `handle_display` in `DNA_view3d_types.h` */
167# define CURVE_HANDLE_SELECTED 0u
168# define CURVE_HANDLE_ALL 1u
169# define CURVE_HANDLE_NONE 2u
170
171# define GP_EDIT_POINT_SELECTED 1u /* 1 << 0 */
172# define GP_EDIT_STROKE_SELECTED 2u /* 1 << 1 */
173# define GP_EDIT_MULTIFRAME 4u /* 1 << 2 */
174# define GP_EDIT_STROKE_START 8u /* 1 << 3 */
175# define GP_EDIT_STROKE_END 16u /* 1 << 4 */
176# define GP_EDIT_POINT_DIMMED 32u /* 1 << 5 */
177
178# define MOTIONPATH_VERT_SEL (1u << 0)
179# define MOTIONPATH_VERT_KEY (1u << 1)
180#endif
181
182#ifndef GPU_SHADER
183# define CURVE_HANDLE_SELECTED blender::CURVE_HANDLE_SELECTED
184# define CURVE_HANDLE_ALL blender::CURVE_HANDLE_ALL
185# define MOTIONPATH_VERT_SEL blender::MOTIONPATH_VERT_SEL
186# define MOTIONPATH_VERT_KEY blender::MOTIONPATH_VERT_KEY
187/* TODO(fclem): Find a better way to share enums/defines from DNA files with GLSL. */
188BLI_STATIC_ASSERT(CURVE_HANDLE_SELECTED == 0u, "Ensure value is sync");
189BLI_STATIC_ASSERT(CURVE_HANDLE_ALL == 1u, "Ensure value is sync");
190BLI_STATIC_ASSERT(MOTIONPATH_VERT_SEL == (1u << 0), "Ensure value is sync");
191BLI_STATIC_ASSERT(MOTIONPATH_VERT_KEY == (1u << 1), "Ensure value is sync");
192#endif
193
194/* All colors in this struct are converted to display linear RGB color-space. */
196 /* UBOs data needs to be 16 byte aligned (size of float4) */
199 float4 active_object; /* "active" is reserved keyword in GLSL. */
200 float4 object_select; /* "select" is defined as a macro for GLSL. */
209 float4 vert; /* "vertex" is reserved keyword in MSL. */
214 float4 edge_select; /* Stands for edge selection, not edge select mode. */
215 float4 edge_mode_select; /* Stands for edge mode selection. */
223 float4 face_select; /* Stands for face selection, not face select mode. */
224 float4 face_mode_select; /* Stands for face mode selection. */
235
239
246
261
277
280
282
287
291
297
300
302};
303
304/* All values in this struct are premultiplied by U.pixelsize. */
306 float pixel; /* Equivalent to U.pixelsize. */
307
309
313
314 float vert; /* "vertex" is reserved keyword in MSL. */
315 float edge;
316 float face_dot;
317
318 float checker;
320 float _pad1;
321 float _pad2;
322};
323
338
339#ifdef GPU_SHADER
340/* The uniform_buf mostly contains theme properties.
341 * This alias has better semantic and shorter syntax. */
342# define theme uniform_buf
343#endif
344
348
349#ifndef GPU_SHADER
350 ExtraInstanceData(const float4x4 &object_to_world, const float4 &color, float draw_size)
351 {
352 this->color_ = color;
353 this->object_to_world = object_to_world;
354 this->object_to_world[3][3] = draw_size;
355 };
356
358 {
359 ExtraInstanceData copy = *this;
360 copy.color_ = color;
361 return copy;
362 }
363
364 /* For degrees of freedom. */
366 const float4 &color,
367 float angle_min_x,
368 float angle_min_z,
369 float angle_max_x,
370 float angle_max_z)
371 {
372 this->color_ = color;
373 this->object_to_world = object_to_world;
374 this->object_to_world[0][3] = angle_min_x;
375 this->object_to_world[1][3] = angle_min_z;
376 this->object_to_world[2][3] = angle_max_x;
377 this->object_to_world[3][3] = angle_max_z;
378 };
379#endif
380};
381
384 /* TODO: change to color_id. Idea expressed in #125894. */
386};
387
388/* Limited by expand_prim_len bit count. */
389#define PARTICLE_SHAPE_CIRCLE_RESOLUTION 7
390
396
399 /* Can either be velocity or acceleration. */
400 float value;
401 /* Rotation encoded as quaternion. */
403};
404
408 /* TODO(pragma37): wire width is never used in the shader. */
412
413#ifndef GPU_SHADER
414 BoneEnvelopeData() = default;
415
416 /* For bone fills. */
427
428 /* For bone outlines. */
431 float4 &color_and_wire_width,
432 float3 &x_axis)
435 bone_color_and_wire_width(color_and_wire_width),
436 x_axis(x_axis, 0.0f) {};
437
438 /* For bone distance volumes. */
441#endif
442};
443
451
452#ifndef GPU_SHADER
453 BoneStickData() = default;
454
455 /* For bone fills. */
468#endif
469};
470
482#define M_1_SQRTPI 0.5641895835477563f /* `1/sqrt(pi)`. */
483#define DISC_RADIUS (M_1_SQRTPI * 1.05f)
484#define LINE_SMOOTH_START (0.5f - DISC_RADIUS)
485#define LINE_SMOOTH_END (0.5f + DISC_RADIUS)
486/* Returns 0 before LINE_SMOOTH_START and 1 after LINE_SMOOTH_END. */
487#define LINE_STEP(dist) smoothstep(LINE_SMOOTH_START, LINE_SMOOTH_END, dist)
#define ENUM_OPERATORS(_enum_type)
#define host_shared
int32_t bool32_t
#define BLI_STATIC_ASSERT(a, msg)
#define VCLASS_LIGHT_AREA_SHAPE
Definition draw_cache.cc:47
#define VCLASS_CAMERA_DIST
Definition draw_cache.cc:54
#define VCLASS_EMPTY_AXES_NAME
Definition draw_cache.cc:62
#define VCLASS_LIGHT_SPOT_BLEND
Definition draw_cache.cc:49
#define VCLASS_EMPTY_AXES
Definition draw_cache.cc:61
#define VCLASS_EMPTY_AXES_SHADOW
Definition draw_cache.cc:63
#define VCLASS_EMPTY_SCALED
Definition draw_cache.cc:60
#define VCLASS_LIGHT_DIST
Definition draw_cache.cc:51
#define VCLASS_LIGHT_SPOT_SHAPE
Definition draw_cache.cc:48
#define VCLASS_CAMERA_FRAME
Definition draw_cache.cc:53
#define VCLASS_CAMERA_VOLUME
Definition draw_cache.cc:55
#define VCLASS_LIGHT_SPOT_CONE
Definition draw_cache.cc:50
#define VCLASS_SCREENALIGNED
Definition draw_cache.cc:58
#define VCLASS_SCREENSPACE
Definition draw_cache.cc:57
#define VCLASS_EMPTY_SIZE
Definition draw_cache.cc:64
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< float, 2 > float2
VecBase< float, 3 > float3
@ GRID_BEHIND_GEOMETRY
@ GRID_OVER_IMAGE
@ PART_SHAPE_CIRCLE
static uint outline_id_pack(uint outline_id, uint object_id)
OVERLAY_BackgroundType
@ BG_SOLID_CHECKER
#define MOTIONPATH_VERT_SEL
@ 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 CURVE_HANDLE_ALL
#define OVERLAY_GRID_STEPS_LEN
#define CURVE_HANDLE_SELECTED
#define MOTIONPATH_VERT_KEY
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]
struct ThemeSizes sizes
struct ThemeColors colors