blob: 41a8df3cf82b54eaaa457ac4d78878356dd66c38 (
plain)
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
|
/* To be compile with common_subdiv_lib.glsl */
layout(std430, binding = 1) readonly buffer inputVertexData
{
PosNorLoop pos_nor[];
};
layout(std430, binding = 2) readonly buffer extraCoarseFaceData
{
uint extra_coarse_face_data[];
};
layout(std430, binding = 3) writeonly buffer outputLoopNormals
{
vec3 output_lnor[];
};
void main()
{
/* We execute for each quad. */
uint quad_index = get_global_invocation_index();
if (quad_index >= total_dispatch_size) {
return;
}
/* The start index of the loop is quad_index * 4. */
uint start_loop_index = quad_index * 4;
uint coarse_quad_index = coarse_polygon_index_from_subdiv_quad_index(quad_index,
coarse_poly_count);
if ((extra_coarse_face_data[coarse_quad_index] & coarse_face_smooth_mask) != 0) {
/* Face is smooth, use vertex normals. */
for (int i = 0; i < 4; i++) {
PosNorLoop pos_nor_loop = pos_nor[start_loop_index + i];
output_lnor[start_loop_index + i] = get_vertex_nor(pos_nor_loop);
}
}
else {
/* Face is flat shaded, compute flat face normal from an inscribed triangle. */
vec3 verts[3];
for (int i = 0; i < 3; i++) {
verts[i] = get_vertex_pos(pos_nor[start_loop_index + i]);
}
vec3 face_normal = normalize(cross(verts[1] - verts[0], verts[2] - verts[0]));
for (int i = 0; i < 4; i++) {
output_lnor[start_loop_index + i] = face_normal;
}
}
}
|