Skip to content

Commit

Permalink
some minor changes in shaders, still flickering-issue with meshlet-oc…
Browse files Browse the repository at this point in the history
…clusion
  • Loading branch information
crocdialer committed Oct 21, 2024
1 parent 10f4db0 commit d56ac36
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
32 changes: 17 additions & 15 deletions shaders/pbr/cull_meshlets.task
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool cone_cull(vec3 center, float radius, vec3 cone_axis, float cone_cutoff, vec

bool is_visible(uint visibility_base_index, uint meshlet_index)
{
return (meshlet_visibilities[visibility_base_index + (meshlet_index >> 5)] & (1 << (meshlet_index & 31U))) != 0;
return (meshlet_visibilities[visibility_base_index + (meshlet_index >> 5)] & (1 << (meshlet_index & 31U))) != 0;
}

void set_visible(uint visibility_base_index, uint meshlet_index, bool visible)
Expand Down Expand Up @@ -109,7 +109,9 @@ void main()
vec3 cone_axis = normalize(mat3(m) * meshlets[mi].cone_axis);
float cone_cutoff = meshlets[mi].cone_cutoff;
vec3 center = (m * vec4(meshlets[mi].sphere_center, 1.0)).xyz;
float radius = meshlets[mi].sphere_radius * length(m[0].xyz);
float radius = meshlets[mi].sphere_radius * max(max(abs(draws[object_index].current_matrices.transform.scale_x),
abs(draws[object_index].current_matrices.transform.scale_y)),
abs(draws[object_index].current_matrices.transform.scale_z));

// cone-culling
visible = materials[draws[object_index].material_index].two_sided ||
Expand All @@ -133,19 +135,19 @@ void main()
visible = max(screen_area.x, screen_area.y) >= size_thresh;
}

// occlusion-culling
if(visible && sphere_visible)
{
float width = screen_area.x * pyramid_size.x;
float height = screen_area.y * pyramid_size.y;
float level = floor(log2(max(width, height)));

// Sampler is set up to do min reduction, so this computes the minimum depth of a 2x2 texel quad
float depth = textureLod(u_depth_pyramid, (aabb.xy + aabb.zw) * 0.5, level).x;
float depth_sphere = camera.near / (-center.z - radius);

visible = depth_sphere >= depth;
}
// // occlusion-culling
// if(visible && sphere_visible)
// {
// float width = screen_area.x * pyramid_size.x;
// float height = screen_area.y * pyramid_size.y;
// float level = floor(log2(max(width, height)));
//
// // Sampler is set up to do min reduction, so this computes the minimum depth of a 2x2 texel quad
// float depth = camera.near / textureLod(u_depth_pyramid, (aabb.xy + aabb.zw) * 0.5, level).x;
// float depth_sphere = -center.z - radius;
//
// visible = depth_sphere <= depth;
// }

// became visible this frame -> not drawn in 1st-pass
bool needs_post_draw = visible && !is_visible(draw_command.meshlet_visibility_index, mi);
Expand Down
14 changes: 4 additions & 10 deletions shaders/pbr/g_buffer.mesh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
#extension GL_EXT_shader_16bit_storage: require
#extension GL_EXT_shader_explicit_arithmetic_types: require

#include "../renderer/mesh_task_payload.glsl"
#include "g_buffer_vertex_data.glsl"
#include "../renderer/types.glsl"
#include "../utils/camera.glsl"
#include "../renderer/mesh_task_payload.glsl"
#include "../utils/packed_vertex.glsl"
#include "../utils/camera.glsl"

// TODO: not really worth it? not sure ...
#define CULLING 0
Expand Down Expand Up @@ -59,14 +60,7 @@ layout(push_constant) uniform PushConstants
taskPayloadSharedEXT mesh_task_payload_t task_payload;

layout(location = LOCATION_INDEX_BUNDLE) flat out index_bundle_t indices[];
layout(location = LOCATION_VERTEX_BUNDLE) out VertexData
{
vec2 tex_coord;
vec3 normal;
vec3 tangent;
vec4 current_position;
vec4 last_position;
} vertex_out[];
layout(location = LOCATION_VERTEX_BUNDLE) out g_buffer_vertex_data_t vertex_out[];

#if CULLING
shared vec3 vertex_clip[MESHLET_MAX_VERTICES];
Expand Down
5 changes: 1 addition & 4 deletions shaders/pbr/g_buffer.vert
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ layout(push_constant) uniform PushConstants
};

layout(location = LOCATION_INDEX_BUNDLE) flat out index_bundle_t indices;
layout(location = LOCATION_VERTEX_BUNDLE) out VertexData
{
g_buffer_vertex_data_t vertex_out;
};
layout(location = LOCATION_VERTEX_BUNDLE) out g_buffer_vertex_data_t vertex_out;

void main()
{
Expand Down
6 changes: 3 additions & 3 deletions shaders/pbr/indirect_cull.comp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ void main()
float level = floor(log2(max(width, height)));

// Sampler is set up to do min reduction, so this computes the minimum depth of a 2x2 texel quad
float depth = textureLod(u_depth_pyramid, (aabb.xy + aabb.zw) * 0.5, level).x;
float depth_sphere = cull_data.znear / (-center.z - radius);
float depth = cull_data.znear / textureLod(u_depth_pyramid, (aabb.xy + aabb.zw) * 0.5, level).x;
float depth_sphere = -center.z - radius;

visible = visible && (depth_sphere >= depth);
visible = depth_sphere <= depth;
if(!visible){ atomicAdd(cull_data.draw_result.v.num_occlusion_culled, 1); }
}

Expand Down

0 comments on commit d56ac36

Please sign in to comment.