Skip to content
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

Merged
merged 65 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
976338c
There you go.
mosra Aug 23, 2023
01fe173
Wire in the HBAO graphical effect
jturner65 Feb 6, 2023
573081b
Cleanups.
mosra Aug 24, 2023
fceed03
Port to GLSL 3.3 and GLSL ES 3.0.
mosra Aug 24, 2023
7b3f0e2
The GS has a passthrough-less variant too, use it.
mosra Aug 24, 2023
c42faff
Skip a test variant if image load/store is not supported.
mosra Aug 24, 2023
2ba7424
--remove unnecessary include
jturner65 Aug 24, 2023
f512f05
--address segfault if hbao not enabled.
jturner65 Aug 24, 2023
033ac08
--initial webgl guards
jturner65 Aug 24, 2023
a5c1dc7
--more clang-tidy
jturner65 Aug 28, 2023
a38f39d
--style; populate sensor horizontal fov.
jturner65 Aug 28, 2023
0616a89
--fix projection scale calculation.
jturner65 Aug 28, 2023
d1507fb
--fix sensor bugs; add accessors to sensorSubType and projectionMatrix
jturner65 Aug 29, 2023
7329ad0
--access hbao draw through config and visualsensor vals
jturner65 Aug 29, 2023
6ef0154
--initial test update
jturner65 Aug 29, 2023
c9f462d
-clang-tidy
jturner65 Aug 29, 2023
7655f78
--fix bugs in special blur algorithm
jturner65 Aug 30, 2023
a418d5f
--easier state setting; use appropriate configuration for HBAO init.
jturner65 Aug 30, 2023
10c8a4f
--enable Geometry shader capability.
jturner65 Aug 30, 2023
f979614
--better main function name
jturner65 Aug 30, 2023
8eee32b
--add ortho support; a few minor things
jturner65 Aug 31, 2023
b4d458e
--gate HBAO object creation if unsupported
jturner65 Aug 31, 2023
a8b0087
--minor
jturner65 Aug 31, 2023
c12e2c8
--fix bug with projectionScaling calculation.
jturner65 Sep 5, 2023
1bc4b36
--remove needless function in VisualSensor
jturner65 Sep 5, 2023
91cb001
--minor
jturner65 Sep 5, 2023
826d5be
--clean up compiler directives.
jturner65 Sep 5, 2023
2f5d204
--tweak default radius to compensate for incorrect "ground truth" calc.
jturner65 Sep 5, 2023
213cf4b
--fix test draw call
jturner65 Sep 5, 2023
c8ac3d8
--modify test order
jturner65 Sep 7, 2023
ef94c55
--add appropriate HBAO test mesh.ply file to test assets.
jturner65 Sep 7, 2023
2542cc9
--properly configure tests with updated images
jturner65 Sep 7, 2023
1f03efd
--update images; Always have blur set
jturner65 Sep 7, 2023
11621c6
--revert inappropriate FOV for test proj matrix
jturner65 Sep 7, 2023
c2c9400
--add orthographic projection tests.
jturner65 Sep 7, 2023
1bf1bb8
--made ortho test images a bit bigger
jturner65 Sep 7, 2023
3b0bdbe
--reviewer suggestions
jturner65 Sep 8, 2023
40a349c
--reviewer suggestions - hbao toggle binding name
jturner65 Sep 13, 2023
dce98f6
--remove unnecessary constructor; streamline testing
jturner65 Sep 14, 2023
bab3292
--shader fixes; precision; naming conventions (blur shaders)
jturner65 Sep 18, 2023
9e57092
--shader fixes; precision; naming conventions (depth linearize)
jturner65 Sep 18, 2023
648230f
--shader fixes; precision; naming conventions (de/re interleave)
jturner65 Sep 18, 2023
e9066e6
--shader fixes; precision; naming conventions (viewnormal)
jturner65 Sep 18, 2023
80d030f
--compiler direct AO_DEINTERLEAVED
jturner65 Sep 18, 2023
93c9d2c
--fix incorrect blur bug/assumptions.
jturner65 Sep 19, 2023
d25573b
--minor
jturner65 Sep 19, 2023
d175b5e
--clean up AO_SPECIAL_BLUR
jturner65 Sep 19, 2023
a5108b7
--update copyrights
jturner65 Sep 19, 2023
f335490
--make hbao.frag compatible with es300
jturner65 Sep 19, 2023
4f59d36
--fix issue with non-layered cache-aware alg
jturner65 Sep 19, 2023
1717166
--fix issue with inappropriate type and handling for texLinearDepth
jturner65 Sep 19, 2023
942a1e4
--change blur flag to enable no-blur instead.
jturner65 Sep 19, 2023
1819e50
--fix improper layered load/store framebuffer config
jturner65 Sep 20, 2023
ca523ea
--update and expand tests
jturner65 Sep 20, 2023
bc24e50
--tighten up test bounds
jturner65 Sep 20, 2023
ff6e09e
-change size and aspect ratio not square
jturner65 Sep 20, 2023
2b11f35
--move ply mesh to test assets; add perspective rotation test;
jturner65 Sep 20, 2023
4a3e285
--pull the most recent test assets to get the van-gogh ply used in th…
jturner65 Sep 20, 2023
502dadd
--only build hbao for supported camera types; stub out cubemap support
jturner65 Sep 21, 2023
752adda
--uniform naming conventions
jturner65 Sep 21, 2023
00d3f28
--address geometry shader/passthrough confusion regarding texCoords
jturner65 Sep 21, 2023
59f9f72
--reviewer suggestions.
jturner65 Sep 21, 2023
b28501f
--format; copyright header;
jturner65 Sep 22, 2023
6f97652
--reviewer suggestions
jturner65 Sep 22, 2023
f72ab20
--improve test config setup; temp bypass of bench code;
jturner65 Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,11 @@ def next_frame() -> None:
action="store_true",
help="Override configured lighting to use default lighting for the stage.",
)
parser.add_argument(
"--hbao",
action="store_true",
help="Enable horizon-based ambient occlusion, which provides soft shadows in corners and crevices.",
)
parser.add_argument(
"--enable-batch-renderer",
action="store_true",
Expand Down Expand Up @@ -1174,6 +1179,7 @@ def next_frame() -> None:
sim_settings["window_width"] = args.width
sim_settings["window_height"] = args.height
sim_settings["default_agent_navmesh"] = False
sim_settings["enable_hbao"] = args.hbao

# start the application
HabitatSimInteractiveViewer(sim_settings).exec()
3 changes: 3 additions & 0 deletions src/esp/bindings/SimBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ void initSimBindings(py::module& m) {
.def_readwrite(
"navmesh_settings", &SimulatorConfiguration::navMeshSettings,
R"(Optionally provide a pre-configured NavMeshSettings. If provided, the NavMesh will be recomputed with the provided settings if: A. no NavMesh was loaded, or B. the loaded NavMesh's settings differ from the configured settings. If not provided, no NavMesh recompute will be done automatically.)")
.def_readwrite(
"enable_hbao", &SimulatorConfiguration::enableHBAO,
R"(Whether or not to enable horizon-based ambient occlusion, which provides soft shadows in corners and crevices.)")
.def(py::self == py::self)
.def(py::self != py::self);

Expand Down
5 changes: 5 additions & 0 deletions src/esp/gfx/BackgroundRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,14 @@ int BackgroundRenderer::threadRender() {
sensor.renderTarget().renderEnter();

auto* camera = sensor.getRenderCamera();

for (auto& transforms : jobTransforms[i]) {
camera->draw(transforms, flags);
}
auto sensorType = sensor.specification()->sensorType;
if (sensorType == sensor::SensorType::Color) {
sensor.renderTarget().tryDrawHbao();
}

if (!(flags & RenderCamera::Flag::ObjectsOnly))
sensor.renderTarget().renderExit();
Expand Down
37 changes: 37 additions & 0 deletions src/esp/gfx/RenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "esp/sensor/VisualSensor.h"

#include "esp/gfx_batch/DepthUnprojection.h"
#include "esp/gfx_batch/Hbao.h"

#ifdef ESP_BUILD_WITH_CUDA
#include <cuda_gl_interop.h>
Expand Down Expand Up @@ -117,6 +118,24 @@ struct RenderTarget::Impl {
CORRADE_INTERNAL_ASSERT(
framebuffer_.checkStatus(Mn::GL::FramebufferTarget::Draw) ==
Mn::GL::Framebuffer::Status::Complete);

if (flags_ & Flag::HorizonBasedAmbientOcclusion) {
#ifndef MAGNUM_TARGET_WEBGL
// depth texture is required for HBAO
CORRADE_INTERNAL_ASSERT(flags_ & Flag::DepthTextureAttachment);
// TODO Drive construction based on premade configurations
hbao_ = gfx_batch::Hbao{
gfx_batch::HbaoConfiguration{}
.setSize(size)
.setUseSpecialBlur(true)
.setUseLayeredGeometryShader(true)
// TODO other options here?
};
#else
ESP_ERROR()
<< "HBAO functionality requested but not supported for WebGL builds";
#endif
}
}

void initDepthUnprojector() {
Expand Down Expand Up @@ -181,6 +200,18 @@ struct RenderTarget::Impl {

void renderExit() {}

void tryDrawHbao() {
if (!hbao_) {
return;
}
// TODO:Support a toggle between cache-aware and classic algorithm. For now
// we just use cache aware
bool useCacheAware = true;

hbao_->drawEffect(visualSensor_->getProjectionMatrix(), useCacheAware,
depthRenderTexture_, framebuffer_);
}

void blitRgbaTo(Mn::GL::AbstractFramebuffer& target,
const Mn::Range2Di& targetRectangle) {
CORRADE_ASSERT(
Expand Down Expand Up @@ -367,6 +398,8 @@ struct RenderTarget::Impl {
cudaGraphicsResource_t objecIdBufferCugl_ = nullptr;
cudaGraphicsResource_t depthBufferCugl_ = nullptr;
#endif

Cr::Containers::Optional<gfx_batch::Hbao> hbao_{};
}; // namespace gfx

RenderTarget::RenderTarget(const Mn::Vector2i& size,
Expand Down Expand Up @@ -426,6 +459,10 @@ Mn::GL::Texture2D& RenderTarget::getObjectIdTexture() {
return pimpl_->getObjectIdTexture();
}

void RenderTarget::tryDrawHbao() {
return pimpl_->tryDrawHbao();
}

#ifdef ESP_BUILD_WITH_CUDA
void RenderTarget::readFrameRgbaGPU(uint8_t* devPtr) {
pimpl_->readFrameRgbaGPU(devPtr);
Expand Down
10 changes: 10 additions & 0 deletions src/esp/gfx/RenderTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class RenderTarget {
* rendering slower (default depth buffer will be used in this case.)
*/
DepthTextureAttachment = 1 << 2,

/**
* Enable HBAO visual effect that adds soft shadows to corners and crevices.
*/
HorizonBasedAmbientOcclusion = 1 << 3,
};

typedef Corrade::Containers::EnumSet<Flag> Flags;
Expand Down Expand Up @@ -170,6 +175,11 @@ class RenderTarget {
*/
Magnum::GL::Texture2D& getObjectIdTexture();

/**
* @brief draw HBAO effect if enabled for this render target
*/
void tryDrawHbao();

// @brief Delete copy Constructor
RenderTarget(const RenderTarget&) = delete;
// @brief Delete copy operator
Expand Down
8 changes: 8 additions & 0 deletions src/esp/gfx/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ struct Renderer::Impl {
"render buffer while the simulator was initialized with "
"requiresTextures = false", );
renderTargetFlags |= RenderTarget::Flag::RgbaAttachment;
// TODO complete support for other camera types (fisheye,
// equirectanguular) to use hbao.
if ((sensor.canUseHBAO()) &&
(flags_ & Renderer::Flag::HorizonBasedAmbientOcclusion)) {
// force depth texture for Color sensor, needed for HBAO
renderTargetFlags |= RenderTarget::Flag::DepthTextureAttachment;
renderTargetFlags |= RenderTarget::Flag::HorizonBasedAmbientOcclusion;
}
break;

case sensor::SensorType::Depth:
Expand Down
5 changes: 5 additions & 0 deletions src/esp/gfx/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class Renderer {
*/
LeaveContextWithBackgroundRenderer = 1 << 3,

/**
* Enable HBAO visual effect that adds soft shadows to corners and crevices.
*/
HorizonBasedAmbientOcclusion = 1 << 4,

};

typedef Corrade::Containers::EnumSet<Flag> Flags;
Expand Down
2 changes: 2 additions & 0 deletions src/esp/gfx_batch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ set(
Renderer.h
RendererStandalone.cpp
RendererStandalone.h
Hbao.cpp
Hbao.h
)

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)
Expand Down
Loading