MCPcopy Index your code
hub / github.com/stemkoski/stemkoski.github.com / calculateLight

Function calculateLight

Three.js/js/Three66.js:16478–16518  ·  view source on GitHub ↗
( position, normal, color )

Source from the content-addressed store, hash-verified

16476 }
16477
16478 function calculateLight( position, normal, color ) {
16479
16480 for ( var l = 0, ll = _lights.length; l < ll; l ++ ) {
16481
16482 var light = _lights[ l ];
16483
16484 _lightColor.copy( light.color );
16485
16486 if ( light instanceof THREE.DirectionalLight ) {
16487
16488 var lightPosition = _vector3.setFromMatrixPosition( light.matrixWorld ).normalize();
16489
16490 var amount = normal.dot( lightPosition );
16491
16492 if ( amount <= 0 ) continue;
16493
16494 amount *= light.intensity;
16495
16496 color.add( _lightColor.multiplyScalar( amount ) );
16497
16498 } else if ( light instanceof THREE.PointLight ) {
16499
16500 var lightPosition = _vector3.setFromMatrixPosition( light.matrixWorld );
16501
16502 var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );
16503
16504 if ( amount <= 0 ) continue;
16505
16506 amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
16507
16508 if ( amount == 0 ) continue;
16509
16510 amount *= light.intensity;
16511
16512 color.add( _lightColor.multiplyScalar( amount ) );
16513
16514 }
16515
16516 }
16517
16518 }
16519
16520 function renderSprite( v1, element, material ) {
16521

Callers 1

renderFace3Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected