API Docs for:
Show:

LS.Renderer Class

Module: LS

The Renderer is in charge of generating one frame of the scene. Contains all the passes and intermediate functions to create the frame.

Constructor

LS.Renderer

()

Methods

addRenderQueue

(
  • name
  • sorting
  • options
)
Number

Adds a new RenderQueue to the Renderer.

Parameters:

  • name RenderQueue

    name of the render pass as in render_passes

  • sorting Number

    which algorithm use to sort ( LS.RenderQueue.NO_SORT, LS.RenderQueue.SORT_NEAR_TO_FAR, LS.RenderQueue.SORT_FAR_TO_NEAR )

  • options Object

    extra stuff to add to the queue ( like callbacks onStart, onFinish )

Returns:

Number:

index of the render queue

blit

(
  • source
  • destination
  • shader
  • uniforms
)

Renders one texture into another texture, it allows to apply a shader

Parameters:

  • source GL.Texture
  • destination GL.Texture
  • shader GL.Shader

    [optional] shader to apply, it must use the GL.Shader.QUAD_VERTEX_SHADER as vertex shader

  • uniforms Object

    [optional] uniforms for the shader

clearBuffer

(
  • camera
  • render_settings
)

clear color using camera info ( background color, viewport scissors, clear depth, etc )

Parameters:

enableCamera

(
  • camera
  • render_settings
)

Sets camera as the current camera, sets the viewport according to camera info, updates matrices, and prepares LS.Draw

Parameters:

  • camera Camera
  • render_settings RenderSettings

enableFrameShaderBlock

(
  • shader_block_name
)

Enables a ShaderBlock ONLY DURING THIS FRAME

Parameters:

  • shader_block_name String

getCameraAtPosition

(
  • x
  • y
  • scene
)
Camera

Returns the last camera that falls into a given screen position

Parameters:

  • x Number
  • y Number
  • scene Scene

    if not specified last rendered scene will be used

Returns:

Camera:

the camera

getCurrentCamera

() Camera

Returns the camera active

Returns:

Camera:

camera

getNearLights

(
  • instance
  • result
)
Array

returns a list of all the lights overlapping this instance (it uses sperical bounding so it could returns lights that are not really overlapping) It is used by the multipass lighting to iterate

Parameters:

  • instance RenderInstance

    the render instance

  • result Array

    [optional] the output array

Returns:

Array:

array containing a list of LS.Light affecting this RenderInstance

processVisibleData

(
  • scene
  • render_settings
  • cameras
)

Collects and process the rendering instances, cameras and lights that are visible Its a prepass shared among all rendering passes Warning: rendering order is computed here, so it is shared among all the cameras (TO DO, move somewhere else)

Parameters:

  • scene Scene
  • render_settings RenderSettings
  • cameras Array

    in case you dont want to use the scene cameras

render

(
  • scene
  • render_settings
  • [cameras=null]
)

Renders the current scene to the screen Many steps are involved, from gathering info from the scene tree, generating shadowmaps, setup FBOs, render every camera If you want to change the rendering pipeline, do not overwrite this function, try to understand it first, otherwise you will miss lots of features

Parameters:

  • scene Scene
  • render_settings RenderSettings
  • [cameras=null] Array optional

    if no cameras are specified the cameras are taken from the scene

renderFrame

(
  • camera
  • render_settings
  • scene
)

renders the view from one camera to the current viewport (could be the screen or a texture)

Parameters:

  • camera Camera
  • render_settings Object
  • scene Scene

    [optional] this can be passed when we are rendering a different scene from LS.GlobalScene (used in renderMaterialPreview)

renderFrameCameras

(
  • cameras
  • render_settings
)

Calls renderFrame of every camera in the cameras list (triggering the appropiate events)

Parameters:

  • cameras Array
  • render_settings RenderSettings

renderInstances

(
  • render_settings
  • instances
)

Calls the render method for every RenderInstance (it also takes into account events and frustrum culling)

Parameters:

  • render_settings RenderSettings
  • instances Array

    array of RIs, if not specified the last visible_instances are rendered

renderInstancesToRT

(
  • cam
  • texture
  • render_settings
)

Renders a frame into a texture (could be a cubemap, in which case does the six passes)

Parameters:

  • cam Camera
  • texture Texture
  • render_settings RenderSettings

renderMaterialPreview

(
  • material
  • size
  • options
  • canvas
)
Image

Renders the material preview to an image (or to the screen)

Parameters:

  • material Material
  • size Number

    image size

  • options Object

    could be environment_texture, to_viewport

  • canvas HTMLCanvas

    [optional] the output canvas where to store the preview

Returns:

Image:

the preview image (in canvas format) or null if it was rendered to the viewport

renderToCubemap

(
  • position
  • size
  • texture
  • render_settings
  • near
  • far
)
Texture

Renders the current scene to a cubemap centered in the given position

Parameters:

  • position Vec3

    center of the camera where to render the cubemap

  • size Number

    texture size

  • texture Texture

    to reuse the same texture

  • render_settings RenderSettings
  • near Number
  • far Number

Returns:

Texture:

the resulting texture

resetGLState

(
  • render_settings
)

To set gl state to a known and constant state in every render pass

Parameters:

  • render_settings RenderSettings