30 layout(local_size_x = 64) in;
79 uint
count = atomicCounterIncrement(instanceCountLOD0);
85 for (
int f = 0;
f < 6;
f++)
87 float plane_distance = dot(uFrustum[
f],
vec4(center, 1.0));
89 if (plane_distance < -radius)
98 if (ident >= uNumBoundingBoxes)
101 vec4 instance_data = input_instance.data[ident].position;
102 vec3 center = instance_data.xyz;
108 vec3 view_center = (uView *
vec4(center, 1.0)).xyz;
109 float nearest_z = view_center.z + radius;
112 if (nearest_z >= -zNearFar.x)
118 float az_plane_horiz_length =
length(view_center.xz);
119 float az_plane_vert_length =
length(view_center.yz);
120 vec2 az_plane_horiz_norm = view_center.xz / az_plane_horiz_length;
121 vec2 az_plane_vert_norm = view_center.yz / az_plane_vert_length;
123 vec2 t = sqrt(
vec2(az_plane_horiz_length, az_plane_vert_length) *
vec2(az_plane_horiz_length, az_plane_vert_length) - radius * radius);
124 vec4 w =
vec4(t, radius, radius) /
vec2(az_plane_horiz_length, az_plane_vert_length).xyxy;
126 vec4 horiz_cos_sin = az_plane_horiz_norm.xyyx * t.x *
vec4(w.xx, -w.
z, w.
z);
127 vec4 vert_cos_sin = az_plane_vert_norm.xyyx * t.y * vec4(w.yy, -w.
w, w.
w);
129 vec2 horiz0 = horiz_cos_sin.xy + horiz_cos_sin.zw;
130 vec2 horiz1 = horiz_cos_sin.xy - horiz_cos_sin.zw;
131 vec2 vert0 = vert_cos_sin.xy + vert_cos_sin.zw;
132 vec2 vert1 = vert_cos_sin.xy - vert_cos_sin.zw;
134 vec4 projected = -0.5 * vec4(uProj[0][0], uProj[0][0], uProj[1][1], uProj[1][1]) *
135 vec4(horiz0.
x, horiz1.
x, vert0.
x, vert1.
x) /
136 vec4(horiz0.
y, horiz1.
y, vert0.
y, vert1.
y) + 0.5;
138 vec2 min_xy = projected.yw;
139 vec2 max_xy = projected.xz;
141 vec2 zw = mat2(uProj[2].zw, uProj[3].zw) *
vec2(nearest_z, 1.0);
142 nearest_z = 0.5 * zw.x / zw.y + 0.5;
144 vec2 diff_pix = (max_xy - min_xy) *
vec2(textureSize(uDepth, 0));
145 float max_diff =
max(
max(diff_pix.
x, diff_pix.
y), 1.0);
146 float lod = ceil(log2(max_diff));
147 vec2 mid_pix = 0.5 * (max_xy + min_xy);
149 if (textureLod(uDepth,
vec3(mid_pix, nearest_z), lod) > 0.0)
precision highp sampler2DShadow
GLenum GLuint GLintptr offset
bool frustum_test(vec3 center, float radius)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei count
layout(local_size_x=64) in
GLfloat GLfloat GLfloat w
float max(float x, float y)
void uniform(string name, const mat4 &v)
GLint GLint GLint GLint GLint x
GLenum GLuint GLenum GLsizei length