Skip to content

Commit

Permalink
GLTFLoader: Specify color space of 'srgb-linear' sources
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Aug 4, 2023
1 parent b1fbdc5 commit cb34e98
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BufferGeometry,
ClampToEdgeWrapping,
Color,
ColorManagement,
DirectionalLight,
DoubleSide,
FileLoader,
Expand All @@ -25,6 +26,7 @@ import {
LinearFilter,
LinearMipmapLinearFilter,
LinearMipmapNearestFilter,
LinearSRGBColorSpace,
Loader,
LoaderUtils,
Material,
Expand Down Expand Up @@ -545,7 +547,7 @@ class GLTFLightsExtension {

const color = new Color( 0xffffff );

if ( lightDef.color !== undefined ) color.fromArray( lightDef.color );
if ( lightDef.color !== undefined ) color.setRGB( ...lightDef.color, LinearSRGBColorSpace )

const range = lightDef.range !== undefined ? lightDef.range : 0;

Expand Down Expand Up @@ -663,7 +665,7 @@ class GLTFMaterialsUnlitExtension {

const array = metallicRoughness.baseColorFactor;

materialParams.color.fromArray( array );
materialParams.color.setRGB( ...array, LinearSRGBColorSpace );
materialParams.opacity = array[ 3 ];

}
Expand Down Expand Up @@ -939,7 +941,7 @@ class GLTFMaterialsSheenExtension {

if ( extension.sheenColorFactor !== undefined ) {

materialParams.sheenColor.fromArray( extension.sheenColorFactor );
materialParams.sheenColor.setRGB( ...extension.sheenColorFactor, LinearSRGBColorSpace );

}

Expand Down Expand Up @@ -1077,7 +1079,7 @@ class GLTFMaterialsVolumeExtension {
materialParams.attenuationDistance = extension.attenuationDistance || Infinity;

const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
materialParams.attenuationColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
materialParams.attenuationColor = new Color().setRGB( ...colorArray, LinearSRGBColorSpace );

return Promise.all( pending );

Expand Down Expand Up @@ -1180,7 +1182,7 @@ class GLTFMaterialsSpecularExtension {
}

const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
materialParams.specularColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
materialParams.specularColor = new Color().setRGB( ...colorArray, LinearSRGBColorSpace );

if ( extension.specularColorTexture !== undefined ) {

Expand Down Expand Up @@ -3386,7 +3388,7 @@ class GLTFParser {

const array = metallicRoughness.baseColorFactor;

materialParams.color.fromArray( array );
materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
materialParams.opacity = array[ 3 ];

}
Expand Down Expand Up @@ -3478,7 +3480,7 @@ class GLTFParser {

if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) {

materialParams.emissive = new Color().fromArray( materialDef.emissiveFactor );
materialParams.emissive = new Color().setRGB( ...materialDef.emissiveFactor, LinearSRGBColorSpace );

}

Expand Down Expand Up @@ -4559,6 +4561,12 @@ function addPrimitiveAttributes( geometry, primitiveDef, parser ) {

}

if ( ColorManagement.workingColorSpace !== LinearSRGBColorSpace && 'COLOR_0' in attributes ) {

console.warn( `THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ColorManagement.workingColorSpace}" not supported.` );

}

assignExtrasToUserData( geometry, primitiveDef );

computeBounds( geometry, primitiveDef, parser );
Expand Down

0 comments on commit cb34e98

Please sign in to comment.