# all files / src/light/ Directional.js

60% Statements 6/10
100% Branches 2/2
66.67% Functions 2/3
60% Lines 6/10

    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
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75

    1×

    5×

    5×

    5×
    5×
    5×

     import Light from '../Light';
    import Vector3 from '../math/Vector3';

    /**
     * @constructor clay.light.Directional
     * @extends clay.Light
     *
     * @example
     *     var light = new clay.light.Directional({
     *         intensity: 0.5,
     *         color: [1.0, 0.0, 0.0]
     *     });
     *     light.position.set(10, 10, 10);
     *     light.lookAt(clay.Vector3.ZERO);
     *     scene.add(light);
     */
    var DirectionalLight = Light.extend(
    /** @lends clay.light.Directional# */
    {
        /**
         * @type {number}
         */
        shadowBias: 0.001,
        /**
         * @type {number}
         */
        shadowSlopeScale: 2.0,
        /**
         * Shadow cascade.
         * Use PSSM technique when it is larger than 1 and have a unique directional light in scene.
         * @type {number}
         */
        shadowCascade: 1,

        /**
         * Available when shadowCascade is larger than 1 and have a unique directional light in scene.
         * @type {number}
         */
        cascadeSplitLogFactor: 0.2
    }, {

        type: 'DIRECTIONAL_LIGHT',

        uniformTemplates: {
            directionalLightDirection: {
                type: '3f',
                value: function (instance) {
                    instance.__dir = instance.__dir || new Vector3();
                    // Direction is target to eye
                    return instance.__dir.copy(instance.worldTransform.z).normalize().negate().array;
                }
            },
            directionalLightColor: {
                type: '3f',
                value: function (instance) {
                    var color = instance.color;
                    var intensity = instance.intensity;
                    return [color[0] * intensity, color[1] * intensity, color[2] * intensity];
                }
            }
        },
        /**
         * @return {clay.light.Directional}
         * @memberOf clay.light.Directional.prototype
         */
        clone: function () {
            var light = Light.prototype.clone.call(this);
            light.shadowBias = this.shadowBias;
            light.shadowSlopeScale = this.shadowSlopeScale;
            return light;
        }
    });

    export default DirectionalLight;