Skip to content

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
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

WestLangley
Copy link
Collaborator

As the title says.

@WestLangley WestLangley added this to the r180 milestone Aug 4, 2025
//texture.generateMipmaps = false;
//texture.minFilter = LinearFilter;
//texture.magFilter = LinearFilter;
texture.colorSpace = THREE.LinearSRGBColorSpace;
Copy link
Collaborator

@Mugen87 Mugen87 Aug 4, 2025

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Owner

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?

Copy link
Collaborator

@Mugen87 Mugen87 Aug 5, 2025

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.

LinearSRGBColorSpace

colorSpace: LinearSRGBColorSpace,

texture.colorSpace = LinearSRGBColorSpace;

Copy link
Collaborator Author

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.

Copy link
Collaborator

@donmccurdy donmccurdy Aug 5, 2025

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.

Copy link
Contributor

@CodyJasonBennett CodyJasonBennett Aug 9, 2025

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.

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.

5 participants