blob: 8006c51a94623d61dd3b177b70745d82f53d776d (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
uniform depth2D depthBuffer;
uniform mat4 gridModelMatrix;
uniform bool isTransform;
out vec4 finalColor;
vec4 color_from_id(float color_id)
{
if (isTransform) {
return colorTransform;
}
else if (color_id == 1.0) {
return colorActive;
}
else /* 2.0 */ {
return colorSelect;
}
return colorTransform;
}
/* Replace top 2 bits (of the 16bit output) by outlineId.
* This leaves 16K different IDs to create outlines between objects.
* SHIFT = (32 - (16 - 2)) */
#define SHIFT 18u
void main()
{
mat4 model_mat = gridModelMatrix;
model_mat[0][3] = model_mat[1][3] = model_mat[2][3] = 0.0;
model_mat[3][3] = 1.0;
float color_id = gridModelMatrix[3].w;
ivec3 grid_resolution = ivec3(gridModelMatrix[0].w, gridModelMatrix[1].w, gridModelMatrix[2].w);
vec3 ls_cell_location;
/* Keep in sync with update_irradiance_probe */
ls_cell_location.z = float(gl_VertexID % grid_resolution.z);
ls_cell_location.y = float((gl_VertexID / grid_resolution.z) % grid_resolution.y);
ls_cell_location.x = float(gl_VertexID / (grid_resolution.z * grid_resolution.y));
ls_cell_location += 0.5;
ls_cell_location /= vec3(grid_resolution);
ls_cell_location = ls_cell_location * 2.0 - 1.0;
vec3 ws_cell_location = (model_mat * vec4(ls_cell_location, 1.0)).xyz;
gl_Position = point_world_to_ndc(ws_cell_location);
gl_PointSize = sizeVertex * 2.0;
finalColor = color_from_id(color_id);
/* Shade occluded points differently. */
vec4 p = gl_Position / gl_Position.w;
float z_depth = texture(depthBuffer, p.xy * 0.5 + 0.5).r * 2.0 - 1.0;
float z_delta = p.z - z_depth;
if (z_delta > 0.0) {
float fac = 1.0 - z_delta * 10000.0;
/* Smooth blend to avoid flickering. */
finalColor = mix(colorBackground, finalColor, clamp(fac, 0.5, 1.0));
}
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(ws_cell_location);
#endif
}
|