Skip to content

[PBR][IBL] Upgrade the cubemap#1412

Merged
bigbike merged 12 commits intomasterfrom
new_cubemap
Aug 4, 2021
Merged

[PBR][IBL] Upgrade the cubemap#1412
bigbike merged 12 commits intomasterfrom
new_cubemap

Conversation

@bigbike
Copy link
Copy Markdown
Contributor

@bigbike bigbike commented Jul 29, 2021

Motivation and Context

Refactor the cubemap so that it can be used in the PBR IBL.

  • Allow the developer to compute and customize the mipmap of each level by herself.
  • Enable multiple drawable groups (with different names as index) in the scene graph.
  • Upgrade the sensor, the CubeMapCamera accordingly.

How Has This Been Tested

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@bigbike bigbike requested a review from erikwijmans July 29, 2021 00:58
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jul 29, 2021
Comment thread src/esp/scene/SceneGraph.h Outdated
// TODO: remove this
gfx::DrawableGroup& getDrawables() {
return drawableGroups_.at(std::string{});
gfx::DrawableGroup& getDrawables(const char* groupName = "") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why char pointers as args instead of std::string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am passing a string literal to this function, so I use const char* here. It would be faster if std::string can be avoided.
But here it will be converted to the std::string anyway, so I guess you are right, I can just use string directly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigbike Couldn't you use corrade::stringview or something to avoid a copy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrade::stringview

@Skylion007 : No, that is exactly for the C string literals. To avoid the copy then the data structure should not use std::string as the key which I doubt.

Comment thread src/esp/scene/SceneGraph.h Outdated
}
const gfx::DrawableGroup& getDrawables(const char* groupName = "") const {
return drawableGroups_.at(std::string{groupName});
const gfx::DrawableGroup& getDrawables(std::string groupName = "") const {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, shoudln't these be const refs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think so since reference is rvalue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, it is const string& so it would work (compile).
But it will not help since it will construct a string anyway (because the input parameter is a string literal.)

Copy link
Copy Markdown
Contributor

@mosra mosra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry If I'm going too overboard with those microoptimizations, spending a lot of time in low-level code lately and it shows 😅

Comment thread src/esp/gfx/CubeMap.cpp Outdated
void textureTypeSanityCheck(CubeMap::Flags& flag,
CubeMap::TextureType type,
const std::string& functionNameStr) {
void textureTypeSanityCheck(const std::string& functionNameStr,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be overdoing the optimizations, but since the string is used only for assertions and thus should be as zero-overhead as possible, maybe go with just

Suggested change
void textureTypeSanityCheck(const std::string& functionNameStr,
void textureTypeSanityCheck(const char* functionNameStr,

instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, thanks! Good suggestions.

Comment thread src/esp/gfx/CubeMap.cpp Outdated
}

/** @brief do a couple of sanity checks based on mipLevel value */
void mipLevelSanityCheck(const std::string& msgPrefix,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, maybe this instead?

Suggested change
void mipLevelSanityCheck(const std::string& msgPrefix,
void mipLevelSanityCheck(const char* msgPrefix,

Comment thread src/esp/gfx/CubeMap.cpp
Comment thread src/esp/gfx/CubeMap.cpp Outdated
Comment on lines +270 to +271
Mn::Vector2i viewportSize{int(framebufferSize),
int(framebufferSize)}; // at mip level 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code golf -- the single-argument constructor is there exactly for this:

Suggested change
Mn::Vector2i viewportSize{int(framebufferSize),
int(framebufferSize)}; // at mip level 0
Mn::Vector2i viewportSize{int(framebufferSize)}; // at mip level 0

About the casts, I ended up using Vector2i instead of Vector2ui for sizes because the extra annoyance with unsigned types wasn't worth it. So maybe here just int framebufferSize could be fine as well.

Comment thread src/esp/gfx/CubeMap.cpp Outdated
mipmapLevels_);

if ((flags_ & Flag::ManuallyBuildMipmap) && (flags_ & Flag::ColorTexture)) {
int size = imageSize_ / pow(2, mipLevel);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int size = imageSize_ / pow(2, mipLevel);
int size = imageSize_ / (1 << mipLevel);

(I used to have Math::pow2(n) for this but ... it felt weird to have that wrapping just a bit shift, so it's no longer there.)

Comment thread src/esp/gfx/CubeMap.cpp Outdated
0, // color attachment
Mn::Color4{0, 0, 0, 1} // clear color
0, // color attachment
Mn::Color4{0.0, 0.0, 0.0, 1.0} // clear color
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you go the extra way, why not extra extra :D

Suggested change
Mn::Color4{0.0, 0.0, 0.0, 1.0} // clear color
Mn::Color4{0.0f, 0.0f, 0.0f, 1.0f} // clear color

(I wonder, did the compiler warn here? My assumption is that it shouldn't have for the integer literals, but it should for the double literals?)

Comment thread src/esp/gfx/CubeMap.cpp Outdated
int size = imageSize_ / pow(2, mipLevel);

#ifndef MAGNUM_TARGET_WEBGL
CORRADE_ASSERT(texture.imageSize(0) == Mn::Vector2i(size, size),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the single-argument constructor does exactly this:

Suggested change
CORRADE_ASSERT(texture.imageSize(0) == Mn::Vector2i(size, size),
CORRADE_ASSERT(texture.imageSize(0) == Mn::Vector2i{size},

Comment thread src/esp/scene/SceneGraph.h Outdated
// TODO: remove this
gfx::DrawableGroup& getDrawables() {
return drawableGroups_.at(std::string{});
gfx::DrawableGroup& getDrawables(const std::string& groupName = "") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gfx::DrawableGroup& getDrawables(const std::string& groupName = "") {
gfx::DrawableGroup& getDrawables(const std::string& groupName = {}) {

std::string initialization from an empty C string literal involves a lot of nasty code including a strlen(), calling the default constructor not.

Same below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good to know.
I was thinking the empty string was OK, since strlen() returned 0.

@bigbike bigbike merged commit 4ceb312 into master Aug 4, 2021
@bigbike bigbike deleted the new_cubemap branch August 4, 2021 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants