Blender V5.3
draw_debug_draw_display.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
13#include "draw_debug_shared.hh"
14
15/* TODO(fclem): Deduplicate with overlay. */
16/* edge_start and edge_pos needs to be in the range [0..sizeViewport]. */
17float4 pack_line_data(float2 frag_co, float2 edge_start, float2 edge_pos)
18{
19 float2 edge = edge_start - edge_pos;
20 float len = length(edge);
21 if (len > 0.0f) {
22 edge /= len;
23
24 /* Get perpendicular in direction of upper hemicircle. */
25 float2 perp = float2(-edge.y, edge.x);
26 if (perp.y < 0.0) {
27 perp = -perp;
28 }
29
30 /* Get distance along perpendicular by projection of edge. */
31 float sin_theta = perp.x;
32 float dist = dot(perp, frag_co - edge_start);
33
34 /* Leave 0.1f boundary around dist to differentiate cleared or intentionally blocked pixels. */
35 return float4(sin_theta * 0.5f + 0.5f, dist * 0.4f + 0.5f, 0.0f, 1.0f);
36 }
37 /* Default line if the origin is perfectly aligned with a pixel. */
38 return float4(0.0f, 0.5f, 0.0f, 1.0f);
39}
40
41namespace draw::debug {
42
48
50 [[storage(DRW_DEBUG_DRAW_SLOT, read)]] DRWDebugVertPair (&in_debug_lines_buf)[];
51 [[storage(DRW_DEBUG_DRAW_FEEDBACK_SLOT, read_write)]] DRWDebugVertPair (&out_debug_lines_buf)[];
52
55};
56
57[[vertex]]
59 [[out]] VertOut &v_out,
60 [[position]] float4 &out_pos,
61 [[vertex_id]] const int vert_id)
62{
63 int line_id = (vert_id / 2);
64 bool is_provoking_vertex = (vert_id & 1) == 0;
65 /* Skip the first vertex containing header data. */
66 DRWDebugVertPair vert = srt.in_debug_lines_buf[line_id + drw_debug_draw_offset];
67
68 float3 pos = uintBitsToFloat((is_provoking_vertex) ?
69 uint3(vert.pos1_x, vert.pos1_y, vert.pos1_z) :
70 uint3(vert.pos2_x, vert.pos2_y, vert.pos2_z));
71 float4 col = float4((uint4(vert.vert_color) >> uint4(0, 8, 16, 24)) & 0xFFu) / 255.0f;
72
73 /* Lifetime management. */
74 if (is_provoking_vertex && vert.lifetime > 1) {
75 /* drw_debug_draw_v_count */
76 uint vertid = atomicAdd(srt.out_debug_lines_buf[0].pos1_x, 2u);
77 if (vertid < DRW_DEBUG_DRAW_VERT_MAX) {
78 uint out_line_id = vertid / 2u;
79 vert.lifetime -= 1;
80 srt.out_debug_lines_buf[out_line_id + drw_debug_draw_offset] = vert;
81 }
82 }
83
84 v_out.final_color = col;
85 out_pos = srt.persmat * float4(pos, 1.0f);
86
87 v_out.edge_start = v_out.edge_pos = (0.5f * (out_pos.xy / out_pos.w) + 0.5f) * srt.size_viewport;
88}
89
94
95[[fragment]]
96void frag_main([[in]] const VertOut &v_out,
97 [[out]] FragOut &frag_out,
98 [[frag_coord]] const float4 frag_co)
99{
100 frag_out.color = v_out.final_color;
101 frag_out.line_data = pack_line_data(frag_co.xy, v_out.edge_start, v_out.edge_pos);
102}
103
105
106} // namespace draw::debug
ccl_device_inline float sin_theta(const float3 w)
float4 pack_line_data(float2 frag_co, float2 edge_start, float2 edge_pos)
#define DRW_DEBUG_DRAW_VERT_MAX
#define drw_debug_draw_offset
#define DRW_DEBUG_DRAW_SLOT
#define DRW_DEBUG_DRAW_FEEDBACK_SLOT
#define storage(slot, qualifiers)
#define position
#define flat
#define frag_coord
#define push_constant
#define resource_table
#define fragment
#define vertex_id
#define no_perspective
#define vertex
#define frag_color(slot)
float dot(VecOp< float, D >, VecOp< float, D >) RET
int atomicAdd(int &, int) RET
VecBase< float, D > uintBitsToFloat(VecOp< uint, D >) RET
float length(VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
MatBase< float, 4, 4 > float4x4
void vert_main(DebugDrawDisplay &srt, VertOut &v_out, float4 &out_pos, const int vert_id)
PipelineGraphic draw_display(vert_main, frag_main)
void frag_main(const VertOut &v_out, FragOut &frag_out, const float4 frag_co)
float x
float y