-
-
Notifications
You must be signed in to change notification settings - Fork 36k
Examples: Specify color space when loading texture #31571
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
Open
WestLangley
wants to merge
1
commit into
mrdoob:dev
Choose a base branch
from
WestLangley:dev-examples_color_space
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we define
LinearSRGBColorSpace
as the default color space in HDR loaders instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All three loaders in this PR return linear-sRGB as the default.
I filed this PR because I think only
KTX2Loader
currently honors the color space defined in the file.Since three.js generally expects users to set the color space, I thought maintaining a consistent pattern for users to copy would be advisable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've mentioned this multiple times in the past but I personally am not a fan to setting default values again since it makes the code verbose. The idea is to keep the code simple and compact and users should rely on proper default values.
If one color space is by far the most used in textures returned by the loaders, I think there is no reason the define the color space again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, so in this case we're setting this color space redundantly?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, that's what the PR does.
three.js/examples/jsm/loaders/UltraHDRLoader.js
Line 326 in 7a1f975
three.js/examples/jsm/loaders/EXRLoader.js
Line 2405 in 7a1f975
three.js/examples/jsm/loaders/RGBELoader.js
Line 464 in 7a1f975
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user should not be expected to comprehend the source code to know that it is necessary to set a correct color space.
Or, for that matter, to know that a loader, such as EXRLoader, does not honor the color space, even if it is defined in the file.
Or to know that the loader is guessing.
The other examples of this type define a color space upon loading. I think that is a good thing, because it is a pattern users copy.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally — I do think it's a good habit to explicitly assign color space when loading individual textures. For most formats (excluding KTX2) we don't have reliable metadata, so the loaders can't do more than guess with a reasonable default. For EXR things might improve eventually, see AcademySoftwareFoundation/openexr#1783.
Another example, when loading individual textures in R3F with TextureLoader, the default is sRGB. In three.js the default is NoColorSpace.1 Not all users are subject to the same defaults.
1 I prefer our choice, because at least when you forget to assign
THREE.SRGBColorSpace
to a color texture, it is visible as a problem in color, rather than a problem in occlusion or normals or metalness that may be much less obvious to diagnose.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, that information about R3F is recently incorrect, and now defers to three.js defaults. We agree with Don here and made this change with v9. Both R3F and the three.js editor will assign sRGB if otherwise unset only if they see a texture applied to a known list of material fields (IMO it is confusing this isn't managed by three, as this can be done conservatively). It is valid usage to use something other than sRGB for color textures, as users may include P3-authored textures in the future (or another wide gamut color space like Rec 2020). That makes it impossible to guess the correct option and only possible to guess an incorrect option if the context is known.