1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/* NOTE: To be used with UNIFORM_RESOURCE_ID and INSTANCED_ATTR as define. */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
int pointcloud_get_point_id()
{
return gl_VertexID / 32;
}
mat3 pointcloud_get_facing_matrix(vec3 p)
{
mat3 facing_mat;
facing_mat[2] = cameraVec(p);
facing_mat[1] = normalize(cross(ViewMatrixInverse[0].xyz, facing_mat[2]));
facing_mat[0] = cross(facing_mat[1], facing_mat[2]);
return facing_mat;
}
/* Returns world center position and radius. */
void pointcloud_get_pos_and_radius(out vec3 outpos, out float outradius)
{
int id = pointcloud_get_point_id();
vec4 pos_rad = texelFetch(ptcloud_pos_rad_tx, id);
outpos = point_object_to_world(pos_rad.xyz);
outradius = dot(abs(mat3(ModelMatrix) * pos_rad.www), vec3(1.0 / 3.0));
}
/* Return world position and normal. */
void pointcloud_get_pos_and_nor(out vec3 outpos, out vec3 outnor)
{
vec3 p;
float radius;
pointcloud_get_pos_and_radius(p, radius);
mat3 facing_mat = pointcloud_get_facing_matrix(p);
/** \note: Avoid modulo by non-power-of-two in shader. See Index buffer setup. */
int vert_id = gl_VertexID % 32;
vec3 pos_inst = vec3(0.0);
switch (vert_id) {
case 0:
pos_inst.z = 1.0;
break;
case 1:
pos_inst.x = 1.0;
break;
case 2:
pos_inst.y = 1.0;
break;
case 3:
pos_inst.x = -1.0;
break;
case 4:
pos_inst.y = -1.0;
break;
}
/* TODO(fclem): remove multiplication here. Here only for keeping the size correct for now. */
radius *= 0.01;
outnor = facing_mat * pos_inst;
outpos = p + outnor * radius;
}
vec3 pointcloud_get_pos()
{
vec3 outpos, outnor;
pointcloud_get_pos_and_nor(outpos, outnor);
return outpos;
}
float pointcloud_get_customdata_float(const samplerBuffer cd_buf)
{
int id = pointcloud_get_point_id();
return texelFetch(cd_buf, id).r;
}
vec2 pointcloud_get_customdata_vec2(const samplerBuffer cd_buf)
{
int id = pointcloud_get_point_id();
return texelFetch(cd_buf, id).rg;
}
vec3 pointcloud_get_customdata_vec3(const samplerBuffer cd_buf)
{
int id = pointcloud_get_point_id();
return texelFetch(cd_buf, id).rgb;
}
vec4 pointcloud_get_customdata_vec4(const samplerBuffer cd_buf)
{
int id = pointcloud_get_point_id();
return texelFetch(cd_buf, id).rgba;
}
vec2 pointcloud_get_barycentric(void)
{
/* TODO: To be implemented. */
return vec2(0.0);
}
|