41 layout(local_size_x = 64) in;
100 uint
count = atomicCounterIncrement(instanceCountLOD0);
105 uint
count = atomicCounterIncrement(instanceCountLOD1);
108 else if (minz < 0.95)
110 uint
count = atomicCounterIncrement(instanceCountLOD2);
115 uint
count = atomicCounterIncrement(instanceCountLOD3);
122 for (
int f = 0;
f < 6;
f++)
124 float plane_distance = dot(uFrustum[
f],
vec4(center, 1.0));
126 if (plane_distance < -radius)
135 if (ident >= uNumBoundingBoxes)
138 vec4 instance_data = input_instance.data[ident].position;
139 vec3 center = instance_data.xyz;
147 vec3 view_center = (uView *
vec4(center, 1.0)).xyz;
148 float nearest_z = view_center.z + radius;
151 if (nearest_z >= -zNearFar.x)
166 float az_plane_horiz_length =
length(view_center.xz);
167 float az_plane_vert_length =
length(view_center.yz);
168 vec2 az_plane_horiz_norm = view_center.xz / az_plane_horiz_length;
169 vec2 az_plane_vert_norm = view_center.yz / az_plane_vert_length;
171 vec2 t = sqrt(
vec2(az_plane_horiz_length, az_plane_vert_length) *
vec2(az_plane_horiz_length, az_plane_vert_length) - radius * radius);
172 vec4 w =
vec4(t, radius, radius) /
vec2(az_plane_horiz_length, az_plane_vert_length).xyxy;
176 vec4 horiz_cos_sin = az_plane_horiz_norm.xyyx * t.x *
vec4(w.xx, -w.
z, w.
z);
177 vec4 vert_cos_sin = az_plane_vert_norm.xyyx * t.y * vec4(w.yy, -w.
w, w.
w);
179 vec2 horiz0 = horiz_cos_sin.xy + horiz_cos_sin.zw;
180 vec2 horiz1 = horiz_cos_sin.xy - horiz_cos_sin.zw;
181 vec2 vert0 = vert_cos_sin.xy + vert_cos_sin.zw;
182 vec2 vert1 = vert_cos_sin.xy - vert_cos_sin.zw;
185 vec4 projected = -0.5 * vec4(uProj[0][0], uProj[0][0], uProj[1][1], uProj[1][1]) *
186 vec4(horiz0.
x, horiz1.
x, vert0.
x, vert1.
x) /
187 vec4(horiz0.
y, horiz1.
y, vert0.
y, vert1.
y) + 0.5;
190 vec2 min_xy = projected.yw;
191 vec2 max_xy = projected.xz;
194 vec2 zw = mat2(uProj[2].zw, uProj[3].zw) *
vec2(nearest_z, 1.0);
195 nearest_z = 0.5 * zw.x / zw.y + 0.5;
198 vec2 diff_pix = (max_xy - min_xy) *
vec2(textureSize(uDepth, 0));
199 float max_diff =
max(
max(diff_pix.
x, diff_pix.
y), 1.0);
200 float lod = ceil(log2(max_diff));
202 vec2 mid_pix = 0.5 * (max_xy + min_xy);
205 if (textureLod(uDepth,
vec3(mid_pix, nearest_z), lod) > 0.0)
layout(local_size_x=64) in
GLenum GLuint GLintptr offset
bool frustum_test(vec3 center, float radius)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei count
void append_instance(float minz)
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
precision highp sampler2DShadow