Untitled
Loading...
Searching...
No Matches
init_cluster_aabbs.comp
Go to the documentation of this file.
1
2#version 430 core
3layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
4
5layout(std140, binding = 0) uniform CameraData {
6 vec4 cam_pos;
7 vec4 cam_vel;
9 mat4 unjittered_projection;
10 mat4 view;
11 mat4 inv_projection;
12 mat4 unjittered_inv_projection;
13 mat4 inv_view;
14};
15layout(std140, binding = 1) uniform RenderingData {
16 ivec4 resolution;
17};
18layout(std140, binding = 2) uniform LightCameraData {
19 mat4 light_proj[4];
20 mat4 light_view[4];
21};
22
23layout(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
34struct AABB {
35 vec4 min;
36 vec4 max;
37};
38
39layout(std430, binding = 12) buffer ClusterAABBData {
40 AABB cluster_AABBs[];
41};
42
44uniform float uNear;
45uniform float uFar;
46
48
49
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
59vec3 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
73void 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(local_size_x=16, local_size_y=16) in
void main()
uniform float uFar
uniform uvec3 uGridSize
uniform float uNear
uniform uvec2 uScreenDimensions
vec3 screen_to_view_space(vec2 screen_coord)
vec3 line_intersection_z(vec3 start, vec3 end, float z)
uniform mat4 projection
Definition shadow.vert:15
uniform mat4 view
Definition shadow.vert:16
float w
Definition types.h:13
uint32_t x
Definition types.h:18
uint32_t z
Definition types.h:18
uint32_t y
Definition types.h:18
Definition types.h:16
Definition types.h:21
Definition types.h:17
Definition types.h:18
Definition types.h:11
Definition types.h:12
Definition types.h:13