Skip to content

Commit

Permalink
Normalize base color output
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Jul 30, 2024
1 parent 7a41bd5 commit 8986c76
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 51 deletions.
7 changes: 5 additions & 2 deletions internal/CoreSIMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -7952,8 +7952,11 @@ void Ray::NS::ShadePrimary(const pass_settings_t &ps, Span<const hit_data_t<S>>
if (out_base_color) {
if (cache_mode != eSpatialCacheMode::Update) {
auto old_val = fvec4(out_base_color[y[j] * img_w + x[j]].v, vector_aligned);
old_val +=
(fvec4{base_color[0][j], base_color[1][j], base_color[2][j], 0.0f} - old_val) * mix_factor;
auto new_val = fvec4{base_color[0][j], base_color[1][j], base_color[2][j], 0.0f};
const float norm_factor =
fmaxf(fmaxf(new_val.get<0>(), new_val.get<1>()), fmaxf(new_val.get<2>(), 1.0f));
new_val /= norm_factor;
old_val += (new_val - old_val) * mix_factor;
old_val.store_to(out_base_color[y[j] * img_w + x[j]].v, vector_aligned);
} else {
UNROLLED_FOR(k, 3, { out_base_color[y[j] * img_w + x[j]].v[k] = base_color[k][j]; })
Expand Down
6 changes: 5 additions & 1 deletion internal/ShadeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,11 @@ void Ray::Ref::ShadePrimary(const pass_settings_t &ps, Span<const hit_data_t> in
if (out_base_color) {
if (cache_mode != eSpatialCacheMode::Update) {
auto old_val = Ref::fvec4{out_base_color[y * img_w + x].v, Ref::vector_aligned};
old_val += (Ref::fvec4{base_color.v, Ref::vector_aligned} - old_val) * mix_factor;
auto new_val = Ref::fvec4{base_color.v, Ref::vector_aligned};
const float norm_factor =
fmaxf(fmaxf(new_val.get<0>(), new_val.get<1>()), fmaxf(new_val.get<2>(), 1.0f));
new_val /= norm_factor;
old_val += (new_val - old_val) * mix_factor;
old_val.store_to(out_base_color[y * img_w + x].v, Ref::vector_aligned);
} else {
out_base_color[y * img_w + x] = base_color;
Expand Down
6 changes: 3 additions & 3 deletions internal/shaders/output/shade_primary_atlas.comp.cso.inl

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_primary_atlas_sky.comp.cso.inl

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_primary_bindless.comp.cso.inl

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions internal/shaders/shade.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,8 @@ void main() {
#endif
imageStore(g_out_img, ivec2(x, y), vec4(col, 1.0));
#if OUTPUT_BASE_COLOR && !CACHE_UPDATE
const float norm_factor = max(max(base_color.x, base_color.y), max(base_color.z, 1.0));
base_color /= norm_factor;
imageStore(g_out_base_color_img, ivec2(x, y), vec4(base_color, 0.0));
#endif
#if OUTPUT_DEPTH_NORMALS || CACHE_UPDATE
Expand Down

0 comments on commit 8986c76

Please sign in to comment.