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

Function calculateLight

Three.js/js/Three62dev.js:15647–15687  ·  view source on GitHub ↗
( position, normal, color )

Source from the content-addressed store, hash-verified

15645 }
15646
15647 function calculateLight( position, normal, color ) {
15648
15649 for ( var l = 0, ll = _lights.length; l < ll; l ++ ) {
15650
15651 var light = _lights[ l ];
15652
15653 _lightColor.copy( light.color );
15654
15655 if ( light instanceof THREE.DirectionalLight ) {
15656
15657 var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ).normalize();
15658
15659 var amount = normal.dot( lightPosition );
15660
15661 if ( amount <= 0 ) continue;
15662
15663 amount *= light.intensity;
15664
15665 color.add( _lightColor.multiplyScalar( amount ) );
15666
15667 } else if ( light instanceof THREE.PointLight ) {
15668
15669 var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld );
15670
15671 var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );
15672
15673 if ( amount <= 0 ) continue;
15674
15675 amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
15676
15677 if ( amount == 0 ) continue;
15678
15679 amount *= light.intensity;
15680
15681 color.add( _lightColor.multiplyScalar( amount ) );
15682
15683 }
15684
15685 }
15686
15687 }
15688
15689 function renderParticle( v1, element, material ) {
15690

Callers 1

renderFace3Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected