Class WebGLRenderer

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

Implements

Constructors

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

    Parameters

    Returns WebGLRenderer

Properties

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.

document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' )
autoClear: boolean

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

true
autoClearColor: boolean

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

true
autoClearDepth: boolean

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

true
autoClearStencil: boolean

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

true
debug: WebGLDebug

Debug configurations.

{ checkShaderErrors: true }
sortObjects: boolean

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

true
clippingPlanes: Plane[]
[]
localClippingEnabled: boolean
false
extensions: WebGLExtensions
toneMapping: ToneMapping
THREE.NoToneMapping
toneMappingExposure: number
1
info: WebGLInfo
shadowMap: WebGLShadowMap
pixelRatio: number
capabilities: WebGLCapabilities
properties: WebGLProperties
renderLists: WebGLRenderLists
state: WebGLState
compile: ((scene: Object3D<Object3DEventMap>, camera: Camera, targetScene?: null | Scene) => 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.

compileAsync: ((scene: Object3D<Object3DEventMap>, camera: Camera, targetScene?: null | Scene) => 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.

vr: boolean

Use .xr instead.

shadowMapEnabled: boolean

Use .shadowMap.enabled instead.

shadowMapType: ShadowMapType

Use .shadowMap.type instead.

shadowMapCullFace: CullFace

Use .shadowMap.cullFace instead.

Accessors

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

    Returns ColorSpace

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

    Returns void

  • get coordinateSystem(): 2000
  • Returns 2000

Methods

  • Return the WebGL context.

    Returns WebGLRenderingContext | WebGL2RenderingContext

  • Returns any

  • Returns void

  • Returns void

  • Returns number

    Use .capabilities.getMaxAnisotropy() instead.

  • Returns string

    Use .capabilities.precision instead.

  • Returns number

  • Parameters

    • value: number

    Returns void

  • Parameters

    Returns Vector2

  • Parameters

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

    Returns void

  • Parameters

    Returns Vector2

  • 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
    • OptionalupdateStyle: boolean

    Returns void

  • Parameters

    Returns Vector4

  • Copies the viewport into target.

    Parameters

    Returns Vector4

  • 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
    • Optionaly: number
    • Optionalwidth: number
    • Optionalheight: number

    Returns void

  • Copies the scissor area into target.

    Parameters

    Returns Vector4

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

    Parameters

    • x: number | Vector4
    • Optionaly: number
    • Optionalwidth: number
    • Optionalheight: number

    Returns void

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

    Returns boolean

  • 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

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

    Parameters

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

          • a: any
          • b: any

          Returns number

    Returns void

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

    Parameters

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

          • a: any
          • b: any

          Returns number

    Returns void

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

    Parameters

    Returns Color

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

    Parameters

    Returns void

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

    Returns number

  • Parameters

    • alpha: number

    Returns void

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

    Parameters

    • Optionalcolor: boolean
    • Optionaldepth: boolean
    • Optionalstencil: boolean

    Returns void

  • Returns void

  • Returns void

  • Returns void

  • Parameters

    Returns void

  • Returns void

    Use .state.reset() instead.

  • 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

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

    Returns void

    Use .setAnimationLoop() instead.

  • 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 the current active cube face.

    Returns number

  • Returns the current active mipmap level.

    Returns number

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

    Returns null | WebGLRenderTarget<Texture>

  • Sets the active render target.

    Parameters

    • renderTarget: null | WebGLRenderTarget<Texture> | WebGLRenderTarget<Texture[]>

      The renderTarget that needs to be activated. When null is given, the canvas is set as the active render target instead.

    • OptionalactiveCubeFace: number

      Specifies the active cube side (PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5) of WebGLCubeRenderTarget.

    • OptionalactiveMipmapLevel: number

      Specifies the active mipmap level.

    Returns void

  • Parameters

    Returns void

  • Parameters

    Returns Promise<TypedArray>

  • 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

    • texture: Texture

      Specifies the destination texture.

    • Optionalposition: null | Vector2

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

    • Optionallevel: number

      Specifies the destination mipmap level of the texture.

    Returns void

  • Copies the pixels of a texture in the bounds srcRegion in the destination texture starting from the given
    position.

    Parameters

    • srcTexture: Texture

      Specifies the source texture.

    • dstTexture: Texture

      Specifies the destination texture.

    • OptionalsrcRegion: null | Box2

      Specifies the bounds

    • OptionaldstPosition: null | Vector2

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

    • Optionallevel: number

      Specifies the destination mipmap level of the texture.

    Returns void

  • Copies the pixels of a texture in the bounds srcRegion in the destination texture starting from the given
    position.

    Parameters

    • srcTexture: Texture

      Specifies the source texture.

    • dstTexture: Data3DTexture | DataArrayTexture

      Specifies the destination texture.

    • OptionalsrcRegion: null | Box3

      Specifies the bounds

    • OptionaldstPosition: null | Vector3

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

    • Optionallevel: number

      Specifies the destination mipmap level of the texture.

    Returns void

  • Initializes the given WebGLRenderTarget memory. Useful for initializing a render target so data can be copied
    into it using WebGLRenderer.copyTextureToTexture before it has been rendered to.

    Parameters

    Returns void

  • 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

  • Can be used to reset the internal WebGL state.

    Returns void

  • Returns any

    Use .capabilities.vertexTextures instead.

  • Parameters

    • boolean: any

    Returns any

    Use .setScissorTest() instead.