Blender V5.3
overlay_shape.cc
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#include "GPU_batch_utils.hh"
10#include "draw_cache.hh"
11
12#include "overlay_private.hh"
13
14namespace blender::draw::overlay {
15
16static constexpr int diamond_nsegments = 4;
17static constexpr int inner_nsegments = 8;
18static constexpr int outer_nsegments = 10;
19static constexpr int circle_nsegments = 32;
20
21static constexpr float bone_box_verts[8][3] = {
22 {1.0f, 0.0f, 1.0f},
23 {1.0f, 0.0f, -1.0f},
24 {-1.0f, 0.0f, -1.0f},
25 {-1.0f, 0.0f, 1.0f},
26 {1.0f, 1.0f, 1.0f},
27 {1.0f, 1.0f, -1.0f},
28 {-1.0f, 1.0f, -1.0f},
29 {-1.0f, 1.0f, 1.0f},
30};
31
32static constexpr std::array<uint, 24> bone_box_wire_lines = {
33 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7,
34};
35
36static const std::array<uint3, 12> bone_box_solid_tris{
37 uint3{0, 2, 1}, /* bottom */
38 {0, 3, 2},
39
40 {0, 1, 5}, /* sides */
41 {0, 5, 4},
42
43 {1, 2, 6},
44 {1, 6, 5},
45
46 {2, 3, 7},
47 {2, 7, 6},
48
49 {3, 0, 4},
50 {3, 4, 7},
51
52 {4, 5, 6}, /* top */
53 {4, 6, 7},
54};
55
60static const std::array<uint4, 12> bone_box_wire_lines_adjacency = {
61 uint4{4, 2, 0, 11},
62 {0, 1, 2, 8},
63 {2, 4, 1, 14},
64 {1, 0, 4, 20}, /* bottom */
65 {0, 8, 11, 14},
66 {2, 14, 8, 20},
67 {1, 20, 14, 11},
68 {4, 11, 20, 8}, /* top */
69 {20, 0, 11, 2},
70 {11, 2, 8, 1},
71 {8, 1, 14, 4},
72 {14, 4, 20, 0}, /* sides */
73};
74
75/* aligned with bone_box_solid_tris */
76static const std::array<float3, 12> bone_box_solid_normals = {
77 float3{0.0f, -1.0f, 0.0f},
78 {0.0f, -1.0f, 0.0f},
79
80 {1.0f, 0.0f, 0.0f},
81 {1.0f, 0.0f, 0.0f},
82
83 {0.0f, 0.0f, -1.0f},
84 {0.0f, 0.0f, -1.0f},
85
86 {-1.0f, 0.0f, 0.0f},
87 {-1.0f, 0.0f, 0.0f},
88
89 {0.0f, 0.0f, 1.0f},
90 {0.0f, 0.0f, 1.0f},
91
92 {0.0f, 1.0f, 0.0f},
93 {0.0f, 1.0f, 0.0f},
94};
95
96static const std::array<float3, 6> bone_octahedral_verts{
97 float3{0.0f, 0.0f, 0.0f},
98 {0.1f, 0.1f, 0.1f},
99 {0.1f, 0.1f, -0.1f},
100 {-0.1f, 0.1f, -0.1f},
101 {-0.1f, 0.1f, 0.1f},
102 {0.0f, 1.0f, 0.0f},
103};
104
105static const std::array<uint2, 12> bone_octahedral_wire_lines = {
106 uint2{0, 1},
107 {1, 5},
108 {5, 3},
109 {3, 0},
110 {0, 4},
111 {4, 5},
112 {5, 2},
113 {2, 0},
114 {1, 2},
115 {2, 3},
116 {3, 4},
117 {4, 1},
118};
119
120static const std::array<uint3, 8> bone_octahedral_solid_tris = {
121 uint3{2, 1, 0}, /* bottom */
122 {3, 2, 0},
123 {4, 3, 0},
124 {1, 4, 0},
125
126 {5, 1, 2}, /* top */
127 {5, 2, 3},
128 {5, 3, 4},
129 {5, 4, 1},
130};
131
144static const std::array<uint4, 12> bone_octahedral_wire_lines_adjacency = {
145 uint4{0, 1, 2, 6},
146 {0, 12, 1, 6},
147 {0, 3, 12, 6},
148 {0, 2, 3, 6},
149 {1, 6, 2, 3},
150 {1, 12, 6, 3},
151 {1, 0, 12, 3},
152 {1, 2, 0, 3},
153 {2, 0, 1, 12},
154 {2, 3, 0, 12},
155 {2, 6, 3, 12},
156 {2, 1, 6, 12},
157};
158
159/* aligned with bone_octahedral_solid_tris */
160static const float bone_octahedral_solid_normals[8][3] = {
161 {M_SQRT1_2, -M_SQRT1_2, 0.00000000f},
162 {-0.00000000f, -M_SQRT1_2, -M_SQRT1_2},
163 {-M_SQRT1_2, -M_SQRT1_2, 0.00000000f},
164 {0.00000000f, -M_SQRT1_2, M_SQRT1_2},
165 {0.99388373f, 0.11043154f, -0.00000000f},
166 {0.00000000f, 0.11043154f, -0.99388373f},
167 {-0.99388373f, 0.11043154f, 0.00000000f},
168 {0.00000000f, 0.11043154f, 0.99388373f},
169};
170
172 Vector<Vertex> &dest, Span<float2> verts, float z, VertexClass flag, bool dashed = false)
173{
174 const int step = dashed ? 2 : 1;
175 for (const int i : IndexRange(verts.size() / step)) {
176 for (const int j : IndexRange(2)) {
177 const float2 &cv = verts[(i * step + j) % verts.size()];
178 dest.append({{cv[0], cv[1], z}, flag});
179 }
180 }
181}
182
183static float light_distance_z_get(char axis, const bool start)
184{
185 switch (axis) {
186 case 'x': /* - X */
187 return start ? 0.4f : 0.3f;
188 case 'X': /* + X */
189 return start ? 0.6f : 0.7f;
190 case 'y': /* - Y */
191 return start ? 1.4f : 1.3f;
192 case 'Y': /* + Y */
193 return start ? 1.6f : 1.7f;
194 case 'z': /* - Z */
195 return start ? 2.4f : 2.3f;
196 case 'Z': /* + Z */
197 return start ? 2.6f : 2.7f;
198 }
199 return 0.0;
200}
201
202/* A single ring of vertices. */
203static Vector<float2> ring_vertices(const float radius,
204 const int segments,
205 const bool half = false)
206{
207 Vector<float2> verts;
208 const float full = (half ? 1.0f : 2.0f) * std::numbers::pi;
209 for (const int angle_i : IndexRange(segments + (half ? 1 : 0))) {
210 const float angle = (full * angle_i) / segments;
211 verts.append(radius * float2(math::cos(angle), math::sin(angle)));
212 }
213 return verts;
214}
215
216/* Returns lines segment geometry forming 3 circles, one on each axis. */
217static Vector<Vertex> sphere_axes_circles(const float radius,
218 const VertexClass vclass,
219 const int segments)
220{
221 Vector<float2> ring = ring_vertices(radius, segments);
222
223 Vector<Vertex> verts;
224 for (int axis : IndexRange(3)) {
225 for (int i : IndexRange(segments)) {
226 for (int j : IndexRange(2)) {
227 float2 cv = ring[(i + j) % segments];
228 if (axis == 0) {
229 verts.append({{cv[0], cv[1], 0.0f}, vclass});
230 }
231 else if (axis == 1) {
232 verts.append({{cv[0], 0.0f, cv[1]}, vclass});
233 }
234 else {
235 verts.append({{0.0f, cv[0], cv[1]}, vclass});
236 }
237 }
238 }
239 }
240 return verts;
241}
242
243static void light_append_direction_line(const char axis,
244 Span<float2> diamond,
245 Vector<Vertex> &verts)
246{
247 const float zsta = light_distance_z_get(axis, true);
248 const float zend = light_distance_z_get(axis, false);
249 verts.append({{0.0, 0.0, zsta}, VCLASS_LIGHT_DIST});
250 verts.append({{0.0, 0.0, zend}, VCLASS_LIGHT_DIST});
253}
254
256{
257 const Vector<float2> diamond = ring_vertices(1.2f, diamond_nsegments);
258 light_append_direction_line('z', diamond, verts);
259}
260
261static VertShaded sphere_lat_lon_vert(const float2 &lat_pt, const float2 &lon_pt)
262{
263 const float x = lon_pt.y * lat_pt.x;
264 const float y = lon_pt.x;
265 const float z = lon_pt.y * lat_pt.y;
266 return VertShaded{{x, y, z}, VCLASS_EMPTY_SCALED, {x, y, z}};
267}
268
269static void append_sphere(Vector<VertShaded> &dest, const eDRWLevelOfDetail level_of_detail)
270{
271 /* Sphere shape resolution */
272 /* Low */
273 constexpr int drw_sphere_shape_latitude_low = 32;
274 constexpr int drw_sphere_shape_longitude_low = 24;
275 /* Medium */
276 constexpr int drw_sphere_shape_latitude_medium = 64;
277 constexpr int drw_sphere_shape_longitude_medium = 48;
278 /* High */
279 constexpr int drw_sphere_shape_latitude_high = 80;
280 constexpr int drw_sphere_shape_longitude_high = 60;
281
282 BLI_assert(level_of_detail >= DRW_LOD_LOW && level_of_detail < DRW_LOD_MAX);
283 const std::array<Vector<float2>, DRW_LOD_MAX> latitude_rings = {
284 ring_vertices(1.0f, drw_sphere_shape_latitude_low),
285 ring_vertices(1.0f, drw_sphere_shape_latitude_medium),
286 ring_vertices(1.0f, drw_sphere_shape_latitude_high)};
287 const std::array<Vector<float2>, DRW_LOD_MAX> longitude_half_rings = {
288 ring_vertices(1.0f, drw_sphere_shape_longitude_low, true),
289 ring_vertices(1.0f, drw_sphere_shape_longitude_medium, true),
290 ring_vertices(1.0f, drw_sphere_shape_longitude_high, true)};
291
292 const Vector<float2> &latitude_ring = latitude_rings[level_of_detail];
293 const Vector<float2> &longitude_half_ring = longitude_half_rings[level_of_detail];
294
295 for (const int i : latitude_ring.index_range()) {
296 const float2 lat_pt = latitude_ring[i];
297 const float2 next_lat_pt = latitude_ring[(i + 1) % latitude_ring.size()];
298 for (const int j : IndexRange(longitude_half_ring.size() - 1)) {
299 const float2 lon_pt = longitude_half_ring[j];
300 const float2 next_lon_pt = longitude_half_ring[j + 1];
301 if (j != 0) { /* Pole */
302 dest.append(sphere_lat_lon_vert(next_lat_pt, next_lon_pt));
303 dest.append(sphere_lat_lon_vert(next_lat_pt, lon_pt));
304 dest.append(sphere_lat_lon_vert(lat_pt, lon_pt));
305 }
306 if (j != longitude_half_ring.index_range().last(1)) { /* Pole */
307 dest.append(sphere_lat_lon_vert(lat_pt, next_lon_pt));
308 dest.append(sphere_lat_lon_vert(next_lat_pt, next_lon_pt));
309 dest.append(sphere_lat_lon_vert(lat_pt, lon_pt));
310 }
311 }
312 }
313}
314
316{
318
319 /* Armature Octahedron. */
320 {
321 Vector<VertShaded> verts;
322 for (int tri = 0; tri < 8; tri++) {
323 for (int v = 0; v < 3; v++) {
327 }
328 }
329 bone_octahedron = BatchPtr(
330 GPU_batch_create_ex(GPU_PRIM_TRIS, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
331 }
332 {
335
336 for (auto line : bone_octahedral_wire_lines_adjacency) {
337 GPU_indexbuf_add_line_adj_verts(&elb, line[0], line[1], line[2], line[3]);
338 }
340
341 /* NOTE: Reuses the same VBO as bone_octahedron. Thus has the same vertex format. */
344 }
345
346 /* Armature Sphere. */
347 {
348 constexpr int resolution = 64;
349 Vector<float2> ring = ring_vertices(0.05f, resolution);
350
351 Vector<Vertex> verts;
352 for (int a : IndexRange(resolution + 1)) {
353 float2 cv = ring[a % resolution];
354 verts.append({{cv.x, cv.y, 0.0f}, VCLASS_EMPTY_SCALED});
355 }
356
358 GPU_PRIM_TRI_FAN, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
359 }
360 {
361 bone_sphere_wire = BatchPtr(
362 GPU_batch_create(GPU_PRIM_LINE_STRIP, bone_sphere.get()->verts[0], nullptr));
363 }
364
365 /* Armature Stick. */
366 {
368 /* Gather as a strip and add to main buffer as a list of triangles. */
369 Vector<VertexBone> vert_strip;
370 vert_strip.append({{0.0f, 1.0f, 0.0f}, StickBoneFlag(bone | POS_HEAD | COL_HEAD | COL_WIRE)});
371 vert_strip.append({{0.0f, 1.0f, 0.0f}, StickBoneFlag(bone | POS_TAIL | COL_TAIL | COL_WIRE)});
372 vert_strip.append({{0.0f, 0.0f, 0.0f}, StickBoneFlag(bone | POS_HEAD | COL_HEAD)});
373 vert_strip.append({{0.0f, 0.0f, 0.0f}, StickBoneFlag(bone | POS_TAIL | COL_TAIL)});
374 vert_strip.append({{0.0f, -1.0f, 0.0f}, StickBoneFlag(bone | POS_HEAD | COL_HEAD | COL_WIRE)});
375 vert_strip.append({{0.0f, -1.0f, 0.0f}, StickBoneFlag(bone | POS_TAIL | COL_TAIL | COL_WIRE)});
376
377 Vector<VertexBone> verts;
378 /* Bone rectangle */
379 for (int t : IndexRange(vert_strip.size() - 2)) {
380 /* NOTE: Don't care about winding.
381 * Theses triangles are facing the camera and should not be backface culled. */
382 verts.append(vert_strip[t]);
383 verts.append(vert_strip[t + 1]);
384 verts.append(vert_strip[t + 2]);
385 }
386
387 constexpr int resolution = 12;
388 Vector<float2> ring = ring_vertices(2.0f, resolution);
389 for (int a : IndexRange(resolution)) {
390 float2 cv1 = ring[a % resolution];
391 float2 cv2 = ring[(a + 1) % resolution];
392 /* Head point. */
393 verts.append({{0.0f, 0.0f, 0.0f}, StickBoneFlag(POS_HEAD | COL_HEAD)});
394 verts.append({{cv1.x, cv1.y, 0.0f}, StickBoneFlag(POS_HEAD | COL_HEAD | COL_WIRE)});
395 verts.append({{cv2.x, cv2.y, 0.0f}, StickBoneFlag(POS_HEAD | COL_HEAD | COL_WIRE)});
396 /* Tail point. */
397 verts.append({{0.0f, 0.0f, 0.0f}, StickBoneFlag(POS_TAIL | COL_TAIL)});
398 verts.append({{cv1.x, cv1.y, 0.0f}, StickBoneFlag(POS_TAIL | COL_TAIL | COL_WIRE)});
399 verts.append({{cv2.x, cv2.y, 0.0f}, StickBoneFlag(POS_TAIL | COL_TAIL | COL_WIRE)});
400 }
401
402 bone_stick = BatchPtr(
403 GPU_batch_create_ex(GPU_PRIM_TRIS, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
404 }
405
406 /* Armature BBones. */
407 {
408 Vector<VertShaded> verts;
409 for (int tri = 0; tri < 12; tri++) {
410 for (int v = 0; v < 3; v++) {
411 verts.append({bone_box_verts[bone_box_solid_tris[tri][v]],
414 }
415 }
416 bone_box = BatchPtr(
417 GPU_batch_create_ex(GPU_PRIM_TRIS, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
418 }
419 {
422
423 for (auto line : bone_box_wire_lines_adjacency) {
424 GPU_indexbuf_add_line_adj_verts(&elb, line[0], line[1], line[2], line[3]);
425 }
427
428 /* NOTE: Reuses the same VBO as bone_box. Thus has the same vertex format. */
430 GPU_PRIM_LINES_ADJ, bone_box.get()->verts[0], ibo, GPU_BATCH_OWNS_INDEX));
431 }
432
433 /* Armature Envelope. */
434 {
435 constexpr int lon_res = 24;
436 constexpr int lat_res = 24;
437 constexpr float lon_inc = 2.0f * M_PI / lon_res;
438 constexpr float lat_inc = M_PI / lat_res;
439
440 auto lat_lon_to_co = [](const float lat, const float lon) {
441 return float3(sinf(lat) * cosf(lon), sinf(lat) * sinf(lon), cosf(lat));
442 };
443
444 Vector<Vertex> verts;
445 float lon = 0.0f;
446 for (int i = 0; i < lon_res; i++, lon += lon_inc) {
447 float lat = 0.0f;
448 /* NOTE: the poles are duplicated on purpose, to restart the strip. */
449 for (int j = 0; j < lat_res; j++, lat += lat_inc) {
450 verts.append({lat_lon_to_co(lat, lon), VCLASS_NONE});
451 verts.append({lat_lon_to_co(lat, lon + lon_inc), VCLASS_NONE});
452 }
453 /* Closing the loop */
454 verts.append({lat_lon_to_co(M_PI, lon), VCLASS_NONE});
455 verts.append({lat_lon_to_co(M_PI, lon + lon_inc), VCLASS_NONE});
456 }
457
459 GPU_PRIM_TRI_STRIP, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
460 }
461 {
462 constexpr int circle_resolution = 64;
463 float2 v0, v1, v2;
464
465 auto circle_pt = [](const float angle) { return float2(sinf(angle), cosf(angle)); };
466
468 /* Output 3 verts for each position. See shader for explanation. */
469 v0 = circle_pt((2.0f * M_PI * -2) / float(circle_resolution));
470 v1 = circle_pt((2.0f * M_PI * -1) / float(circle_resolution));
471 for (int a = 0; a <= circle_resolution; a++, v0 = v1, v1 = v2) {
472 v2 = circle_pt((2.0f * M_PI * a) / float(circle_resolution));
473 verts.append({v0, v1, v2});
474 }
475
477 GPU_PRIM_LINE_STRIP, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
478 }
479
480 /* Degrees of freedom. */
481 {
482 constexpr int resolution = 16;
483
484 Vector<Vertex> verts;
485 auto set_vert = [&](const float x, const float y, const int quarter) {
486 verts.append({{(quarter % 2 == 0) ? -x : x, (quarter < 2) ? -y : y, 0.0f}, VCLASS_NONE});
487 };
488
489 for (int quarter : IndexRange(4)) {
490 float prev_z = 0.0f;
491 for (int i : IndexRange(1, resolution - 1)) {
492 float z = sinf(M_PI_2 * i / float(resolution - 1));
493 float prev_x = 0.0f;
494 for (int j : IndexRange(1, resolution - i)) {
495 float x = sinf(M_PI_2 * j / float(resolution - 1));
496 if (j == resolution - i) {
497 /* Pole triangle. */
498 set_vert(prev_x, z, quarter);
499 set_vert(prev_x, prev_z, quarter);
500 set_vert(x, prev_z, quarter);
501 }
502 else {
503 /* Quad. */
504 set_vert(x, z, quarter);
505 set_vert(x, prev_z, quarter);
506 set_vert(prev_x, z, quarter);
507
508 set_vert(x, prev_z, quarter);
509 set_vert(prev_x, prev_z, quarter);
510 set_vert(prev_x, z, quarter);
511 }
512 prev_x = x;
513 }
514 prev_z = z;
515 }
516 }
517
518 bone_degrees_of_freedom = BatchPtr(
519 GPU_batch_create_ex(GPU_PRIM_TRIS, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
520 }
521 {
522 constexpr int resolution = 16 * 4;
523 Vector<float2> ring = ring_vertices(1.0f, resolution);
524
525 Vector<Vertex> verts;
526 for (int a : IndexRange(resolution + 1)) {
527 float2 cv = ring[a % resolution];
528 verts.append({{cv.x, cv.y, 0.0f}, VCLASS_NONE});
529 }
530
532 GPU_PRIM_LINE_STRIP, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
533 }
534
535 /* quad_wire */
536 {
537 Vector<Vertex> verts;
538 verts.append({{-1.0f, -1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
539 verts.append({{-1.0f, +1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
540 verts.append({{-1.0f, +1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
541 verts.append({{+1.0f, +1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
542 verts.append({{+1.0f, +1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
543 verts.append({{+1.0f, -1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
544 verts.append({{+1.0f, -1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
545 verts.append({{-1.0f, -1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
546
547 quad_wire = BatchPtr(
548 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
549 }
550 /* quad_solid */
551 {
552 const Array<float2> quad = {{-1.0f, 1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f}, {1.0f, -1.0f}};
553 Vector<Vertex> verts;
554 for (const float2 &point : quad) {
555 verts.append({{point, 0.0f}, VCLASS_EMPTY_SCALED});
556 }
558 GPU_PRIM_TRI_STRIP, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
559 }
560 /* plain_axes */
561 {
562 Vector<Vertex> verts;
563 verts.append({{0.0f, -1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
564 verts.append({{0.0f, +1.0f, 0.0f}, VCLASS_EMPTY_SCALED});
565 verts.append({{-1.0f, 0.0f, 0.0f}, VCLASS_EMPTY_SCALED});
566 verts.append({{+1.0f, 0.0f, 0.0f}, VCLASS_EMPTY_SCALED});
567 verts.append({{0.0f, 0.0f, -1.0f}, VCLASS_EMPTY_SCALED});
568 verts.append({{0.0f, 0.0f, +1.0f}, VCLASS_EMPTY_SCALED});
569
570 plain_axes = BatchPtr(
571 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
572 }
573 /* single_arrow */
574 {
575 Vector<Vertex> verts;
576 float p[3][3] = {{0}};
577 p[0][2] = 1.0f;
578 p[1][0] = 0.035f;
579 p[1][1] = 0.035f;
580 p[2][0] = -0.035f;
581 p[2][1] = 0.035f;
582 p[1][2] = p[2][2] = 0.75f;
583 for (int sides : IndexRange(4)) {
584 if (sides % 2 == 1) {
585 p[1][0] = -p[1][0];
586 p[2][1] = -p[2][1];
587 }
588 else {
589 p[1][1] = -p[1][1];
590 p[2][0] = -p[2][0];
591 }
592 for (int i = 0, a = 1; i < 2; i++, a++) {
593 verts.append({{p[i][0], p[i][1], p[i][2]}, VCLASS_EMPTY_SCALED});
594 verts.append({{p[a][0], p[a][1], p[a][2]}, VCLASS_EMPTY_SCALED});
595 }
596 }
597 verts.append({{0.0f, 0.0f, 0.0}, VCLASS_EMPTY_SCALED});
598 verts.append({{0.0f, 0.0f, 0.75f}, VCLASS_EMPTY_SCALED});
599
600 single_arrow = BatchPtr(
601 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
602 }
603 /* cube */
604 {
605 Vector<Vertex> verts;
606 for (auto index : bone_box_wire_lines) {
607 float x = bone_box_verts[index][0];
608 float y = bone_box_verts[index][1] * 2.0 - 1.0f;
609 float z = bone_box_verts[index][2];
610 verts.append({{x, y, z}, VCLASS_EMPTY_SCALED});
611 }
612
613 cube = BatchPtr(
614 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
615 }
616 /* cube_solid */
617 {
618 cube_solid = BatchPtr(GPU_batch_unit_cube());
619 }
620 /* circle */
621 {
622 constexpr int resolution = 64;
623 Vector<float2> ring = ring_vertices(1.0f, resolution);
624
625 Vector<Vertex> verts;
626 for (int a : IndexRange(resolution + 1)) {
627 float2 cv1 = ring[(a + 0) % resolution];
628 float2 cv2 = ring[(a + 1) % resolution];
629 verts.append({{cv1.x, 0.0f, cv1.y}, VCLASS_EMPTY_SCALED});
630 verts.append({{cv2.x, 0.0f, cv2.y}, VCLASS_EMPTY_SCALED});
631 }
632
633 circle = BatchPtr(
634 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
635 }
636 /* empty_sphere */
637 {
639
640 empty_sphere = BatchPtr(
641 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
642 }
643 /* empty_cone */
644 {
645 constexpr int resolution = 8;
646 Vector<float2> ring = ring_vertices(1.0f, resolution);
647
648 Vector<Vertex> verts;
649 for (int i : IndexRange(resolution)) {
650 float2 cv = ring[i % resolution];
651 /* Cone sides. */
652 verts.append({{cv[0], 0.0f, cv[1]}, VCLASS_EMPTY_SCALED});
653 verts.append({{0.0f, 2.0f, 0.0f}, VCLASS_EMPTY_SCALED});
654 /* Base ring. */
655 for (int j : IndexRange(2)) {
656 float2 cv = ring[(i + j) % resolution];
657 verts.append({{cv[0], 0.0f, cv[1]}, VCLASS_EMPTY_SCALED});
658 }
659 }
660
661 empty_cone = BatchPtr(
662 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
663 }
664 /* cylinder */
665 {
666 constexpr int n_segments = 12;
667 const Vector<float2> ring = ring_vertices(1.0f, n_segments);
668 Vector<Vertex> verts;
669 /* top ring */
670 append_line_loop(verts, ring, 1.0f, VCLASS_EMPTY_SCALED);
671 /* bottom ring */
672 append_line_loop(verts, ring, -1.0f, VCLASS_EMPTY_SCALED);
673 /* cylinder sides */
674 for (const float2 &point : ring) {
675 verts.append({{point.x, point.y, 1.0f}, VCLASS_EMPTY_SCALED});
676 verts.append({{point.x, point.y, -1.0f}, VCLASS_EMPTY_SCALED});
677 }
678 cylinder = BatchPtr(
679 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
680 }
681 /* capsule body */
682 {
683 const Vector<float2> diamond = ring_vertices(1.0f, 4);
684 Vector<Vertex> verts;
685 for (const float2 &point : diamond) {
686 verts.append({{point.x, point.y, 1.0f}, VCLASS_NONE});
687 verts.append({{point.x, point.y, 0.0f}, VCLASS_NONE});
688 }
689 capsule_body = BatchPtr(
690 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
691 }
692 /* capsule cap */
693 {
694 constexpr int n_segments = 24;
695 const Vector<float2> ring = ring_vertices(1.0f, n_segments);
696 Vector<Vertex> verts;
697 /* Base circle */
698 append_line_loop(verts, ring, 0.0f, VCLASS_NONE);
699 for (const int i : IndexRange(n_segments / 2)) {
700 const float2 &point = ring[i];
701 const float2 &next_point = ring[i + 1];
702 /* Y half circle */
703 verts.append({{point.x, 0.0f, point.y}, VCLASS_NONE});
704 verts.append({{next_point.x, 0.0f, next_point.y}, VCLASS_NONE});
705 /* X half circle */
706 verts.append({{0.0f, point.x, point.y}, VCLASS_NONE});
707 verts.append({{0.0f, next_point.x, next_point.y}, VCLASS_NONE});
708 }
709 capsule_cap = BatchPtr(
710 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
711 }
712 /* arrows */
713 {
714 float2 x_axis_name_scale = {0.0215f, 0.025f};
715 Vector<float2> x_axis_name = {
716 float2(0.9f, 1.0f) * x_axis_name_scale,
717 float2(-1.0f, -1.0f) * x_axis_name_scale,
718 float2(-0.9f, 1.0f) * x_axis_name_scale,
719 float2(1.0f, -1.0f) * x_axis_name_scale,
720 };
721
722 float2 y_axis_name_scale = {0.0175f, 0.025f};
723 Vector<float2> y_axis_name = {
724 float2(-1.0f, 1.0f) * y_axis_name_scale,
725 float2(0.0f, -0.1f) * y_axis_name_scale,
726 float2(1.0f, 1.0f) * y_axis_name_scale,
727 float2(0.0f, -0.1f) * y_axis_name_scale,
728 float2(0.0f, -0.1f) * y_axis_name_scale,
729 float2(0.0f, -1.0f) * y_axis_name_scale,
730 };
731
732 float2 z_axis_name_scale = {0.02f, 0.025f};
733 Vector<float2> z_axis_name = {
734 float2(-0.95f, 1.00f) * z_axis_name_scale,
735 float2(0.95f, 1.00f) * z_axis_name_scale,
736 float2(0.95f, 1.00f) * z_axis_name_scale,
737 float2(0.95f, 0.90f) * z_axis_name_scale,
738 float2(0.95f, 0.90f) * z_axis_name_scale,
739 float2(-1.00f, -0.90f) * z_axis_name_scale,
740 float2(-1.00f, -0.90f) * z_axis_name_scale,
741 float2(-1.00f, -1.00f) * z_axis_name_scale,
742 float2(-1.00f, -1.00f) * z_axis_name_scale,
743 float2(1.00f, -1.00f) * z_axis_name_scale,
744 };
745
746 float2 axis_marker_scale = {0.007f, 0.007f};
747 Vector<float2> axis_marker = {
748#if 0 /* square */
749 float2(-1.0f, 1.0f) * axis_marker_scale,
750 float2(1.0f, 1.0f) * axis_marker_scale,
751 float2(1.0f, 1.0f) * axis_marker_scale,
752 float2(1.0f, -1.0f) * axis_marker_scale,
753 float2(1.0f, -1.0f) * axis_marker_scale,
754 float2(-1.0f, -1.0f) * axis_marker_scale,
755 float2(-1.0f, -1.0f) * axis_marker_scale,
756 float2(-1.0f, 1.0f) * axis_marker_scale,
757#else /* diamond */
758 float2(-1.0f, 0.0f) * axis_marker_scale,
759 float2(0.0f, 1.0f) * axis_marker_scale,
760 float2(0.0f, 1.0f) * axis_marker_scale,
761 float2(1.0f, 0.0f) * axis_marker_scale,
762 float2(1.0f, 0.0f) * axis_marker_scale,
763 float2(0.0f, -1.0f) * axis_marker_scale,
764 float2(0.0f, -1.0f) * axis_marker_scale,
765 float2(-1.0f, 0.0f) * axis_marker_scale,
766#endif
767 };
768
769 Vector<Vertex> verts;
770 for (int axis : IndexRange(3)) {
771 /* Vertex layout is XY screen position and axis in Z.
772 * Fractional part of Z is a positive offset at axis unit position. */
774 /* Center to axis line. */
775 /* NOTE: overlay_armature_shape_wire_vert.glsl expects the axis verts at the origin to be the
776 * only ones with this coordinates (it derives the VCLASS from it). */
777 float pos_on_axis = float(axis) + 1e-8f;
778 verts.append({{0.0f, 0.0f, 0.0f}, VCLASS_NONE});
779 verts.append({{0.0f, 0.0f, pos_on_axis}, flag});
780 /* Axis end marker. */
781 constexpr int marker_fill_layer = 6;
782 for (int j = 1; j < marker_fill_layer + 1; j++) {
783 for (float2 axis_marker_vert : axis_marker) {
784 verts.append({{axis_marker_vert * ((4.0f * j) / marker_fill_layer), pos_on_axis}, flag});
785 }
786 }
787 /* Axis name. */
788 const Vector<float2> *axis_names[3] = {&x_axis_name, &y_axis_name, &z_axis_name};
789 for (float2 axis_name_vert : *(axis_names[axis])) {
791 verts.append({{axis_name_vert * 4.0f, pos_on_axis + 0.25f}, flag});
792 }
793 }
794 arrows = BatchPtr(
795 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
796 }
797 /* metaball_wire_circle */
798 {
799 constexpr int resolution = 64;
800 constexpr float radius = 1.0f;
801 Vector<float2> ring = ring_vertices(radius, resolution);
802
803 Vector<Vertex> verts;
804 for (int i : IndexRange(resolution + 1)) {
805 float2 cv = ring[i % resolution];
806 verts.append({{cv[0], cv[1], 0.0f}, VCLASS_SCREENALIGNED});
807 }
809 GPU_PRIM_LINE_STRIP, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
810 };
811 /* speaker */
812 {
813 constexpr int segments = 16;
814 constexpr float bottom_r = 0.5f;
815 constexpr float bottom_z = -0.125f;
816 constexpr float step_z = 0.25f;
817 const Vector<float2> diamond = ring_vertices(bottom_r, 4);
818 Vector<float2> ring = ring_vertices(bottom_r, segments);
819 Vector<Vertex> verts;
820
821 append_line_loop(verts, ring, bottom_z, VCLASS_NONE);
822 for (float2 &point : ring) {
823 point *= 0.5f;
824 }
825 for (const int j : IndexRange(1, 2)) {
826 const float z = step_z * j + bottom_z;
827 append_line_loop(verts, ring, z, VCLASS_NONE);
828 }
829
830 for (const float2 &point : diamond) {
831 Vertex vertex{float3(point, bottom_z)};
832 verts.append(vertex);
833 vertex.pos = float3(point * 0.5f, bottom_z + step_z);
834 verts.append(vertex);
835 verts.append(vertex);
836 vertex.pos.z += step_z;
837 verts.append(vertex);
838 }
839 speaker = BatchPtr(
840 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
841 }
842 /* camera distances */
843 {
844 const Vector<float2> diamond = ring_vertices(1.5f, 5);
845 const Vector<float2> cross = {{1.0f, 0.0f}, {-1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, -1.0f}};
846
847 Vector<Vertex> verts;
848 verts.append({{0.0f, 0.0f, 0.0f}, VCLASS_CAMERA_DIST});
849 verts.append({{0.0f, 0.0f, 1.0f}, VCLASS_CAMERA_DIST});
850
853
854 /* Focus cross */
855 for (const float2 &point : cross) {
856 verts.append({{point.x, point.y, 2.0f}, VCLASS_CAMERA_DIST});
857 }
858 camera_distances = BatchPtr(
859 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
860 }
861 /* camera frame */
862 {
863 const Vector<float2> rect{{-1.0f, -1.0f}, {-1.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, -1.0f}};
864 Vector<Vertex> verts;
865 /* Frame */
866 append_line_loop(verts, rect, 1.0f, VCLASS_CAMERA_FRAME);
867 /* Wires to origin. */
868 for (const float2 &point : rect) {
869 verts.append({{point.x, point.y, 1.0f}, VCLASS_CAMERA_FRAME});
870 verts.append({{point.x, point.y, 0.0f}, VCLASS_CAMERA_FRAME});
871 }
872 camera_frame = BatchPtr(
873 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
874 }
875 /* camera tria */
876 {
877 const Vector<float2> triangle = {{-1.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}};
878 Vector<Vertex> verts;
879 /* Wire */
880 append_line_loop(verts, triangle, 1.0f, VCLASS_CAMERA_FRAME);
881 camera_tria_wire = BatchPtr(
882 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
883
884 verts.clear();
885 /* Triangle */
886 for (const float2 &point : triangle) {
887 verts.append({{point.x, point.y, 1.0f}, VCLASS_CAMERA_FRAME});
888 }
889 camera_tria = BatchPtr(
890 GPU_batch_create_ex(GPU_PRIM_TRIS, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
891 }
892 /* camera volume */
893 {
894 Vector<Vertex> verts;
895 for (const uint3 &tri : bone_box_solid_tris) {
896 for (const int i : IndexRange(uint3::type_length)) {
897 const int v = tri[i];
898 const float x = bone_box_verts[v][2];
899 const float y = bone_box_verts[v][0];
900 const float z = bone_box_verts[v][1];
901 verts.append({{x, y, z}, VCLASS_CAMERA_FRAME | VCLASS_CAMERA_VOLUME});
902 }
903 }
904 camera_volume = BatchPtr(
905 GPU_batch_create_ex(GPU_PRIM_TRIS, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
906 }
907 /* camera volume wire */
908 {
909 Vector<Vertex> verts;
910 for (int i : bone_box_wire_lines) {
911 const float x = bone_box_verts[i][2];
912 const float y = bone_box_verts[i][0];
913 const float z = bone_box_verts[i][1];
914 verts.append({{x, y, z}, VCLASS_CAMERA_FRAME | VCLASS_CAMERA_VOLUME});
915 }
916 camera_volume_wire = BatchPtr(
917 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
918 }
919 /* spheres */
920 {
921 Vector<VertShaded> verts;
923 sphere_low_detail = BatchPtr(
924 GPU_batch_create_ex(GPU_PRIM_TRIS, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
925 }
926 /* ground line */
927 {
929
930 Vector<Vertex> verts;
931 /* Ground Point */
932 append_line_loop(verts, ring, 0.0f, VCLASS_NONE);
933 /* Ground Line */
934 verts.append({{0.0, 0.0, 1.0}, VCLASS_NONE});
935 verts.append({{0.0, 0.0, 0.0}, VCLASS_NONE});
936
937 ground_line = BatchPtr(
938 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
939 }
940 /* image_quad */
941 {
942 const Array<float2> quad = {{0.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 0.0f}};
943 Vector<Vertex> verts;
944 for (const float2 &point : quad) {
945 verts.append({{point, 0.75f}, VCLASS_NONE});
946 }
948 GPU_PRIM_TRI_STRIP, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
949 }
950 /* light spot volume */
951 {
952 Vector<Vertex> verts;
953
954 /* Cone apex */
955 verts.append({{0.0f, 0.0f, 0.0f}, VCLASS_NONE});
956 /* Cone silhouette */
957 for (const int angle_i : IndexRange(circle_nsegments + 1)) {
958 const float angle = (2.0f * std::numbers::pi * angle_i) / circle_nsegments;
959 const float s = sinf(-angle);
960 const float c = cosf(-angle);
961 verts.append({{s, c, -1.0f}, VCLASS_LIGHT_SPOT_SHAPE});
962 }
964 GPU_PRIM_TRI_FAN, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
965 }
966 /* light icon outer lines */
967 {
968 constexpr float r = 9.0f;
969 const Vector<float2> ring = ring_vertices(r * 1.33f, outer_nsegments * 2);
970
971 Vector<Vertex> verts;
972 append_line_loop(verts, ring, 0.0f, VCLASS_SCREENSPACE, true);
973 light_icon_outer_lines = BatchPtr(
974 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
975 }
976 /* light icon inner lines */
977 {
978 constexpr float r = 9.0f;
979 const Vector<float2> diamond = ring_vertices(r * 0.3f, diamond_nsegments);
980 const Vector<float2> ring = ring_vertices(r, inner_nsegments * 2);
981
982 Vector<Vertex> verts;
983 append_line_loop(verts, diamond, 0.0f, VCLASS_SCREENSPACE);
984 append_line_loop(verts, ring, 0.0f, VCLASS_SCREENSPACE, true);
985
986 light_icon_inner_lines = BatchPtr(
987 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
988 }
989 /* light icon sun rays */
990 {
991 constexpr int num_rays = 8;
992 constexpr float r = 9.0f;
993 const Vector<float2> ring = ring_vertices(r, num_rays);
994 const std::array<float, 4> scales{1.6f, 1.9f, 2.2f, 2.5f};
995
996 Vector<Vertex> verts;
997 for (const float2 &point : ring) {
998 for (float scale : scales) {
999 float2 scaled = point * scale;
1000 verts.append({{scaled.x, scaled.y, 0.0f}, VCLASS_SCREENSPACE});
1001 }
1002 }
1003 light_icon_sun_rays = BatchPtr(
1004 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1005 }
1006 /* light point lines */
1007 {
1008 const Vector<float2> ring = ring_vertices(1.0f, circle_nsegments);
1009
1010 Vector<Vertex> verts;
1012 light_point_lines = BatchPtr(
1013 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1014 }
1015 /* light sun lines */
1016 {
1017 Vector<Vertex> verts;
1018 /* Direction Line */
1019 verts.append({{0.0, 0.0, 0.0}, VCLASS_NONE});
1020 verts.append({{0.0, 0.0, -20.0}, VCLASS_NONE}); /* Good default. */
1021 light_sun_lines = BatchPtr(
1022 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1023 }
1024 /* light spot lines */
1025 {
1026 const Vector<float2> ring = ring_vertices(1.0f, circle_nsegments);
1027
1028 Vector<Vertex> verts;
1029 /* Light area */
1031 /* Cone cap */
1032 append_line_loop(verts, ring, 0.0f, VCLASS_LIGHT_SPOT_SHAPE);
1034 /* Cone silhouette */
1035 for (const float2 &point : ring) {
1036 verts.append({{0.0f, 0.0f, 0.0f}, VCLASS_NONE});
1037 verts.append({{point.x, point.y, -1.0f}, VCLASS_LIGHT_SPOT_SHAPE | VCLASS_LIGHT_SPOT_CONE});
1038 }
1039
1041
1042 light_spot_lines = BatchPtr(
1043 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1044 }
1045 /* light area disk lines */
1046 {
1047 const Vector<float2> ring = ring_vertices(0.5f, circle_nsegments);
1048
1049 Vector<Vertex> verts;
1050 /* Light area */
1051 append_line_loop(verts, ring, 0.0f, VCLASS_LIGHT_AREA_SHAPE);
1052
1054
1055 light_area_disk_lines = BatchPtr(
1056 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1057 }
1058 /* light area square lines */
1059 {
1060 const Array<float2> rect{{-0.5f, -0.5f}, {-0.5f, 0.5f}, {0.5f, 0.5f}, {0.5f, -0.5f}};
1061
1062 Vector<Vertex> verts;
1063 /* Light area */
1064 append_line_loop(verts, rect, 0.0f, VCLASS_LIGHT_AREA_SHAPE);
1065
1067
1068 light_area_square_lines = BatchPtr(
1069 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1070 }
1071 /* field_force */
1072 {
1073 constexpr int circle_resol = 32;
1075 constexpr std::array<float, 2> scales{2.0f, 0.75};
1076 Vector<float2> ring = ring_vertices(1.0f, circle_resol);
1077
1078 Vector<Vertex> verts;
1079
1080 append_line_loop(verts, ring, 0.0f, flag);
1081 for (const float scale : scales) {
1082 for (float2 &point : ring) {
1083 point *= scale;
1084 }
1085 append_line_loop(verts, ring, 0.0f, flag);
1086 }
1087
1088 field_force = BatchPtr(
1089 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1090 }
1091 /* field_wind */
1092 {
1093 constexpr int circle_resol = 32;
1094 const Vector<float2> ring = ring_vertices(1.0f, circle_resol);
1095
1096 Vector<Vertex> verts;
1097
1098 for (const int i : IndexRange(4)) {
1099 const float z = 0.05f * float(i);
1100 append_line_loop(verts, ring, z, VCLASS_EMPTY_SIZE);
1101 }
1102
1103 field_wind = BatchPtr(
1104 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1105 }
1106 /* field_vortex */
1107 {
1108 constexpr int spiral_resol = 32;
1109 const Vector<float2> ring = ring_vertices(1.0f, spiral_resol);
1110
1111 Vector<Vertex> verts;
1112
1113 for (const int i : IndexRange(ring.size() * 2 + 1)) {
1114 /* r: [-1, .., 0, .., 1] */
1115 const float r = (i - spiral_resol) / float(spiral_resol);
1116 /* index: [9, spiral_resol - 1, spiral_resol - 2, .., 2, 1, 0, 1, 2, .., spiral_resol - 1, 0]
1117 */
1118 const float2 point = ring[abs(spiral_resol - i) % spiral_resol] * r;
1119 verts.append({float3(point.y, point.x, 0.0f), VCLASS_EMPTY_SIZE});
1120 }
1122 GPU_PRIM_LINE_STRIP, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1123 }
1124 /* field_curve */
1125 {
1126 constexpr int circle_resol = 32;
1127 const Vector<float2> ring = ring_vertices(1.0f, circle_resol);
1128
1129 Vector<Vertex> verts;
1130
1132
1133 field_curve = BatchPtr(
1134 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1135 }
1136 /* field_sphere_limit */
1137 {
1138 constexpr int circle_resol = 32 * 2;
1139 const Vector<float2> ring = ring_vertices(1.0f, circle_resol);
1140
1141 Vector<Vertex> verts;
1142
1143 append_line_loop(verts, ring, 0.0f, VCLASS_EMPTY_SIZE | VCLASS_SCREENALIGNED, true);
1144
1145 field_sphere_limit = BatchPtr(
1146 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1147 }
1148 /* field_tube_limit */
1149 {
1150 constexpr int circle_resol = 32;
1151 constexpr int side_stipple = 32;
1152 const Vector<float2> ring = ring_vertices(1.0f, circle_resol);
1153 const Vector<float2> diamond = ring_vertices(1.0f, 4);
1154
1155 Vector<Vertex> verts;
1156
1157 /* Caps */
1158 for (const int i : IndexRange(2)) {
1159 const float z = i * 2.0f - 1.0f;
1160 append_line_loop(verts, ring, z, VCLASS_EMPTY_SIZE, true);
1161 }
1162 /* Side Edges */
1163 for (const float2 &point : diamond) {
1164 for (const int i : IndexRange(side_stipple)) {
1165 const float z = (i / float(side_stipple)) * 2.0f - 1.0f;
1166 verts.append({float3(point.y, point.x, z), VCLASS_EMPTY_SIZE});
1167 }
1168 }
1169
1170 field_tube_limit = BatchPtr(
1171 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1172 }
1173 /* field_cone_limit */
1174 {
1175 constexpr int circle_resol = 32;
1176 constexpr int side_stipple = 32;
1177 const Vector<float2> ring = ring_vertices(1.0f, circle_resol);
1178 const Vector<float2> diamond = ring_vertices(1.0f, 4);
1179
1180 Vector<Vertex> verts;
1181
1182 /* Caps */
1183 for (const int i : IndexRange(2)) {
1184 const float z = i * 2.0f - 1.0f;
1185 append_line_loop(verts, ring, z, VCLASS_EMPTY_SIZE, true);
1186 }
1187 /* Side Edges */
1188 for (const float2 &point : diamond) {
1189 for (const int i : IndexRange(side_stipple)) {
1190 const float z = (i / float(side_stipple)) * 2.0f - 1.0f;
1191 verts.append({float3(point.y * z, point.x * z, z), VCLASS_EMPTY_SIZE});
1192 }
1193 }
1194
1195 field_cone_limit = BatchPtr(
1196 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1197 }
1198 /* lightprobe_cube */
1199 {
1200 constexpr float r = 14.0f;
1201 constexpr VertexClass flag = VCLASS_SCREENSPACE;
1202 /* Icon */
1203 constexpr float sin_pi_3 = 0.86602540378f;
1204 constexpr float cos_pi_3 = 0.5f;
1205 const Array<float2, 6> points = {
1206 float2(0.0f, 1.0f) * r,
1207 float2(sin_pi_3, cos_pi_3) * r,
1208 float2(sin_pi_3, -cos_pi_3) * r,
1209 float2(0.0f, -1.0f) * r,
1210 float2(-sin_pi_3, -cos_pi_3) * r,
1211 float2(-sin_pi_3, cos_pi_3) * r,
1212 };
1213
1214 Vector<Vertex> verts;
1215
1216 append_line_loop(verts, points, 0.0f, flag);
1217 for (const int i : IndexRange(3)) {
1218 const float2 &point = points[i * 2 + 1];
1219 verts.append(Vertex{{point, 0.0f}, flag});
1220 verts.append(Vertex{{0.0f, 0.0f, 0.0f}, flag});
1221 }
1222
1223 /* Direction Lines */
1224 const Vector<float2> diamond = ring_vertices(1.2f, diamond_nsegments);
1225 const std::string axes = "zZyYxX";
1226 for (const char axis : axes) {
1227 light_append_direction_line(axis, diamond, verts);
1228 }
1229
1230 lightprobe_cube = BatchPtr(
1231 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1232 }
1233 /* lightprobe_planar */
1234 {
1235 constexpr float r = 20.0f;
1236 /* Icon */
1237 constexpr float sin_pi_3 = 0.86602540378f;
1238 const Array<float2, 4> points = {
1239 float2(0.0f, 0.5f) * r,
1240 float2(sin_pi_3, 0.0f) * r,
1241 float2(0.0f, -0.5f) * r,
1242 float2(-sin_pi_3, 0.0f) * r,
1243 };
1244
1245 Vector<Vertex> verts;
1246
1247 append_line_loop(verts, points, 0.0f, VCLASS_SCREENSPACE);
1248 lightprobe_planar = BatchPtr(
1249 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1250 }
1251 /* lightprobe_grid */
1252 {
1253 constexpr float r = 14.0f;
1254 constexpr VertexClass flag = VCLASS_SCREENSPACE;
1255 /* Icon */
1256 constexpr float sin_pi_3 = 0.86602540378f;
1257 constexpr float cos_pi_3 = 0.5f;
1258 const Array<float2, 6> points = {float2(0.0f, 1.0f) * r,
1259 float2(sin_pi_3, cos_pi_3) * r,
1260 float2(sin_pi_3, -cos_pi_3) * r,
1261 float2(0.0f, -1.0f) * r,
1262 float2(-sin_pi_3, -cos_pi_3) * r,
1263 float2(-sin_pi_3, cos_pi_3) * r};
1264 Vector<Vertex> verts;
1265
1266 append_line_loop(verts, points, 0.0f, flag);
1267 /* Internal wires. */
1268 for (const int i : IndexRange(6)) {
1269 const float2 tr = points[(i / 2) * 2 + 1] * -0.5f;
1270 const float2 t1 = points[i] + tr;
1271 const float2 t2 = points[(i + 1) % 6] + tr;
1272 verts.append({{t1, 0.0f}, flag});
1273 verts.append({{t2, 0.0f}, flag});
1274 }
1275 for (const int i : IndexRange(3)) {
1276 const float2 &point = points[i * 2 + 1];
1277 verts.append(Vertex{{point, 0.0f}, flag});
1278 verts.append(Vertex{{0.0f, 0.0f, 0.0f}, flag});
1279 }
1280 /* Direction Lines */
1281 const Vector<float2> diamond = ring_vertices(1.2f, diamond_nsegments);
1282 const std::string axes = "zZyYxX";
1283 for (const char axis : axes) {
1284 light_append_direction_line(axis, diamond, verts);
1285 }
1286
1287 lightprobe_grid = BatchPtr(
1288 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1289 }
1290 /* grid */
1291 {
1292 constexpr int resolution = 8;
1293 std::array<float, resolution + 1> steps;
1294 /* [-1, 1] divided into "resolution" steps. */
1295 for (const int i : IndexRange(resolution + 1)) {
1296 steps[i] = -1.0f + float(i * 2) / resolution;
1297 }
1298
1299 Vector<Vertex> verts;
1300 verts.reserve(resolution * resolution * 6);
1301 for (const int x : IndexRange(resolution)) {
1302 for (const int y : IndexRange(resolution)) {
1303 verts.append(Vertex{{steps[x], steps[y], 0.0f}});
1304 verts.append(Vertex{{steps[x + 1], steps[y], 0.0f}});
1305 verts.append(Vertex{{steps[x], steps[y + 1], 0.0f}});
1306
1307 verts.append(Vertex{{steps[x], steps[y + 1], 0.0f}});
1308 verts.append(Vertex{{steps[x + 1], steps[y], 0.0f}});
1309 verts.append(Vertex{{steps[x + 1], steps[y + 1], 0.0f}});
1310 }
1311 }
1312 grid = BatchPtr(
1313 GPU_batch_create_ex(GPU_PRIM_TRIS, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1314 }
1315 /* cursor circle */
1316 {
1317 const int segments = 12;
1318 const float radius = 0.5f;
1319 const float color_primary[3] = {1.0f, 0.0f, 0.0f};
1320 const float color_secondary[3] = {1.0f, 1.0f, 1.0f};
1321
1323
1324 for (int i = 0; i < segments + 1; i++) {
1325 float angle = float(2 * M_PI) * (float(i) / float(segments));
1326 verts.append({radius * float3(cosf(angle), sinf(angle), 0.0f),
1327 (i % 2 == 0) ? color_secondary : color_primary});
1328 }
1329
1331 GPU_PRIM_LINE_STRIP, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1332 }
1333 /* cursor lines */
1334 {
1335 const float outer_limit = 1.0f;
1336 const float color_limit = 0.85f;
1337 const float inner_limit = 0.25f;
1338 const std::array<int, 3> axis_theme = {TH_AXIS_X, TH_AXIS_Y, TH_AXIS_Z};
1339
1340 float crosshair_color[3];
1341
1343
1344 for (int i = 0; i < 3; i++) {
1345 float3 axis(0.0f);
1346 axis[i] = 1.0f;
1347 /* Draw the positive axes. */
1348 ui::theme::get_color_3fv(axis_theme[i], crosshair_color);
1349 verts.append({outer_limit * axis, crosshair_color});
1350 verts.append({color_limit * axis, crosshair_color});
1351
1352 /* Inner crosshair. */
1353 ui::theme::get_color_3fv(TH_VIEW_OVERLAY, crosshair_color);
1354 verts.append({color_limit * axis, crosshair_color});
1355 verts.append({inner_limit * axis, crosshair_color});
1356
1357 /* Draw the negative axis a little darker and desaturated. */
1358 axis[i] = -1.0f;
1359 ui::theme::get_color_blend_shade_3fv(axis_theme[i], TH_WHITE, .25f, -60, crosshair_color);
1360 verts.append({outer_limit * axis, crosshair_color});
1361 verts.append({color_limit * axis, crosshair_color});
1362
1363 /* Inner crosshair. */
1364 ui::theme::get_color_3fv(TH_VIEW_OVERLAY, crosshair_color);
1365 verts.append({color_limit * axis, crosshair_color});
1366 verts.append({inner_limit * axis, crosshair_color});
1367 }
1368
1369 cursor_lines = BatchPtr(
1370 GPU_batch_create_ex(GPU_PRIM_LINES, vbo_from_vector(verts), nullptr, GPU_BATCH_OWNS_VBO));
1371 }
1372}
1373
1374} // namespace blender::draw::overlay
#define M_PI_2
#define M_SQRT1_2
#define M_PI
#define GPU_batch_create(primitive_type, vertex_buf, index_buf)
Definition GPU_batch.hh:143
#define UNUSED_VARS(...)
btMatrix3x3 scaled(const btVector3 &s) const
Create a scaled copy of the matrix.
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
constexpr IndexRange()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
Definition half.h:29
#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_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
#define vertex
#define abs
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
float3x3 scale(float3x3 mat, float2 scale)
static const std::array< uint3, 12 > bone_box_solid_tris
static const std::array< float3, 12 > bone_box_solid_normals
static constexpr int circle_nsegments
static Vector< float2 > ring_vertices(const float radius, const int segments, const bool half=false)
static const float bone_octahedral_solid_normals[8][3]
static const std::array< float3, 6 > bone_octahedral_verts
static float light_distance_z_get(char axis, const bool start)
static constexpr int inner_nsegments
static constexpr float bone_box_verts[8][3]
static constexpr int diamond_nsegments
static const std::array< uint3, 8 > bone_octahedral_solid_tris
static const std::array< uint2, 12 > bone_octahedral_wire_lines
static void light_append_direction_line(const char axis, Span< float2 > diamond, Vector< Vertex > &verts)
static void append_sphere(Vector< VertShaded > &dest, const eDRWLevelOfDetail level_of_detail)
static constexpr std::array< uint, 24 > bone_box_wire_lines
static VertShaded sphere_lat_lon_vert(const float2 &lat_pt, const float2 &lon_pt)
static const std::array< uint4, 12 > bone_box_wire_lines_adjacency
static Vector< Vertex > sphere_axes_circles(const float radius, const VertexClass vclass, const int segments)
static void append_line_loop(Vector< Vertex > &dest, Span< float2 > verts, float z, VertexClass flag, bool dashed=false)
static constexpr int outer_nsegments
static const std::array< uint4, 12 > bone_octahedral_wire_lines_adjacency
T cos(const AngleRadianBase< T > &a)
T sin(const AngleRadianBase< T > &a)
void get_color_3fv(int colorid, float col[3])
void get_color_blend_shade_3fv(int colorid1, int colorid2, float fac, int offset, float col[3])
VecBase< uint32_t, 2 > uint2
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
Definition gpu_batch.cc:53
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
VecBase< uint32_t, 4 > uint4
@ GPU_PRIM_TRI_STRIP
@ GPU_PRIM_LINES_ADJ
@ GPU_PRIM_LINE_STRIP
gpu::Batch * GPU_batch_unit_cube() ATTR_WARN_UNUSED_RESULT
void GPU_indexbuf_add_line_adj_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3, uint v4)
VecBase< uint32_t, 3 > uint3
ATTR_WARN_UNUSED_RESULT const BMVert * v
gpu::IndexBuf * GPU_indexbuf_build(GPUIndexBufBuilder *)
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:44
@ GPU_BATCH_OWNS_INDEX
Definition GPU_batch.hh:48
ATTR_WARN_UNUSED_RESULT const BMVert * v2
#define sinf
#define cosf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
int size() const
Definition vector.hh:130
void reserve(int new_size)
Definition vector.hh:78