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
Rendering Configuration Constants
Face Culling
Controls which triangle faces are rendered based on their winding order. These constants determine GPU-level culling optimization.
| Constant | Value | Description |
|---|---|---|
CullFaceNone | 0 | Disables face culling (renders both sides) |
CullFaceBack | 1 | Culls back faces (default behavior) |
CullFaceFront | 2 | Culls front faces |
CullFaceFrontBack | 3 | Culls 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.
| Constant | Value | Description |
|---|---|---|
BasicShadowMap | 0 | Unfiltered shadow maps (fastest) |
PCFShadowMap | 1 | Percentage-Closer Filtering |
PCFSoftShadowMap | 2 | PCF with better soft shadows |
VSMShadowMap | 3 | Variance Shadow Maps |
Usage Context: Set on WebGLRenderer.shadowMap.type to configure shadow rendering quality.
Side Constants
Determines which faces of geometry are rendered.
| Constant | Value | Description |
|---|---|---|
FrontSide | 0 | Render only front-facing triangles |
BackSide | 1 | Render only back-facing triangles |
DoubleSide | 2 | Render both front and back faces |
Blending Modes
Blending Mode Constants:
| Constant | Value | Behavior |
|---|---|---|
NoBlending | 0 | Disables alpha transparency |
NormalBlending | 1 | Standard alpha blending (default) |
AdditiveBlending | 2 | Adds source and destination colors |
SubtractiveBlending | 3 | Subtracts destination from source |
MultiplyBlending | 4 | Multiplies colors |
CustomBlending | 5 | Requires manual equation/factor setup |
MaterialBlending | 6 | Material-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.
| Constant | Value | Description |
|---|---|---|
NeverDepth | 0 | Never pass depth test |
AlwaysDepth | 1 | Always pass depth test |
LessDepth | 2 | Pass if incoming < buffer |
LessEqualDepth | 3 | Pass if incoming ≤ buffer (default) |
EqualDepth | 4 | Pass if incoming == buffer |
GreaterEqualDepth | 5 | Pass if incoming ≥ buffer |
GreaterDepth | 6 | Pass if incoming > buffer |
NotEqualDepth | 7 | Pass 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.
| Constant | Value | Type | Description |
|---|---|---|---|
UVMapping | 300 | number | Standard UV coordinate mapping |
CubeReflectionMapping | 301 | number | Cube environment reflection |
CubeRefractionMapping | 302 | number | Cube environment refraction |
EquirectangularReflectionMapping | 303 | number | Equirectangular reflection |
EquirectangularRefractionMapping | 304 | number | Equirectangular refraction |
CubeUVReflectionMapping | 306 | number | PMREM cube UV reflection |
Texture Wrapping
Controls behavior when texture coordinates exceed [0, 1] range.
| Constant | Value | Description |
|---|---|---|
RepeatWrapping | 1000 | Texture repeats infinitely |
ClampToEdgeWrapping | 1001 | Edge pixels stretch to boundary |
MirroredRepeatWrapping | 1002 | Texture repeats with mirroring |
Usage Context: Set on Texture.wrapS and Texture.wrapT properties.
Texture Filtering
Filtering Constants:
| Constant | Value | Description |
|---|---|---|
NearestFilter | 1003 | Point sampling (no interpolation) |
NearestMipmapNearestFilter | 1004 | Nearest mip level, point sample |
NearestMipmapLinearFilter | 1005 | Interpolate between mip levels, point sample |
LinearFilter | 1006 | Bilinear interpolation |
LinearMipmapNearestFilter | 1007 | Nearest mip level, bilinear sample |
LinearMipmapLinearFilter | 1008 | Trilinear filtering (best quality) |
Texture Data Types
Defines the data type for texture pixel components.
| Constant | Value | Description |
|---|---|---|
UnsignedByteType | 1009 | 8-bit unsigned integer |
ByteType | 1010 | 8-bit signed integer |
ShortType | 1011 | 16-bit signed integer |
UnsignedShortType | 1012 | 16-bit unsigned integer |
IntType | 1013 | 32-bit signed integer |
UnsignedIntType | 1014 | 32-bit unsigned integer |
FloatType | 1015 | 32-bit floating point |
HalfFloatType | 1016 | 16-bit floating point |
UnsignedShort4444Type | 1017 | Packed 4-4-4-4 format |
UnsignedShort5551Type | 1018 | Packed 5-5-5-1 format |
UnsignedInt248Type | 1020 | Packed depth-stencil format |
UnsignedInt5999Type | 35902 | Packed 5-9-9-9 HDR format |
UnsignedInt101111Type | 35899 | Packed 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:
| Category | Example Constants | Value Range |
|---|---|---|
| Basic Formats | AlphaFormat, RGBFormat, RGBAFormat | 1021-1023 |
| Depth Formats | DepthFormat, DepthStencilFormat | 1026-1027 |
| Integer Formats | RedIntegerFormat, RGBAIntegerFormat | 1029-1033 |
| Compressed DXT | RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT5_Format | 33776-33779 |
| Compressed PVRTC | RGB_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format | 35840-35843 |
| Compressed ETC | RGB_ETC1_Format, RGBA_ETC2_EAC_Format | 36196-37496 |
| Compressed ASTC | RGBA_ASTC_4x4_Format ... RGBA_ASTC_12x12_Format | 37808-37821 |
| Compressed BPTC | RGBA_BPTC_Format, RGB_BPTC_UNSIGNED_Format | 36492-36495 |
| Compressed RGTC | RED_RGTC1_Format, RED_GREEN_RGTC2_Format | 36283-36286 |
Material Configuration Constants
Normal Map Types
| Constant | Value | Description |
|---|---|---|
TangentSpaceNormalMap | 0 | Normals relative to surface (default) |
ObjectSpaceNormalMap | 1 | Normals relative to object |
Normal Map Packing
| Constant | Value | Type | Description |
|---|---|---|---|
NoNormalPacking | "" | string | No special packing |
NormalRGPacking | "rg" | string | Normals in RG channels |
NormalGAPacking | "ga" | string | Normals in GA channels |
Depth Packing
Defines how depth values are encoded for rendering.
| Constant | Value | Description |
|---|---|---|
BasicDepthPacking | 3200 | Inverted depth (1.0 - z) |
RGBADepthPacking | 3201 | 32-bit RGBA encoding |
RGBDepthPacking | 3202 | 24-bit RGB encoding |
RGDepthPacking | 3203 | 16-bit RG encoding |
Color Space Constants
Three.js uses string identifiers for color spaces to match CSS Color Module Level 4 and WebGPU specifications.
Color Space Constants:
| Constant | Value | Description |
|---|---|---|
NoColorSpace | "" | No color space defined |
SRGBColorSpace | "srgb" | Standard sRGB color space |
LinearSRGBColorSpace | "srgb-linear" | Linear sRGB (no gamma curve) |
Transfer Function Constants:
| Constant | Value | Description |
|---|---|---|
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.
| Constant | Value | Description |
|---|---|---|
NoToneMapping | 0 | No tone mapping applied |
LinearToneMapping | 1 | Simple linear mapping |
ReinhardToneMapping | 2 | Reinhard operator |
CineonToneMapping | 3 | Cineon filmic curve |
ACESFilmicToneMapping | 4 | ACES filmic curve |
CustomToneMapping | 5 | User-defined in shader |
AgXToneMapping | 6 | AgX tone mapper |
NeutralToneMapping | 7 | Khronos neutral tone mapper |
Usage Context: Set on WebGLRenderer.toneMapping to control HDR-to-LDR conversion.
Animation Constants
Loop Modes
| Constant | Value | Description |
|---|---|---|
LoopOnce | 2200 | Play animation once |
LoopRepeat | 2201 | Loop from end to start |
LoopPingPong | 2202 | Alternate forward/backward |
Interpolation Modes
| Constant | Value | Description |
|---|---|---|
InterpolateDiscrete | 2300 | No interpolation (stepped) |
InterpolateLinear | 2301 | Linear interpolation |
InterpolateSmooth | 2302 | Smooth cubic interpolation |
InterpolateBezier | 2303 | Bezier curve interpolation |
Ending Behaviors
| Constant | Value | Description |
|---|---|---|
ZeroCurvatureEnding | 2400 | Zero curvature at endpoints |
ZeroSlopeEnding | 2401 | Zero slope at endpoints |
WrapAroundEnding | 2402 | Wrap to beginning |
Blend Modes
| Constant | Value | Description |
|---|---|---|
NormalAnimationBlendMode | 2500 | Standard blending (default) |
AdditiveAnimationBlendMode | 2501 | Additive layer blending |
Stencil Operation Constants
Stencil Operations
| Constant | Value | GL Enum | Description |
|---|---|---|---|
ZeroStencilOp | 0 | - | Set stencil to 0 |
KeepStencilOp | 7680 | GL_KEEP | Keep current value |
ReplaceStencilOp | 7681 | GL_REPLACE | Replace with reference |
IncrementStencilOp | 7682 | GL_INCR | Increment (clamped) |
DecrementStencilOp | 7683 | GL_DECR | Decrement (clamped) |
IncrementWrapStencilOp | 34055 | GL_INCR_WRAP | Increment (wrapped) |
DecrementWrapStencilOp | 34056 | GL_DECR_WRAP | Decrement (wrapped) |
InvertStencilOp | 5386 | GL_INVERT | Bitwise invert |
Stencil Comparison Functions
| Constant | Value | GL Enum | Description |
|---|---|---|---|
NeverStencilFunc | 512 | GL_NEVER | Never pass |
LessStencilFunc | 513 | GL_LESS | Pass if ref < stencil |
EqualStencilFunc | 514 | GL_EQUAL | Pass if ref == stencil |
LessEqualStencilFunc | 515 | GL_LEQUAL | Pass if ref ≤ stencil |
GreaterStencilFunc | 516 | GL_GREATER | Pass if ref > stencil |
NotEqualStencilFunc | 517 | GL_NOTEQUAL | Pass if ref ≠ stencil |
GreaterEqualStencilFunc | 518 | GL_GEQUAL | Pass if ref ≥ stencil |
AlwaysStencilFunc | 519 | GL_ALWAYS | Always pass |
Drawing Mode Constants
Defines how vertex data is interpreted for rendering.
| Constant | Value | Description |
|---|---|---|
TrianglesDrawMode | 0 | Every 3 vertices form a triangle |
TriangleStripDrawMode | 1 | Strip of connected triangles |
TriangleFanDrawMode | 2 | Fan of triangles from first vertex |
Usage Context: Set on BufferGeometry.drawMode (deprecated) or used in custom draw calls.
Miscellaneous Constants
Bind Modes
| Constant | Value | Type | Description |
|---|---|---|---|
AttachedBindMode | "attached" | string | Skinned mesh shares skeleton space |
DetachedBindMode | "detached" | string | Skinned mesh independent of skeleton |
Environment Map Operations
| Constant | Value | Description |
|---|---|---|
MultiplyOperation | 0 | Multiply env map with surface color |
MixOperation | 1 | Blend using reflectivity |
AddOperation | 2 | Add env map to surface color |
Input Control Constants
| Constant | Properties | Description |
|---|---|---|
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
| Constant | Value | Description |
|---|---|---|
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 blendingConstants 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;