Skip to content

Constants & Configuration

This page documents the constants system in Three.js, which provides named numeric and string identifiers used throughout the library to configure rendering behavior, material properties, texture parameters, and other aspects of 3D scene management. These constants ensure type-safe configuration and improve code readability by replacing magic numbers with semantic names.

For information about how materials use these constants, see Material & Texture System. For renderer-specific configuration, see WebGL Rendering Pipeline.

Purpose and Organization

Three.js constants are defined in a single source file and exported as numeric values or strings. They configure:

  • Rendering pipeline behavior (culling, blending, depth testing)
  • Texture sampling and wrapping modes
  • Pixel formats and data types
  • Color space transformations
  • Material appearance parameters
  • Animation and interpolation modes

All constants are immutable exports that can be imported from the main Three.js module. The constants system allows developers to configure complex rendering behavior without memorizing numeric WebGL enum values.

Constants System Architecture

SVG
100%

Rendering Configuration Constants

Face Culling

Controls which triangle faces are rendered based on their winding order. These constants determine GPU-level culling optimization.

ConstantValueDescription
CullFaceNone0Disables face culling (renders both sides)
CullFaceBack1Culls back faces (default behavior)
CullFaceFront2Culls front faces
CullFaceFrontBack3Culls both front and back faces

Usage Context: Set on Material.side property as FrontSide, BackSide, or DoubleSide, which internally map to culling modes.

Shadow Map Types

Defines shadow rendering algorithms with varying quality and performance characteristics.

ConstantValueDescription
BasicShadowMap0Unfiltered shadow maps (fastest)
PCFShadowMap1Percentage-Closer Filtering
PCFSoftShadowMap2PCF with better soft shadows
VSMShadowMap3Variance Shadow Maps

Usage Context: Set on WebGLRenderer.shadowMap.type to configure shadow rendering quality.

Side Constants

Determines which faces of geometry are rendered.

ConstantValueDescription
FrontSide0Render only front-facing triangles
BackSide1Render only back-facing triangles
DoubleSide2Render both front and back faces

Blending Modes

SVG
100%

Blending Mode Constants:

ConstantValueBehavior
NoBlending0Disables alpha transparency
NormalBlending1Standard alpha blending (default)
AdditiveBlending2Adds source and destination colors
SubtractiveBlending3Subtracts destination from source
MultiplyBlending4Multiplies colors
CustomBlending5Requires manual equation/factor setup
MaterialBlending6Material-specific blending

Usage Context: Set on Material.blending to control transparency behavior. Custom blending requires additional configuration via Material.blendEquation, Material.blendSrc, and Material.blendDst.

Depth Testing

Controls how fragments pass or fail depth buffer comparison.

ConstantValueDescription
NeverDepth0Never pass depth test
AlwaysDepth1Always pass depth test
LessDepth2Pass if incoming < buffer
LessEqualDepth3Pass if incoming ≤ buffer (default)
EqualDepth4Pass if incoming == buffer
GreaterEqualDepth5Pass if incoming ≥ buffer
GreaterDepth6Pass if incoming > buffer
NotEqualDepth7Pass if incoming ≠ buffer

Usage Context: Set on Material.depthFunc to customize depth testing behavior.

Texture Configuration Constants

Texture Mapping Modes

Defines how textures map to geometry surfaces.

ConstantValueTypeDescription
UVMapping300numberStandard UV coordinate mapping
CubeReflectionMapping301numberCube environment reflection
CubeRefractionMapping302numberCube environment refraction
EquirectangularReflectionMapping303numberEquirectangular reflection
EquirectangularRefractionMapping304numberEquirectangular refraction
CubeUVReflectionMapping306numberPMREM cube UV reflection

Texture Wrapping

Controls behavior when texture coordinates exceed [0, 1] range.

ConstantValueDescription
RepeatWrapping1000Texture repeats infinitely
ClampToEdgeWrapping1001Edge pixels stretch to boundary
MirroredRepeatWrapping1002Texture repeats with mirroring

Usage Context: Set on Texture.wrapS and Texture.wrapT properties.

Texture Filtering

SVG
100%

Filtering Constants:

ConstantValueDescription
NearestFilter1003Point sampling (no interpolation)
NearestMipmapNearestFilter1004Nearest mip level, point sample
NearestMipmapLinearFilter1005Interpolate between mip levels, point sample
LinearFilter1006Bilinear interpolation
LinearMipmapNearestFilter1007Nearest mip level, bilinear sample
LinearMipmapLinearFilter1008Trilinear filtering (best quality)

Texture Data Types

Defines the data type for texture pixel components.

ConstantValueDescription
UnsignedByteType10098-bit unsigned integer
ByteType10108-bit signed integer
ShortType101116-bit signed integer
UnsignedShortType101216-bit unsigned integer
IntType101332-bit signed integer
UnsignedIntType101432-bit unsigned integer
FloatType101532-bit floating point
HalfFloatType101616-bit floating point
UnsignedShort4444Type1017Packed 4-4-4-4 format
UnsignedShort5551Type1018Packed 5-5-5-1 format
UnsignedInt248Type1020Packed depth-stencil format
UnsignedInt5999Type35902Packed 5-9-9-9 HDR format
UnsignedInt101111Type35899Packed 10-11-11 format

Usage Context: Set on Texture.type to specify pixel component precision and encoding.

Texture Formats

Extensive format constants defining channel layout and compression:

CategoryExample ConstantsValue Range
Basic FormatsAlphaFormat, RGBFormat, RGBAFormat1021-1023
Depth FormatsDepthFormat, DepthStencilFormat1026-1027
Integer FormatsRedIntegerFormat, RGBAIntegerFormat1029-1033
Compressed DXTRGB_S3TC_DXT1_Format, RGBA_S3TC_DXT5_Format33776-33779
Compressed PVRTCRGB_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format35840-35843
Compressed ETCRGB_ETC1_Format, RGBA_ETC2_EAC_Format36196-37496
Compressed ASTCRGBA_ASTC_4x4_Format ... RGBA_ASTC_12x12_Format37808-37821
Compressed BPTCRGBA_BPTC_Format, RGB_BPTC_UNSIGNED_Format36492-36495
Compressed RGTCRED_RGTC1_Format, RED_GREEN_RGTC2_Format36283-36286

Material Configuration Constants

Normal Map Types

ConstantValueDescription
TangentSpaceNormalMap0Normals relative to surface (default)
ObjectSpaceNormalMap1Normals relative to object

Normal Map Packing

ConstantValueTypeDescription
NoNormalPacking""stringNo special packing
NormalRGPacking"rg"stringNormals in RG channels
NormalGAPacking"ga"stringNormals in GA channels

Depth Packing

Defines how depth values are encoded for rendering.

ConstantValueDescription
BasicDepthPacking3200Inverted depth (1.0 - z)
RGBADepthPacking320132-bit RGBA encoding
RGBDepthPacking320224-bit RGB encoding
RGDepthPacking320316-bit RG encoding

Color Space Constants

Three.js uses string identifiers for color spaces to match CSS Color Module Level 4 and WebGPU specifications.

SVG
100%

Color Space Constants:

ConstantValueDescription
NoColorSpace""No color space defined
SRGBColorSpace"srgb"Standard sRGB color space
LinearSRGBColorSpace"srgb-linear"Linear sRGB (no gamma curve)

Transfer Function Constants:

ConstantValueDescription
LinearTransfer"linear"Linear transfer function
SRGBTransfer"srgb"sRGB gamma transfer function

Usage Context: Set on Texture.colorSpace and WebGLRenderer.outputColorSpace to ensure correct color management throughout the rendering pipeline.

Tone Mapping Constants

Defines algorithms for mapping HDR values to display range.

ConstantValueDescription
NoToneMapping0No tone mapping applied
LinearToneMapping1Simple linear mapping
ReinhardToneMapping2Reinhard operator
CineonToneMapping3Cineon filmic curve
ACESFilmicToneMapping4ACES filmic curve
CustomToneMapping5User-defined in shader
AgXToneMapping6AgX tone mapper
NeutralToneMapping7Khronos neutral tone mapper

Usage Context: Set on WebGLRenderer.toneMapping to control HDR-to-LDR conversion.

Animation Constants

Loop Modes

ConstantValueDescription
LoopOnce2200Play animation once
LoopRepeat2201Loop from end to start
LoopPingPong2202Alternate forward/backward

Interpolation Modes

ConstantValueDescription
InterpolateDiscrete2300No interpolation (stepped)
InterpolateLinear2301Linear interpolation
InterpolateSmooth2302Smooth cubic interpolation
InterpolateBezier2303Bezier curve interpolation

Ending Behaviors

ConstantValueDescription
ZeroCurvatureEnding2400Zero curvature at endpoints
ZeroSlopeEnding2401Zero slope at endpoints
WrapAroundEnding2402Wrap to beginning

Blend Modes

ConstantValueDescription
NormalAnimationBlendMode2500Standard blending (default)
AdditiveAnimationBlendMode2501Additive layer blending

Stencil Operation Constants

Stencil Operations

ConstantValueGL EnumDescription
ZeroStencilOp0-Set stencil to 0
KeepStencilOp7680GL_KEEPKeep current value
ReplaceStencilOp7681GL_REPLACEReplace with reference
IncrementStencilOp7682GL_INCRIncrement (clamped)
DecrementStencilOp7683GL_DECRDecrement (clamped)
IncrementWrapStencilOp34055GL_INCR_WRAPIncrement (wrapped)
DecrementWrapStencilOp34056GL_DECR_WRAPDecrement (wrapped)
InvertStencilOp5386GL_INVERTBitwise invert

Stencil Comparison Functions

ConstantValueGL EnumDescription
NeverStencilFunc512GL_NEVERNever pass
LessStencilFunc513GL_LESSPass if ref < stencil
EqualStencilFunc514GL_EQUALPass if ref == stencil
LessEqualStencilFunc515GL_LEQUALPass if ref ≤ stencil
GreaterStencilFunc516GL_GREATERPass if ref > stencil
NotEqualStencilFunc517GL_NOTEQUALPass if ref ≠ stencil
GreaterEqualStencilFunc518GL_GEQUALPass if ref ≥ stencil
AlwaysStencilFunc519GL_ALWAYSAlways pass

Drawing Mode Constants

Defines how vertex data is interpreted for rendering.

ConstantValueDescription
TrianglesDrawMode0Every 3 vertices form a triangle
TriangleStripDrawMode1Strip of connected triangles
TriangleFanDrawMode2Fan of triangles from first vertex

Usage Context: Set on BufferGeometry.drawMode (deprecated) or used in custom draw calls.

Miscellaneous Constants

Bind Modes

ConstantValueTypeDescription
AttachedBindMode"attached"stringSkinned mesh shares skeleton space
DetachedBindMode"detached"stringSkinned mesh independent of skeleton

Environment Map Operations

ConstantValueDescription
MultiplyOperation0Multiply env map with surface color
MixOperation1Blend using reflectivity
AddOperation2Add env map to surface color

Input Control Constants

ConstantPropertiesDescription
MOUSE{LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2}Mouse button mappings for controls
TOUCH{ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3}Touch gesture types

Version

ConstantValueDescription
REVISION"183dev"Current Three.js version string

Usage Patterns

Material Configuration

// Example from typical material setup
material.side = FrontSide;           // Only render front faces
material.blending = NormalBlending;  // Standard alpha blending
material.depthFunc = LessEqualDepth; // Default depth testing
material.transparent = true;          // Enable alpha blending

Constants are typically accessed as named imports:

import { 
    FrontSide, 
    DoubleSide,
    NormalBlending,
    AdditiveBlending,
    RepeatWrapping,
    LinearFilter
} from 'three';

Texture Configuration

// Example texture setup
texture.wrapS = RepeatWrapping;
texture.wrapT = RepeatWrapping;
texture.magFilter = LinearFilter;
texture.minFilter = LinearMipmapLinearFilter;
texture.colorSpace = SRGBColorSpace;

Renderer Configuration

// Example renderer setup
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = PCFSoftShadowMap;
renderer.toneMapping = ACESFilmicToneMapping;
renderer.outputColorSpace = SRGBColorSpace;