| 38 | |
| 39 | // Class to manage ambient, point and directional light sources in deck |
| 40 | export default class LightingEffect implements Effect { |
| 41 | id = 'lighting-effect'; |
| 42 | props!: LightingEffectProps; |
| 43 | shadowColor: [number, number, number, number] = DEFAULT_SHADOW_COLOR; |
| 44 | context?: EffectContext; |
| 45 | |
| 46 | private shadow: boolean = false; |
| 47 | private ambientLight?: AmbientLight; |
| 48 | private directionalLights: DirectionalLight[] = []; |
| 49 | private pointLights: PointLight[] = []; |
| 50 | private shadowPasses: ShadowPass[] = []; |
| 51 | private dummyShadowMap: Texture | null = null; |
| 52 | private shadowMatrices?: Matrix4[]; |
| 53 | |
| 54 | constructor(props: LightingEffectProps = {}) { |
| 55 | this.setProps(props); |
| 56 | } |
| 57 | |
| 58 | setup(context: EffectContext) { |
| 59 | this.context = context; |
| 60 | const {device, deck} = context; |
| 61 | |
| 62 | if (this.shadow && !this.dummyShadowMap) { |
| 63 | this._createShadowPasses(device); |
| 64 | |
| 65 | deck._addDefaultShaderModule(shadow); |
| 66 | |
| 67 | this.dummyShadowMap = device.createTexture({ |
| 68 | width: 1, |
| 69 | height: 1 |
| 70 | }); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | setProps(props: LightingEffectProps) { |
| 75 | this.ambientLight = undefined; |
| 76 | this.directionalLights = []; |
| 77 | this.pointLights = []; |
| 78 | |
| 79 | for (const key in props) { |
| 80 | const lightSource = props[key]; |
| 81 | |
| 82 | switch (lightSource.type) { |
| 83 | case 'ambient': |
| 84 | this.ambientLight = lightSource; |
| 85 | break; |
| 86 | |
| 87 | case 'directional': |
| 88 | this.directionalLights.push(lightSource); |
| 89 | break; |
| 90 | |
| 91 | case 'point': |
| 92 | this.pointLights.push(lightSource); |
| 93 | break; |
| 94 | default: |
| 95 | } |
| 96 | } |
| 97 | this._applyDefaultLights(); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…