[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.
precision — shader precision. Can be *"highp"*, *"mediump"* or *"lowp"*.
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*.
maxLights — [page:Integer], default is *4*.
Properties
.[page: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.
.[page:WebGLRenderingContext context]
The HTML5 Canvas's 'webgl' context obtained from the canvas where the renderer will draw.
.[page:Boolean autoClear]
Defines whether the renderer should automatically clear its output before rendering.
.[page:Boolean autoClearColor]
If autoClear is true, defines whether the renderer should clear the color buffer. Default is true.
.[page:Boolean autoClearDepth]
If autoClear is true, defines whether the renderer should clear the depth buffer. Default is true.
.[page:Boolean autoClearStencil]
If autoClear is true, defines whether the renderer should clear the stencil buffer. Default is true.
.[page: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.
.[page:Boolean autoUpdateObjects]
Defines whether the renderer should auto update objects. Default is true.
.[page:Boolean gammaInput]
Default is false. If set, then it expects that all textures and colors are premultiplied gamma.
.[page:Boolean gammaOutput]
Default is false. If set, then it expects that all textures and colors need to be outputted in premultiplied gamma.
.[page:Boolean shadowMapEnabled]
Default is false. If set, use shadow maps in the scene.
.[page:Boolean shadowMapAutoUpdate]
Default is true. If set, autoupdate the shadowmaps every frame.
.[page:Integer shadowMapType]
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.
.[page:Integer shadowMapCullFace]
Default is THREE.CullFaceFront. The faces that needed to be culled. Possible values: THREE.CullFaceFront and THREE.CullFaceBack
[page:Boolean shadowMapDebug]
Default is false. If set, then the shadowmaps get a specific color to identify which shadow is from which shadowmap.
.[page:Boolean shadowMapCascade]
Default is false. If Set, use cascaded shadowmaps. See [link:http://developer.download.nvidia.com/SDK/10.5/opengl/src/cascaded_shadow_maps/doc/cascaded_shadow_maps.pdf cascaded shadowmaps] for more information.
.[page: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.
.[page: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.
.[page:Boolean autoScaleCubemaps]
Default is true. If set, then Cubemaps are scaled, when they are bigger than the maximum size, to make sure that they aren't bigger than the maximum size.
.[page:Boolean renderPluginsPre]
An array with render plugins to be applied before rendering.
Default is an empty array, or [].
.[page:Boolean renderPluginsPost]
An array with render plugins to be applied after rendering.
Default is an empty array, or [].
.[page: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:
- memory:
- programs
- geometries
- textures
- render:
- calls
- vertices
- faces
- points
.[page:ShadowMapPlugin shadowMapPlugin]
This contains the reference to the shadowMapPlugin.
.[page:number devicePixelRatio]
The pixel ration of the devices.
Methods
.getContext()
Return the WebGL context.
.supportsVertexTextures()
Return a [page:Boolean] true if the context supports vertex textures.
.setSize( [page:Integer width], [page:Integer height] )
Resizes the output canvas to (width, height), and also sets the viewport to fit that size, starting in (0, 0).
.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).
.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).
.enableScissorTest( [page:Boolean enable] )
Enable the scissor test. When this is enabled, only the pixels within the defined scissor area will be affected by further renderer actions.
.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, 1);
.getClearColor() [page:Color]
Returns a [page:Color THREE.Color] instance with the current clear color.
.getClearAlpha() [page:Float]
Returns a [page:Float float] with the current clear alpha. Ranges from 0 to 1.
.clear( [page:Boolean color], [page:Boolean depth], [page:Boolean stencil] )
Tells the renderer to clear its color, depth or stencil drawing buffer(s).
If no parameters are passed, no buffer will be cleared.
.addPostPlugin( plugin )
Initialises the postprocessing plugin, and adds it to the renderPluginsPost array.
.addPrePlugin( plugin )
Initialises the preprocessing plugin, and adds it to the renderPluginsPre array.
.updateShadowMap( [page:Scene scene], [page:Camera camera] )
scene — an instance of [page:Scene]
camera — an instance of [page:Camera]
Tells the shadow map plugin to update using the passed scene and camera parameters.
.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.
.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.
.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.
.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.
.renderImmediateObject( camera, lights, fog, material, object )
Renders an immediate Object using a camera.
.initWebGLObjects( [page:Scene scene] )
[page:Scene scene] -- The scene to initialize.
This method initializes the scene. This means adding and removing all objects from the scene and updating them to make sure we have the correct webgl buffers.
.initMaterial( [page:Material material], [page:Array lights], [page:Fog fog], [page:Object3D object])
[page:Material material] -- The material to initialize.
[page:Array lights] -- An array of lights that influence the material.
[page:Fog fog] -- The fog of the scene.
[page:Object3D object] -- The object of the material that needs init.
This method initializes the material as a webgl program to be used.
.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.
.setDepthTest( [page:boolean depthTest] )
depthTest -- The boolean to decide if depth of a fragment needs to be tested against the depth buffer .
This sets, based on depthTest, whether or not the depth data needs to be tested against the depth buffer.
.setDepthWrite( [page:boolean depthWrite] )
depthWrite -- The boolean to decide if depth of a fragment needs to be kept.
This sets, based on depthWrite, whether or not the depth data needs to be written in the depth buffer.
.setBlending( [page:number blending], [page:number blendEquation], [page:number blendSrc], [page:number blendDst] )
blending -- A number indicating the blending mode. Possible value are THREE.NoBlending, THREE.NormalBlending, THREE.AdditiveBlending, THREE.SubtractiveBlending, THREE.MultiplyBlending or THREE.CustomBlending
blendEquation -- When blending is THREE.CustomBlending, then you can set the blendEquation. Possible values are THREE.AddEquation, THREE.SubtractEquation or THREE.ReverseSubtractEquation.
blendSrc -- When blending is THREE.CustomBlending, then you can set the blendSrc. Possible values are THREE.ZeroFactor, THREE.OneFactor,THREE.SrcColorFactor, THREE.OneMinusSrcColorFactor, THREE.SrcAlphaFactor, THREE.OneMinusSrcAlphaFactor, THREE.DstAlphaFactor, THREE.OneMinusDstAlphaFactor, THREE.DstColorFactor,THREE.OneMinusDstColorFactor or THREE.SrcAlphaSaturateFactor
blendDst -- When blending is THREE.CustomBlending, then you can set the blendDst. Possible values are THREE.ZeroFactor, THREE.OneFactor,THREE.SrcColorFactor, THREE.OneMinusSrcColorFactor, THREE.SrcAlphaFactor, THREE.OneMinusSrcAlphaFactor, THREE.DstAlphaFactor, THREE.OneMinusDstAlphaFactor, THREE.DstColorFactor,THREE.OneMinusDstColorFactor or THREE.SrcAlphaSaturateFactor
This method sets the correct blending.
.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.
.setRenderTarget( [page:WebGLRenderTarget renderTarget] )
renderTarget -- The [page:WebGLRenderTarget renderTarget] that needs to be activated.
This method sets the active rendertarget.
.supportsCompressedTextureS3TC() [page:boolean]
This method returns true if the webgl implementation supports compressed textures of the format S3TC.
.getMaxAnisotropy() [page:number]
This returns the anisotropy level of the textures.
.getPrecision() [page:string]
This gets the precision used by the shaders. It returns "highp","mediump" or "lowp".
.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.
.supportsStandardDerivatives() [page:boolean]
This method returns true if the webgl implementation supports standard derivatives.
.supportsFloatTextures() [page:boolean]
This method returns true if the webgl implementation supports float textures.
.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]