The WebGL renderer displays your beautifully crafted scenes using WebGL.
null
.
"highp"
, "mediump"
or "lowp"
.
Defaults to "highp"
if supported by the device.
true
, the value is 0
. Otherwise it's 1
. Default is false
.
true
.
false
.
true
.
false
.
"high-performance"
, "low-power"
or "default"
. Default is "default"
.
See WebGL spec for details.
false
.
See WebGL spec for details.
true
.
false
.
Defines whether the renderer should automatically clear its output before rendering a frame.
If autoClear is true, defines whether the renderer should clear the color buffer.
Default is true
.
If autoClear is true, defines whether the renderer should clear the depth buffer.
Default is true
.
If autoClear is true, defines whether the renderer should clear the stencil buffer.
Default is true
.
checkShaderErrors:
If it is true, defines whether material shader programs are checked
for errors during compilation and linkage process. It may be useful to disable this check in production for performance gain.
It is strongly recommended to keep these checks enabled during development.
If the shader does not compile and link - it will not work and associated material will not render.
Default is true
.
An object containing details about the capabilities of the current RenderingContext.
true
if floatFragmentTextures and vertexTextures are both true.true
if the context in use is a WebGL2RenderingContext object.true
if the logarithmicDepthBuffer
was set to true in the constructor and the context supports the EXT_frag_depth extension.gl.MAX_VERTEX_ATTRIBS
.gl.MAX_CUBE_MAP_TEXTURE_SIZE
. Maximum height * width of cube map textures that a shader can use.gl.MAX_FRAGMENT_UNIFORM_VECTORS
. The number of uniforms that can be used by a fragment shader.gl.MAX_SAMPLES
. Maximum number of samples in context of Multisample anti-aliasing (MSAA).gl.MAX_TEXTURE_SIZE
. Maximum height * width of a texture that a shader use.gl.MAX_TEXTURE_IMAGE_UNITS
. The maximum number of textures that can be used by a shader.gl.MAX_VARYING_VECTORS
. The number of varying vectors that can used by shaders.gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS
. The number of textures that can be used in a vertex shader.gl.MAX_VERTEX_UNIFORM_VECTORS
. The maximum number of uniforms that can be used in a vertex shader.true
if maxVertexTextures is greater than 0 (i.e. vertex textures can be used).User-defined clipping planes specified as 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 [].
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 like so:
document.body.appendChild(renderer.domElement);
get(extensionName : String):
Checks whether extensionName
is supported and returns an object with details of the extension if available.
has(extensionName : String):
Checks whether extensionName
is supported.
These methods are known to work the following extensions:
ANGLE_instanced_arrays
EXT_blend_minmax
EXT_color_buffer_float
EXT_color_buffer_half_float
EXT_disjoint_timer_query_webgl
EXT_disjoint_timer_query_webgl2
EXT_sRGB
EXT_texture_compression_bptc
EXT_texture_filter_anisotropic
KHR_parallel_shader_compile
OES_element_index_uint
OES_standard_derivatives
OES_texture_float
OES_texture_float_linear
OES_texture_half_float
OES_texture_half_float_linear
OES_vertex_array_object
WEBGL_compressed_texture_etc
WEBGL_compressed_texture_etc1
WEBGL_compressed_texture_pvrtc
WEBGL_compressed_texture_s3tc_srgb
WEBGL_compressed_texture_s3tc
WEBGL_debug_renderer_info
WEBGL_depth_texture
WEBGL_draw_buffers
WEBGL_lose_context
WEBGL_multisampled_render_to_texture
Defines the output encoding of the renderer. Default is v3d.LinearEncoding.
If a render target has been set using .setRenderTarget then renderTarget.texture.encoding will be used instead.
See the texture constants page for details of other formats.
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:
By default these data are reset at each render call but when having multiple render passes per frame (e.g. when using post processing) it can be preferred to reset with a custom pattern.
First, set autoReset
to false
.
renderer.info.autoReset = false;
Call reset()
whenever you have finished to render a single frame.
renderer.info.reset();
Defines whether the renderer respects object-level clipping planes. Default is false
.
Used internally by the renderer to keep track of various sub object properties.
Used internally to handle ordering of scene object rendering.
This contains the reference to the shadow map, if used.
false
.
true
. If you do not require dynamic lighting / shadows, you may set this to false
when the renderer is instantiated.
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.
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 necessary to turn off sorting and use other methods to deal with transparency rendering e.g. manually determining each object's rendering order.
Contains functions for setting various properties of the WebGLRenderer.context state.
Default is NoToneMapping. See the Renderer constants for other choices.
Exposure level of tone mapping. Default is 1
.
Provides access to the WebXR related interface of the renderer.
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
.
Clear the color buffer. Equivalent to calling .clear(true, false, false).
Clear the depth buffer. Equivalent to calling .clear(false, true, false).
Clear the stencil buffers. Equivalent to calling .clear(false, false, true).
Compiles all materials in the scene with the camera. This is useful to precompile shaders before the first rendering.
Compiles all materials in the scene with the camera asynchronously. This is useful to precompile shaders before the first rendering. The optional progressCb function receives a percentage parameter.
Copies pixels from the current WebGLFramebuffer into a 2D texture. Enables access to WebGLRenderingContext.copyTexImage2D.
Copies all pixels of a texture to an existing texture starting from the given position. Enables access to WebGLRenderingContext.texSubImage2D.
Copies the pixels of a texture in the bounds 'sourceBox' in the destination texture starting from the given position. Enables access to WebGL2RenderingContext.texSubImage3D.
Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
Simulate loss of the WebGL context. This requires support for the WEBGL_lose_context extensions.
Simulate restore of the WebGL context. This requires support for the WEBGL_lose_context extensions.
Returns a float with the current clear alpha. Ranges from 0 to 1.
Returns a v3d.Color instance with the current clear color.
Return the current WebGL context.
Returns an object that describes the attributes set on the WebGL context when it was created.
Returns the current active cube face.
Returns the current active mipmap level.
Returns the current RenderTarget if there are; returns null
otherwise.
target — the result will be copied into this Vector4.
Returns the current viewport.
target — the result will be copied into this Vector2.
Returns the width and height of the renderer's drawing buffer, in pixels.
Returns current device pixel ratio used.
target — the result will be copied into this Vector4.
Returns the scissor region.
Returns true
if scissor test is enabled; returns false
otherwise.
target — the result will be copied into this Vector2.
Returns the width and height of the renderer's output canvas, in pixels.
target — the result will be copied into this Vector4.
Returns the viewport.
Initializes the given texture. Useful for preloading a texture rather than waiting until first render (which can cause noticeable lags due to decode and GPU upload overhead).
Reset the GL state to default. Called internally if the WebGL context is lost.
buffer - Uint8Array is the only destination type supported in all cases, other types are renderTarget and platform dependent. See WebGL spec for details.
Reads the pixel data from the renderTarget into the buffer you pass in. This is a wrapper around WebGLRenderingContext.readPixels().
For reading out a WebGLCubeRenderTarget use the optional parameter activeCubeFaceIndex to determine which face should be read.
Render a scene or another type of object using a camera.
The render is done to a previously specified 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 or more buffers call .clear.
Can be used to reset the internal WebGL state. This method is mostly relevant for applications which share a single WebGL context across multiple WebGL libraries.
callback — The function will be called every available frame. If null
is passed it will stop any already ongoing animation.
A built in function that can be used instead of requestAnimationFrame. For WebXR projects this function must be used.
Sets the clear alpha. Valid input is a float between 0.0
and 1.0
.
Sets the clear color and opacity.
Sets device pixel ratio. This is usually used for HiDPI device to prevent blurring output canvas.
renderTarget — The renderTarget that needs to be activated. When null
is given, the canvas is set as the active render target instead.
activeCubeFace — Specifies the active cube side (PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5) of WebGLCubeRenderTarget. When passing a WebGLArrayRenderTarget or WebGL3DRenderTarget this indicates the z layer to render in to (optional).
activeMipmapLevel — Specifies the active mipmap level (optional).
This method sets the active rendertarget.
The x, y, width, and height parameters of the scissor region. Optionally, a 4-component vector specifying the parameters of the region.
Sets the scissor region from (x, y) to (x + width, y + height). (x, y) is the lower-left corner of the scissor region.
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.
Sets the custom opaque sort function for the WebGLRenderLists. Pass null
to use the default painterSortStable function.
Sets the custom transparent sort function for the WebGLRenderLists. Pass null
to use the default reversePainterSortStable function.
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 false prevents any style changes to the output canvas.
The x, y, width, and height parameters of the viewport. Optionally, a 4-component vector specifying the parameters of a viewport.
Sets the viewport to render from (x, y) to (x + width, y + height). (x, y) is the lower-left corner of the region.
For more info on how to obtain the source code of this module see this page.