Blender V5.3
overlay_armature.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "draw_view.bsl.hh"
13#include "overlay_common.bsl.hh"
14
16
17struct Armature {
19};
20
21/* -------------------------------------------------------------------- */
24
26
27struct Resources {
28 [[storage(0, read)]] const ExtraInstanceData (&data_buf)[];
29};
30
31struct VertIn {
33};
34
35float3 sphere_project(float ax, float az)
36{
37 float sine = 1.0f - ax * ax - az * az;
38 float q3 = sqrt(max(0.0f, sine));
39
40 return float3(-az * q3, 0.5f - sine, ax * q3) * 2.0f;
41}
42
43[[vertex]]
44void vert([[resource_table]] const Resources &srt,
46 [[resource_table]] const Uniform &uni,
47 [[resource_table]] const Clipping &clip,
48 [[resource_table]] const draw::View &views,
49 [[instance_index]] const int inst_index,
50 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
51 [[in]] const VertIn &v_in,
52 [[out]] VertOut &v_out,
53 [[position]] float4 &out_pos)
54{
55 float4x4 inst_obmat = srt.data_buf[inst_index].object_to_world;
56 float4x4 model_mat = inst_obmat;
57 model_mat[0][3] = model_mat[1][3] = model_mat[2][3] = 0.0f;
58 model_mat[3][3] = 1.0f;
59
60 float2 amin = float2(inst_obmat[0][3], inst_obmat[1][3]);
61 float2 amax = float2(inst_obmat[2][3], inst_obmat[3][3]);
62
63 float3 final_pos = sphere_project(v_in.pos.x * abs((v_in.pos.x > 0.0f) ? amax.x : amin.x),
64 v_in.pos.y * abs((v_in.pos.y > 0.0f) ? amax.y : amin.y));
65
66 float3 world_pos = (model_mat * float4(final_pos, 1.0f)).xyz;
67
68 ViewMatrices view = views.get(0);
69 out_pos = view.point_world_to_homogenous(world_pos);
70 v_out.final_color = srt.data_buf[inst_index].color_;
71 v_out.final_color.a *= armature.alpha;
72
73 v_out.edge_start = v_out.edge_pos = ((out_pos.xy / out_pos.w) * 0.5f + 0.5f) *
74 uni.uniform_buf.size_viewport;
75
76 if (clip.constants.use_clipping) [[static_branch]] {
77 clip.set_clipping_distances(world_pos,
78 clip_distances[0],
79 clip_distances[1],
80 clip_distances[2],
81 clip_distances[3],
82 clip_distances[4],
83 clip_distances[5]);
84 }
85}
86
87/* TODO(fclem): Deduplicate. */
88[[fragment]]
89void frag([[in]] const VertOut &v_out, [[out]] FragOut &frag_out)
90{
91 frag_out.color = v_out.final_color;
92 frag_out.line_output = float4(0.0f);
93}
94
95} // namespace degrees_of_freedom
96
99 ClippingConstant{.use_clipping = false});
102 ClippingConstant{.use_clipping = true});
104
105/* -------------------------------------------------------------------- */
108
109namespace envelope {
110
111float3x3 compute_mat(ViewMatrices view, float4 sphere, float3 bone_vec, float &z_ofs)
112{
113 bool is_persp = (view.winmat[3][3] == 0.0f);
114 float3 cam_ray = (is_persp) ? sphere.xyz - view.viewinv[3].xyz : -view.viewinv[2].xyz;
115
116 /* Sphere center distance from the camera (persp) in world space. */
117 float cam_dist = length(cam_ray);
118
119 /* Compute view aligned orthonormal space. */
120 float3 z_axis = cam_ray / cam_dist;
121 float3 x_axis = normalize(cross(bone_vec, z_axis));
122 float3 y_axis = cross(z_axis, x_axis);
123 z_ofs = 0.0f;
124
125 if (is_persp) {
126 /* For perspective, the projected sphere radius
127 * can be bigger than the center disc. Compute the
128 * max angular size and compensate by sliding the disc
129 * towards the camera and scale it accordingly. */
130 constexpr float half_pi = 3.1415926f * 0.5f;
131 float rad = sphere.w;
132 /* Let be :
133 * V the view vector origin.
134 * O the sphere origin.
135 * T the point on the target circle.
136 * We compute the angle between (OV) and (OT). */
137 float a = half_pi - asin(rad / cam_dist);
138 float cos_b = cos(a);
139 float sin_b = sqrt(clamp(1.0f - cos_b * cos_b, 0.0f, 1.0f));
140
141 x_axis *= sin_b;
142 y_axis *= sin_b;
143 z_ofs = -rad * cos_b;
144 }
145
146 return float3x3(x_axis, y_axis, z_axis);
147}
148
149namespace outline {
150
151struct Resources {
152 [[storage(0, read)]] const BoneEnvelopeData (&data_buf)[];
153};
154
160
161struct Bone {
163 float sinb;
164};
165
167{
168 /* we just want to know when the head sphere starts interpolating. */
169 return dot(p, b.vec) > -b.sinb;
170}
171
173 float4 sph_near,
174 float4 sph_far,
175 float3x3 mat_near,
176 float3x3 mat_far,
177 float z_ofs_near,
178 float z_ofs_far,
179 Bone b)
180{
181 /* Compute outline position on the nearest sphere and check
182 * if it penetrates the capsule body. If it does, put this
183 * vertex on the farthest sphere. */
184 float3 wpos = mat_near * float3(pos * sph_near.w, z_ofs_near);
185 if (bone_blend_starts(wpos, b)) {
186 wpos = sph_far.xyz + mat_far * float3(pos * sph_far.w, z_ofs_far);
187 }
188 else {
189 wpos += sph_near.xyz;
190 }
191 return wpos;
192}
193
194[[vertex]]
195void vert([[resource_table]] const Resources &srt,
197 [[resource_table]] const Uniform &uni,
198 [[resource_table]] const Clipping &clip,
199 [[resource_table]] const draw::View &views,
200 [[resource_table, condition(selectable)]] const draw::Select &sel,
201 [[out, condition(selectable)]] draw::SelectOut &sel_out,
202 [[instance_index]] const int inst_index,
203 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
204 [[in]] const VertIn &v_in,
205 [[out]] VertOut &v_out,
206 [[position]] float4 &out_pos)
207{
208 if (sel.consts.selectable) [[static_branch]] {
209 sel_out.select_id = sel.in_select_buf[inst_index];
210 }
211
212 const ViewMatrices view = views.get(0);
213
214 float dst_head = distance(srt.data_buf[inst_index].head_sphere.xyz, view.viewinv[3].xyz);
215 float dst_tail = distance(srt.data_buf[inst_index].tail_sphere.xyz, view.viewinv[3].xyz);
216 // float dst_head = -dot(data_buf[inst_index].head_sphere.xyz, view.viewmat[2].xyz);
217 // float dst_tail = -dot(data_buf[inst_index].tail_sphere.xyz, view.viewmat[2].xyz);
218
219 float4 sph_near, sph_far;
220 if ((dst_head > dst_tail) && (view.winmat[3][3] == 0.0f)) {
221 sph_near = srt.data_buf[inst_index].tail_sphere;
222 sph_far = srt.data_buf[inst_index].head_sphere;
223 }
224 else {
225 sph_near = srt.data_buf[inst_index].head_sphere;
226 sph_far = srt.data_buf[inst_index].tail_sphere;
227 }
228
229 float3 bone_vec = (sph_far.xyz - sph_near.xyz) + 1e-8f;
230
231 Bone b;
232 float bone_lenrcp = 1.0f / max(1e-8f, sqrt(dot(bone_vec, bone_vec)));
233 b.sinb = (sph_far.w - sph_near.w) * bone_lenrcp * sph_near.w;
234 b.vec = bone_vec * bone_lenrcp;
235
236 float z_ofs_near, z_ofs_far;
237 float3x3 mat_near = compute_mat(view, sph_near, bone_vec, z_ofs_near);
238 float3x3 mat_far = compute_mat(view, sph_far, bone_vec, z_ofs_far);
239
241 v_in.pos0, sph_near, sph_far, mat_near, mat_far, z_ofs_near, z_ofs_far, b);
243 v_in.pos1, sph_near, sph_far, mat_near, mat_far, z_ofs_near, z_ofs_far, b);
245 v_in.pos2, sph_near, sph_far, mat_near, mat_far, z_ofs_near, z_ofs_far, b);
246
247 if (clip.constants.use_clipping) [[static_branch]] {
248 clip.set_clipping_distances(wpos1,
249 clip_distances[0],
250 clip_distances[1],
251 clip_distances[2],
252 clip_distances[3],
253 clip_distances[4],
254 clip_distances[5]);
255 }
256
257 float4 p0 = view.point_world_to_homogenous(wpos0);
258 float4 p1 = view.point_world_to_homogenous(wpos1);
259 float4 p2 = view.point_world_to_homogenous(wpos2);
260
261 out_pos = p1;
262
263 /* compute position from 3 vertex because the change in direction
264 * can happen very quickly and lead to very thin edges. */
265 float2 ss0 = uni.proj(p0);
266 float2 ss1 = uni.proj(p1);
267 float2 ss2 = uni.proj(p2);
268 float2 ofs_dir = compute_dir(ss0, ss1, ss2);
269
270 /* Offset away from the center to avoid overlap with solid shape. */
271 out_pos.xy += ofs_dir * uni.uniform_buf.size_viewport_inv * out_pos.w;
272
273 v_out.edge_start = v_out.edge_pos = uni.proj(out_pos);
274
275 v_out.final_color = float4(srt.data_buf[inst_index].bone_color_and_wire_width.rgb,
276 armature.alpha);
277}
278
279} // namespace outline
280
281namespace solid {
282
283struct Resources {
284 [[storage(0, read)]] const BoneEnvelopeData (&data_buf)[];
286};
287
288struct VertIn {
290};
291
297
298[[vertex]]
299void vert([[resource_table]] const Resources &srt,
300 [[resource_table]] const Clipping &clip,
301 [[resource_table]] const draw::View &views,
302 [[resource_table, condition(selectable)]] const draw::Select &sel,
303 [[out, condition(selectable)]] draw::SelectOut &sel_out,
304 [[instance_index]] const int inst_index,
305 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
306 [[in]] const VertIn &v_in,
307 [[out]] VertOut &v_out,
308 [[position]] float4 &out_pos)
309{
310 if (sel.consts.selectable) [[static_branch]] {
311 sel_out.select_id = sel.in_select_buf[inst_index];
312 }
313
314 const ViewMatrices view = views.get(0);
315
316 float3 bone_vec = srt.data_buf[inst_index].tail_sphere.xyz -
317 srt.data_buf[inst_index].head_sphere.xyz;
318 float bone_len = max(1e-8f, sqrt(dot(bone_vec, bone_vec)));
319 float bone_lenrcp = 1.0f / bone_len;
320#if 0 /* SMOOTH_ENVELOPE */
321 float sinb = (srt.data_buf[inst_index].tail_sphere.w - srt.data_buf[inst_index].head_sphere.w) *
322 bone_lenrcp;
323#else
324 constexpr float sinb = 0.0f;
325#endif
326
327 float3 y_axis = bone_vec * bone_lenrcp;
328 float3 z_axis = normalize(cross(srt.data_buf[inst_index].x_axis.xyz, -y_axis));
329 /* cannot trust srt.data_buf[inst_index].x_axis.xyz to be orthogonal. */
330 float3 x_axis = cross(y_axis, z_axis);
331
332 float3 sp, nor;
333 nor = sp = v_in.pos.xyz;
334
335 /* In bone space */
336 bool is_head = (v_in.pos.z < -sinb);
337 sp *= (is_head) ? srt.data_buf[inst_index].head_sphere.w :
338 srt.data_buf[inst_index].tail_sphere.w;
339 sp.z += (is_head) ? 0.0f : bone_len;
340
341 /* Convert to world space */
342 float3x3 bone_mat = float3x3(x_axis, y_axis, z_axis);
343 sp = bone_mat * sp.xzy + srt.data_buf[inst_index].head_sphere.xyz;
344 nor = bone_mat * nor.xzy;
345
346 v_out.view_normal = to_float3x3(view.viewmat) * nor;
347
348 v_out.final_state_color = srt.data_buf[inst_index].state_color.xyz;
349 v_out.final_bone_color = srt.data_buf[inst_index].bone_color_and_wire_width.xyz;
350
351 if (clip.constants.use_clipping) [[static_branch]] {
352 clip.set_clipping_distances(sp,
353 clip_distances[0],
354 clip_distances[1],
355 clip_distances[2],
356 clip_distances[3],
357 clip_distances[4],
358 clip_distances[5]);
359 }
360
361 float4 pos_4d = float4(sp, 1.0f);
362 out_pos = view.winmat * (view.viewmat * pos_4d);
363}
364
365[[fragment]]
366void frag([[resource_table]] const Resources &srt,
368 [[resource_table, condition(selectable)]] draw::Select &sel,
369 [[frag_coord]] const float4 frag_co,
370 [[in]] const VertOut &v_out,
371 [[in, condition(selectable)]] const draw::SelectOut &sel_out,
372 [[out]] FragOut &frag_out)
373{
374 float n = normalize(v_out.view_normal).z;
375 if (srt.is_distance) {
376 n = 1.0f - clamp(-n, 0.0f, 1.0f);
377 frag_out.color = float4(1.0f, 1.0f, 1.0f, 0.33f * armature.alpha) * n;
378 }
379 else {
380 /* Smooth lighting factor. */
381 constexpr float s = 0.2f; /* [0.0f-0.5f] range */
382 float fac = clamp((n * (1.0f - s)) + s, 0.0f, 1.0f);
383 frag_out.color.rgb = mix(v_out.final_state_color, v_out.final_bone_color, fac * fac);
384 frag_out.color.a = armature.alpha;
385 }
386 frag_out.line_output = float4(0.0f);
387
388 if (sel.consts.selectable) [[static_branch]] {
389 sel.select_id_output(sel_out.select_id, frag_co);
390 }
391}
392
393} // namespace solid
394
395} // namespace envelope
396
398 wire_frag,
399 ClippingConstant{.use_clipping = false},
400 draw::SelectConstant{.selectable = false});
402 wire_frag,
403 ClippingConstant{.use_clipping = true},
404 draw::SelectConstant{.selectable = false});
406 wire_frag,
407 ClippingConstant{.use_clipping = false},
408 draw::SelectConstant{.selectable = true});
410 wire_frag,
411 ClippingConstant{.use_clipping = true},
412 draw::SelectConstant{.selectable = true});
413
416 ClippingConstant{.use_clipping = false},
417 draw::SelectConstant{.selectable = false});
420 ClippingConstant{.use_clipping = true},
421 draw::SelectConstant{.selectable = false});
424 ClippingConstant{.use_clipping = false},
425 draw::SelectConstant{.selectable = true});
428 ClippingConstant{.use_clipping = true},
429 draw::SelectConstant{.selectable = true});
430
432
433/* -------------------------------------------------------------------- */
438
439namespace shape {
440
441namespace outline {
442
447
456
457struct Resources {
459 [[storage(0, read), frequency(GEOMETRY)]] float (&pos)[];
460 [[storage(1, read)]] float4x4 (&data_buf)[];
461
464
465 VertIn input_assembly(uint in_vertex_id, float4x4 inst_matrix) const
466 {
467 uint v_i = indices.load(in_vertex_id);
469 return {.ls_P = ls_P, .inst_matrix = inst_matrix};
470 }
471
472 VertOut vertex_main(const ViewMatrices view, VertIn v_in) const
473 {
474 float4 bone_color, state_color;
475 float4x4 model_mat = extract_matrix_packed_data(v_in.inst_matrix, state_color, bone_color);
476
477 VertOut v_out;
478 v_out.ws_P = transform_point(model_mat, v_in.ls_P);
479 v_out.vs_P = view.point_world_to_view(v_out.ws_P);
480 v_out.hs_P = view.point_view_to_homogenous(v_out.vs_P);
481 v_out.ss_P = view.perspective_divide(v_out.hs_P).xy * uni.uniform_buf.size_viewport;
482 v_out.inverted = int(dot(cross(model_mat[0].xyz, model_mat[1].xyz), model_mat[2].xyz) < 0.0f);
483 v_out.color_size = bone_color;
484
485 return v_out;
486 }
487
488 void emit_vertex(const uint strip_index,
489 uint out_vertex_id,
490 uint out_primitive_id,
491 float4 color,
492 float4 hs_P,
493 float3 ws_P,
494 float2 offset,
495 bool is_persp,
496 overlay::VertOut &v_out,
497 float4 &out_pos,
498 float3 &out_wP) const
499 {
500 bool is_odd_primitive = (out_primitive_id & 1u) != 0u;
501 /* Maps triangle list primitives to triangle strip indices. */
502 uint out_strip_index = (is_odd_primitive ? (2u - out_vertex_id) : out_vertex_id) +
503 out_primitive_id;
504
505 if (out_strip_index != strip_index) {
506 return;
507 }
508
509 v_out.final_color = color;
510
511 out_pos = hs_P;
512 /* Offset away from the center to avoid overlap with solid shape. */
513 out_pos.xy += offset * uni.uniform_buf.size_viewport_inv * out_pos.w;
514 /* Improve AA bleeding inside bone silhouette. */
515 out_pos.z -= (is_persp) ? 1e-4f : 1e-6f;
516
517 v_out.edge_start = v_out.edge_pos = ((out_pos.xy / out_pos.w) * 0.5f + 0.5f) *
519
520 out_wP = ws_P;
521 }
522
524 const VertOut geom_in[4],
525 uint out_vertex_id,
526 uint out_primitive_id,
527 uint /*out_invocation_id*/,
528 overlay::VertOut &v_out,
529 float4 &out_pos,
530 float3 &out_wP) const
531 {
532 bool is_persp = (view.winmat[3][3] == 0.0f);
533
534 float3 view_vec = (is_persp) ? normalize(geom_in[1].vs_P) : float3(0.0f, 0.0f, -1.0f);
535 float3 v10 = geom_in[0].vs_P - geom_in[1].vs_P;
536 float3 v12 = geom_in[2].vs_P - geom_in[1].vs_P;
537 float3 v13 = geom_in[3].vs_P - geom_in[1].vs_P;
538
539 /* Known Issue: This also generates outlines for connected-overlapping edges, since their
540 * vector is zero-length. */
541 float3 n0 = cross(v12, v10);
542 n0 *= safe_rcp(length(n0));
543 float3 n3 = cross(v13, v12);
544 n3 *= safe_rcp(length(n3));
545
546 float fac0 = dot(view_vec, n0);
547 float fac3 = dot(view_vec, n3);
548
549 /* If one of the face is perpendicular to the view,
550 * consider it an outline edge. */
551 if (abs(fac0) > 1e-5f && abs(fac3) > 1e-5f) {
552 /* If both adjacent verts are facing the camera the same way,
553 * then it isn't an outline edge. */
554 if (sign(fac0) == sign(fac3)) {
555 return;
556 }
557 }
558
559 n0 = (geom_in[0].inverted == 1) ? -n0 : n0;
560 /* Don't outline if concave edge. */
561 if (dot(n0, v13) > 0.0001f) {
562 return;
563 }
564
565 float2 perp = normalize(geom_in[2].ss_P - geom_in[1].ss_P);
566 float2 edge_dir = float2(-perp.y, perp.x);
567
568 float2 hidden_point;
569 /* Take the farthest point to compute edge direction
570 * (avoid problems with point behind near plane).
571 * If the chosen point is parallel to the edge in screen space,
572 * choose the other point anyway.
573 * This fixes some issue with cubes in orthographic views. */
574 if (geom_in[0].vs_P.z < geom_in[3].vs_P.z) {
575 hidden_point = (abs(fac0) > 1e-5f) ? geom_in[0].ss_P : geom_in[3].ss_P;
576 }
577 else {
578 hidden_point = (abs(fac3) > 1e-5f) ? geom_in[3].ss_P : geom_in[0].ss_P;
579 }
580 float2 hidden_dir = normalize(hidden_point - geom_in[1].ss_P);
581
582 float fac = dot(-hidden_dir, edge_dir);
583 edge_dir *= (fac < 0.0f) ? -1.0f : 1.0f;
584
585 emit_vertex(0,
586 out_vertex_id,
587 out_primitive_id,
588 float4(geom_in[0].color_size.rgb, 1.0f),
589 geom_in[1].hs_P,
590 geom_in[1].ws_P,
591 edge_dir - perp,
592 is_persp,
593 v_out,
594 out_pos,
595 out_wP);
596
597 emit_vertex(1,
598 out_vertex_id,
599 out_primitive_id,
600 float4(geom_in[0].color_size.rgb, 1.0f),
601 geom_in[2].hs_P,
602 geom_in[2].ws_P,
603 edge_dir + perp,
604 is_persp,
605 v_out,
606 out_pos,
607 out_wP);
608 }
609};
610
611[[vertex]]
612void vert([[resource_table]] const Resources &srt,
614 [[resource_table]] const Clipping &clip,
615 [[resource_table]] const draw::View &views,
616 [[resource_table, condition(selectable)]] const draw::Select &sel,
617 [[out, condition(selectable)]] draw::SelectOut &sel_out,
618 [[vertex_id]] const int vert_id,
619 [[instance_index]] const int inst_index,
620 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
621 [[out]] overlay::VertOut &v_out,
622 [[position]] float4 &out_pos)
623{
624 if (sel.consts.selectable) [[static_branch]] {
625 sel_out.select_id = sel.in_select_buf[inst_index];
626 }
627
628 /* Line Adjacency primitive. */
629 constexpr uint input_primitive_vertex_count = 4u;
630 /* Line list primitive. */
631 constexpr uint output_primitive_vertex_count = 2u;
632 constexpr uint output_primitive_count = 1u;
633 constexpr uint output_invocation_count = 1u;
634 constexpr uint output_vertex_count_per_invocation = output_primitive_count *
635 output_primitive_vertex_count;
636 constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
637 output_invocation_count;
638
639 uint in_primitive_id = uint(vert_id) / output_vertex_count_per_input_primitive;
640 uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;
641
642 uint out_vertex_id = uint(vert_id) % output_primitive_vertex_count;
643 uint out_primitive_id = (uint(vert_id) / output_primitive_vertex_count) % output_primitive_count;
644 uint out_invocation_id = (uint(vert_id) / output_vertex_count_per_invocation) %
645 output_invocation_count;
646
647 float4x4 inst_matrix = srt.data_buf[inst_index];
648
649 VertIn vert_in[input_primitive_vertex_count];
650 vert_in[0] = srt.input_assembly(in_primitive_first_vertex + 0u, inst_matrix);
651 vert_in[1] = srt.input_assembly(in_primitive_first_vertex + 1u, inst_matrix);
652 vert_in[2] = srt.input_assembly(in_primitive_first_vertex + 2u, inst_matrix);
653 vert_in[3] = srt.input_assembly(in_primitive_first_vertex + 3u, inst_matrix);
654
655 const ViewMatrices view = views.get(0);
656
657 VertOut vert_out[input_primitive_vertex_count];
658 vert_out[0] = srt.vertex_main(view, vert_in[0]);
659 vert_out[1] = srt.vertex_main(view, vert_in[1]);
660 vert_out[2] = srt.vertex_main(view, vert_in[2]);
661 vert_out[3] = srt.vertex_main(view, vert_in[3]);
662
663 /* Discard by default. */
664 float3 ws_P = float3(NAN_FLT);
665 out_pos = float4(NAN_FLT);
666 srt.geometry_main(
667 view, vert_out, out_vertex_id, out_primitive_id, out_invocation_id, v_out, out_pos, ws_P);
668
669 if (clip.constants.use_clipping) [[static_branch]] {
670 clip.set_clipping_distances(ws_P,
671 clip_distances[0],
672 clip_distances[1],
673 clip_distances[2],
674 clip_distances[3],
675 clip_distances[4],
676 clip_distances[5]);
677 }
678
679 v_out.final_color.a = armature.alpha;
680}
681
682} // namespace outline
683
684namespace solid {
685
686struct VertIn {
689};
690
695
696struct Resources {
697 [[storage(0, read)]] const float4x4 (&data_buf)[];
698};
699
700[[vertex]]
701void vert([[resource_table]] const Resources &srt,
703 [[resource_table]] const Clipping &clip,
704 [[resource_table]] const draw::View &views,
705 [[resource_table, condition(selectable)]] const draw::Select &sel,
706 [[out, condition(selectable)]] draw::SelectOut &sel_out,
707 [[instance_index]] const int inst_index,
708 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
709 [[in]] const VertIn &v_in,
710 [[out]] VertOut &v_out,
711 [[position]] float4 &out_pos)
712{
713 if (sel.consts.selectable) [[static_branch]] {
714 sel_out.select_id = sel.in_select_buf[inst_index];
715 }
716
717 const ViewMatrices view = views.get(0);
718
719 float4 bone_color, state_color;
720 float4x4 inst_obmat = srt.data_buf[inst_index];
721 float4x4 model_mat = extract_matrix_packed_data(inst_obmat, state_color, bone_color);
722
723 /* This is slow and run per vertex, but it's still faster than
724 * doing it per instance on CPU and sending it on via instance attribute. */
725 float3x3 normal_mat = transpose(inverse(to_float3x3(model_mat)));
726 float3 normal = normalize(view.normal_world_to_view(normal_mat * v_in.nor));
727
728 v_out.inverted = int(dot(cross(model_mat[0].xyz, model_mat[1].xyz), model_mat[2].xyz) < 0.0f);
729
730 /* Do lighting at an angle to avoid flat shading on front facing bone. */
731 constexpr float3 light = float3(0.1f, 0.1f, 0.8f);
732 float n = dot(normal, light);
733
734 /* Smooth lighting factor. */
735 constexpr float s = 0.2f; /* [0.0f-0.5f] range */
736 float fac = clamp((n * (1.0f - s)) + s, 0.0f, 1.0f);
737 v_out.final_color.rgb = mix(state_color.rgb, bone_color.rgb, fac * fac);
738 v_out.final_color.a = armature.alpha;
739
740 float3 ws_P = transform_point(model_mat, v_in.pos);
741 out_pos = view.point_world_to_homogenous(ws_P);
742
743 if (clip.constants.use_clipping) [[static_branch]] {
744 clip.set_clipping_distances(ws_P,
745 clip_distances[0],
746 clip_distances[1],
747 clip_distances[2],
748 clip_distances[3],
749 clip_distances[4],
750 clip_distances[5]);
751 }
752}
753
754[[fragment]]
755void frag([[resource_table, condition(selectable)]] draw::Select &sel,
756 [[frag_coord]] const float4 frag_co,
757 [[front_facing]] const bool facing,
758 [[in]] const VertOut &v_out,
759 [[in, condition(selectable)]] const draw::SelectOut &sel_out,
760 [[out]] FragOut &frag_out)
761{
762 /* Manual back-face culling. Not ideal for performance
763 * but needed for view clarity in X-ray mode and support
764 * for inverted bone matrices. */
765 if ((v_out.inverted == 1) == facing) {
767 return;
768 }
769 frag_out.color = v_out.final_color;
770 frag_out.line_output = float4(0.0f);
771
772 if (sel.consts.selectable) [[static_branch]] {
773 sel.select_id_output(sel_out.select_id, frag_co);
774 }
775}
776
777} // namespace solid
778
779namespace wire {
780
785
792
798
802
803struct Resources {
806
807 [[storage(0, read), frequency(GEOMETRY)]] float (&pos)[];
808 [[storage(1, read)]] float4x4 (&data_buf)[];
809
813
814 VertIn input_assembly(uint in_vertex_id, float4x4 inst_matrix) const
815 {
816 uint v_i = indices.load(in_vertex_id);
818 return {.lP = ls_P, .inst_matrix = inst_matrix};
819 }
820
821 VertOut vertex_main(const ViewMatrices view, VertIn v_in) const
822 {
823 float4 bone_color, state_color;
824 float4x4 model_mat = extract_matrix_packed_data(v_in.inst_matrix, state_color, bone_color);
825
826 VertOut v_out;
827
828 /* WORKAROUND: This shape needs a special vertex shader path that should be triggered by
829 * its `vclass` attribute. However, to avoid many changes in the primitive expansion API,
830 * we create a specific path inside the shader only for this shape batch and infer the
831 * value of the `vclass` attribute based on the vertex index. */
832 if (use_arrow_drawing) {
833 /* Keep in sync with the arrows shape batch creation. */
834 /* Adapted from `overlay_extra_vert.glsl`. */
835 float3 vpos = v_in.lP;
836 float3 vofs = float3(0.0f);
837 uint axis = uint(vpos.z);
838 /* Assumes origin vertices are the only one at Z=0. */
839 if (vpos.z > 0.0f) {
840 vofs[axis] = (1.0f + fract(vpos.z));
841 }
842 /* Scale uniformly by axis length */
843 vpos *= length(model_mat[axis].xyz);
844 /* World sized, camera facing geometry. */
845 float3 screen_pos = view.viewinv[0].xyz * vpos.x + view.viewinv[1].xyz * vpos.y;
846 v_out.world_pos = (model_mat * float4(vofs, 1.0f)).xyz + screen_pos;
847 }
848 else {
849 v_out.world_pos = (model_mat * float4(v_in.lP, 1.0f)).xyz;
850 }
852
853 v_out.final_color.rgb = mix(state_color.rgb, bone_color.rgb, 0.5f);
854 v_out.final_color.a = 1.0f;
855 /* Because the packing clamps the value, the wire width is passed in compressed. */
856 v_out.wire_width = bone_color.a * WIRE_WIDTH_COMPRESSION;
857
858 return v_out;
859 }
860
861 void do_vertex(const uint strip_index,
862 uint out_vertex_id,
863 uint out_primitive_id,
864 float4 color,
865 float4 hs_P,
866 float3 ws_P,
867 float coord,
868 float2 offset,
869 GeomOut &v_out,
870 float4 &out_pos,
871 float3 &out_wP) const
872 {
873 bool is_odd_primitive = (out_primitive_id & 1u) != 0u;
874 /* Maps triangle list primitives to triangle strip indices. */
875 uint out_strip_index = (is_odd_primitive ? (2u - out_vertex_id) : out_vertex_id) +
876 out_primitive_id;
877
878 if (out_strip_index != strip_index) {
879 return;
880 }
881
882 v_out.final_color = color;
883 v_out.edge_coord = coord;
884 out_pos = hs_P;
885 /* Multiply offset by 2 because gl_Position range is [-1..1]. */
886 out_pos.xy += offset * 2.0f * hs_P.w;
887 out_wP = ws_P;
888 }
889
890 void geometry_main(VertOut geom_in[2],
891 uint out_vertex_id,
892 uint out_primitive_id,
893 uint /*out_invocation_id*/,
894 GeomOut &v_out,
895 float4 &out_pos,
896 float3 &out_wP) const
897 {
898 /* Clip line against near plane to avoid deformed lines. */
899 float4 pos0 = geom_in[0].gpu_position;
900 float4 pos1 = geom_in[1].gpu_position;
901 float2 pz_ndc = float2(pos0.z / pos0.w, pos1.z / pos1.w);
902 bool2 clipped = lessThan(pz_ndc, float2(-1.0f));
903 if (all(clipped)) {
904 /* Totally clipped. */
905 return;
906 }
907
908 float4 pos01 = pos0 - pos1;
909 float ofs = abs((pz_ndc.y + 1.0f) / (pz_ndc.x - pz_ndc.y));
910 if (clipped.y) {
911 pos1 += pos01 * ofs;
912 }
913 else if (clipped.x) {
914 pos0 -= pos01 * (1.0f - ofs);
915 }
916
917 float2 screen_space_pos[2];
918 screen_space_pos[0] = pos0.xy / pos0.w;
919 screen_space_pos[1] = pos1.xy / pos1.w;
920
921 /* `theme.sizes.edge` is defined as the distance from the center to the outer edge.
922 * As such to get the total width it needs to be doubled. */
923 v_out.wire_width = geom_in[0].wire_width * (uni.uniform_buf.sizes.edge * 2);
924 float half_size = max(v_out.wire_width / 2.0f, 0.5f);
925
926 if (do_smooth_wire) {
927 /* Add 1px for AA */
928 half_size += 0.5f;
929 }
930
931 float2 line = (screen_space_pos[0] - screen_space_pos[1]) * uni.uniform_buf.size_viewport;
932 float2 line_norm = normalize(float2(line[1], -line[0]));
933 float2 edge_ofs = (half_size * line_norm) * uni.uniform_buf.size_viewport_inv;
934
935 float4 final_color = geom_in[0].final_color;
936 do_vertex(0,
937 out_vertex_id,
938 out_primitive_id,
939 final_color,
940 pos0,
941 geom_in[0].world_pos,
942 half_size,
943 edge_ofs,
944 v_out,
945 out_pos,
946 out_wP);
947 do_vertex(1,
948 out_vertex_id,
949 out_primitive_id,
950 final_color,
951 pos0,
952 geom_in[0].world_pos,
953 -half_size,
954 -edge_ofs,
955 v_out,
956 out_pos,
957 out_wP);
958
959 do_vertex(2,
960 out_vertex_id,
961 out_primitive_id,
962 final_color,
963 pos1,
964 geom_in[1].world_pos,
965 half_size,
966 edge_ofs,
967 v_out,
968 out_pos,
969 out_wP);
970 do_vertex(3,
971 out_vertex_id,
972 out_primitive_id,
973 final_color,
974 pos1,
975 geom_in[1].world_pos,
976 -half_size,
977 -edge_ofs,
978 v_out,
979 out_pos,
980 out_wP);
981 }
982};
983
984[[vertex]]
985void vert([[resource_table]] const Resources &srt,
986 [[resource_table]] const Constants &consts,
988 [[resource_table]] const Clipping &clip,
989 [[resource_table]] const draw::View &views,
990 [[resource_table, condition(selectable)]] const draw::Select &sel,
991 [[out, condition(selectable)]] draw::SelectOut &sel_out,
992 [[vertex_id]] const int vert_id,
993 [[instance_index]] const int inst_index,
994 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
995 [[out]] GeomOut &v_out,
996 [[position]] float4 &out_pos)
997{
998 if (sel.consts.selectable) [[static_branch]] {
999 sel_out.select_id = sel.in_select_buf[inst_index];
1000 }
1001
1002 const ViewMatrices view = views.get(0);
1003
1004 /* Line primitive. */
1005 uint input_primitive_vertex_count = 2u;
1006 if (consts.from_line_strip) [[static_branch]] {
1007 /* Line strip primitive. */
1008 input_primitive_vertex_count = 1u;
1009 }
1010 /* Triangle list primitive. */
1011 constexpr uint output_primitive_vertex_count = 3u;
1012 constexpr uint output_primitive_count = 2u;
1013 constexpr uint output_invocation_count = 1u;
1014 constexpr uint output_vertex_count_per_invocation = output_primitive_count *
1015 output_primitive_vertex_count;
1016 constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
1017 output_invocation_count;
1018
1019 uint in_primitive_id = uint(vert_id) / output_vertex_count_per_input_primitive;
1020 uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;
1021
1022 uint out_vertex_id = uint(vert_id) % output_primitive_vertex_count;
1023 uint out_primitive_id = (uint(vert_id) / output_primitive_vertex_count) % output_primitive_count;
1024 uint out_invocation_id = (uint(vert_id) / output_vertex_count_per_invocation) %
1025 output_invocation_count;
1026
1027 float4x4 inst_obmat = srt.data_buf[inst_index];
1028 float4x4 inst_matrix = inst_obmat;
1029
1030 if (consts.from_line_strip) [[static_branch]] {
1031 uint32_t RESTART_INDEX = srt.indices.gpu_index_16bit ? 0xFFFF : 0xFFFFFFFF;
1032 if (srt.indices.load(in_primitive_first_vertex + 0u) == RESTART_INDEX ||
1033 srt.indices.load(in_primitive_first_vertex + 1u) == RESTART_INDEX)
1034 {
1035 /* Discard. */
1036 out_pos = float4(NAN_FLT);
1037 return;
1038 }
1039 }
1040
1041 VertIn vert_in[2];
1042 vert_in[0] = srt.input_assembly(in_primitive_first_vertex + 0u, inst_matrix);
1043 vert_in[1] = srt.input_assembly(in_primitive_first_vertex + 1u, inst_matrix);
1044
1045 VertOut vert_out[2];
1046 vert_out[0] = srt.vertex_main(view, vert_in[0]);
1047 vert_out[1] = srt.vertex_main(view, vert_in[1]);
1048
1049 /* Discard by default. */
1050 float3 ws_P = float3(NAN_FLT);
1051 out_pos = float4(NAN_FLT);
1052 srt.geometry_main(
1053 vert_out, out_vertex_id, out_primitive_id, out_invocation_id, v_out, out_pos, ws_P);
1054
1055 v_out.final_color.a = armature.alpha;
1056
1057 if (clip.constants.use_clipping) [[static_branch]] {
1058 clip.set_clipping_distances(ws_P,
1059 clip_distances[0],
1060 clip_distances[1],
1061 clip_distances[2],
1062 clip_distances[3],
1063 clip_distances[4],
1064 clip_distances[5]);
1065 }
1066}
1067
1068float edge_step(bool do_smooth_wire, float dist)
1069{
1070 if (do_smooth_wire) {
1072 }
1073 return step(0.5f, dist);
1074}
1075
1076[[fragment]]
1077void frag([[resource_table]] const Resources &srt,
1078 [[resource_table, condition(selectable)]] draw::Select &sel,
1079 [[frag_coord]] const float4 frag_co,
1080 [[in]] const GeomOut &v_out,
1081 [[in, condition(selectable)]] const draw::SelectOut &sel_out,
1082 [[out]] FragOut &frag_out)
1083{
1084 float half_size = (srt.do_smooth_wire ? v_out.wire_width - 0.5f : v_out.wire_width) / 2.0f;
1085
1086 float dist = abs(v_out.edge_coord) - half_size;
1087 float mix_w = saturate(edge_step(srt.do_smooth_wire, dist));
1088
1089 frag_out.color = mix(v_out.final_color, float4(0), mix_w);
1090 frag_out.color.a *= 1.0f - mix_w;
1091 frag_out.line_output = float4(0.0f);
1092
1093 if (sel.consts.selectable) [[static_branch]] {
1094 sel.select_id_output(sel_out.select_id, frag_co);
1095 }
1096}
1097
1098} // namespace wire
1099} // namespace shape
1100
1102 wire_frag,
1103 ClippingConstant{.use_clipping = false},
1104 draw::SelectConstant{.selectable = false});
1106 wire_frag,
1107 ClippingConstant{.use_clipping = false},
1108 draw::SelectConstant{.selectable = true});
1110 wire_frag,
1111 ClippingConstant{.use_clipping = true},
1112 draw::SelectConstant{.selectable = false});
1114 wire_frag,
1115 ClippingConstant{.use_clipping = true},
1116 draw::SelectConstant{.selectable = true});
1117
1120 ClippingConstant{.use_clipping = false},
1121 draw::SelectConstant{.selectable = false});
1124 ClippingConstant{.use_clipping = false},
1125 draw::SelectConstant{.selectable = true});
1128 ClippingConstant{.use_clipping = true},
1129 draw::SelectConstant{.selectable = false});
1132 ClippingConstant{.use_clipping = true},
1133 draw::SelectConstant{.selectable = true});
1134
1137 shape::wire::Constants{.from_line_strip = false},
1138 ClippingConstant{.use_clipping = false},
1139 draw::SelectConstant{.selectable = false});
1142 shape::wire::Constants{.from_line_strip = false},
1143 ClippingConstant{.use_clipping = false},
1144 draw::SelectConstant{.selectable = true});
1147 shape::wire::Constants{.from_line_strip = false},
1148 ClippingConstant{.use_clipping = true},
1149 draw::SelectConstant{.selectable = false});
1152 shape::wire::Constants{.from_line_strip = false},
1153 ClippingConstant{.use_clipping = true},
1154 draw::SelectConstant{.selectable = true});
1155
1158 shape::wire::Constants{.from_line_strip = true},
1159 ClippingConstant{.use_clipping = false},
1160 draw::SelectConstant{.selectable = false});
1163 shape::wire::Constants{.from_line_strip = true},
1164 ClippingConstant{.use_clipping = false},
1165 draw::SelectConstant{.selectable = true});
1168 shape::wire::Constants{.from_line_strip = true},
1169 ClippingConstant{.use_clipping = true},
1170 draw::SelectConstant{.selectable = false});
1174 .from_line_strip = true},
1175 ClippingConstant{.use_clipping = true},
1176 draw::SelectConstant{.selectable = true});
1177
1179
1180/* -------------------------------------------------------------------- */
1183
1184namespace sphere {
1185
1186namespace outline {
1187
1188struct VertIn {
1190};
1191
1193 [[storage(0, read)]] const float4x4 (&data_buf)[];
1194};
1195
1196[[vertex]]
1197void vert([[resource_table]] const Resources &srt,
1198 [[resource_table]] const Armature &armature,
1199 [[resource_table]] const Uniform &uni,
1200 [[resource_table]] const Clipping &clip,
1201 [[resource_table]] const draw::View &views,
1202 [[resource_table, condition(selectable)]] const draw::Select &sel,
1203 [[out, condition(selectable)]] draw::SelectOut &sel_out,
1204 [[instance_index]] const int inst_index,
1205 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
1206 [[in]] const VertIn &v_in,
1207 [[out]] VertOut &v_out,
1208 [[position]] float4 &out_pos)
1209{
1210 if (sel.consts.selectable) [[static_branch]] {
1211 sel_out.select_id = sel.in_select_buf[inst_index];
1212 }
1213
1214 const ViewMatrices view = views.get(0);
1215
1216 float4 bone_color, state_color;
1217 float4x4 inst_obmat = srt.data_buf[inst_index];
1218 float4x4 model_mat = extract_matrix_packed_data(inst_obmat, state_color, bone_color);
1219
1220 float4x4 model_view_matrix = view.viewmat * model_mat;
1221 float4x4 sphere_matrix = inverse(model_view_matrix);
1222
1223 bool is_persp = (view.winmat[3][3] == 0.0f);
1224
1225 /* This is the local space camera ray (not normalize).
1226 * In perspective mode it's also the view-space position
1227 * of the sphere center. */
1228 float3 cam_ray = (is_persp) ? model_view_matrix[3].xyz : float3(0.0f, 0.0f, -1.0f);
1229 cam_ray = to_float3x3(sphere_matrix) * cam_ray;
1230
1231 /* Sphere center distance from the camera (persp) in local space. */
1232 float cam_dist = length(cam_ray);
1233
1234 /* Compute view aligned orthonormal space. */
1235 float3 z_axis = cam_ray / cam_dist;
1236 float3 x_axis = normalize(cross(sphere_matrix[1].xyz, z_axis));
1237 float3 y_axis = cross(z_axis, x_axis);
1238 float z_ofs = 0.0f;
1239
1240 if (is_persp) {
1241 /* For perspective, the projected sphere radius
1242 * can be bigger than the center disc. Compute the
1243 * max angular size and compensate by sliding the disc
1244 * towards the camera and scale it accordingly. */
1245 constexpr float half_pi = 3.1415926f * 0.5f;
1246 constexpr float rad = 0.05f;
1247 /* Let be (in local space):
1248 * V the view vector origin.
1249 * O the sphere origin.
1250 * T the point on the target circle.
1251 * We compute the angle between (OV) and (OT). */
1252 float a = half_pi - asin(rad / cam_dist);
1253 float cos_b = cos(a);
1254 float sin_b = sqrt(clamp(1.0f - cos_b * cos_b, 0.0f, 1.0f));
1255
1256 x_axis *= sin_b;
1257 y_axis *= sin_b;
1258 z_ofs = -rad * cos_b;
1259 }
1260
1261 /* Camera oriented position (but still in local space) */
1262 float3 cam_pos0 = x_axis * v_in.pos.x + y_axis * v_in.pos.y + z_axis * z_ofs;
1263
1264 float4 V = model_view_matrix * float4(cam_pos0, 1.0f);
1265 out_pos = view.winmat * V;
1266 float4 center = view.winmat * float4(model_view_matrix[3].xyz, 1.0f);
1267
1268 /* Offset away from the center to avoid overlap with solid shape. */
1269 float2 ofs_dir = normalize(uni.proj(out_pos) - uni.proj(center));
1270 out_pos.xy += ofs_dir * uni.uniform_buf.size_viewport_inv * out_pos.w;
1271
1272 v_out.edge_start = v_out.edge_pos = uni.proj(out_pos);
1273
1274 v_out.final_color = float4(bone_color.rgb, armature.alpha);
1275
1276 float3 world_pos = transform_point(model_mat, cam_pos0);
1277
1278 if (clip.constants.use_clipping) [[static_branch]] {
1279 clip.set_clipping_distances(world_pos,
1280 clip_distances[0],
1281 clip_distances[1],
1282 clip_distances[2],
1283 clip_distances[3],
1284 clip_distances[4],
1285 clip_distances[5]);
1286 }
1287}
1288
1289} // namespace outline
1290
1291namespace solid {
1292
1293struct VertIn {
1295 /* Per instance. */
1297};
1298
1309
1311 [[storage(0, read)]] const float4x4 (&data_buf)[];
1312};
1313
1314[[vertex]]
1315void vert([[resource_table]] const Resources &srt,
1316 [[resource_table]] const Clipping &clip,
1317 [[resource_table]] const draw::View &views,
1318 [[resource_table, condition(selectable)]] const draw::Select &sel,
1319 [[out, condition(selectable)]] draw::SelectOut &sel_out,
1320 [[instance_index]] const int inst_index,
1321 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
1322 [[in]] const VertIn &v_in,
1323 [[out]] VertOut &v_out,
1324 [[position]] float4 &out_pos)
1325{
1326 if (sel.consts.selectable) [[static_branch]] {
1327 sel_out.select_id = sel.in_select_buf[inst_index];
1328 }
1329
1330 const ViewMatrices view = views.get(0);
1331
1332 float4 bone_color, state_color;
1333 float4x4 inst_obmat = srt.data_buf[inst_index];
1334 float4x4 model_mat = extract_matrix_packed_data(inst_obmat, state_color, bone_color);
1335
1336 float4x4 model_view_matrix = view.viewmat * model_mat;
1337 const float4x4 sphere_matrix = inverse(model_view_matrix);
1338 v_out.sphere_matrix0 = sphere_matrix[0];
1339 v_out.sphere_matrix1 = sphere_matrix[1];
1340 v_out.sphere_matrix2 = sphere_matrix[2];
1341 v_out.sphere_matrix3 = sphere_matrix[3];
1342
1343 bool is_persp = (view.winmat[3][3] == 0.0f);
1344
1345 /* This is the local space camera ray (not normalize).
1346 * In perspective mode it's also the view-space position
1347 * of the sphere center. */
1348 float3 cam_ray = (is_persp) ? model_view_matrix[3].xyz : float3(0.0f, 0.0f, -1.0f);
1349 cam_ray = to_float3x3(sphere_matrix) * cam_ray;
1350
1351 /* Sphere center distance from the camera (persp) in local space. */
1352 float cam_dist = length(cam_ray);
1353
1354 /* Compute view aligned orthonormal space. */
1355 float3 z_axis = cam_ray / cam_dist;
1356 float3 x_axis = normalize(cross(sphere_matrix[1].xyz, z_axis));
1357 float3 y_axis = cross(z_axis, x_axis);
1358
1359 /* Sphere radius */
1360 constexpr float rad = 0.05f;
1361
1362 float z_ofs = -rad - 1e-8f; /* offset to the front of the sphere */
1363 if (is_persp) {
1364 /* For perspective, the projected sphere radius
1365 * can be bigger than the center disc. Compute the
1366 * max angular size and compensate by sliding the disc
1367 * towards the camera and scale it accordingly. */
1368 constexpr float half_pi = 3.1415926f * 0.5f;
1369 /* Let be (in local space):
1370 * V the view vector origin.
1371 * O the sphere origin.
1372 * T the point on the target circle.
1373 * We compute the angle between (OV) and (OT). */
1374 float a = half_pi - asin(rad / cam_dist);
1375 float cos_b = cos(a);
1376 float sin_b = sqrt(clamp(1.0f - cos_b * cos_b, 0.0f, 1.0f));
1377#if 1
1378 /* Instead of choosing the biggest circle in screen-space,
1379 * we choose the nearest with the same angular size. This
1380 * permit us to leverage GL_ARB_conservative_depth in the
1381 * fragment shader. */
1382 float minor = cam_dist - rad;
1383 float major = cam_dist - cos_b * rad;
1384 float fac = minor / major;
1385 sin_b *= fac;
1386#else
1387 z_ofs = -rad * cos_b;
1388#endif
1389 x_axis *= sin_b;
1390 y_axis *= sin_b;
1391 }
1392
1393 /* Camera oriented position (but still in local space) */
1394 float3 cam_pos = x_axis * v_in.pos.x + y_axis * v_in.pos.y + z_axis * z_ofs;
1395
1396 float4 pos_4d = float4(cam_pos, 1.0f);
1397 float4 V = model_view_matrix * pos_4d;
1398 out_pos = view.winmat * V;
1399 v_out.view_position = V.xyz;
1400
1401 v_out.final_state_color = state_color.xyz;
1402 v_out.final_bone_color = bone_color.xyz;
1403
1404 float3 world_pos = transform_point(model_mat, cam_pos);
1405
1406 if (clip.constants.use_clipping) [[static_branch]] {
1407 clip.set_clipping_distances(world_pos,
1408 clip_distances[0],
1409 clip_distances[1],
1410 clip_distances[2],
1411 clip_distances[3],
1412 clip_distances[4],
1413 clip_distances[5]);
1414 }
1415}
1416
1417[[fragment]]
1419 [[resource_table]] const draw::View &views,
1420 [[resource_table, condition(selectable)]] draw::Select &sel,
1421 [[frag_coord]] const float4 frag_co,
1422 [[in]] const VertOut &v_out,
1423 [[in, condition(selectable)]] const draw::SelectOut &sel_out,
1424 [[frag_depth(GREATER), condition(!selectable)]] float &depth_out,
1425 [[out]] FragOut &frag_out)
1426{
1427 const ViewMatrices view = views.get(0);
1428
1429 constexpr float sphere_radius = 0.05f;
1430 float4x4 sphere_matrix;
1431 sphere_matrix[0] = v_out.sphere_matrix0;
1432 sphere_matrix[1] = v_out.sphere_matrix1;
1433 sphere_matrix[2] = v_out.sphere_matrix2;
1434 sphere_matrix[3] = v_out.sphere_matrix3;
1435
1436 bool is_perp = (view.winmat[3][3] == 0.0f);
1437 float3 ray_ori_view = (is_perp) ? float3(0.0f) : v_out.view_position.xyz;
1438 float3 ray_dir_view = (is_perp) ? v_out.view_position : float3(0.0f, 0.0f, -1.0f);
1439
1440 /* Single matrix mul without branch. */
1441 float4 mul_vec = (is_perp) ? float4(ray_dir_view, 0.0f) : float4(ray_ori_view, 1.0f);
1442 float3 mul_res = (sphere_matrix * mul_vec).xyz;
1443
1444 /* Reminder :
1445 * sphere_matrix[3] is the view space origin in sphere space (sph_ori -> view_ori).
1446 * sphere_matrix[2] is the view space Z axis in sphere space. */
1447
1448 /* convert to sphere local space */
1449 float3 ray_ori = (is_perp) ? sphere_matrix[3].xyz : mul_res;
1450 float3 ray_dir = (is_perp) ? mul_res : -sphere_matrix[2].xyz;
1451 float ray_len = length(ray_dir);
1452 ray_dir /= ray_len;
1453
1454 /* Line to sphere intersect */
1455 constexpr float sphere_radius_sqr = sphere_radius * sphere_radius;
1456 float b = dot(ray_ori, ray_dir);
1457 float c = dot(ray_ori, ray_ori) - sphere_radius_sqr;
1458 float h = b * b - c;
1459 float t = -sqrt(max(0.0f, h)) - b;
1460
1461 /* Compute dot product for lighting */
1462 float3 p = ray_dir * t + ray_ori; /* Point on sphere */
1463 float3 n = normalize(p); /* Normal is just the point in sphere space, normalized. */
1464 float3 l = normalize(sphere_matrix[2].xyz); /* Just the view Z axis in the sphere space. */
1465
1466 /* Smooth lighting factor. */
1467 constexpr float s = 0.2f; /* [0.0f-0.5f] range */
1468 float fac = clamp((dot(n, l) * (1.0f - s)) + s, 0.0f, 1.0f);
1469 frag_out.color.rgb = mix(v_out.final_state_color, v_out.final_bone_color, fac * fac);
1470
1471 /* 2x2 dither pattern to smooth the lighting. */
1472 float dither = (0.5f + dot(float2(int2(frag_co.xy) & int2(1)), float2(1.0f, 2.0f))) * 0.25f;
1473 dither *= (1.0f / 255.0f); /* Assume 8bit per color buffer. */
1474
1475 frag_out.color = float4(frag_out.color.rgb + dither, armature.alpha);
1476 frag_out.line_output = float4(0.0f);
1477
1478 t /= ray_len;
1479
1480 if (sel.consts.selectable) [[static_branch]] {
1481 sel.select_id_output(sel_out.select_id, frag_co);
1482 }
1483 else {
1484 depth_out = view.depth_view_to_screen(ray_dir_view.z * t + ray_ori_view.z);
1485 }
1486}
1487
1488} // namespace solid
1489} // namespace sphere
1490
1492 wire_frag,
1493 ClippingConstant{.use_clipping = false},
1494 draw::SelectConstant{.selectable = false});
1496 wire_frag,
1497 ClippingConstant{.use_clipping = false},
1498 draw::SelectConstant{.selectable = true});
1500 wire_frag,
1501 ClippingConstant{.use_clipping = true},
1502 draw::SelectConstant{.selectable = false});
1504 wire_frag,
1505 ClippingConstant{.use_clipping = true},
1506 draw::SelectConstant{.selectable = true});
1507
1510 ClippingConstant{.use_clipping = false},
1511 draw::SelectConstant{.selectable = false});
1514 ClippingConstant{.use_clipping = false},
1515 draw::SelectConstant{.selectable = true});
1518 ClippingConstant{.use_clipping = true},
1519 draw::SelectConstant{.selectable = false});
1522 ClippingConstant{.use_clipping = true},
1523 draw::SelectConstant{.selectable = true});
1524
1526
1527/* -------------------------------------------------------------------- */
1530
1531namespace stick_bone {
1532
1533struct VertIn {
1534 /* Position in Bone-aligned screen space. */
1536 [[attribute(1)]] int vclass;
1537};
1538
1544
1546 [[storage(0, read)]] const BoneStickData (&data_buf)[];
1547};
1548
1549[[vertex]]
1550void vert([[resource_table]] const Resources &srt,
1551 [[resource_table]] const Uniform &uni,
1552 [[resource_table]] const Clipping &clip,
1553 [[resource_table]] const draw::View &views,
1554 [[resource_table, condition(selectable)]] const draw::Select &sel,
1555 [[out, condition(selectable)]] draw::SelectOut &sel_out,
1556 [[instance_index]] const int inst_index,
1557 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
1558 [[in]] const VertIn &v_in,
1559 [[out]] VertOut &v_out,
1560 [[position]] float4 &out_pos)
1561{
1562 if (sel.consts.selectable) [[static_branch]] {
1563 sel_out.select_id = sel.in_select_buf[inst_index];
1564 }
1565
1566 const ViewMatrices view = views.get(0);
1567
1568 StickBoneFlag bone_flag = StickBoneFlag(v_in.vclass);
1569 v_out.final_inner_color = flag_test(bone_flag, COL_HEAD) ? srt.data_buf[inst_index].head_color :
1570 srt.data_buf[inst_index].tail_color;
1571 v_out.final_inner_color = flag_test(bone_flag, COL_BONE) ? srt.data_buf[inst_index].bone_color :
1572 v_out.final_inner_color;
1573 v_out.final_wire_color = (srt.data_buf[inst_index].wire_color.a > 0.0f) ?
1574 srt.data_buf[inst_index].wire_color :
1575 v_out.final_inner_color;
1576 v_out.color_fac = flag_test(bone_flag, COL_WIRE) ?
1577 0.0f :
1578 (flag_test(bone_flag, COL_BONE) ? 1.0f : 2.0f);
1579
1580 float4 boneStart_4d = float4(srt.data_buf[inst_index].bone_start.xyz, 1.0f);
1581 float4 boneEnd_4d = float4(srt.data_buf[inst_index].bone_end.xyz, 1.0f);
1582 float4 v0 = view.viewmat * boneStart_4d;
1583 float4 v1 = view.viewmat * boneEnd_4d;
1584
1585 /* Clip the bone to the camera origin plane (not the clip plane)
1586 * to avoid glitches if one end is behind the camera origin (in perspective mode). */
1587 float clip_dist = (view.winmat[3][3] == 0.0f) ?
1588 -1e-7f :
1589 1e20f; /* hard-coded, -1e-8f is giving glitches. */
1590 float3 bvec = v1.xyz - v0.xyz;
1591 float3 clip_pt = v0.xyz + bvec * ((v0.z - clip_dist) / -bvec.z);
1592 if (v0.z > clip_dist) {
1593 v0.xyz = clip_pt;
1594 }
1595 else if (v1.z > clip_dist) {
1596 v1.xyz = clip_pt;
1597 }
1598
1599 float4 p0 = view.winmat * v0;
1600 float4 p1 = view.winmat * v1;
1601
1602 bool is_head = flag_test(bone_flag, POS_HEAD);
1603 bool is_bone = flag_test(bone_flag, POS_BONE);
1604
1605 float h = (is_head) ? p0.w : p1.w;
1606
1607 float2 x_screen_vec = normalize(uni.proj(p1) - uni.proj(p0) + 1e-8f);
1608 float2 y_screen_vec = float2(x_screen_vec.y, -x_screen_vec.x);
1609
1610 /* 2D screen aligned pos at the point */
1611 float2 vpos = v_in.pos.x * x_screen_vec + v_in.pos.y * y_screen_vec;
1612 vpos *= (view.winmat[3][3] == 0.0f) ? h : 1.0f;
1613 vpos *= (srt.data_buf[inst_index].wire_color.a > 0.0f) ? 1.0f : 0.5f;
1614
1615 if (v_out.final_inner_color.a > 0.0f) {
1616 float stick_size = uni.uniform_buf.sizes.pixel * 5.0f;
1617 out_pos = (is_head) ? p0 : p1;
1618 out_pos.xy += stick_size * (vpos * uni.uniform_buf.size_viewport_inv);
1619 out_pos.z += (is_bone) ? 0.0f : 1e-6f; /* Avoid Z fighting of head/tails. */
1620
1621 if (clip.constants.use_clipping) [[static_branch]] {
1622 clip.set_clipping_distances((is_head ? boneStart_4d : boneEnd_4d).xyz,
1623 clip_distances[0],
1624 clip_distances[1],
1625 clip_distances[2],
1626 clip_distances[3],
1627 clip_distances[4],
1628 clip_distances[5]);
1629 }
1630 }
1631 else {
1632 out_pos = float4(0.0f);
1633 }
1634}
1635
1636[[fragment]]
1638 [[resource_table, condition(selectable)]] draw::Select &sel,
1639 [[frag_coord]] const float4 frag_co,
1640 [[in]] const VertOut &v_out,
1641 [[in, condition(selectable)]] const draw::SelectOut &sel_out,
1642 [[out]] FragOut &frag_out)
1643{
1644 float fac = smoothstep(1.0f, 0.2f, v_out.color_fac);
1645 frag_out.color.rgb = mix(v_out.final_inner_color.rgb, v_out.final_wire_color.rgb, fac);
1646 frag_out.color.a = armature.alpha;
1647 frag_out.line_output = float4(0.0f);
1648
1649 if (sel.consts.selectable) [[static_branch]] {
1650 sel.select_id_output(sel_out.select_id, frag_co);
1651 }
1652}
1653
1654} // namespace stick_bone
1655
1658 ClippingConstant{.use_clipping = false},
1659 draw::SelectConstant{.selectable = false});
1662 ClippingConstant{.use_clipping = false},
1663 draw::SelectConstant{.selectable = true});
1666 ClippingConstant{.use_clipping = true},
1667 draw::SelectConstant{.selectable = false});
1670 ClippingConstant{.use_clipping = true},
1671 draw::SelectConstant{.selectable = true});
1672
1674
1675/* -------------------------------------------------------------------- */
1678
1679namespace wire_bone {
1680
1682 [[storage(0, read)]] const VertexData (&data_buf)[];
1683};
1684
1685[[vertex]]
1686void vert([[resource_table]] const Resources &srt,
1687 [[resource_table]] const Armature &armature,
1688 [[resource_table]] const Uniform &uni,
1689 [[resource_table]] const Clipping &clip,
1690 [[resource_table]] const draw::View &views,
1691 [[resource_table, condition(selectable)]] const draw::Select &sel,
1692 [[out, condition(selectable)]] draw::SelectOut &sel_out,
1693 [[vertex_id]] const int vert_id,
1694 [[clip_distance, condition(use_clipping)]] float (&clip_distances)[6],
1695 [[out]] VertOut &v_out,
1696 [[position]] float4 &out_pos)
1697{
1698 if (sel.consts.selectable) [[static_branch]] {
1699 sel_out.select_id = sel.in_select_buf[vert_id / 2];
1700 }
1701
1702 const ViewMatrices view = views.get(0);
1703
1704 v_out.final_color.rgb = srt.data_buf[vert_id].color_.rgb;
1705 v_out.final_color.a = armature.alpha;
1706
1707 float3 world_pos = srt.data_buf[vert_id].pos_.xyz;
1708 out_pos = view.point_world_to_homogenous(world_pos);
1709
1710 v_out.edge_start = v_out.edge_pos = ((out_pos.xy / out_pos.w) * 0.5f + 0.5f) *
1711 uni.uniform_buf.size_viewport;
1712
1713 if (clip.constants.use_clipping) [[static_branch]] {
1714 clip.set_clipping_distances(world_pos,
1715 clip_distances[0],
1716 clip_distances[1],
1717 clip_distances[2],
1718 clip_distances[3],
1719 clip_distances[4],
1720 clip_distances[5]);
1721 }
1722}
1723
1724} // namespace wire_bone
1725
1727
1729 wire_frag,
1730 ClippingConstant{.use_clipping = false},
1731 draw::SelectConstant{.selectable = false});
1733 wire_frag,
1734 ClippingConstant{.use_clipping = false},
1735 draw::SelectConstant{.selectable = true});
1737 wire_frag,
1738 ClippingConstant{.use_clipping = true},
1739 draw::SelectConstant{.selectable = false});
1741 wire_frag,
1742 ClippingConstant{.use_clipping = true},
1743 draw::SelectConstant{.selectable = true});
1744
1745} // namespace overlay::armature
#define NAN_FLT
btScalar max
float3 gpu_attr_load_float3(const float(&data_buf)[], int2 stride_and_offset, uint i)
#define instance_index
#define storage(slot, qualifiers)
#define position
#define front_facing
#define flat
#define frag_coord
#define smooth
#define push_constant
#define compilation_constant
#define resource_table
#define attribute(slot)
#define static_branch
#define frag_depth(mode)
#define fragment
#define vertex_id
#define frequency(freq)
#define no_perspective
#define clip_distance
#define condition(cond)
#define vertex
T smoothstep(T, T, T) RET
void gpu_discard_fragment()
T fract(T) RET
MatBase< C, R > inverse(MatBase< C, R >) RET
#define cos
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
constexpr T sign(T) RET
#define abs
float distance(float, float) RET
bool all(VecOp< bool, D >) RET
#define sqrt
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
MatBase< R, C > transpose(MatBase< C, R >) RET
#define asin
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
VecBase< bool, D > lessThan(VecOp< T, D >, VecOp< T, D >) RET
constexpr T clamp(T, U, U) RET
float length(VecOp< float, D >) RET
VecBase< bool, 2 > bool2
float3 transform_point(float3x3 mat, float3 point)
float safe_rcp(float a)
bool flag_test(uint flag, uint val)
MatBase< float, 4, 4 > float4x4
void vert(const Resources &srt, const Armature &armature, const Uniform &uni, const Clipping &clip, const draw::View &views, const int inst_index, float(&clip_distances)[6], const VertIn &v_in, VertOut &v_out, float4 &out_pos)
void frag(const VertOut &v_out, FragOut &frag_out)
float3 get_outline_point(float2 pos, float4 sph_near, float4 sph_far, float3x3 mat_near, float3x3 mat_far, float z_ofs_near, float z_ofs_far, Bone b)
void vert(const Resources &srt, const Armature &armature, const Uniform &uni, const Clipping &clip, const draw::View &views, const draw::Select &sel, draw::SelectOut &sel_out, const int inst_index, float(&clip_distances)[6], const VertIn &v_in, VertOut &v_out, float4 &out_pos)
void vert(const Resources &srt, const Clipping &clip, const draw::View &views, const draw::Select &sel, draw::SelectOut &sel_out, const int inst_index, float(&clip_distances)[6], const VertIn &v_in, VertOut &v_out, float4 &out_pos)
void frag(const Resources &srt, const Armature &armature, draw::Select &sel, const float4 frag_co, const VertOut &v_out, const draw::SelectOut &sel_out, FragOut &frag_out)
float3x3 compute_mat(ViewMatrices view, float4 sphere, float3 bone_vec, float &z_ofs)
void vert(const Resources &srt, const Armature &armature, const Clipping &clip, const draw::View &views, const draw::Select &sel, draw::SelectOut &sel_out, const int vert_id, const int inst_index, float(&clip_distances)[6], overlay::VertOut &v_out, float4 &out_pos)
void vert(const Resources &srt, const Armature &armature, const Clipping &clip, const draw::View &views, const draw::Select &sel, draw::SelectOut &sel_out, const int inst_index, float(&clip_distances)[6], const VertIn &v_in, VertOut &v_out, float4 &out_pos)
void frag(draw::Select &sel, const float4 frag_co, const bool facing, const VertOut &v_out, const draw::SelectOut &sel_out, FragOut &frag_out)
float edge_step(bool do_smooth_wire, float dist)
void frag(const Resources &srt, draw::Select &sel, const float4 frag_co, const GeomOut &v_out, const draw::SelectOut &sel_out, FragOut &frag_out)
void vert(const Resources &srt, const Constants &consts, const Armature &armature, const Clipping &clip, const draw::View &views, const draw::Select &sel, draw::SelectOut &sel_out, const int vert_id, const int inst_index, float(&clip_distances)[6], GeomOut &v_out, float4 &out_pos)
void vert(const Resources &srt, const Armature &armature, const Uniform &uni, const Clipping &clip, const draw::View &views, const draw::Select &sel, draw::SelectOut &sel_out, const int inst_index, float(&clip_distances)[6], const VertIn &v_in, VertOut &v_out, float4 &out_pos)
void frag(const Armature &armature, const draw::View &views, draw::Select &sel, const float4 frag_co, const VertOut &v_out, const draw::SelectOut &sel_out, float &depth_out, FragOut &frag_out)
void vert(const Resources &srt, const Clipping &clip, const draw::View &views, const draw::Select &sel, draw::SelectOut &sel_out, const int inst_index, float(&clip_distances)[6], const VertIn &v_in, VertOut &v_out, float4 &out_pos)
void vert(const Resources &srt, const Uniform &uni, const Clipping &clip, const draw::View &views, const draw::Select &sel, draw::SelectOut &sel_out, const int inst_index, float(&clip_distances)[6], const VertIn &v_in, VertOut &v_out, float4 &out_pos)
void frag(const Armature &armature, draw::Select &sel, const float4 frag_co, const VertOut &v_out, const draw::SelectOut &sel_out, FragOut &frag_out)
void vert(const Resources &srt, const Armature &armature, const Uniform &uni, const Clipping &clip, const draw::View &views, const draw::Select &sel, draw::SelectOut &sel_out, const int vert_id, float(&clip_distances)[6], VertOut &v_out, float4 &out_pos)
PipelineGraphic envelope_solid(envelope::solid::vert, envelope::solid::frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic sphere_outline_clipped(sphere::outline::vert, wire_frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic wire_selectable_clipped(wire_bone::vert, wire_frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic shape_solid_selectable_clipped(shape::solid::vert, shape::solid::frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic stick(stick_bone::vert, stick_bone::frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic envelope_outline_selectable(envelope::outline::vert, wire_frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic sphere_solid_clipped(sphere::solid::vert, sphere::solid::frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic shape_wire_clipped(shape::wire::vert, shape::wire::frag, shape::wire::Constants{.from_line_strip=false}, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic shape_outline_selectable_clipped(shape::outline::vert, wire_frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic shape_wire_selectable(shape::wire::vert, shape::wire::frag, shape::wire::Constants{.from_line_strip=false}, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic sphere_solid_selectable_clipped(sphere::solid::vert, sphere::solid::frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic envelope_outline(envelope::outline::vert, wire_frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic shape_solid(shape::solid::vert, shape::solid::frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic shape_solid_selectable(shape::solid::vert, shape::solid::frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic stick_clipped(stick_bone::vert, stick_bone::frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic wire(wire_bone::vert, wire_frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic dof_clipped(degrees_of_freedom::vert, degrees_of_freedom::frag, ClippingConstant{.use_clipping=true})
PipelineGraphic sphere_outline(sphere::outline::vert, wire_frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic shape_solid_clipped(shape::solid::vert, shape::solid::frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic envelope_solid_clipped(envelope::solid::vert, envelope::solid::frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic wire_clipped(wire_bone::vert, wire_frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic sphere_solid(sphere::solid::vert, sphere::solid::frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic shape_wire_strip_clipped(shape::wire::vert, shape::wire::frag, shape::wire::Constants{.from_line_strip=true}, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic stick_selectable(stick_bone::vert, stick_bone::frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic shape_wire_selectable_clipped(shape::wire::vert, shape::wire::frag, shape::wire::Constants{.from_line_strip=false}, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic stick_selectable_clipped(stick_bone::vert, stick_bone::frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic shape_outline(shape::outline::vert, wire_frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic sphere_outline_selectable(sphere::outline::vert, wire_frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic envelope_outline_clipped(envelope::outline::vert, wire_frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic shape_outline_selectable(shape::outline::vert, wire_frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic envelope_solid_selectable_clipped(envelope::solid::vert, envelope::solid::frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic sphere_outline_selectable_clipped(sphere::outline::vert, wire_frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic shape_wire_strip(shape::wire::vert, shape::wire::frag, shape::wire::Constants{.from_line_strip=true}, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic shape_wire_strip_selectable(shape::wire::vert, shape::wire::frag, shape::wire::Constants{.from_line_strip=true}, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic envelope_solid_selectable(envelope::solid::vert, envelope::solid::frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic shape_wire_strip_selectable_clipped(shape::wire::vert, shape::wire::frag, shape::wire::Constants{ .from_line_strip=true}, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic envelope_outline_selectable_clipped(envelope::outline::vert, wire_frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=true})
PipelineGraphic wire_selectable(wire_bone::vert, wire_frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic shape_outline_clipped(shape::outline::vert, wire_frag, ClippingConstant{.use_clipping=true}, draw::SelectConstant{.selectable=false})
PipelineGraphic shape_wire(shape::wire::vert, shape::wire::frag, shape::wire::Constants{.from_line_strip=false}, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=false})
PipelineGraphic sphere_solid_selectable(sphere::solid::vert, sphere::solid::frag, ClippingConstant{.use_clipping=false}, draw::SelectConstant{.selectable=true})
PipelineGraphic dof(degrees_of_freedom::vert, degrees_of_freedom::frag, ClippingConstant{.use_clipping=false})
void wire_frag(draw::Select &sel, const float4 frag_co, const VertOut &v_out, const draw::SelectOut &sel_out, FragOut &frag_out)
float2 compute_dir(float2 v0, float2, float2 v2)
float4x4 extract_matrix_packed_data(float4x4 mat, float4 &dataA, float4 &dataB)
#define LINE_SMOOTH_START
#define LINE_SMOOTH_END
#define WIRE_WIDTH_COMPRESSION
#define mix
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define saturate(a)
Definition smaa.cc:319
BoneEnvelopeData()=default
BoneStickData()=default
ExtraInstanceData(const float4x4 &object_to_world, const float4 &color, float draw_size)
uint load(uint element_index) const
struct ThemeSizes sizes
float3 point_world_to_view(float3 P) const
float3 perspective_divide(float4 hs_P) const
float4 point_view_to_homogenous(float3 vP) const
float4 point_world_to_homogenous(float3 P) const
float depth_view_to_screen(float v_depth) const
float x
float y
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
float z
Definition sky_math.h:225
float w
Definition sky_math.h:225
VertOut vertex_main(const ViewMatrices view, VertIn v_in) const
void geometry_main(const ViewMatrices view, const VertOut geom_in[4], uint out_vertex_id, uint out_primitive_id, uint, overlay::VertOut &v_out, float4 &out_pos, float3 &out_wP) const
void emit_vertex(const uint strip_index, uint out_vertex_id, uint out_primitive_id, float4 color, float4 hs_P, float3 ws_P, float2 offset, bool is_persp, overlay::VertOut &v_out, float4 &out_pos, float3 &out_wP) const
VertIn input_assembly(uint in_vertex_id, float4x4 inst_matrix) const
void geometry_main(VertOut geom_in[2], uint out_vertex_id, uint out_primitive_id, uint, GeomOut &v_out, float4 &out_pos, float3 &out_wP) const
VertOut vertex_main(const ViewMatrices view, VertIn v_in) const
VertIn input_assembly(uint in_vertex_id, float4x4 inst_matrix) const
void do_vertex(const uint strip_index, uint out_vertex_id, uint out_primitive_id, float4 color, float4 hs_P, float3 ws_P, float coord, float2 offset, GeomOut &v_out, float4 &out_pos, float3 &out_wP) const
CCL_NAMESPACE_BEGIN struct Window V