Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

uber / deck.gl / 13779

18 Sep 2019 - 0:00 coverage decreased (-2.9%) to 79.902%
13779

Pull #3623

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
beta.2
Pull Request #3623: Bump dependency versions

3405 of 4619 branches covered (73.72%)

Branch coverage included in aggregate %.

7031 of 8442 relevant lines covered (83.29%)

5687.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.08
/modules/core/src/effects/lighting/lighting-effect.js
1
import {AmbientLight, Texture2D, ProgramManager} from '@luma.gl/core';
19×
2
import DirectionalLight from './directional-light';
3
import Effect from '../../lib/effect';
4
import {Matrix4, Vector3} from 'math.gl';
5
import ShadowPass from '../../passes/shadow-pass';
6
import {default as shadow} from '../../shaderlib/shadow/shadow';
7

8
const DEFAULT_AMBIENT_LIGHT_PROPS = {color: [255, 255, 255], intensity: 1.0};
1×
9
const DEFAULT_DIRECTIONAL_LIGHT_PROPS = [
1×
10
  {
11
    color: [255, 255, 255],
12
    intensity: 1.0,
13
    direction: [-1, -3, -1]
14
  },
15
  {
16
    color: [255, 255, 255],
17
    intensity: 0.9,
18
    direction: [1, 8, -2.5]
19
  }
20
];
21
const DEFAULT_SHADOW_COLOR = [0, 0, 0, 200 / 255];
1×
22

23
// Class to manage ambient, point and directional light sources in deck
24
export default class LightingEffect extends Effect {
25
  constructor(props) {
26
    super(props);
7×
27
    this.ambientLight = null;
7×
28
    this.directionalLights = [];
7×
29
    this.pointLights = [];
7×
30

31
    this.shadowColor = DEFAULT_SHADOW_COLOR;
7×
32
    this.shadowPasses = [];
7×
33
    this.dummyShadowMap = null;
7×
34
    this.shadow = false;
7×
35
    this.programManager = null;
7×
36

37
    for (const key in props) {
7×
38
      const lightSource = props[key];
5×
39

40
      switch (lightSource.type) {
Branches [[0, 0], [0, 3]] missed. 5×
41
        case 'ambient':
UNCOV
42
          this.ambientLight = lightSource;
!
UNCOV
43
          break;
!
44

45
        case 'directional':
46
          this.directionalLights.push(lightSource);
3×
47
          break;
3×
48

49
        case 'point':
50
          this.pointLights.push(lightSource);
2×
51
          break;
2×
52
        default:
53
      }
54
    }
55
    this._applyDefaultLights();
7×
56

57
    this.shadow = this.directionalLights.some(light => light.shadow);
8×
58
  }
59

60
  prepare(gl, {layers, viewports, onViewportActive, views}) {
61
    if (!this.shadow) return {};
10×
62

63
    // create light matrix every frame to make sure always updated from light source
64
    const shadowMatrices = this._createLightMatrix();
2×
65

66
    if (this.shadowPasses.length === 0) {
Branches [[2, 1]] missed. 2×
67
      this._createShadowPasses(gl);
2×
68
    }
69
    if (!this.programManager) {
Branches [[3, 1]] missed. 2×
70
      // TODO - support multiple contexts
71
      this.programManager = ProgramManager.getDefaultProgramManager(gl);
2×
72
      if (shadow) {
Branches [[4, 1]] missed. 2×
73
        this.programManager.addDefaultModule(shadow);
2×
74
      }
75
    }
76

77
    if (!this.dummyShadowMap) {
Branches [[5, 1]] missed. 2×
78
      this.dummyShadowMap = new Texture2D(gl, {
2×
79
        width: 1,
80
        height: 1
81
      });
82
    }
83

84
    const shadowMaps = [];
2×
85

86
    for (let i = 0; i < this.shadowPasses.length; i++) {
2×
87
      const shadowPass = this.shadowPasses[i];
3×
88
      shadowPass.render({
3×
89
        layers: layers.filter(layer => layer.props.shadowEnabled !== false),
6×
90
        viewports,
91
        onViewportActive,
92
        views,
93
        effectProps: {
94
          shadowLightId: i,
95
          dummyShadowMap: this.dummyShadowMap,
96
          shadowMatrices
97
        }
98
      });
99
      shadowMaps.push(shadowPass.shadowMap);
3×
100
    }
101

102
    return {
2×
103
      shadowMaps,
104
      dummyShadowMap: this.dummyShadowMap,
105
      shadowColor: this.shadowColor,
106
      shadowMatrices
107
    };
108
  }
109

110
  getParameters(layer) {
111
    const {ambientLight} = this;
10×
112
    const pointLights = this._getProjectedPointLights(layer);
10×
113
    const directionalLights = this._getProjectedDirectionalLights(layer);
10×
114
    return {
10×
115
      lightSources: {ambientLight, directionalLights, pointLights}
116
    };
117
  }
118

119
  cleanup() {
120
    for (const shadowPass of this.shadowPasses) {
20×
121
      shadowPass.delete();
3×
122
    }
123
    this.shadowPasses.length = 0;
20×
124

125
    if (this.dummyShadowMap) {
20×
126
      this.dummyShadowMap.delete();
2×
127
      this.dummyShadowMap = null;
2×
128
    }
129

130
    if (this.shadow && this.programManager) {
20×
131
      this.programManager.removeDefaultModule(shadow);
2×
132
      this.programManager = null;
2×
133
    }
134
  }
135

136
  _createLightMatrix() {
137
    const lightMatrices = [];
2×
138
    for (const light of this.directionalLights) {
2×
139
      const viewMatrix = new Matrix4().lookAt({
3×
140
        eye: new Vector3(light.direction).negate()
141
      });
142

143
      lightMatrices.push(viewMatrix);
3×
144
    }
145
    return lightMatrices;
2×
146
  }
147

148
  _createShadowPasses(gl) {
149
    for (let i = 0; i < this.directionalLights.length; i++) {
2×
150
      this.shadowPasses.push(new ShadowPass(gl));
3×
151
    }
152
  }
153

154
  _applyDefaultLights() {
155
    const {ambientLight, pointLights, directionalLights} = this;
7×
156
    if (!ambientLight && pointLights.length === 0 && directionalLights.length === 0) {
7×
157
      this.ambientLight = new AmbientLight(DEFAULT_AMBIENT_LIGHT_PROPS);
3×
158
      this.directionalLights.push(new DirectionalLight(DEFAULT_DIRECTIONAL_LIGHT_PROPS[0]));
3×
159
      this.directionalLights.push(new DirectionalLight(DEFAULT_DIRECTIONAL_LIGHT_PROPS[1]));
3×
160
    }
161
  }
162

163
  _getProjectedPointLights(layer) {
164
    const projectedPointLights = [];
12×
165

166
    for (let i = 0; i < this.pointLights.length; i++) {
12×
167
      const pointLight = this.pointLights[i];
3×
168
      projectedPointLights.push(pointLight.getProjectedLight({layer}));
3×
169
    }
170
    return projectedPointLights;
12×
171
  }
172

173
  _getProjectedDirectionalLights(layer) {
174
    const projectedDirectionalLights = [];
10×
175

176
    for (let i = 0; i < this.directionalLights.length; i++) {
10×
177
      const directionalLight = this.directionalLights[i];
18×
178
      projectedDirectionalLights.push(directionalLight.getProjectedLight({layer}));
18×
179
    }
180
    return projectedDirectionalLights;
10×
181
  }
182
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC