Blender V5.3
draw_pointcloud.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "draw_defines.hh"
12#include "draw_model.bsl.hh"
17
19
20struct Point {
22 float radius;
23 /* Point index for attribute loading. */
25 /* Position on shape facing the camera. */
27};
28
35
36struct ShapePoint {
37 /* Position on the shape. */
39 /* Shading normal at the position on the shape. */
41};
42
43float3x3 facing_matrix(const float3 V, const float3 up_axis, bool flip)
44{
45 float3x3 facing_mat;
46 facing_mat[2] = V;
47 if (flip) {
48 facing_mat[2] = -facing_mat[2];
49 }
50 facing_mat[1] = normalize(cross(up_axis, facing_mat[2]));
51 facing_mat[0] = cross(facing_mat[1], facing_mat[2]);
52 return facing_mat;
53}
54
61 const float3 V,
62 const float3 up_axis,
63 const eObjectInfoFlag ob_flag,
64 bool flip = false)
65{
66 ShapePoint shape;
67 shape.N = facing_matrix(V, up_axis, flip) * pt.shape_pos;
68 if (flag_test(ob_flag, OBJECT_NEGATIVE_SCALE)) {
69 shape.N = -shape.N;
70 }
71 shape.P = pt.P + shape.N * pt.radius;
72 return shape;
73}
74
75} // namespace draw::pointcloud
76
77namespace draw {
78
79struct PointCloud {
81
83
84 static int point_id_get(uint vert_id)
85 {
86 /* Remove shape indices. */
87 return int(vert_id / uint(DRW_POINTCLOUD_STRIP_TILE_SIZE));
88 }
89
90 /* Return data about the pointcloud point. */
91 pointcloud::Point point_get(uint vert_id) const
92 {
94 pt.point_id = point_id_get(vert_id);
95
97 pt.P = pos_rad.xyz;
98 pt.radius = pos_rad.w;
100 switch (vert_id % DRW_POINTCLOUD_STRIP_TILE_SIZE) {
101 case 0:
102 pt.shape_pos = float3(-1.0, 0.0, 0.0);
103 break;
104 case 1:
105 pt.shape_pos = float3(0.0, -1.0, 0.0);
106 break;
107 case 2:
108 pt.shape_pos = float3(0.0, 0.0, 1.0);
109 break;
110 case 3:
111 pt.shape_pos = float3(1.0, 0.0, 0.0);
112 break;
113 case 4:
114 pt.shape_pos = float3(0.0, 0.0, 1.0);
115 break;
116 case 5:
117 pt.shape_pos = float3(0.0, 1.0, 0.0);
118 break;
119 case 6:
120 pt.shape_pos = float3(-1.0, 0.0, 0.0);
121 break;
122 default:
123 break;
124 }
125 return pt;
126 }
127};
128
129} // namespace draw
130
131namespace draw::pointcloud {
132
133float get_customdata_float(const int point_id, const samplerBuffer cd_buf)
134{
135 return texelFetch(cd_buf, point_id).r;
136}
137
138float2 get_customdata_vec2(const int point_id, const samplerBuffer cd_buf)
139{
140 return texelFetch(cd_buf, point_id).rg;
141}
142
143float3 get_customdata_vec3(const int point_id, const samplerBuffer cd_buf)
144{
145 return texelFetch(cd_buf, point_id).rgb;
146}
147
148float4 get_customdata_vec4(const int point_id, const samplerBuffer cd_buf)
149{
150 return texelFetch(cd_buf, point_id).rgba;
151}
152
154{
155 /* TODO: To be implemented. */
156 return float2(0.0f);
157}
158
159} // namespace draw::pointcloud
#define NAN_FLT
#define M_SQRT1_3
#define DRW_POINTCLOUD_STRIP_TILE_SIZE
@ OBJECT_NEGATIVE_SCALE
#define resource_table
#define sampler(slot)
#define frequency(freq)
VecBase< float, D > normalize(VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
float length(VecOp< float, D >) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
SamplerBase< float, 1 > samplerBuffer
float3 to_scale(float3x3 mat)
float3 transform_point(float3x3 mat, float3 point)
bool flag_test(uint flag, uint val)
MatBase< float, 4, 4 > float4x4
float3x3 facing_matrix(const float3 V, const float3 up_axis, bool flip)
Point object_to_world(Point pt, float4x4 object_to_world)
float get_customdata_float(const int point_id, const samplerBuffer cd_buf)
float3 get_customdata_vec3(const int point_id, const samplerBuffer cd_buf)
float4 get_customdata_vec4(const int point_id, const samplerBuffer cd_buf)
ShapePoint shape_point_get(const Point pt, const float3 V, const float3 up_axis, const eObjectInfoFlag ob_flag, bool flip=false)
float2 get_customdata_vec2(const int point_id, const samplerBuffer cd_buf)
pointcloud::Point point_get(uint vert_id) const
samplerBuffer ptcloud_pos_rad_tx
static int point_id_get(uint vert_id)
float w
Definition sky_math.h:225
CCL_NAMESPACE_BEGIN struct Window V