Blender V4.5
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#if !defined(GPU_SHADER) && !defined(GLSL_CPP_STUBS)
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
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] (2st 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
238
254
257
259
264
268
274
277
279};
281
282/* All values in this struct are premultiplied by U.pixelsize. */
284 float pixel; /* Equivalent to U.pixelsize. */
285
287
291
292 float vert; /* "vertex" is reserved keyword in MSL. */
293 float edge;
294 float face_dot;
295
296 float checker;
298 float _pad1, _pad2;
299};
301
317
318#ifdef GPU_SHADER
319/* The uniform_buf mostly contains theme properties.
320 * This alias has better semantic and shorter syntax. */
321# define theme uniform_buf
322#endif
323
327
328#if !defined(GPU_SHADER)
329 ExtraInstanceData(const float4x4 &object_to_world, const float4 &color, float draw_size)
330 {
331 this->color_ = color;
332 this->object_to_world = object_to_world;
333 this->object_to_world[3][3] = draw_size;
334 };
335
337 {
338 ExtraInstanceData copy = *this;
339 copy.color_ = color;
340 return copy;
341 }
342
343 /* For degrees of freedom. */
345 const float4 &color,
346 float angle_min_x,
347 float angle_min_z,
348 float angle_max_x,
349 float angle_max_z)
350 {
351 this->color_ = color;
352 this->object_to_world = object_to_world;
353 this->object_to_world[0][3] = angle_min_x;
354 this->object_to_world[1][3] = angle_min_z;
355 this->object_to_world[2][3] = angle_max_x;
356 this->object_to_world[3][3] = angle_max_z;
357 };
358#endif
359};
361
364 /* TODO: change to color_id. Idea expressed in #125894. */
366};
368
369/* Limited by expand_prim_len bit count. */
370#define PARTICLE_SHAPE_CIRCLE_RESOLUTION 7
371
377
380 /* Can either be velocity or acceleration. */
381 float value;
382 /* Rotation encoded as quaternion. */
384};
386
390 /* TODO(pragma37): wire width is never used in the shader. */
394
395#ifndef GPU_SHADER
396 BoneEnvelopeData() = default;
397
398 /* For bone fills. */
409
410 /* For bone outlines. */
413 float4 &color_and_wire_width,
414 float3 &x_axis)
417 bone_color_and_wire_width(color_and_wire_width),
418 x_axis(x_axis, 0.0f){};
419
420 /* For bone distance volumes. */
423#endif
424};
426
434
435#ifndef GPU_SHADER
436 BoneStickData() = default;
437
438 /* For bone fills. */
451#endif
452};
454
455
466#define M_1_SQRTPI 0.5641895835477563f /* `1/sqrt(pi)`. */
467#define DISC_RADIUS (M_1_SQRTPI * 1.05f)
468#define LINE_SMOOTH_START (0.5f - DISC_RADIUS)
469#define LINE_SMOOTH_END (0.5f + DISC_RADIUS)
470/* Returns 0 before LINE_SMOOTH_START and 1 after LINE_SMOOTH_END. */
471#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:44
#define VCLASS_CAMERA_DIST
Definition draw_cache.cc:51
#define VCLASS_EMPTY_AXES_NAME
Definition draw_cache.cc:59
#define VCLASS_LIGHT_SPOT_BLEND
Definition draw_cache.cc:46
#define VCLASS_EMPTY_AXES
Definition draw_cache.cc:58
#define VCLASS_EMPTY_AXES_SHADOW
Definition draw_cache.cc:60
#define VCLASS_EMPTY_SCALED
Definition draw_cache.cc:57
#define VCLASS_LIGHT_DIST
Definition draw_cache.cc:48
#define VCLASS_LIGHT_SPOT_SHAPE
Definition draw_cache.cc:45
#define VCLASS_CAMERA_FRAME
Definition draw_cache.cc:50
#define VCLASS_CAMERA_VOLUME
Definition draw_cache.cc:52
#define VCLASS_LIGHT_SPOT_CONE
Definition draw_cache.cc:47
#define VCLASS_SCREENALIGNED
Definition draw_cache.cc:55
#define VCLASS_SCREENSPACE
Definition draw_cache.cc:54
#define VCLASS_EMPTY_SIZE
Definition draw_cache.cc:61
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]