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

Better default material #596

Merged
merged 3 commits into from
Apr 24, 2020
Merged

Better default material #596

merged 3 commits into from
Apr 24, 2020

Conversation

aclegg3
Copy link
Contributor

@aclegg3 aclegg3 commented Apr 22, 2020

Motivation and Context

The DEFAULT_MATERIAL was initialized with full white ambient and diffuse light, causing objects to appear flat shaded. These values have been modified for a subjectively better appearance.

How Has This Been Tested

Original:
image

New:
image

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.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Apr 22, 2020
@codecov
Copy link

codecov bot commented Apr 22, 2020

Codecov Report

Merging #596 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #596   +/-   ##
=======================================
  Coverage   56.55%   56.55%           
=======================================
  Files         128      128           
  Lines        5621     5621           
  Branches       84       84           
=======================================
  Hits         3179     3179           
  Misses       2442     2442           
Flag Coverage Δ
#CPP 52.01% <ø> (ø)
#JavaScript 10.00% <ø> (ø)
#Python 75.64% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d34c345...8920e2b. Read the comment docs.

Copy link
Collaborator

@msavva msavva left a comment

Choose a reason for hiding this comment

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

Thanks @aclegg3 for the rapid PR. So it was indeed a default material configuration issue that was causing the lack of shading!

A comment unrelated to the content of the changes: the use of naked new makes loud alarm bells ring in my head whenever I see it outside the innards of class construction/destruction logic that is neatly paired up. 😅I assume this is safe because the ShaderManager takes responsibility to free the memory eventually?

Copy link
Contributor

@jturner65 jturner65 left a comment

Choose a reason for hiding this comment

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

Sort of tangent to the PR, but in line with what was stated above : Since a PhongMaterialData has pointers to textures, and only a default destructor, is this not a possible source of memory leaking?

@aclegg3
Copy link
Contributor Author

aclegg3 commented Apr 22, 2020

Sort of tangent to the PR, but in line with what was stated above : Since a PhongMaterialData has pointers to textures, and only a default destructor, is this not a possible source of memory leaking?

These textures live in the textures_ map as shared pointers. The pointers stored in the material structure are pointing here (assigned in getPhongShadedMaterialData), so no issue with memory leaks. We also don't allow textures to be freed during runtime, so none of these pointers should get stale.

@aclegg3
Copy link
Contributor Author

aclegg3 commented Apr 22, 2020

A comment unrelated to the content of the changes: the use of naked new makes loud alarm bells ring in my head whenever I see it outside the innards of class construction/destruction logic that is neatly paired up. 😅I assume this is safe because the ShaderManager takes responsibility to free the memory eventually?

That is a valid concern. In this case we don't remove any materials once added and as a member of esp::assets::ResourceManager the shaderManager_ outlives a Simulator so there is no potential for missed deletion within the current assumptions.

@mosra I see the reference counting and freeing functionality in Magnum::ResourceManager. For these gfx::MaterialData pointers, free handles deletion, right?

@mosra
Copy link
Collaborator

mosra commented Apr 23, 2020

Sorry, missed the comments above.

I assume this is safe because the ShaderManager takes responsibility to free the memory eventually?

For these gfx::MaterialData pointers, free handles deletion, right?

Yes to both. This API originates in early C++11 times and it was only updated to take r-value references and smart pointers quite recently (it was waiting for a lighter-weight unique pointer implementation), and most of existing code, docs and examples still uses the discouraged "naked new" way. The PR doesn't touch the relevant part anymore, but what could be done to hide the raw new is for example

shaderManager_.set<gfx::MaterialData>(DEFAULT_MATERIAL_KEY,
                                      gfx::PhongMaterialData{});
shaderManager_.set<gfx::MaterialData>(DEFAULT_MATERIAL_KEY,
                                      Cr::Containers::pointer<gfx::PhongMaterialData>());

or, using the standard unique pointers

#include <Corrade/Containers/PointerStl.h>

shaderManager_.set<gfx::MaterialData>(DEFAULT_MATERIAL_KEY,
                                      std::make_unique<gfx::PhongMaterialData>());

Copy link
Collaborator

@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.

The change of specular to 0.2 also makes everything less extremely shiny, right? :)

@aclegg3 aclegg3 merged commit 2de28ac into master Apr 24, 2020
@aclegg3 aclegg3 deleted the better-default-material branch April 24, 2020 22:30
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
* Modify default material to display geometry by reducing ambient, diffuse, and specular color.
luoj1 pushed a commit to luoj1/habitat-sim that referenced this pull request Aug 16, 2022
* Version change from 0.1.6 to 0.1.7

* Made flake8 happy
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.

None yet

5 participants