diff options
author | jfons <joan.fonssanchez@gmail.com> | 2021-04-25 23:36:39 +0200 |
---|---|---|
committer | jfons <joan.fonssanchez@gmail.com> | 2021-05-03 18:10:34 +0200 |
commit | 6995b0429c5b42d41cc4d1851ea1f2272f121a26 (patch) | |
tree | 4356830f39c5efbc959b5d8dcdff472a5e96fa75 /thirdparty/oidn | |
parent | eb57dcdb909dd45eaff6e25858a1907e13df4f59 (diff) |
Assorted fixes to UV unwrapping and GPU lightmapper
Various fixes to UV2 unwrapping and the GPU lightmapper. Listed here for
context in case of git blame/bisect:
* Fix UV2 unwrapping on import, also cleaned up the unwrap cache code.
* Fix saving of RGBA images in EXR format.
* Fixes to the GPU lightmapper:
- Added padding between atlas elements, avoids bleeding.
- Remove old SDF generation code.
- Fix baked attenuation for Omni/Spot lights.
- Fix baking of material properties onto UV2 (wireframe was
wrongly used before).
- Disable statically baked lights for objects that have a
lightmap texture to avoid applying the same light twice.
- Fix lightmap pairing in RendererSceneCull.
- Fix UV2 array generated from `RenderingServer::mesh_surface_get_arrays()`.
- Port autoexposure fix for OIDN from 3.x.
- Save debug textures as EXR when using floating point format.
Diffstat (limited to 'thirdparty/oidn')
-rw-r--r-- | thirdparty/oidn/core/transfer_function.cpp | 107 | ||||
-rw-r--r-- | thirdparty/oidn/patches/godot-changes-c58c5216.patch | 68 |
2 files changed, 103 insertions, 72 deletions
diff --git a/thirdparty/oidn/core/transfer_function.cpp b/thirdparty/oidn/core/transfer_function.cpp index 487f0a9f75..ce5deca56b 100644 --- a/thirdparty/oidn/core/transfer_function.cpp +++ b/thirdparty/oidn/core/transfer_function.cpp @@ -24,10 +24,6 @@ namespace oidn { float AutoexposureNode::autoexposure(const Image& color) { assert(color.format == Format::Float3); -// -- GODOT start -- -// We don't want to mess with TTB and we don't use autoexposure, so we disable this code -#if 0 -// -- GODOT end -- constexpr float key = 0.18f; constexpr float eps = 1e-8f; @@ -42,61 +38,66 @@ namespace oidn { // Compute the average log luminance of the downsampled image using Sum = std::pair<float, int>; - Sum sum = - tbb::parallel_reduce( - tbb::blocked_range2d<int>(0, HK, 0, WK), - Sum(0.f, 0), - [&](const tbb::blocked_range2d<int>& r, Sum sum) -> Sum + // -- GODOT start -- + // Sum sum = + // tbb::parallel_reduce( + // tbb::blocked_range2d<int>(0, HK, 0, WK), + // Sum(0.f, 0), + // [&](const tbb::blocked_range2d<int>& r, Sum sum) -> Sum + // { + // // Iterate over blocks + // for (int i = r.rows().begin(); i != r.rows().end(); ++i) + // { + // for (int j = r.cols().begin(); j != r.cols().end(); ++j) + // { + + Sum sum = Sum(0.0f, 0); + + for (int i = 0; i != HK; ++i) + { + for (int j = 0; j != WK; ++j) + { + // Compute the average luminance in the current block + const int beginH = int(ptrdiff_t(i) * H / HK); + const int beginW = int(ptrdiff_t(j) * W / WK); + const int endH = int(ptrdiff_t(i+1) * H / HK); + const int endW = int(ptrdiff_t(j+1) * W / WK); + + float L = 0.f; + + for (int h = beginH; h < endH; ++h) { - // Iterate over blocks - for (int i = r.rows().begin(); i != r.rows().end(); ++i) + for (int w = beginW; w < endW; ++w) { - for (int j = r.cols().begin(); j != r.cols().end(); ++j) - { - // Compute the average luminance in the current block - const int beginH = int(ptrdiff_t(i) * H / HK); - const int beginW = int(ptrdiff_t(j) * W / WK); - const int endH = int(ptrdiff_t(i+1) * H / HK); - const int endW = int(ptrdiff_t(j+1) * W / WK); - - float L = 0.f; - - for (int h = beginH; h < endH; ++h) - { - for (int w = beginW; w < endW; ++w) - { - const float* rgb = (const float*)color.get(h, w); - - const float r = maxSafe(rgb[0], 0.f); - const float g = maxSafe(rgb[1], 0.f); - const float b = maxSafe(rgb[2], 0.f); - - L += luminance(r, g, b); - } - } - - L /= (endH - beginH) * (endW - beginW); - - // Accumulate the log luminance - if (L > eps) - { - sum.first += log2(L); - sum.second++; - } - } + const float* rgb = (const float*)color.get(h, w); + + const float r = maxSafe(rgb[0], 0.f); + const float g = maxSafe(rgb[1], 0.f); + const float b = maxSafe(rgb[2], 0.f); + + L += luminance(r, g, b); } + } - return sum; - }, - [](Sum a, Sum b) -> Sum { return Sum(a.first+b.first, a.second+b.second); }, - tbb::static_partitioner() - ); + L /= (endH - beginH) * (endW - beginW); + + // Accumulate the log luminance + if (L > eps) + { + sum.first += log2(L); + sum.second++; + } + } + } + + // return sum; + // }, + // [](Sum a, Sum b) -> Sum { return Sum(a.first+b.first, a.second+b.second); }, + // tbb::static_partitioner() + // ); + // -- GODOT end -- return (sum.second > 0) ? (key / exp2(sum.first / float(sum.second))) : 1.f; -// -- GODOT start -- -#endif - return 1.0; -// -- GODOT end -- } } // namespace oidn diff --git a/thirdparty/oidn/patches/godot-changes-c58c5216.patch b/thirdparty/oidn/patches/godot-changes-c58c5216.patch index 6a54703064..c01f00187b 100644 --- a/thirdparty/oidn/patches/godot-changes-c58c5216.patch +++ b/thirdparty/oidn/patches/godot-changes-c58c5216.patch @@ -280,28 +280,58 @@ index 8c2de09..ed8328c 100644 namespace oidn { diff --git a/core/transfer_function.cpp b/core/transfer_function.cpp -index 601f814..487f0a9 100644 +index 601f814..ce5deca 100644 --- a/core/transfer_function.cpp +++ b/core/transfer_function.cpp -@@ -24,6 +24,10 @@ namespace oidn { - float AutoexposureNode::autoexposure(const Image& color) - { - assert(color.format == Format::Float3); -+// -- GODOT start -- -+// We don't want to mess with TTB and we don't use autoexposure, so we disable this code -+#if 0 -+// -- GODOT end -- +@@ -38,16 +38,24 @@ namespace oidn { + // Compute the average log luminance of the downsampled image + using Sum = std::pair<float, int>; + +- Sum sum = +- tbb::parallel_reduce( +- tbb::blocked_range2d<int>(0, HK, 0, WK), +- Sum(0.f, 0), +- [&](const tbb::blocked_range2d<int>& r, Sum sum) -> Sum ++ // -- GODOT start -- ++ // Sum sum = ++ // tbb::parallel_reduce( ++ // tbb::blocked_range2d<int>(0, HK, 0, WK), ++ // Sum(0.f, 0), ++ // [&](const tbb::blocked_range2d<int>& r, Sum sum) -> Sum ++ // { ++ // // Iterate over blocks ++ // for (int i = r.rows().begin(); i != r.rows().end(); ++i) ++ // { ++ // for (int j = r.cols().begin(); j != r.cols().end(); ++j) ++ // { ++ ++ Sum sum = Sum(0.0f, 0); ++ ++ for (int i = 0; i != HK; ++i) + { +- // Iterate over blocks +- for (int i = r.rows().begin(); i != r.rows().end(); ++i) +- { +- for (int j = r.cols().begin(); j != r.cols().end(); ++j) ++ for (int j = 0; j != WK; ++j) + { + // Compute the average luminance in the current block + const int beginH = int(ptrdiff_t(i) * H / HK); +@@ -82,11 +90,12 @@ namespace oidn { + } + } - constexpr float key = 0.18f; - constexpr float eps = 1e-8f; -@@ -89,6 +93,10 @@ namespace oidn { - ); +- return sum; +- }, +- [](Sum a, Sum b) -> Sum { return Sum(a.first+b.first, a.second+b.second); }, +- tbb::static_partitioner() +- ); ++ // return sum; ++ // }, ++ // [](Sum a, Sum b) -> Sum { return Sum(a.first+b.first, a.second+b.second); }, ++ // tbb::static_partitioner() ++ // ); ++ // -- GODOT end -- return (sum.second > 0) ? (key / exp2(sum.first / float(sum.second))) : 1.f; -+// -- GODOT start -- -+#endif -+ return 1.0; -+// -- GODOT end -- } - - } // namespace oidn |