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

PMREMGenerator: Remove calls of convertSRGBToLinear(). #22318

Merged
merged 3 commits into from
Aug 13, 2021

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Aug 12, 2021

Related issue: see #22286 (comment)

Description

PMREMGenerator now honors WebGLRenderer.outputEncoding when converting to linear color space.

This PR removes calls of convertSRGBToLinear(). Background/clear colors are assumed to be in linear color space.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 12, 2021

webgl_furnace_test assumes sRGB for Scene.background.

envScene.background = new THREE.Color( COLOR ); // sRGB colorspace assumed, apparently

That means it is now necessary to set WebGLRenderer.outputEncoding to sRGBEncoding which slightly changes its visuals.

@Mugen87 Mugen87 requested a review from WestLangley August 12, 2021 09:03
Copy link
Collaborator

@WestLangley WestLangley left a comment

Choose a reason for hiding this comment

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

That means it is now necessary to set WebGLRenderer.outputEncoding to sRGBEncoding

No, that does not follow. The furnace test can be rendered in any colorspace. I'd remove the changes to the furnace test.

I think it would be best if @gkjohnson reviews the PMREM edits in this PR.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 12, 2021

I've edited the example since Scene.background is explicitly defined as a sRGB color (see comment).

@WestLangley
Copy link
Collaborator

I've edited the example since Scene.background is explicitly defined as a sRGB color (see comment).

I wrote the comment, and the comment is referring to the fact that PMREMGenerator is assuming the color is sRGB. This PR supposedly fixes that limitation of PMREMGenerator.

The furnace test is broken until other issues with PMREMGenerator are fixed.

@gkjohnson
Copy link
Collaborator

The changes to PMREMGenerator look good -- I'm not sure if any other types of output encodings are ever used for the renderer but my only comment is if only SRGB and Linear are supported and other output encodings might be used by users (not sure why they would be) you might want to log a warning.

I'm not familiar enough with the furnace test or the interpretation of RGBE colors in the shaders to be much help there, though. @elalish might be a better one to ping when you start looking into that more.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 12, 2021

I'm not sure if any other types of output encodings are ever used for the renderer

Um, I guess I would add support for THREE.GammaEncoding. The conversion can be done via convertGammaToLinear(). For all other constants, a warning should be logged.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 13, 2021

With the last commit I've added support for THREE.GammaEncoding. PMREMGenerator also logs a warning now when color spaces other than linear, gamma and srgb are used.

@WestLangley
Copy link
Collaborator

WestLangley commented Aug 13, 2021

@Mugen87 @gkjohnson Sorry, but this PR is not correct.

PMREMGenerator.fromScene() was written to create a PMREM from something like Room Environment. The current renderer's output colorspace is irrelevant in that case. envScene background color should be specified in linear space because the renderer will render the PMREM in linear space. The background color should not be converted by PMREM.

If @gkjohnson is creating a PMREM from his current scene, that would be different use case.

EDIT- And thank you @Mugen87 for working on this because it has helped me to clarify the problem. I think my statements are correct. :-)

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 13, 2021

The background color should not be converted by PMREM.

But in this case, any calls of convertSRGBToLinear() should be removed from PMREMGenerator, right?

@WestLangley
Copy link
Collaborator

WestLangley commented Aug 13, 2021

But in this case, any calls of convertSRGBToLinear() should be removed from PMREMGenerator, right?

Yes.

And as I said, sRGB output encoding in webgl_furnace_test.html is optional, and should be noted as such. The conversion of envScene background color to linear (if needed) belongs at the app level.

@Mugen87 Mugen87 changed the title PMREMGenerator: Honor outputEncoding for color conversion. PMREMGenerator: Remove calls of convertSRGBToLinear(). Aug 13, 2021
@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 13, 2021

Changed the title of the PR and updated the code.

@gkjohnson
Copy link
Collaborator

If @gkjohnson is creating a PMREM from his current scene, that would be different use case.

I see what you're saying. The couple times I've used PMREMGenerator it's been to render my current scene in order to get reflections on objects in that scene. It seems it would be difficult to simply support both use cases here.

This comes back to something like #22275 and / or bookkeeping color space information on the Color class so the renderer has the relevant information to interpret the colors correctly.

@WestLangley
Copy link
Collaborator

Merging for now so #22326 can be fixed.

@mrdoob
Copy link
Owner

mrdoob commented Aug 15, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants