Skip to content

Commit

Permalink
Add option to visualize focus-region in DoF shader
Browse files Browse the repository at this point in the history
  • Loading branch information
crocdialer committed Dec 6, 2024
1 parent e32d6cc commit 3af59b7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/vierkant/PBRDeferred.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class PBRDeferred : public vierkant::SceneRenderer
//! enable depth of field
bool depth_of_field = false;

//! enable depth of field focus-visualization
bool use_dof_focus_overlay = false;

//! enable ray-query support
bool use_ray_queries = true;

Expand Down Expand Up @@ -249,6 +252,7 @@ class PBRDeferred : public vierkant::SceneRenderer
float sensor_width;
float near;
float far;
VkBool32 debug = false;
};

//! morph_params_t contains information to access a morph-target buffer
Expand Down
9 changes: 8 additions & 1 deletion shaders/utils/dof.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct dof_params_t
float sensor_width;
float near;
float far;
bool debug;
};

float linearize(float depth, float near, float far)
Expand Down Expand Up @@ -69,8 +70,14 @@ vec4 depth_of_field(sampler2D color_map, sampler2D depth_map, vec2 coord, vec2 v
color += texture(color_map, coord + offset).rgb;
}
color /= num_taps;

if(p.debug)
{
// visualize focus-region using overlayed jet-colormap
vec3 focus_overlay = jet(1.0 - clamp(circle_of_confusion_sz * (p.focal_distance) / p.focal_length, 0.0, 1.0));
return vec4(mix(color, focus_overlay, 0.2), 1.0);
}
return vec4(color, 1.0);
// return vec4(mix(color, jet(1.0 - clamp(circle_of_confusion_sz * (p.focal_distance) / p.focal_length, 0.0, 1.0)), 0.2), 1.0);
}

#endif // DOF_GLSL
2 changes: 2 additions & 0 deletions src/PBRDeferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,7 @@ vierkant::ImagePtr PBRDeferred::post_fx_pass(const CameraPtr &cam, const vierkan
dof_params.aperture = static_cast<float>(cam_params.aperture_size());
dof_params.near = cam_params.clipping_distances.x;
dof_params.far = cam_params.clipping_distances.y;
dof_params.debug = frame_context.settings.use_dof_focus_overlay;
vierkant::staging_copy_info_t staging_copy_info = {};
staging_copy_info.data = &dof_params;
staging_copy_info.num_bytes = sizeof(dof_params);
Expand Down Expand Up @@ -1564,6 +1565,7 @@ bool operator==(const PBRDeferred::settings_t &lhs, const PBRDeferred::settings_
if(lhs.use_ray_queries != rhs.use_ray_queries) { return false; }
if(lhs.timing_history_size != rhs.timing_history_size) { return false; }
if(lhs.depth_of_field != rhs.depth_of_field) { return false; }
if(lhs.use_dof_focus_overlay != rhs.use_dof_focus_overlay) { return false; }
return true;
// return memcmp(&lhs, &rhs, sizeof(PBRDeferred::settings_t)) == 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/imgui/imgui_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ void draw_scene_renderer_ui_intern(const PBRDeferredPtr &pbr_renderer)
ImGui::Checkbox("bloom", &pbr_renderer->settings.bloom);
ImGui::Checkbox("motionblur", &pbr_renderer->settings.motionblur);
ImGui::Checkbox("depth of field", &pbr_renderer->settings.depth_of_field);
ImGui::Checkbox("dof focus-overlay", &pbr_renderer->settings.use_dof_focus_overlay);

// motionblur gain
ImGui::SliderFloat("motionblur gain", &pbr_renderer->settings.motionblur_gain, 0.f, 10.f);
Expand Down Expand Up @@ -1170,7 +1171,7 @@ void draw_camera_param_ui(vierkant::physical_camera_params_t &camera_params)
// f-stop/aperture
constexpr float f_stop_min = 0.1f, f_stop_max = 128.f;
ImGui::BulletText("aperture: %.1f mm", camera_params.aperture_size() * 1000);
ImGui::SliderFloat("f-stop", &camera_params.fstop, f_stop_min, f_stop_max);
ImGui::SliderFloat("f-stop", &camera_params.fstop, f_stop_min, f_stop_max, "%.2f", ImGuiSliderFlags_Logarithmic);
}

}// namespace vierkant::gui

0 comments on commit 3af59b7

Please sign in to comment.