Skip to content

Commit

Permalink
Fix negative values in variance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Apr 16, 2024
1 parent f95f9c2 commit cdcb46f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion internal/RendererCPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ void Ray::Cpu::Renderer<SIMDPolicy>::RenderScene(const SceneBase &scene, RegionC
const Ref::fvec4 tonemapped_res = Tonemap(tonemap_params, full_val);
tonemapped_res.store_to(final_buf_[y * w_ + x].v, Ref::vector_aligned);

const Ref::fvec4 p1 = reversible_tonemap(2.0f * full_val - half_val);
const Ref::fvec4 p1 = reversible_tonemap(max(2.0f * full_val - half_val, 0.0f));
const Ref::fvec4 p2 = reversible_tonemap(half_val);

const Ref::fvec4 variance = 0.5f * (p1 - p2) * (p1 - p2);
Expand Down
10 changes: 5 additions & 5 deletions internal/RendererDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,13 +1281,13 @@ void Ray::Dx::Renderer::UpdateSpatialCache(const SceneBase &scene, RegionContext
cam.fstop = 0.0f;
cam.filter = ePixelFilter::Box;

// TODO: Use common command buffer for all uploads
if (cam.filter != filter_table_filter_ || cam.filter_width != filter_table_width_) {
// TODO: Filter table is unused, this can be removed
if (orig_cam.filter != filter_table_filter_ || orig_cam.filter_width != filter_table_width_) {
CommandBuffer cmd_buf = BegSingleTimeCommands(ctx_->api(), ctx_->device(), ctx_->temp_command_pool());

UpdateFilterTable(cmd_buf, cam.filter, cam.filter_width);
filter_table_filter_ = cam.filter;
filter_table_width_ = cam.filter_width;
UpdateFilterTable(cmd_buf, orig_cam.filter, orig_cam.filter_width);
filter_table_filter_ = orig_cam.filter;
filter_table_width_ = orig_cam.filter_width;

EndSingleTimeCommands(ctx_->api(), ctx_->device(), ctx_->graphics_queue(), cmd_buf, ctx_->temp_command_pool());
}
Expand Down
6 changes: 3 additions & 3 deletions internal/shaders/output/postprocess.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/postprocess.comp.spv.inl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/shaders/postprocess.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void main() {
#endif
imageStore(g_out_img, gi, tonemapped_res);

vec4 p1 = reversible_tonemap(2.0 * full_val - half_val);
vec4 p1 = reversible_tonemap(max(2.0 * full_val - half_val, 0.0));
vec4 p2 = reversible_tonemap(half_val);

vec4 variance = 0.5 * (p1 - p2) * (p1 - p2);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_materials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ void test_complex_mat6_sun_light(const char *arch_list[], const char *preferred_
void test_complex_mat6_hdri_light(const char *arch_list[], const char *preferred_device) {
const int SampleCount = 62;
const double MinPSNR = 21.0;
const int PixThres = 6249;
const int PixThres = 6250;

Ray::principled_mat_desc_t olive_mat_desc;
olive_mat_desc.base_color[0] = 0.836164f;
Expand Down

0 comments on commit cdcb46f

Please sign in to comment.