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

--[PBR Update 2 of 3] PBR rewrite-motivated default lighting and IBL fix/reworking #2119

Merged
merged 16 commits into from
Jun 1, 2023

Conversation

jturner65
Copy link
Contributor

@jturner65 jturner65 commented May 29, 2023

Motivation and Context

As part of the ongoing PBR shader rewrite/functional expansion effort, this PR contains changes that were made to the default lighting configurations, as well as providing a few fixes. Specifically :

  1. A heuristically-derived constant intensity scaling factor was added to the PBR shader code, instead of having a large scaling/intensity factor hardcoded into the default lighting values themselves. This way the lights will work acceptably for both phong and PBR shaded objects. NOTE : This hardcoded value is obviated and removed in the PBR fragment shader PR.
  2. The default lights themselves were tweaked to give reasonable performance, both intensity and visuals, for both PBR and Phong shaded scenes. NOTE : PBR performance is in reference to the new shader functionality, not the existing shader, although the existing shader also looks better.
  3. The IBL implementation was fixed so that it will work with the python viewer. This required a rework of how it was instantiated (i.e. taking it out of the ResourceManager constructor).
  4. Shader direct/indirect diffuse & specular lighting balance in PBR was adjusted so that IBL lighting is not overpowered/washed out. NOTE : Although this balancing was made with the new PBR shader in mind, the existing PBR output looks better as well.
  5. New test images were added to reflect the new lighting. NOTE : These new test images will need to be replaced again when the new PBR shader work is merged.

NOTE : Many of these changes were driven by the new PBR shader, and so may not appear ideal with the current shader.

How Has This Been Tested

Existing c++ and python tests pass, with the addition of new test images to account for lighting changes.

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 May 29, 2023
@jturner65
Copy link
Contributor Author

jturner65 commented May 29, 2023

One thing to note : any existing dataset that has lighting configs defined and is intended for PBR shading will probably need those lights adjusted. AFAIK ReplicaCAD is the only dataset currently that would need this rebalancing, but I'm not sure. @aclegg3 ?

Edit : I've renormalized the lighting configs in ReplicaCAD Interactive to account for the changes in this PR and have made a new version of the dataset (1.6 I guess) with these changes. Just need to upload it to wherever it goes.

LightPositionModel::Camera}, // forward
{{0.0, -0.3, 1.0, 0.0},
{0.5, 0.5, 0.5},
LightPositionModel::Camera}, // backward (for glancing speculars)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid emitting light from the camera by default here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done specifically so that surface details such as normal or clearcoat texture/specular can be readily seen in the new PBR shader regardless of camera orientation (i.e. demo screen captures).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like I said below, I can remove these in favor of a custom lighting config added to /data that folks could just load up to take screen shots and such.

* TODO: this will be replaced by config-driven IBL asset loading and
* registration
*/
void initPbrImageBasedLighting(const std::string& hdriImageFilename);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the current workflow to generate these cubemaps?

Copy link
Contributor Author

@jturner65 jturner65 May 29, 2023

Choose a reason for hiding this comment

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

Same as this, only it is instantiated from ResourceManager constructor. This will fail if there's no context existing, which is what happens when enabled from python.

{0.5, 0.5, 0.5},
LightPositionModel::Camera}, // backward (for glancing speculars)

};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just so everyone is aware -- this is 7 lights instead of 5, which makes the fragment shader roughly as much as 40% more computationally expensive.

Personally I don't think that many lights is needed, even a three-point lighting was often enough to get a balanced output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was aware of the potential impact of these two additional camera-related lights, but their intention is specifically to give easily visualized specular/textural response for those materials that have texture-based surface normals, clearcoat texture and cc normal texture and anisotropy (so far).

If folks think this is too expensive, I can remove the two camera facing lights, and instead provide a lighting config that would define the lights in this manner that folks making demos could consume.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is also pretty easy to just author a new light config with fewer lights if the default is considered too computationally expensive.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But you know how it usually goes -- people will treat the default as the "normal perf", completely unaware that it could get faster with some tweaks.

Same as they treated the extraordinary light setup that was here before as "this is how magnum renders things".

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that one directional light and an ambient light would suffice as a default.

Copy link
Contributor Author

@jturner65 jturner65 May 31, 2023

Choose a reason for hiding this comment

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

A single directional light will not look good at all for PBR scenes (I've tried it), and ambient light is neither used nor useful in PBR, since it lacks a light vector. Of course it probably will be fine with Phong lighting, so perhaps we should set up a different default for Phong?

At least for PBR, I would suggest the 5 base global directional lights I have in the current default setup (minus the camera-relative ones).

I pushed up a 4-light setup that seems to work pretty well for Phong and PBR (both old/current and new).

@jturner65 jturner65 force-pushed the pbr_lighting_update branch 3 times, most recently from 9d58dfe to 5486123 Compare May 31, 2023 14:05
@jturner65
Copy link
Contributor Author

jturner65 commented May 31, 2023

@0mdc @aclegg3 Ok, I've modified the default lights - now there are only 4, and they seem to give reasonable illumination in both Phong and PBR scenes (using the old PBR shader). See images

Phong shader :
phongDefaultLights

Current (before refactor/rewrite) PBR shader :
currPBRDefaultLights

@jturner65
Copy link
Contributor Author

Here are these default lights using the new PBR shader - very similar (some of the surfaces are a bit darker due to clearcoat effect).

newPBRDefaultLights

Default lights should work well for both PBR and Phong shading. By moving the scaling value to the PBR shader, the lights can now be agnostic to shader.
The PBR 2.0 shader refactor will remove the hardcoded scaling by a change of units conversion.
By having the main lights global, constructive interference (i.e. the lights getting brighter because of overlap) is avoided when turning the camera.  The camera-relative backwards light makes sure there's always a glancing specular when looking at horizontal clearcoat/specular/metallic object surfaces.  Also, this has a better mix of direct and indirect lighting when IBL is active
Having the IBL env map loaded in the ResourceManager constructor was failing since there usually wasn't a GL context built yet, which was needed to instantiate the shader.

This is just a stop-gap measure so that IBL can be invoked successfully.  Much engineering needs to be done for IBL to be fully ready for prime time.
NOTE :  Some of these images will need to be updated again with the full PBR fragment shader rewrite.
Copy link
Contributor

@aclegg3 aclegg3 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. We'll merge once ReplicaCAD update is ready.

@aclegg3 aclegg3 mentioned this pull request Jun 1, 2023
11 tasks
@jturner65 jturner65 merged commit d32d751 into main Jun 1, 2023
@jturner65 jturner65 deleted the pbr_lighting_update branch June 1, 2023 21:31
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.

6 participants