Untitled
Toggle main menu visibility
Loading...
Searching...
No Matches
cull_clusters.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
vec4
light_cam_pos;
20
vec4
light_cam_vel;
21
mat4
light_projection;
22
mat4
light_unjittered_projection;
23
mat4
light_view;
24
mat4
light_inv_projection;
25
mat4
light_unjittered_inv_projection;
26
mat4
light_inv_view;
27
};
28
29
layout
(std140, binding = 4) uniform PrevCameraData {
30
vec4
prev_cam_pos;
31
vec4
prev_cam_vel;
32
mat4
prev_projection;
33
mat4
prev_unjittered_projection;
34
mat4
prev_view;
35
mat4
prev_inv_projection;
36
mat4
prev_unjittered_inv_projection;
37
mat4
prev_inv_view;
38
};
39
40
41
struct
Light
42
{
43
44
vec3
pos
;
45
uint
entity_id
;
46
47
vec3
dir
;
48
float
outer_cos
;
49
50
vec3
color
;
51
float
cos_diff
;
52
53
float
intensity
;
54
uint
light_type
;
55
float
inner_angle
;
56
float
outer_angle
;
57
58
float
radius
;
59
uint
layer
;
60
uint
mesh
;
61
uint
tri
;
62
63
float
area
;
64
uint
pad0
;
65
uint
pad1
;
66
uint
pad2
;
67
68
};
69
layout
(std430, binding = 0) buffer LightData {
70
71
Light
lights[];
72
73
};
74
75
struct
AABB
76
{
77
vec4
min
;
78
vec4
max
;
79
};
80
81
layout
(std430, binding = 12) buffer ClusterAABBData {
82
AABB
cluster_AABBs[];
83
};
84
layout
(std430, binding = 13) buffer GlobalLightIndexData {
85
uint global_light_indices[];
86
};
87
struct
Cluster
88
{
89
90
uint
offset
;
91
uint
count
;
92
};
93
94
layout
(std430, binding = 14) buffer ClusterData {
95
Cluster
clusters[];
96
};
97
98
99
100
uniform
uvec3
uGridSize
;
101
uniform
float
uNear
;
102
uniform
float
uFar
;
103
104
105
uniform uint
uMaxLightsPerCluster
;
106
uniform uint
uLightCount
;
107
108
bool
test_sphere_aabb
(
vec3
light_pos,
float
light_radius,
vec4
min,
vec4
max)
109
{
110
111
vec3
closest_point =
clamp
(light_pos, min.xyz, max.xyz);
112
113
vec3
delta = light_pos - closest_point;
114
115
return
dot(delta, delta) <= (light_radius * light_radius);
116
}
117
void
main
()
118
{
119
120
uvec3
coord = gl_GlobalInvocationID.xyz;
121
if
(coord.
x
>=
uGridSize
.
x
|| coord.
y
>=
uGridSize
.
y
|| coord.
z
>=
uGridSize
.
z
)
return
;
122
123
uint index = coord.
x
+ (coord.
y
*
uGridSize
.
x
) + (coord.
z
*
uGridSize
.
x
*
uGridSize
.
y
);
124
125
AABB
cluster_aabb = cluster_AABBs[index];
126
127
uint offset = index *
uMaxLightsPerCluster
;
128
uint visible_count = 0;
129
130
for
(
int
i = 0; i <
uLightCount
; i++)
131
{
132
Light
l = lights[i];
133
if
(l.
light_type
!= 0)
continue
;
134
135
vec4
view_space_light =
view
*
vec4
(l.
pos
, 1.0);
136
vec3
light_pos_view_space = view_space_light.xyz;
137
138
if
(
test_sphere_aabb
(light_pos_view_space, l.
radius
, cluster_aabb.
min
, cluster_aabb.
max
))
139
{
140
global_light_indices[offset + visible_count] = i;
141
visible_count++;
142
if
(visible_count >=
uMaxLightsPerCluster
)
break
;
143
}
144
}
145
146
clusters[index].offset = offset;
147
clusters[index].count = visible_count;
148
149
150
}
layout
layout(local_size_x=16, local_size_y=16) in
main
void main()
Definition
audio_probe_bake.comp:465
test_sphere_aabb
bool test_sphere_aabb(vec3 light_pos, float light_radius, vec4 min, vec4 max)
Definition
cull_clusters.comp:108
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
uMaxLightsPerCluster
uniform uint uMaxLightsPerCluster
Definition
cull_clusters.comp:105
Light::intensity
float intensity
The intensity of the Light.
Definition
engine_types.h:1473
Light::pad1
uint pad1
Definition
cull_clusters.comp:65
Light::pos
vec3 pos
Position of light.
Definition
engine_types.h:1464
Light::layer
uint32_t layer
Which layer a DIRECTIONAL_LIGHT corresponds to in the SHADOW_MAP_FBO.
Definition
engine_types.h:1483
Cluster::count
uint count
Definition
cull_clusters.comp:91
Light::light_type
LightType light_type
The type of Light.
Definition
engine_types.h:1474
Light::color
vec3 color
Definition
lightmap_bounce.comp:19
Light::dir
vec3 dir
Direction for lights that are not POINT_LIGHTs.
Definition
engine_types.h:1467
Light::inner_angle
float inner_angle
Starting angle for SPOT_LIGHTs.
Definition
engine_types.h:1475
Light::pad2
uint pad2
Definition
lightmap_bounce.comp:35
Light::tri
int tri
The MeshFace this corresponds to.
Definition
engine_types.h:1486
Light::outer_angle
float outer_angle
Outer angle for SPOT_LIGHTs.
Definition
engine_types.h:1476
Light::outer_cos
float outer_cos
Definition
lightmap_bounce.comp:17
Light::cos_diff
float cos_diff
Definition
lightmap_bounce.comp:20
Light::radius
float radius
The radius of the Light.
Definition
engine_types.h:1478
Light::mesh
int mesh
The MeshNode this corresponds to.
Definition
engine_types.h:1485
Cluster::offset
uint offset
Definition
cull_clusters.comp:90
Light::pad0
uint pad0
Definition
cull_clusters.comp:64
Light::area
AABB area
The physical area of AREA_LIGHTs.
Definition
engine_types.h:1480
Light::entity_id
uint32_t entity_id
Entity ID into ENTITIES.
Definition
engine_types.h:1465
Cluster
GPU-side Clusters for clustered forward.
Definition
cull_clusters.comp:88
Light
The CPU side structure for Lights.
Definition
engine_types.h:1462
uLightCount
uniform int uLightCount
Definition
lightmap_bounce.comp:249
clamp
float clamp(float a, float b, float c)
Definition
mathf.h:379
projection
uniform mat4 projection
Definition
shadow.vert:15
view
uniform mat4 view
Definition
shadow.vert:16
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
uvec3
Definition
types.h:18
vec3
Definition
types.h:12
vec4
Definition
types.h:13
src
render
cull_clusters.comp
Generated by
1.18.0