-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
/
Copy pathAnalyticLightNode.js
118 lines (64 loc) · 2.01 KB
/
AnalyticLightNode.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import LightingNode from './LightingNode.js';
import { NodeUpdateType } from '../core/constants.js';
import { uniform } from '../core/UniformNode.js';
import { Color } from '../../math/Color.js';
import { renderGroup } from '../core/UniformGroupNode.js';
import { hash } from '../core/NodeUtils.js';
import { shadow } from './ShadowNode.js';
import { nodeObject } from '../tsl/TSLCore.js';
class AnalyticLightNode extends LightingNode {
static get type() {
return 'AnalyticLightNode';
}
constructor( light = null ) {
super();
this.updateType = NodeUpdateType.FRAME;
this.light = light;
this.color = new Color();
this.colorNode = uniform( this.color ).setGroup( renderGroup );
this.baseColorNode = null;
this.shadowNode = null;
this.shadowColorNode = null;
this.isAnalyticLightNode = true;
}
getCacheKey() {
return hash( super.getCacheKey(), this.light.id, this.light.castShadow ? 1 : 0 );
}
getHash() {
return this.light.uuid;
}
setupShadow( builder ) {
const { renderer } = builder;
if ( renderer.shadowMap.enabled === false ) return;
let shadowColorNode = this.shadowColorNode;
if ( shadowColorNode === null ) {
const customShadowNode = this.light.shadow.shadowNode;
let shadowNode;
if ( customShadowNode !== undefined ) {
shadowNode = nodeObject( customShadowNode );
} else {
shadowNode = shadow( this.light );
}
this.shadowNode = shadowNode;
this.shadowColorNode = shadowColorNode = this.colorNode.mul( shadowNode );
this.baseColorNode = this.colorNode;
}
//
this.colorNode = shadowColorNode;
}
setup( builder ) {
this.colorNode = this.baseColorNode || this.colorNode;
if ( this.light.castShadow ) {
if ( builder.object.receiveShadow ) {
this.setupShadow( builder );
}
} else if ( this.shadowNode !== null ) {
this.shadowNode.dispose();
}
}
update( /*frame*/ ) {
const { light } = this;
this.color.copy( light.color ).multiplyScalar( light.intensity );
}
}
export default AnalyticLightNode;