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

Function calculateLight

7DFPS/js/Three.js:15624–15664  ·  view source on GitHub ↗
( position, normal, color )

Source from the content-addressed store, hash-verified

15622 }
15623
15624 function calculateLight( position, normal, color ) {
15625
15626 for ( var l = 0, ll = _lights.length; l < ll; l ++ ) {
15627
15628 var light = _lights[ l ];
15629
15630 _lightColor.copy( light.color );
15631
15632 if ( light instanceof THREE.DirectionalLight ) {
15633
15634 var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ).normalize();
15635
15636 var amount = normal.dot( lightPosition );
15637
15638 if ( amount <= 0 ) continue;
15639
15640 amount *= light.intensity;
15641
15642 color.add( _lightColor.multiplyScalar( amount ) );
15643
15644 } else if ( light instanceof THREE.PointLight ) {
15645
15646 var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld );
15647
15648 var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );
15649
15650 if ( amount <= 0 ) continue;
15651
15652 amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
15653
15654 if ( amount == 0 ) continue;
15655
15656 amount *= light.intensity;
15657
15658 color.add( _lightColor.multiplyScalar( amount ) );
15659
15660 }
15661
15662 }
15663
15664 }
15665
15666 function renderParticle( v1, element, material ) {
15667

Callers 2

renderFace3Function · 0.70
renderFace4Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected