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

uber / deck.gl / 13074

28 Aug 2019 - 0:36 coverage decreased (-2.5%) to 80.994%
13074

Pull #3496

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
use timeline
Pull Request #3496: Transition system refactor (1/2): use timeline

3394 of 4574 branches covered (74.2%)

Branch coverage included in aggregate %.

54 of 58 new or added lines in 9 files covered. (93.1%)

818 existing lines in 101 files now uncovered.

6953 of 8201 relevant lines covered (84.78%)

4628.87 hits per line

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

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

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

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

36
    this.shadowColor = DEFAULT_SHADOW_COLOR;
7×
37
    this.shadowPasses = [];
7×
38
    this.dummyShadowMap = null;
7×
39
    this.shadow = false;
7×
40

41
    for (const key in props) {
7×
42
      const lightSource = props[key];
5×
43

44
      switch (lightSource.type) {
Branches [[0, 0], [0, 3]] missed. 5×
45
        case 'ambient':
UNCOV
46
          this.ambientLight = lightSource;
!
UNCOV
47
          break;
!
48

49
        case 'directional':
50
          this.directionalLights.push(lightSource);
3×
51
          break;
3×
52

53
        case 'point':
54
          this.pointLights.push(lightSource);
2×
55
          break;
2×
56
        default:
57
      }
58
    }
59
    this._applyDefaultLights();
7×
60

61
    if (this.directionalLights.some(light => light.shadow)) {
8×
62
      this.shadow = true;
2×
63
      this._addShadowModule();
2×
64
    }
65
  }
66

67
  prepare(gl, {layers, viewports, onViewportActive, views, pixelRatio}) {
68
    if (!this.shadow) return {};
8×
69

70
    // create light matrix every frame to make sure always updated from light source
71
    const shadowMatrices = this._createLightMatrix();
1×
72

73
    if (this.shadowPasses.length === 0) {
Branches [[3, 1]] missed. 1×
74
      this._createShadowPasses(gl, pixelRatio);
1×
75
    }
76

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

84
    const shadowMaps = [];
1×
85

86
    for (let i = 0; i < this.shadowPasses.length; i++) {
1×
87
      const shadowPass = this.shadowPasses[i];
2×
88
      shadowPass.render({
2×
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);
2×
100
    }
101

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

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

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

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

130
    if (this.shadow) {
19×
131
      this._removeShadowModule();
2×
132
    }
133
  }
134

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

142
      lightMatrices.push(viewMatrix);
2×
143
    }
144
    return lightMatrices;
1×
145
  }
146

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

153
  _addShadowModule() {
154
    const defaultShaderModules = getDefaultShaderModules();
2×
155
    let hasShadowModule = false;
2×
156
    for (const module of defaultShaderModules) {
2×
157
      if (module.name === `shadow`) {
Branches [[7, 0]] missed. 4×
UNCOV
158
        hasShadowModule = true;
!
UNCOV
159
        break;
!
160
      }
161
    }
162
    if (!hasShadowModule) {
Branches [[8, 1]] missed. 2×
163
      defaultShaderModules.push(shadow);
2×
164
      setDefaultShaderModules(defaultShaderModules);
2×
165
    }
166
  }
167

168
  _removeShadowModule() {
169
    const defaultShaderModules = getDefaultShaderModules();
2×
170
    for (let i = 0; i < defaultShaderModules.length; i++) {
2×
171
      if (defaultShaderModules[i].name === `shadow`) {
6×
172
        defaultShaderModules.splice(i, 1);
2×
173
        setDefaultShaderModules(defaultShaderModules);
2×
174
        break;
2×
175
      }
176
    }
177
  }
178

179
  _applyDefaultLights() {
180
    const {ambientLight, pointLights, directionalLights} = this;
7×
181
    if (!ambientLight && pointLights.length === 0 && directionalLights.length === 0) {
7×
182
      this.ambientLight = new AmbientLight(DEFAULT_AMBIENT_LIGHT_PROPS);
3×
183
      this.directionalLights.push(new DirectionalLight(DEFAULT_DIRECTIONAL_LIGHT_PROPS[0]));
3×
184
      this.directionalLights.push(new DirectionalLight(DEFAULT_DIRECTIONAL_LIGHT_PROPS[1]));
3×
185
    }
186
  }
187

188
  _getProjectedPointLights(layer) {
189
    const projectedPointLights = [];
8×
190

191
    for (let i = 0; i < this.pointLights.length; i++) {
8×
192
      const pointLight = this.pointLights[i];
3×
193
      projectedPointLights.push(pointLight.getProjectedLight({layer}));
3×
194
    }
195
    return projectedPointLights;
8×
196
  }
197

198
  _getProjectedDirectionalLights(layer) {
199
    const projectedDirectionalLights = [];
6×
200

201
    for (let i = 0; i < this.directionalLights.length; i++) {
6×
202
      const directionalLight = this.directionalLights[i];
10×
203
      projectedDirectionalLights.push(directionalLight.getProjectedLight({layer}));
10×
204
    }
205
    return projectedDirectionalLights;
6×
206
  }
207
}
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