[name]

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

Constructor

[name]( [page:Object parameters] )

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.
canvas — A [page:Canvas] where the renderer draws its output.
context — The [page:RenderingContext] context to use.
precision — Shader precision. Can be *"highp"*, *"mediump"* or *"lowp"*. Defaults to *"highp"* if supported by the device.
alpha — [page:Boolean], default is *false*.
premultipliedAlpha — [page:Boolean], default is *true*.
antialias — [page:Boolean], default is *false*.
stencil — [page:Boolean], default is *true*.
preserveDrawingBuffer — [page:Boolean], default is *false*.
depth — [page:Boolean], default is *true*.
logarithmicDepthBuffer — [page:Boolean], default is *false*.

Properties

[property:DOMElement domElement]

A [page: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.

[property:WebGLRenderingContext context]

The HTML5 Canvas's 'webgl' context obtained from the canvas where the renderer will draw.

[property:Boolean autoClear]

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

[property:Boolean autoClearColor]

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

[property:Boolean autoClearDepth]

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

[property:Boolean autoClearStencil]

If autoClear is true, defines whether the renderer should clear the stencil buffer. 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 the object rendering order.

[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:Boolean localClippingEnabled]

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

[property:Boolean gammaInput]

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

[property:Boolean gammaOutput]

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

[property:WebGLShadowMap shadowMap]

This contains the reference to the component implementing shadow mapping.

[property:Boolean shadowMap.enabled]

Default is false. If set, use shadow maps in the 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, THREE.PCFSoftShadowMap. Default is THREE.PCFShadowMap.

[property:Boolean shadowMap.renderReverseSided]

Default is true. 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.

[property:Boolean shadowMap.renderSingleSided]

Default is true. 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.

[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: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:

Methods

[method:WebGLRenderingContext getContext]()

Return the WebGL context.

[method:WebGLContextAttributes getContextAttributes]()

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

[method:Boolean supportsVertexTextures]()

Return a [page:Boolean] true if the context supports vertex textures.

[method:number getPixelRatio]()

Returns current device pixel ratio used.

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

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

[method:Object getSize]()

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

[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 updateStyle to true adds explicit pixel units to the output canvas style.

[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).

[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).
NOTE: The point (x, y) is the lower left corner of the area to be set for both of these methods. The area is defined from left to right in width but bottom to top in height. The sense of the vertical definition is opposite to the fill direction of an HTML canvas element.

[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:null setClearColor]( [page:Color color], [page:Float alpha] )

Sets the clear color and opacity.
// Creates a renderer with red background var renderer = new THREE.WebGLRenderer(); renderer.setSize( 200, 100 ); renderer.setClearColor( 0xff0000 );

[method:Color getClearColor]()

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

[method:Float getClearAlpha]()

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

[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 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 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 correct material.

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

Render a geometry group using the camera and with the correct material.

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

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

[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.

[method:null renderImmediateObject]( camera, lights, fog, material, object )

Renders an immediate Object using a camera.

[method:null setFaceCulling]( cullFace, frontFace )

[page:String cullFace] —- "back", "front", "front_and_back", or false.
[page:String frontFace] —- "ccw" or "cw
Used for setting the gl frontFace, cullFace states in the GPU, thus enabling/disabling face culling when rendering.
If cullFace is false, culling will be disabled.

[method:null setTexture]( [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 wegl shader. The slot number can be found as a value of the uniform of the sampler.

[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:boolean supportsCompressedTextureS3TC]()

This method returns true if the webgl implementation supports compressed textures of the format S3TC.

[method:number getMaxAnisotropy]()

This returns the anisotropy level of the textures.

[method:string getPrecision]()

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

[method:null setMaterialFaces]([page:Material material])

material -- The [page:Material material] with side that shouldn't be culled.
This sets which side needs to be culled in the webgl renderer.

[method:boolean supportsStandardDerivatives]()

This method returns true if the webgl implementation supports standard derivatives.

[method:boolean supportsFloatTextures]()

This method returns true if the webgl implementation supports float textures.

[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.

Source

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