aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/shadowLight.js
blob: 3d6e42f6be792323f459a95e5909929fd9d7e01b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
</copyright> */

// RDGE namespaces
var RDGE = RDGE || {};

/* 
* shadow light - a modified camera used to describe a shadow casting light
*/
RDGE.shadowLight = function () {
    // inherit from the base class
    this.inheritedFrom = RDGE.camera;
    this.inheritedFrom();

    // matrices needed for shadow projection
    this.invViewMatrix = RDGE.mat4.identity();
    this.mvpMatrix = RDGE.mat4.identity();

    // texture matrix
    this.shadowMatrix = RDGE.mat4.identity();
    this.shadowMatrix = RDGE.mat4.scale(this.shadowMatrix, [0.5, 0.5, 0.5]);
    this.shadowMatrix = RDGE.mat4.translate(this.shadowMatrix, [0.5, 0.5, 0.5]);

    // cached references
    this.renderer = null;
    this.cameraManager = null;

    // shadow bias offset
    this.shadowBias = 0.0195;

    this.init = function () {
        this.renderer = RDGE.globals.engine.getContext().renderer;
        this.cameraManager = this.renderer.cameraManager();
    };

    /*
    *	makes the light the current 'camera'
    */
    this.activate = function () {
        this.cameraManager.pushCamera(this);
    };

    /*
    *	restores the camera stack
    */
    this.deactivate = function () {
        this.cameraManager.popCamera();
    };
}