MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / calculateLight

Function calculateLight

Three.js/js/Three59dev.js:15251–15291  ·  view source on GitHub ↗
( position, normal, color )

Source from the content-addressed store, hash-verified

15249 }
15250
15251 function calculateLight( position, normal, color ) {
15252
15253 for ( var l = 0, ll = _lights.length; l < ll; l ++ ) {
15254
15255 var light = _lights[ l ];
15256
15257 _lightColor.copy( light.color );
15258
15259 if ( light instanceof THREE.DirectionalLight ) {
15260
15261 var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ).normalize();
15262
15263 var amount = normal.dot( lightPosition );
15264
15265 if ( amount <= 0 ) continue;
15266
15267 amount *= light.intensity;
15268
15269 color.add( _lightColor.multiplyScalar( amount ) );
15270
15271 } else if ( light instanceof THREE.PointLight ) {
15272
15273 var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld );
15274
15275 var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );
15276
15277 if ( amount <= 0 ) continue;
15278
15279 amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
15280
15281 if ( amount == 0 ) continue;
15282
15283 amount *= light.intensity;
15284
15285 color.add( _lightColor.multiplyScalar( amount ) );
15286
15287 }
15288
15289 }
15290
15291 }
15292
15293 function renderParticle( v1, element, material ) {
15294

Callers 2

renderFace3Function · 0.70
renderFace4Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected