Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/examples/en/loaders/GLTFLoader.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ <h2>Textures</h2>

<code>
// If texture is used for color information, set colorspace.
texture.encoding = THREE.sRGBEncoding;
texture.colorSpace = THREE.SRGBColorSpace;

// UVs use the convention that (0, 0) corresponds to the upper left corner of a texture.
texture.flipY = false;
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/zh/loaders/GLTFLoader.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ <h2>纹理</h2>

<code>
// If texture is used for color information, set colorspace.
texture.encoding = THREE.sRGBEncoding;
texture.colorSpace = THREE.SRGBColorSpace;

// UVs use the convention that (0, 0) corresponds to the upper left corner of a texture.
texture.flipY = false;
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/exporters/EXRExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function buildInfo( renderTarget, options = {} ) {
HEIGHT = renderTarget.height,
TYPE = renderTarget.texture.type,
FORMAT = renderTarget.texture.format,
ENCODING = renderTarget.texture.encoding,
COLOR_SPACE = renderTarget.texture.colorSpace,
COMPRESSION = ( options.compression !== undefined ) ? options.compression : ZIP_COMPRESSION,
EXPORTER_TYPE = ( options.type !== undefined ) ? options.type : HalfFloatType,
OUT_TYPE = ( EXPORTER_TYPE === FloatType ) ? 2 : 1,
Expand All @@ -99,7 +99,7 @@ function buildInfo( renderTarget, options = {} ) {
height: HEIGHT,
type: TYPE,
format: FORMAT,
encoding: ENCODING,
colorSpace: COLOR_SPACE,
compression: COMPRESSION,
blockLines: COMPRESSION_SIZE,
dataType: OUT_TYPE,
Expand Down
8 changes: 4 additions & 4 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DoubleSide,
InterpolateDiscrete,
InterpolateLinear,
LinearEncoding,
NoColorSpace,
LinearFilter,
LinearMipmapLinearFilter,
LinearMipmapNearestFilter,
Expand All @@ -20,7 +20,7 @@ import {
RepeatWrapping,
Scene,
Source,
sRGBEncoding,
SRGBColorSpace,
Vector3
} from 'three';

Expand Down Expand Up @@ -801,7 +801,7 @@ class GLTFWriter {

function getEncodingConversion( map ) {

if ( map.encoding === sRGBEncoding ) {
if ( map.colorSpace === SRGBColorSpace ) {

return function SRGBToLinear( c ) {

Expand Down Expand Up @@ -876,7 +876,7 @@ class GLTFWriter {
const texture = reference.clone();

texture.source = new Source( canvas );
texture.encoding = LinearEncoding;
texture.colorSpace = NoColorSpace;

return texture;

Expand Down
57 changes: 34 additions & 23 deletions examples/jsm/exporters/KTX2Exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
RGIntegerFormat,
RedFormat,
RedIntegerFormat,
LinearEncoding,
sRGBEncoding,
NoColorSpace,
LinearSRGBColorSpace,
SRGBColorSpace,
DataTexture,
REVISION,
} from 'three';
Expand All @@ -22,6 +23,7 @@ import {
KHR_DF_CHANNEL_RGBSDA_RED,
KHR_DF_MODEL_RGBSDA,
KHR_DF_PRIMARIES_BT709,
KHR_DF_PRIMARIES_UNSPECIFIED,
KHR_DF_SAMPLE_DATATYPE_FLOAT,
KHR_DF_SAMPLE_DATATYPE_LINEAR,
KHR_DF_SAMPLE_DATATYPE_SIGNED,
Expand All @@ -45,40 +47,49 @@ const VK_FORMAT_MAP = {

[ RGBAFormat ]: {
[ FloatType ]: {
[ LinearEncoding ]: VK_FORMAT_R32G32B32A32_SFLOAT,
[ NoColorSpace ]: VK_FORMAT_R32G32B32A32_SFLOAT,
[ LinearSRGBColorSpace ]: VK_FORMAT_R32G32B32A32_SFLOAT,
},
[ HalfFloatType ]: {
[ LinearEncoding ]: VK_FORMAT_R16G16B16A16_SFLOAT,
[ NoColorSpace ]: VK_FORMAT_R16G16B16A16_SFLOAT,
[ LinearSRGBColorSpace ]: VK_FORMAT_R16G16B16A16_SFLOAT,
},
[ UnsignedByteType ]: {
[ LinearEncoding ]: VK_FORMAT_R8G8B8A8_UNORM,
[ sRGBEncoding ]: VK_FORMAT_R8G8B8A8_SRGB,
[ NoColorSpace ]: VK_FORMAT_R8G8B8A8_UNORM,
[ LinearSRGBColorSpace ]: VK_FORMAT_R8G8B8A8_UNORM,
[ SRGBColorSpace ]: VK_FORMAT_R8G8B8A8_SRGB,
},
},

[ RGFormat ]: {
[ FloatType ]: {
[ LinearEncoding ]: VK_FORMAT_R32G32_SFLOAT,
[ NoColorSpace ]: VK_FORMAT_R32G32_SFLOAT,
[ LinearSRGBColorSpace ]: VK_FORMAT_R32G32_SFLOAT,
},
[ HalfFloatType ]: {
[ LinearEncoding ]: VK_FORMAT_R16G16_SFLOAT,
[ NoColorSpace ]: VK_FORMAT_R16G16_SFLOAT,
[ LinearSRGBColorSpace ]: VK_FORMAT_R16G16_SFLOAT,
},
[ UnsignedByteType ]: {
[ LinearEncoding ]: VK_FORMAT_R8G8_UNORM,
[ sRGBEncoding ]: VK_FORMAT_R8G8_SRGB,
[ NoColorSpace ]: VK_FORMAT_R8G8_UNORM,
[ LinearSRGBColorSpace ]: VK_FORMAT_R8G8_UNORM,
[ SRGBColorSpace ]: VK_FORMAT_R8G8_SRGB,
},
},

[ RedFormat ]: {
[ FloatType ]: {
[ LinearEncoding ]: VK_FORMAT_R32_SFLOAT,
[ NoColorSpace ]: VK_FORMAT_R32_SFLOAT,
[ LinearSRGBColorSpace ]: VK_FORMAT_R32_SFLOAT,
},
[ HalfFloatType ]: {
[ LinearEncoding ]: VK_FORMAT_R16_SFLOAT,
[ NoColorSpace ]: VK_FORMAT_R16_SFLOAT,
[ LinearSRGBColorSpace ]: VK_FORMAT_R16_SFLOAT,
},
[ UnsignedByteType ]: {
[ LinearEncoding ]: VK_FORMAT_R8_SRGB,
[ sRGBEncoding ]: VK_FORMAT_R8_UNORM,
[ NoColorSpace ]: VK_FORMAT_R8_UNORM,
[ LinearSRGBColorSpace ]: VK_FORMAT_R8_UNORM,
[ SRGBColorSpace ]: VK_FORMAT_R8_SRGB,
},
},

Expand All @@ -96,7 +107,7 @@ const KHR_DF_CHANNEL_MAP = {
const ERROR_INPUT = 'THREE.KTX2Exporter: Supported inputs are DataTexture, Data3DTexture, or WebGLRenderer and WebGLRenderTarget.';
const ERROR_FORMAT = 'THREE.KTX2Exporter: Supported formats are RGBAFormat, RGFormat, or RedFormat.';
const ERROR_TYPE = 'THREE.KTX2Exporter: Supported types are FloatType, HalfFloatType, or UnsignedByteType."';
const ERROR_ENCODING = 'THREE.KTX2Exporter: Supported encodings are sRGB (UnsignedByteType only) or Linear.';
const ERROR_COLOR_SPACE = 'THREE.KTX2Exporter: Supported color spaces are SRGBColorSpace (UnsignedByteType only), LinearSRGBColorSpace, or NoColorSpace.';

export class KTX2Exporter {

Expand Down Expand Up @@ -130,9 +141,9 @@ export class KTX2Exporter {

}

if ( VK_FORMAT_MAP[ texture.format ][ texture.type ][ texture.encoding ] === undefined ) {
if ( VK_FORMAT_MAP[ texture.format ][ texture.type ][ texture.colorSpace ] === undefined ) {

throw new Error( ERROR_ENCODING );
throw new Error( ERROR_COLOR_SPACE );

}

Expand All @@ -142,7 +153,7 @@ export class KTX2Exporter {
const channelCount = getChannelCount( texture );
const container = new KTX2Container();

container.vkFormat = VK_FORMAT_MAP[ texture.format ][ texture.type ][ texture.encoding ];
container.vkFormat = VK_FORMAT_MAP[ texture.format ][ texture.type ][ texture.colorSpace ];
container.typeSize = array.BYTES_PER_ELEMENT;
container.pixelWidth = texture.image.width;
container.pixelHeight = texture.image.height;
Expand All @@ -157,11 +168,11 @@ export class KTX2Exporter {

const basicDesc = container.dataFormatDescriptor[ 0 ];

// TODO: After `texture.encoding` is replaced, distinguish between
// non-color data (unspecified model and primaries) and sRGB or Linear-sRGB colors.
basicDesc.colorModel = KHR_DF_MODEL_RGBSDA;
basicDesc.colorPrimaries = KHR_DF_PRIMARIES_BT709;
basicDesc.transferFunction = texture.encoding === sRGBEncoding
basicDesc.colorPrimaries = texture.colorSpace === NoColorSpace
? KHR_DF_PRIMARIES_UNSPECIFIED
: KHR_DF_PRIMARIES_BT709;
basicDesc.transferFunction = texture.colorSpace === SRGBColorSpace
? KHR_DF_TRANSFER_SRGB
: KHR_DF_TRANSFER_LINEAR;

Expand All @@ -177,7 +188,7 @@ export class KTX2Exporter {

let channelType = KHR_DF_CHANNEL_MAP[ i ];

if ( texture.encoding === LinearEncoding ) {
if ( texture.colorSpace === LinearSRGBColorSpace || texture.colorSpace === NoColorSpace ) {

channelType |= KHR_DF_SAMPLE_DATATYPE_LINEAR;

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/interactive/HTMLMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Mesh,
MeshBasicMaterial,
PlaneGeometry,
sRGBEncoding,
SRGBColorSpace,
Color
} from 'three';

Expand Down Expand Up @@ -59,7 +59,7 @@ class HTMLTexture extends CanvasTexture {
this.dom = dom;

this.anisotropy = 16;
this.encoding = sRGBEncoding;
this.colorSpace = SRGBColorSpace;
this.minFilter = LinearFilter;
this.magFilter = LinearFilter;

Expand Down
20 changes: 11 additions & 9 deletions examples/jsm/lights/LightProbeGenerator.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
Color,
LightProbe,
LinearEncoding,
LinearSRGBColorSpace,
SphericalHarmonics3,
Vector3,
sRGBEncoding
SRGBColorSpace,
NoColorSpace
} from 'three';

class LightProbeGenerator {
Expand Down Expand Up @@ -55,7 +56,7 @@ class LightProbeGenerator {
color.setRGB( data[ i ] / 255, data[ i + 1 ] / 255, data[ i + 2 ] / 255 );

// convert to linear color space
convertColorToLinear( color, cubeTexture.encoding );
convertColorToLinear( color, cubeTexture.colorSpace );

// pixel coordinate on unit cube

Expand Down Expand Up @@ -153,7 +154,7 @@ class LightProbeGenerator {
color.setRGB( data[ i ] / 255, data[ i + 1 ] / 255, data[ i + 2 ] / 255 );

// convert to linear color space
convertColorToLinear( color, cubeRenderTarget.texture.encoding );
convertColorToLinear( color, cubeRenderTarget.texture.colorSpace );

// pixel coordinate on unit cube

Expand Down Expand Up @@ -223,22 +224,23 @@ class LightProbeGenerator {

}

function convertColorToLinear( color, encoding ) {
function convertColorToLinear( color, colorSpace ) {

switch ( encoding ) {
switch ( colorSpace ) {

case sRGBEncoding:
case SRGBColorSpace:

color.convertSRGBToLinear();
break;

case LinearEncoding:
case LinearSRGBColorSpace:
case NoColorSpace:

break;

default:

console.warn( 'WARNING: LightProbeGenerator convertColorToLinear() encountered an unsupported encoding.' );
console.warn( 'WARNING: LightProbeGenerator convertColorToLinear() encountered an unsupported color space.' );
break;

}
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/loaders/3MFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
NearestFilter,
RepeatWrapping,
TextureLoader,
sRGBEncoding
SRGBColorSpace
} from 'three';
import * as fflate from '../libs/fflate.module.js';

Expand Down Expand Up @@ -789,7 +789,7 @@ class ThreeMFLoader extends Loader {

} );

texture.encoding = sRGBEncoding;
texture.colorSpace = SRGBColorSpace;

// texture parameters

Expand Down
14 changes: 7 additions & 7 deletions examples/jsm/loaders/ColladaLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
Vector2,
Vector3,
VectorKeyframeTrack,
sRGBEncoding
SRGBColorSpace
} from 'three';
import { TGALoader } from '../loaders/TGALoader.js';

Expand Down Expand Up @@ -1579,7 +1579,7 @@ class ColladaLoader extends Loader {

material.name = data.name || '';

function getTexture( textureObject, encoding = null ) {
function getTexture( textureObject, colorSpace = null ) {

const sampler = effect.profile.samplers[ textureObject.id ];
let image = null;
Expand Down Expand Up @@ -1627,9 +1627,9 @@ class ColladaLoader extends Loader {

}

if ( encoding !== null ) {
if ( colorSpace !== null ) {

texture.encoding = encoding;
texture.colorSpace = colorSpace;

}

Expand Down Expand Up @@ -1663,7 +1663,7 @@ class ColladaLoader extends Loader {

case 'diffuse':
if ( parameter.color ) material.color.fromArray( parameter.color );
if ( parameter.texture ) material.map = getTexture( parameter.texture, sRGBEncoding );
if ( parameter.texture ) material.map = getTexture( parameter.texture, SRGBColorSpace );
break;
case 'specular':
if ( parameter.color && material.specular ) material.specular.fromArray( parameter.color );
Expand All @@ -1673,14 +1673,14 @@ class ColladaLoader extends Loader {
if ( parameter.texture ) material.normalMap = getTexture( parameter.texture );
break;
case 'ambient':
if ( parameter.texture ) material.lightMap = getTexture( parameter.texture, sRGBEncoding );
if ( parameter.texture ) material.lightMap = getTexture( parameter.texture, SRGBColorSpace );
break;
case 'shininess':
if ( parameter.float && material.shininess ) material.shininess = parameter.float;
break;
case 'emission':
if ( parameter.color && material.emissive ) material.emissive.fromArray( parameter.color );
if ( parameter.texture ) material.emissiveMap = getTexture( parameter.texture, sRGBEncoding );
if ( parameter.texture ) material.emissiveMap = getTexture( parameter.texture, SRGBColorSpace );
break;

}
Expand Down
Loading