[name]

The WebGL renderer displays your beautifully crafted scenes using [link:https://en.wikipedia.org/wiki/WebGL WebGL].

Constructor

[name]( [page:Object parameters] )

[page:Object parameters] - (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. The following are valid parameters:

[page:DOMElement canvas] - A [link:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas canvas] where the renderer draws its output. This corresponds to the [page:WebGLRenderer.domElement domElement] property below. If not passed in here, a new canvas element will be created.
[page:WebGLRenderingContext context] - This can be used to attach the renderer to an existing [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext RenderingContext]. Default is null.
[page:String precision] - Shader precision. Can be *"highp"*, *"mediump"* or *"lowp"*. Defaults to *"highp"* if supported by the device. See the note in "Things to Avoid" [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices here].
[page:Boolean alpha] - whether the canvas contains an alpha (transparency) buffer or not. Default is *false*.
[page:Boolean premultipliedAlpha] - whether the renderer will assume that colors have [link:https://en.wikipedia.org/wiki/Glossary_of_computer_graphics#Premultiplied_alpha premultiplied alpha]. Default is *true*.
[page:Boolean antialias] - whether to perform antialiasing. Default is *false*.
[page:Boolean stencil] - whether the drawing buffer has a [link:https://en.wikipedia.org/wiki/Stencil_buffer stencil buffer] of at least 8 bits. Default is *true*.
[page:Boolean preserveDrawingBuffer] - whether to preserve the buffers until manually cleared or overwritten. Default is *false*.
[page:String powerPreference] - Provides a hint to the user agent indicating what configuration of GPU is suitable for this WebGL context. Can be *"high-performance"*, *"low-power"* or *"default"*. Default is *"default"*.
[page:Boolean depth] - whether the drawing buffer has a [link:https://en.wikipedia.org/wiki/Z-buffering depth buffer] of at least 16 bits. Default is *true*.
[page:Boolean logarithmicDepthBuffer] - whether to use a logarithmic depth buffer. It may be neccesary to use this if dealing with huge differences in scale in a single scene. Default is *false*. See the [example:webgl_camera_logarithmicdepthbuffer camera / logarithmicdepthbuffer] example.

Properties

[property:Boolean autoClear]

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

[property:Boolean autoClearColor]

If [page:.autoClear autoClear] is true, defines whether the renderer should clear the color buffer. Default is *true*.

[property:Boolean autoClearDepth]

If [page:.autoClear autoClear] is true, defines whether the renderer should clear the depth buffer. Default is *true*.

[property:Boolean autoClearStencil]

If [page:.autoClear autoClear] is true, defines whether the renderer should clear the stencil buffer. Default is *true*.

[property:Object capabilities]

An object containing details about the capabilities of the current [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext RenderingContext].
- [property:Boolean floatFragmentTextures]: whether the context supports the [link:https://developer.mozilla.org/en-US/docs/Web/API/OES_texture_float OES_texture_float] extension. According to [link:https://webglstats.com/ WebGLStats], as of February 2016 over 95% of WebGL enabled devices support this.
- [property:Boolean floatVertexTextures]: *true* if [property:Boolean floatFragmentTextures] and [property:Boolean vertexTextures] are both true.
- [property:Method getMaxAnisotropy](): see [page:WebGLRenderer.getMaxAnisotropy getMaxAnisotropy] below.
- [property:Method getMaxPrecision](): see [page:WebGLRenderer.getMaxPrecision getMaxPrecision] below.
- [property:Boolean logarithmicDepthBuffer]: *true* if the [property:parameter logarithmicDepthBuffer] was set to true in the constructor and the context supports the [link:https://developer.mozilla.org/en-US/docs/Web/API/EXT_frag_depth EXT_frag_depth] extension. According to [link:https://webglstats.com/ WebGLStats], as of February 2016 around 66% of WebGL enabled devices support this.
- [property:Integer maxAttributes]: The value of *gl.MAX_VERTEX_ATTRIBS*.
- [property:Integer maxCubemapSize]: The value of *gl.MAX_CUBE_MAP_TEXTURE_SIZE*. Maximum height * width of cube map textures that a shader can use.
- [property:Integer maxFragmentUniforms]: The value of *gl.MAX_FRAGMENT_UNIFORM_VECTORS*. The number of uniforms that can be used by a fragment shader.
- [property:Integer maxTextureSize]: The value of *gl.MAX_TEXTURE_SIZE*. Maximum height * width of a texture that a shader use.
- [property:Integer maxTextures]: The value of *gl.MAX_TEXTURE_IMAGE_UNITS*. The maximum number of textures that can be used by a shader.
- [property:Integer maxVaryings]: The value of *gl.MAX_VARYING_VECTORS*. The number of varying vectors that can used by shaders.
- [property:Integer maxVertexTextures]: The value of *gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS*. The number of textures that can be used in a vertex shader.
- [property:Integer maxVertexUniforms]: The value of *gl.MAX_VERTEX_UNIFORM_VECTORS*. The maximum number of uniforms that can be used in a vertex shader.
- [property:String precision]: The shader precision currently being used by the renderer.
- [property:Boolean vertexTextures]: *true* if [property:Integer maxVertexTextures] is greater than 0 (i.e. vertext textures can be used).

[property:Array clippingPlanes]

User-defined clipping planes specified as THREE.Plane objects in world space. These planes apply globally. Points in space whose dot product with the plane is negative are cut away. Default is [].

[property:WebGLRenderingContext context]

The renderer obtains a [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext RenderingContext] context from its [page:WebGLRenderer.domElement domElement] by default, using [link:https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext HTMLCanvasElement.getContext]().

You can create this manually, however it must correspond to the [page:WebGLRenderer.domElement domElement] in order to render to the screen.

[property:DOMElement domElement]

A [link:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas 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 like so:
document.body.appendChild( renderer.domElement );

[property:Object extensions]

A wrapper for the [page:WebGLRenderer.extensions.get .extensions.get] method, used to check whether various WebGL extensions are supported.

[property:Float gammaFactor]

Default is *2*.

[property:Boolean gammaInput]

If set, then it expects that all textures and colors are premultiplied gamma. Default is *false*.

[property:Boolean gammaOutput]

If set, then it expects that all textures and colors need to be outputted in premultiplied gamma. Default is *false*.

[property:Object info]

An object with a series of statistical information about the graphics board memory and the rendering process. Useful for debugging or just for the sake of curiosity. The object contains the following fields:

[property:Boolean localClippingEnabled]

Defines whether the renderer respects object-level clipping planes. Default is *false*.

[property:Integer maxMorphTargets]

Default is 8. The maximum number of MorphTargets allowed in a shader. Keep in mind that the standard materials only allow 8 MorphTargets.

[property:Integer maxMorphNormals]

Default is 4. The maximum number of MorphNormals allowed in a shader. Keep in mind that the standard materials only allow 4 MorphNormals.

[property:Integer physicallyCorrectLights]

Whether to use physically correct lighting mode. Default is *false*. See the [example:webgl_lights_physical lights / physical] example.

[property:Object properties]

Used internally by the renderer to keep track of various sub object properties.

[property:WebGLRenderLists renderLists]

Used internally to handle ordering of scene object rendering.

[property:WebGLShadowMap shadowMap]

This contains the reference to the shadow map, if used.

[property:Boolean shadowMap.enabled]

If set, use shadow maps in the scene. Default is *false*.

[property:Boolean shadowMap.autoUpdate]

Enables automatic updates to the shadows in the scene. Default is *true*.
If you do not require dynamic lighting / shadows, you may set this to *false* when the renderer is instantiated.

[property:Boolean shadowMap.needsUpdate]

When set to *true*, shadow maps in the scene will be updated in the next *render* call. Default is *false*.
If you have disabled automatic updates to shadow maps (*shadowMap.autoUpdate = false*), you will need to set this to *true* and then make a render call to update the shadows in your scene.

[property:Integer shadowMap.type]

Defines shadow map type (unfiltered, percentage close filtering, percentage close filtering with bilinear filtering in shader)
Options are THREE.BasicShadowMap, THREE.PCFShadowMap (default), THREE.PCFSoftShadowMap. See [page:WebGLRenderer WebGLRenderer constants] for details.

[property:Boolean shadowMap.renderReverseSided]

Whether to render the opposite side as specified by the material into the shadow map. When disabled, an appropriate shadow.bias must be set on the light source for surfaces that can both cast and receive shadows at the same time to render correctly. Default is *true*.

[property:Boolean shadowMap.renderSingleSided]

Whether to treat materials specified as double-sided as if they were specified as front-sided when rendering the shadow map. When disabled, an appropriate shadow.bias must be set on the light source for surfaces that can both cast and receive shadows at the same time to render correctly. Default is *true*.

[property:Boolean sortObjects]

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

Note: Sorting is used to attempt to properly render objects that have some degree of transparency. By definition, sorting objects may not work in all cases. Depending on the needs of application, it may be neccessary to turn off sorting and use other methods to deal with transparency rendering e.g. manually determining each object's rendering order.

[property:Object state]

Contains functions for setting various properties of the [page:WebGLRenderer.context] state.

[property:Constant toneMapping]

Default is [page:Renderer LinearToneMapping]. See the [page:Renderer Renderer constants] for other choices.

[property:Number toneMappingExposure]

Exposure level of tone mapping. Default is *1*.

[property:Number toneMappingWhitePoint]

Tone mapping white point. Default is *1*.

Methods

[method:Integer allocTextureUnit]

Attempt to allocate a texture unit for use by a shader. Will warn if trying to allocate more texture units than the GPU supports. This is mainly used internally. See [page:WebGLRenderer.capabilities capabilities.maxTextures].

[method:null clear]( [page:Boolean color], [page:Boolean depth], [page:Boolean stencil] )

Tells the renderer to clear its color, depth or stencil drawing buffer(s). This method initializes the color buffer to the current clear color value.
Arguments default to *true*.

[method:null clearColor]( )

Clear the color buffer. Equivalent to calling [page:WebGLRenderer.clear .clear]( true, false, false ).

[method:null clearDepth]( )

Clear the depth buffer. Equivalent to calling [page:WebGLRenderer.clear .clear]( false, true, false ).

[method:null clearStencil]( )

Clear the stencil buffers. Equivalent to calling [page:WebGLRenderer.clear .clear]( false, false, true ).

[method:null clearTarget]([page:WebGLRenderTarget renderTarget], [page:boolean color], [page:boolean depth], [page:boolean stencil])

renderTarget -- The [page:WebGLRenderTarget renderTarget] that needs to be cleared.
color -- If set, then the color gets cleared.
depth -- If set, then the depth gets cleared.
stencil -- If set, then the stencil gets cleared.
This method clears a rendertarget. To do this, it activates the rendertarget.

[method:null compile]( [page:Scene scene], [page:Camera camera] )

Compiles all materials in the scene with the camera. This is useful to precompile shaders before the first rendering.

[method:null copyFramebufferToTexture]( [page:Number x], [page:Number y], [page:Texture texture], [page:Number level] )

Copies pixels from the current WebGLFramebuffer into a 2D texture. Enables access to [link:https://developer.mozilla.org/de/docs/Web/API/WebGLRenderingContext/copyTexImage2D WebGLRenderingContext.copyTexImage2D].

[method:null dispose]( )

Dispose of the current rendering context.

[method:Object extensions.get]( [page:String extensionName] )

Used to check whether various extensions are supported and returns an object with details of the extension if available. This method can check for the following extensions:

- *WEBGL_depth_texture*
- *EXT_texture_filter_anisotropic*
- *WEBGL_compressed_texture_s3tc*
- *WEBGL_compressed_texture_pvrtc*
- *WEBGL_compressed_texture_etc1*

[method:null forceContextLoss]( )

Simulate loss of the WebGL context. This requires support for the [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context WEBGL_lose_context] extensions. According to [link:https://webglstats.com/ WebGLStats], as of February 2016 90% of WebGL enabled devices support this.

[method:Float getClearAlpha]()

Returns a [page:Float float] with the current clear alpha. Ranges from 0 to 1.

[method:Color getClearColor]()

Returns a [page:Color THREE.Color] instance with the current clear color.

[method:WebGLRenderingContext getContext]()

Return the current WebGL context.

[method:WebGLContextAttributes getContextAttributes]()

Returns an object that describes the attributes set on the WebGL context when it was created.

[method:RenderTarget getCurrentRenderTarget]( )

Returns the current RenderTarget, if any.

[method:Number getMaxAnisotropy]()

This returns the anisotropy level of the textures.

[method:Object getDrawingBufferSize]()

Returns an object containing the width and height of the renderer's drawing buffer, in pixels.

[method:number getPixelRatio]()

Returns current device pixel ratio used.

[method:string getPrecision]()

This gets the precision used by the shaders. It returns "highp","mediump" or "lowp".

[method:Object getSize]()

Returns an object containing the width and height of the renderer's output canvas, in pixels.

[method:null resetGLState]( )

Reset the GL state to default. Called internally if the WebGL context is lost.

[method:null readRenderTargetPixels]( [page:WebGLRenderTarget renderTarget], [page:Float x], [page:Float y], [page:Float width], [page:Float height], buffer )

Reads the pixel data from the renderTarget into the buffer you pass in. Buffer should be a Javascript Uint8Array instantiated with new Uint8Array( renderTargetWidth * renderTargetWidth * 4 ) to account for size and color information. This is a wrapper around gl.readPixels.
See the [example:webgl_interactive_cubes_gpu interactive / cubes / gpu] example.

[method:null render]( [page:Scene scene], [page:Camera camera], [page:WebGLRenderTarget renderTarget], [page:Boolean forceClear] )

Render a [page:Scene scene] using a [page:Camera camera].
The render is done to the [page:WebGLRenderTarget renderTarget] (if specified) or to the canvas as usual.
If [page:Boolean forceClear] is *true*, the depth, stencil and color buffers will be cleared before rendering even if the renderer's [page:WebGLRenderer.autoClear autoClear] property is false.
Even with forceClear set to true you can prevent certain buffers being cleared by setting either the [page:WebGLRenderer.autoClearColor autoClearColor], [page:WebGLRenderer.autoClearStencil autoClearStencil] or [page:WebGLRenderer.autoClearDepth autoClearDepth] properties to false.

[method:null renderBufferDirect]( [page:Camera camera], [page:Array lights], [page:Fog fog], [page:Material material], [page:Object geometryGroup], [page:Object3D object] )

Render a buffer geometry group using the camera and with the specified material.

[method:null renderBufferImmediate]( [page:Object3D object], [page:shaderprogram program], [page:Material shading] )

object - an instance of [page:Object3D]
program - an instance of shaderProgram
shading - an instance of Material

Render an immediate buffer. Gets called by renderImmediateObject.

[method:null setClearAlpha]( [page:Float alpha] )

Sets the clear alpha. Valid input is a float between *0.0* and *1.0*.

[method:null setClearColor]( [page:Color color], [page:Float alpha] )

Sets the clear color and opacity.

[method:null setFaceCulling]( [page:Renderer cullFace], [page:Renderer frontFace] )

See [page:Renderer WebGLRenderer constants] for all possible values for [page:Renderer cullFace] and [page:Renderer frontFace].
Used for setting the gl.frontFace and gl.cullFace states in the GPU, thus enabling/disabling face culling when rendering.
If cullFace is set to [page:Renderer CullFaceNone], culling will be disabled.

[method:null setPixelRatio]( [page:number value] )

Sets device pixel ratio. This is usually used for HiDPI device to prevent bluring output canvas.

[method:null setRenderTarget]( [page:WebGLRenderTarget renderTarget] )

renderTarget -- The [page:WebGLRenderTarget renderTarget] that needs to be activated (optional).

This method sets the active rendertarget. If the parameter is omitted the canvas is set as the active rendertarget.

[method:null setScissor]( [page:Integer x], [page:Integer y], [page:Integer width], [page:Integer height] )

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

[method:null setScissorTest]( [page:Boolean boolean] )

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

[method:Boolean supportsVertexTextures]()

Return a [page:Boolean] true if the context supports vertex textures. This has been deprecated in favour of [page:WebGLRenderer.capabilities capabilities.vertexTexures].

[method:null setSize]( [page:Integer width], [page:Integer height], [page:Boolean updateStyle] )

Resizes the output canvas to (width, height) with device pixel ratio taken into account, and also sets the viewport to fit that size, starting in (0, 0). Setting [page:Boolean updateStyle] to true adds explicit pixel units to the output canvas style.

[method:null setTexture2D]( [page:Texture texture], [page:number slot] )

texture -- The [page:Texture texture] that needs to be set.
slot -- The number indicating which slot should be used by the texture.

This method sets the correct texture to the correct slot for the WebGL shader. The slot number can be found as a value of the uniform of the sampler.

Note: This method replaces the older [method:null setTexture] method.

[method:null setTextureCube]( [page:CubeTexture cubeTexture], [page:Number slot] )

texture -- The [page:CubeTexture cubeTexture] that needs to be set.
slot -- The number indicating which slot should be used by the texture.

This method sets the correct texture to the correct slot for the WebGL shader. The slot number can be found as a value of the uniform of the sampler.

[method:null setViewport]( [page:Integer x], [page:Integer y], [page:Integer width], [page:Integer height] )

Sets the viewport to render from (x, y) to (x + width, y + height).

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]