The WebGL renderer displays your beautifully crafted scenes using WebGL, if your device supports it. This renderer has way better performance than CanvasRenderer.

see https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLRenderer.js|src/renderers/WebGLRenderer.js

Hierarchy (view full)

Implements

Constructors

  • parameters is an optional object with properties defining the renderer's behaviour. The constructor also accepts no parameters at all. In all cases, it will assume sane defaults when parameters are missing.

    Parameters

    Returns WebGLRenderer

Properties

autoClear: boolean

Defines whether the renderer should automatically clear its output before rendering.

Default

true
autoClearColor: boolean

If autoClear is true, defines whether the renderer should clear the color buffer. Default is true.

Default

true
autoClearDepth: boolean

If autoClear is true, defines whether the renderer should clear the depth buffer. Default is true.

Default

true
autoClearStencil: boolean

If autoClear is true, defines whether the renderer should clear the stencil buffer. Default is true.

Default

true
capabilities: WebGLCapabilities
clippingPlanes: readonly Plane[]

Default

[]
compile: ((scene, camera, targetScene?) => Set<Material>)

Compiles all materials in the scene with the camera. This is useful to precompile shaders before the first rendering. If you want to add a 3D object to an existing scene, use the third optional parameter for applying the target scene. Note that the (target) scene's lighting should be configured before calling this method.

Type declaration

compileAsync: ((scene, camera, targetScene?) => Promise<Object3D<Object3DEventMap>>)

Asynchronous version of compile(). The method returns a Promise that resolves when the given scene can be rendered without unnecessary stalling due to shader compilation. This method makes use of the KHR_parallel_shader_compile WebGL extension.

Type declaration

debug: WebGLDebug

Debug configurations.

Default

{ checkShaderErrors: true }
domElement: HTMLCanvasElement

A Canvas where the renderer draws its output. This is automatically created by the renderer in the constructor (if not provided already); you just need to add it to your page.

Default

document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' )
extensions: WebGLExtensions
info: WebGLInfo
localClippingEnabled: boolean

Default

false
outputEncoding: TextureEncoding

Default is LinearEncoding.

Default

THREE.LinearEncoding

Deprecated

Use .outputColorSpace in three.js r152+.

pixelRatio: number
properties: WebGLProperties
renderLists: WebGLRenderLists
shadowMap: WebGLShadowMap
shadowMapCullFace: CullFace

Deprecated

Use .shadowMap.cullFace instead.

shadowMapEnabled: boolean

Deprecated

Use .shadowMap.enabled instead.

shadowMapType: ShadowMapType

Deprecated

Use .shadowMap.type instead.

sortObjects: boolean

Defines whether the renderer should sort objects. Default is true.

Default

true
state: WebGLState
toneMapping: ToneMapping

Default

THREE.NoToneMapping
toneMappingExposure: number

Default

1
useLegacyLights: boolean

Deprecated

Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.

Default

true
vr: boolean

Deprecated

Use .xr instead.

Accessors

  • get coordinateSystem(): 2000
  • Returns 2000

  • get outputColorSpace(): ColorSpace
  • Color space used for output to HTMLCanvasElement. Supported values are SRGBColorSpace and LinearSRGBColorSpace.

    Returns ColorSpace

    Default

    THREE.SRGBColorSpace.
    
  • set outputColorSpace(colorSpace): void
  • Parameters

    Returns void

Methods

  • Parameters

    • callback: (() => void)
        • (): void
        • Returns void

    Returns void

    Deprecated

    Use .setAnimationLoop() instead.

  • Tells the renderer to clear its color, depth or stencil drawing buffer(s). Arguments default to true

    Parameters

    • Optional color: boolean
    • Optional depth: boolean
    • Optional stencil: boolean

    Returns void

  • Returns void

  • Returns void

  • Returns void

  • Parameters

    Returns void

  • Copies a region of the currently bound framebuffer into the selected mipmap level of the selected texture. This region is defined by the size of the destination texture's mip level, offset by the input position.

    Parameters

    • position: Vector2

      Specifies the pixel offset from which to copy out of the framebuffer.

    • texture: Texture

      Specifies the destination texture.

    • Optional level: number

      Specifies the destination mipmap level of the texture.

    Returns void

  • Copies srcTexture to the specified level of dstTexture, offset by the input position.

    Parameters

    • position: Vector2

      Specifies the pixel offset into the dstTexture where the copy will occur.

    • srcTexture: Texture

      Specifies the source texture.

    • dstTexture: Texture

      Specifies the destination texture.

    • Optional level: number

      Specifies the destination mipmap level of the texture.

    Returns void

  • Copies the pixels of a texture in the bounds sourceBox in the desination texture starting from the given position.

    Parameters

    • sourceBox: Box3

      Specifies the bounds

    • position: Vector3

      Specifies the pixel offset into the dstTexture where the copy will occur.

    • srcTexture: Texture

      Specifies the source texture.

    • dstTexture: Data3DTexture | DataArrayTexture

      Specifies the destination texture.

    • Optional level: number

      Specifies the destination mipmap level of the texture.

    Returns void

  • Returns void

  • Parameters

    • boolean: any

    Returns any

    Deprecated

    Use .setScissorTest() instead.

  • Returns void

  • Returns void

  • Returns the current active cube face.

    Returns number

  • Returns the current active mipmap level.

    Returns number

  • Returns a float with the current clear alpha. Ranges from 0 to 1.

    Returns number

  • Returns a THREE.Color instance with the current clear color.

    Parameters

    Returns Color

  • Return the WebGL context.

    Returns WebGLRenderingContext | WebGL2RenderingContext

  • Returns any

  • Parameters

    Returns Vector4

  • Parameters

    Returns Vector2

  • Returns number

    Deprecated

    Use .capabilities.getMaxAnisotropy() instead.

  • Returns number

  • Returns string

    Deprecated

    Use .capabilities.precision instead.

  • Returns the current render target. If no render target is set, null is returned.

    Returns null | WebGLRenderTarget<Texture>

  • Copies the scissor area into target.

    Parameters

    Returns Vector4

  • Returns true if scissor test is enabled; returns false otherwise.

    Returns boolean

  • Parameters

    Returns Vector2

  • Copies the viewport into target.

    Parameters

    Returns Vector4

  • Initializes the given texture. Can be used to preload a texture rather than waiting until first render (which can cause noticeable lags due to decode and GPU upload overhead).

    Parameters

    • texture: Texture

      The texture to Initialize.

    Returns void

  • Parameters

    Returns void

  • Render a scene or an object using a camera. The render is done to a previously specified WebGLRenderTarget#renderTarget .renderTarget set by calling .setRenderTarget or to the canvas as usual.

    By default render buffers are cleared before rendering but you can prevent this by setting the property autoClear to false. If you want to prevent only certain buffers being cleared you can set either the autoClearColor, autoClearStencil or autoClearDepth properties to false. To forcibly clear one ore more buffers call .clear.

    Parameters

    Returns void

  • Returns void

    Deprecated

    Use .state.reset() instead.

  • Can be used to reset the internal WebGL state.

    Returns void

  • A build in function that can be used instead of requestAnimationFrame. For WebXR projects this function must be used.

    Parameters

    • callback: null | XRFrameRequestCallback

      The function will be called every available frame. If null is passed it will stop any already ongoing animation.

    Returns void

  • Parameters

    • alpha: number

    Returns void

  • Sets the clear color, using color for the color and alpha for the opacity.

    Parameters

    Returns void

  • Parameters

    • width: number
    • height: number
    • pixelRatio: number

    Returns void

  • Sets the custom opaque sort function for the WebGLRenderLists. Pass null to use the default painterSortStable function.

    Parameters

    • method: ((a, b) => number)
        • (a, b): number
        • Parameters

          • a: any
          • b: any

          Returns number

    Returns void

  • Parameters

    • value: number

    Returns void

  • Sets the active render target.

    Parameters

    Returns void

  • Sets the scissor area from (x, y) to (x + width, y + height).

    Parameters

    • x: number | Vector4
    • Optional y: number
    • Optional width: number
    • Optional height: number

    Returns void

  • Enable the scissor test. When this is enabled, only the pixels within the defined scissor area will be affected by further renderer actions.

    Parameters

    • enable: boolean

    Returns void

  • Resizes the output canvas to (width, height), and also sets the viewport to fit that size, starting in (0, 0).

    Parameters

    • width: number
    • height: number
    • Optional updateStyle: boolean

    Returns void

  • Sets the custom transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function.

    Parameters

    • method: ((a, b) => number)
        • (a, b): number
        • Parameters

          • a: any
          • b: any

          Returns number

    Returns void

  • Sets the viewport to render from (x, y) to (x + width, y + height). (x, y) is the lower-left corner of the region.

    Parameters

    • x: number | Vector4
    • Optional y: number
    • Optional width: number
    • Optional height: number

    Returns void

  • Returns any

    Deprecated

    Use .capabilities.vertexTextures instead.