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

Support ptex mesh - step 5: improve the shader and rendering code #203

Merged
merged 7 commits into from
Sep 17, 2019

Conversation

bigbike
Copy link
Contributor

@bigbike bigbike commented Sep 11, 2019

Motivation and Context

As titled.
-) added illumination parameters, gamma, saturation etc.;
-) refactored the PTexMeshShader a bit, moving function implementations to .cpp file;
-) renamed a couple of functions in PTexMeshShader;
-) cached the uniform positions;

How Has This Been Tested

local built

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.

-) added gamma, saturation etc.;
-) refactored the PTexMeshShader a bit, moving function implementations to .cpp file;
-) cached the uniform positions;
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 11, 2019
@bigbike
Copy link
Contributor Author

bigbike commented Sep 11, 2019

This diff is ready to be reviewed. Thanks.

void setGamma(const float& val);

float saturation() const;
void setSaturation(const float& val);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be great to add docstrings here, if nothing else at least a note about the inversion of gamma that's done inside.

Or to the shader. Or both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I am working on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mosra:
I think the replicaSDK makes the code complicated by using the inverse of the gamma.
So the solution here is to remove it everywhere in the code. We only set and use "gamma".
The initial value of gamma, which was 1.6969f, is now changed to 1.0f / 1.6969f.

// Image size in given mip level 0
int mipLevel = 0;
int widthEntry = 0;
const auto width = texture.imageSize(mipLevel)[widthEntry];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I get that this code was already there and you just moved it, but what about texture.imageSize(mipLevel).x()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion.

@@ -64,12 +62,26 @@ class PTexMeshData : public BaseMesh {
virtual void uploadBuffersToGPU(bool forceReload = false) override;
virtual Magnum::GL::Mesh* getMagnumGLMesh(int submeshID) override;

float exposure() const;
void setExposure(const float& val);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just float val, maybe? The reference doesn't save anything (is actually slower than passing by-value in this case).

Same in the two cases below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely you are right. Good catch!

@bigbike
Copy link
Contributor Author

bigbike commented Sep 12, 2019

The code is updated, and ready to be reviewed again. Thanks.

@bigbike
Copy link
Contributor Author

bigbike commented Sep 16, 2019

Please let me know your concerns on this PR. Thanks!

@bigbike
Copy link
Contributor Author

bigbike commented Sep 17, 2019

@mosra : do you have more comments on this PR?

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.

Looks good to me -- I don't have the full context in my head right now, so apologies if I missed something.


// get image width in given mip level 0
int mipLevel = 0;
const auto width = texture.imageSize(mipLevel).x();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the rendering uses geometry shaders, I assume it's not planned to be running on WebGL, right? (If it would be, the imageSize() would be problematic, but otherwise not at all.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@msbaines: May I ask you what our latest plan is on rendering the ptex mesh on WebGL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mosra : Yeah, the geometry shader is a problem as it is not available in WebGL.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am currently planning on using the vertex color information from the ply mesh but at some point would like to migrate to using the ptex textures. Not sure when. It will depend on whether the vertex color-only is OK. The other issue is that the textures are 100s of MB each so may not be feasible for WebGL.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Texture size could be fixed by using Basis texture compression (see mosra/magnum-plugins#62, I'm in process of integrating that), ideally the compressed textures being upstreamed back to Replica.

For vertex colors, when I checked how a PLY file looks compared to the textured GLB, it was quite underwhelming :) For human eyes and a 4K screen at least, when rendering tiny images the difference would probably be minimal.

@bigbike
Copy link
Contributor Author

bigbike commented Sep 17, 2019

I will merge it to master to unblock myself this afternoon.

@bigbike bigbike merged commit f8ffc9d into master Sep 17, 2019
@bigbike bigbike deleted the replica_improve_shader branch September 17, 2019 21:49
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
…cebookresearch#203)

* Support ptex mesh - step 5: improve the shader and rendering code

-) added gamma, saturation etc.;
-) refactored the PTexMeshShader a bit, moving function implementations to .cpp file;
-) cached the uniform positions;

* minor

* minor

* resolve Ci error

* rename gamma as gammaInverse in the shader

* add docstring, get rid of the inverse of gamma everywhere

* minor
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.

5 participants