-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--Implementation of Nvidia's HBAO effect (soft shadows in corners and crevices) via Magnum #2192
Conversation
ead30c4
to
026b403
Compare
4a070aa
to
cf7392c
Compare
25e20af
to
8762518
Compare
Pretty cool! Nice job! |
This comment was marked as outdated.
This comment was marked as outdated.
src/tests/GfxBatchHbaoTest.cpp
Outdated
esp::gfx_batch::HbaoConfiguration{}.flags(), 2.0f, 1.5f, 10.0f, 0.0f, | ||
0.0f}, | ||
{"cache-aware, perspective, layered with image load store", | ||
"hbao_tests/van-gogh-room.hbao-cache-layered.png", false, true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I originally used the same image for the defaults, geometry shader and image load/store was to be sure that they produce the same output (assuming all they do is speed improvements). If you have a dedicated image for each, you can no longer ensure the differences between the two are minimal.
In other words, there shouldn't be the van-gogh-room.hbao-cache-layered.png
, van-gogh-room.hbao-cache-geom.png
, van-gogh-room.hbao-cache-layered-ortho.png
or van-gogh-room.hbao-cache-geom-ortho.png
files, those should be compared to van-gogh-room.hbao-cache.png
/ van-gogh-room.hbao-cache-ortho.png
as well. The "special blur" variant to my understanding, should produce a different / better output than the default blur so it has to be a different file, and the "strong effect" variant is obviously different too.
To save the correct ground truth images, use --save-diagnostics
together with --abort-on-failure
(or with --only
), to ensure the ground truth image is generated from the "defaults" case and the GS etc. variants aren't overwriting it.
And the thresholds for the GS and image load/store variants should be reduced down to a reasonable minimum that still passes -- the 4.5f
and 0.11f
was what my initial (buggy) port had, you'll likely have it lower now. You can see the actual calculated thresholds for passing tests with --verbose
.
src/tests/GfxBatchHbaoTest.cpp
Outdated
Cr::Containers::arraySize(TestData)); | ||
} | ||
|
||
constexpr Mn::Vector2i Size{256, 256}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got an idea for easy verification that the aspect ratio handling is implemented correctly: change this to something non-square (that still reasonably covers the scene, of course) and add a second test variant (testRotated()
?) that uses Size.flipped()
instead of Size
and loads the images rotated by 90°:
/* This rotates the depth image by 90° */
Cr::Containers::Array<char> rotatedDepth{Cr::NoInit, depth->data.size()};
Cr::Utility::copy(depth->pixels().flipped<1>().transposed<0, 1>(),
Cr::Containers::StridedArrayView2D<char>{rotatedDepth, {std::size_t(Size.y()), std::size_t(Size.x())}});
Mn::GL::Texture2D inputDepthTexture;
inputDepthTexture
.setStorage(1, Mn::GL::TextureFormat::DepthComponent32F, Size.flipped())
.setSubImage(0, {}, Mn::ImageView2D{depth->format(), Size.flipped(), rotatedDepth});
Similarly for the color image. The final comparison would be to the original image, but with the pixels rotated back:
CORRADE_COMPARE_WITH(
output.read({{}, Size}, {Mn::PixelFormat::RGBA8Unorm})
.pixels<Color4ub>().transposed<1, 0>().flipped<1>(),
Cr::Utility::Path::join(TEST_ASSETS, data.filename),
(Mn::DebugTools::CompareImageToFile{data.maxThreshold, data.meanThreshold}));
If everything is correct in the implementation, the test should pass without any difference compared to the non-rotated case.
(Details about strided array views and their dimension flipping and transposition are in this blog post.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put these tests in and they are exposing a bias in the algorithm that seems like it exists in the shader, so I have marked them Expect to Fail and will investigate this further. The effect is present and visually pleasing, however, so I don't think this should hold up the PR.
2f6edbf
to
b09150b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some minor comments.
Did you have a change to measure rendering performance with/without HBAO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidentally opened a GitHub notification so had to go through the code and write comments :)
|
||
Hbao& Hbao::operator=(Hbao&&) noexcept = default; | ||
|
||
void Hbao::setConfiguration(const HbaoConfiguration& configuration) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait a moment, I thought we agreed that you'd just replace the instance when configuration changes? This setter is only adding extra potential for bugs as it may not reininitialize all internal state properly.
In other words, this is what I mean:
Hbao hbao;
...
// when settings change
hbao = Hbao{newHbaoConfiguration};
That way the instance is, when constructed, always correct, and there's no chance some state may be stale because setConfiguration()
forgot to overwrite something that was only populated in a constructor.
For changing actual runtime parameters (as we discussed), there should be direct setters instead, separate from the HbaoConfiguration
class which should have only the initial setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rework this when I work on the user-driven attributes-based customization functionality.
|
29ab4a8
to
e3ed691
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for initial merge, thanks @jturner65 and @mosra!
We can follow-up with additional polish.
|
||
constexpr const char* baseTestFilename = "van-gogh-room"; | ||
|
||
const std::string SourceTestPlyDir = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, Utility::Path::join()
, Utility::format()
all return Containers::String
, and the APIs taking strings use StringView
s.
Not that I'd want that changed away from std::string
across all of Habitat, but existing code in gfx_batch
is using the Corrade ones exclusively so it'd be great if it was kept consistent. (I'm probably just annoying at this point, sorry.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all. I wonder about these things, but I don't want to overly annoy you with questions about these little things. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll revisit this in HBAO version 1.1 :)
f4e326c
to
0d46a30
Compare
Also, default should be always have blur - blur should be disabled only for debugging (since no blur looks awful).
Functionality specified with "blur" in the original nvidia code explicitly meant using the special blur algorithm, not both blur and special blur.
-add test cases using layers and special blur
--rotation/de-rotation test results in images that are outside the bounds of our current thresholds, and so this test is marked as expect to fail until it can be repaired. This behavior is not likely
--currently we do not allow for the Geometry-based layer handling if we are not using the cache-aware/interleaving algorithm, so this cleans up some inappropriate but never-reached code in the shader.
--direct flag-setting access was removed due to interdependencies/mutual exclusivity between certain states.
9437aad
to
f72ab20
Compare
Motivation and Context
This PR implements Nvidia's HBAO as per the shaders found here but using Magnum's graphics framework. This work was built from, and compared against, a reference implementation of the Nvidia sample code using Nvidia's graphics framework that was integrated into Habitat-Sim in this WIP PR.
Both Classic and Cache-Aware implementations are available, as well as Perpective and Orthographic sensor support (driven by the projection matrix configuration of the owning visual sensor).
TODO for This PR :
Update test images to match the working effect.Gate test so that it does not attempt to run in WebGL buildsnot necessaryTODO Next PR/Future Work :
Demonstration of with/without effect via CacheAware algorithm, both Perspective and Orthographic projection.
newCacheAwareHBAOHalfScreenExampl.mp4
How Has This Been Tested
New C++ tests to verify integrity of effect; existing c++ and python tests pass
Types of changes
Checklist