Untitled
Toggle main menu visibility
Loading...
Searching...
No Matches
init_cluster_aabbs.comp
Go to the documentation of this file.
1
2
#version 430 core
3
layout
(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
4
5
layout
(std140, binding = 0) uniform CameraData {
6
vec4
cam_pos;
7
vec4
cam_vel;
8
mat4
projection
;
9
mat4
unjittered_projection;
10
mat4
view
;
11
mat4
inv_projection;
12
mat4
unjittered_inv_projection;
13
mat4
inv_view;
14
};
15
layout
(std140, binding = 1) uniform RenderingData {
16
ivec4
resolution;
17
};
18
layout
(std140, binding = 2) uniform LightCameraData {
19
mat4
light_proj[4];
20
mat4
light_view[4];
21
};
22
23
layout
(std140, binding = 4) uniform PrevCameraData {
24
vec4
prev_cam_pos;
25
vec4
prev_cam_vel;
26
mat4
prev_projection;
27
mat4
prev_unjittered_projection;
28
mat4
prev_view;
29
mat4
prev_inv_projection;
30
mat4
prev_unjittered_inv_projection;
31
mat4
prev_inv_view;
32
};
33
34
struct
AABB
{
35
vec4
min
;
36
vec4
max
;
37
};
38
39
layout
(std430, binding = 12) buffer ClusterAABBData {
40
AABB
cluster_AABBs[];
41
};
42
43
uniform
uvec3
uGridSize
;
44
uniform
float
uNear
;
45
uniform
float
uFar
;
46
47
uniform
uvec2
uScreenDimensions
;
48
49
50
vec3
screen_to_view_space
(
vec2
screen_coord) {
51
vec4
ndc =
vec4
(screen_coord /
uScreenDimensions
.xy * 2.0 - 1.0, -1.0, 1.0);
52
vec4
view_space = inv_projection * ndc;
53
54
view_space /= view_space.
w
;
55
56
return
view_space.xyz;
57
}
58
59
vec3
line_intersection_z
(
vec3
start,
vec3
end,
float
z)
60
{
61
62
vec3
direction = end - start;
63
vec3
normal =
vec3
(0, 0, -1);
64
65
float
t = (z - dot(normal, start)) / dot(normal, direction);
66
67
return
start + t * direction;
68
69
}
70
71
72
73
void
main
()
74
{
75
76
uvec3
coord = gl_GlobalInvocationID.xyz;
77
78
uint index = coord.
x
+ (coord.
y
*
uGridSize
.
x
) + (coord.
z
*
uGridSize
.
x
*
uGridSize
.
y
);
79
80
vec2
tile_size =
uScreenDimensions
/
vec2
(
uGridSize
.xy);
81
82
vec2
min_coord =
vec2
(coord.xy) * tile_size;
83
vec2
max_coord =
vec2
(coord.xy + 1) * tile_size;
84
85
86
vec3
min_tile =
screen_to_view_space
(min_coord);
87
vec3
max_tile =
screen_to_view_space
(max_coord);
88
89
float
depth_ratio =
uFar
/
uNear
;
90
float
slice_near =
uNear
* pow(depth_ratio,
float
(coord.
z
) /
float
(
uGridSize
.
z
));
91
float
slice_far =
uNear
* pow(depth_ratio,
float
(coord.
z
+ 1) /
float
(
uGridSize
.
z
));
92
93
vec3
min_near =
line_intersection_z
(
vec3
(0,0,0), min_tile, slice_near);
94
vec3
min_far =
line_intersection_z
(
vec3
(0,0,0), min_tile, slice_far);
95
vec3
max_near =
line_intersection_z
(
vec3
(0,0,0), max_tile, slice_near);
96
vec3
max_far =
line_intersection_z
(
vec3
(0,0,0), max_tile, slice_far);
97
98
99
100
cluster_AABBs[index].min =
vec4
(min(min_near, min_far), 1.0);
101
cluster_AABBs[index].max =
vec4
(max(max_near, max_far), 1.0);
102
103
104
105
106
}
layout
layout(local_size_x=16, local_size_y=16) in
main
void main()
Definition
audio_probe_bake.comp:465
uFar
uniform float uFar
Definition
cull_clusters.comp:102
uGridSize
uniform uvec3 uGridSize
Definition
cull_clusters.comp:100
uNear
uniform float uNear
Definition
cull_clusters.comp:101
uScreenDimensions
uniform uvec2 uScreenDimensions
Definition
init_cluster_aabbs.comp:47
screen_to_view_space
vec3 screen_to_view_space(vec2 screen_coord)
Definition
init_cluster_aabbs.comp:50
line_intersection_z
vec3 line_intersection_z(vec3 start, vec3 end, float z)
Definition
init_cluster_aabbs.comp:59
projection
uniform mat4 projection
Definition
shadow.vert:15
view
uniform mat4 view
Definition
shadow.vert:16
vec4::w
float w
Definition
types.h:13
uvec3::x
uint32_t x
Definition
types.h:18
uvec3::z
uint32_t z
Definition
types.h:18
uvec3::y
uint32_t y
Definition
types.h:18
AABB::min
vec3 min
Definition
audio_probe_bake.comp:113
AABB::max
vec3 max
Definition
audio_probe_bake.comp:115
AABB
Definition
audio_probe_bake.comp:111
ivec4
Definition
types.h:16
mat4
Definition
types.h:21
uvec2
Definition
types.h:17
uvec3
Definition
types.h:18
vec2
Definition
types.h:11
vec3
Definition
types.h:12
vec4
Definition
types.h:13
src
render
init_cluster_aabbs.comp
Generated by
1.18.0