Light

cjcliffe edited this page Nov 28, 2011 · 8 revisions

CubicVR.Light

The Light class represents a light for use in a Scene or as a parameter to renderObject for direct rendering.

Constructor:

Light( obj_init )

Parameters:

   var myLight = new CubicVR.Light({
        type: "point",            // Light type, see setType() for options.
        method: "dynamic",        // Light management method, see setMethod() for options.
        position:  [0.0,0.0,0.0], // Light position in the world.
        direction: [0.0,0.0,0.0], // Light direction (vector) for directional lights.
        diffuse:  [1.0,1.0,1.0],  // Diffuse Light color.
        specular: [0.1,0.1,0.1],  // Specular Light color.
        intensity: 1.0,           // Light intensity.
        distance: 10.0,           // Maximum light distance for point lights.
        cutoff: 60.0,             // For spotlight types this is the cut-off angle of the cone.
        mapRes: 512,              // Shadow resolution when using a shadowed light type.
        areaAxis: [1.0, 1.0],     // With `"area"` light it sets the angle of the sun [North/South, East/West].
        projector: null           // Projector texture used for a light of type `"spot_shadow_projector"`.
    });

Methods:

setType( light_type )

Set the light type.

Parameters:

  • light_type : An enum representing the light type, one of:
    • "point" : A point light, uses Light.distance for maximum range.
    • "directional" : A directional light with infinite distance, uses Light.direction vector for direction.
    • "spot" : Spotlight
    • "spot_shadow" : Shadowed Spotlight
    • "spot_shadow_projector" : Shadowed Spotlight /w projective texture
    • "area" : Area light

Returns:

none

setMethod( method )

Set the method of the light, either static or dynamic. Static lights have additional optimization when used in conjunction with an Octree.

Parameters:

  • method : An enum representing the light method, one of:
    • "dynamic"
    • "static"

Returns:

none

setParent( parent )

Sets the parent object of the light. The light's coordinates will become relative to the parent object. Set parent to null to remove.

This currently only works with spot and point light types.

Parameters:

  • parent : A parent object such as SceneObject containing obj.tMatrix.

Returns:

none

setDiffuse( diffuse )

Set the diffuse value of the light.

Parameters:

  • diffuse : An R,G,B diffuse color value, format [1.0, 1.0, 1.0]

Returns:

none

setSpecular( specular )

Set the specular value of a light.

Parameters:

  • specular : An R,G,B color value, format [1.0, 1.0, 1.0]

Returns:

none

setIntensity( intensity )

Set the intensity of the light.

Parameters:

  • intensity : The intensity of a light, default is 1.0

Returns:

none

setDistance( distance )

Set the maximum distance of a point light.

Parameters:

  • distance : Maximum falloff distance for the light, measured from Light.position

Returns:

none

setRotation( rotation )

Set the rotation of a directional light.

Parameters:

  • rotation : An X,Y,Z rotation value, format [0.0, 0.0, 0.0]

Returns:

none

setDirection( direction )

Set the direction of a directional light.

Parameters:

  • direction : An X,Y,Z vector value, format [0.0, 0.0, 0.0]

Returns:

none

lookat( x, y, z ) or lookat( pos )

Set the direction of a spot or directional light type by using a 'look at' method.

Parameters:

  • x : X position to look at.
  • y : Y position to look at.
  • z : Z position to look at.
  • pos : A position [x, y, z] to look at.

Returns:

none

Example usage:

From samples/basic/materials.html:

// ...
var light = new CubicVR.Light({
   type: "point",
   method: "dynamic",
   diffuse: [1,1,1],
   specular: [1,1,1],
   position: [0,5,-2],
   distance: 20
});

scene.bindLight(light);