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

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

fillSceneShaderQuery

(
  • scene
  • render_settings
)

Update the scene shader query according to the render pass Do not reuse the query, they change between rendering passes (shadows, reflections, etc)

Parameters:

  • scene SceneTree
  • render_settings RenderSettings

getCameraAtPosition

(
  • x
  • y
  • scene
)
Camera

Returns the last camera that falls into a given screen position

Parameters:

  • x Number
  • y Number
  • scene SceneTree

    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 SceneTree
  • render_settings RenderSettings
  • cameras Array

    in case you dont want to use the scene cameras

registerRenderPass

(
  • name
  • info
)

Register a render pass to be used during the rendering

Parameters:

  • name String

    name of the render pass as in render_passes

  • info Object

    render pass info, { render_instance: Function( instance, render_settings ) }

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 SceneTree
  • render_settings RenderSettings
  • [cameras=null] Array optional

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

renderColorMultiPassLightingInstance

(
  • instance
  • render_settings
  • lights
)

Renders the RenderInstance taking into account all the lights that affect it and doing a render for every light This function it is not as fast as I would like but enables lots of interesting features

Parameters:

  • instance RenderInstance
  • render_settings RenderSettings
  • lights Array

    array containing al the lights affecting this RI

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 SceneTree

    [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

renderPickingInstance

(
  • instance
  • render_settings
)

Render instance into the picking buffer

Parameters:

  • instance RenderInstance
  • render_settings RenderSettings

renderShadowPassInstance

(
  • instance
  • render_settings
)

Renders this RenderInstance into the shadowmap

Parameters:

  • instance RenderInstance
  • render_settings RenderSettings

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

setRenderPass

(
  • name
)

Sets the render pass to use, this allow to change between "color","shadow","picking",etc

Parameters:

  • name String

    name of the render pass as in render_passes