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

Function calculateLight

Three.js/js/ThreeDebug.js:9419–9464  ·  view source on GitHub ↗
( lights, position, normal, color )

Source from the content-addressed store, hash-verified

9417 }
9418
9419 function calculateLight( lights, position, normal, color ) {
9420
9421 var l, ll, light, lightColor, lightPosition, amount;
9422
9423 for ( l = 0, ll = lights.length; l < ll; l ++ ) {
9424
9425 light = lights[ l ];
9426 lightColor = light.color;
9427
9428 if ( light instanceof THREE.DirectionalLight ) {
9429
9430 lightPosition = light.matrixWorld.getPosition();
9431
9432 amount = normal.dot( lightPosition );
9433
9434 if ( amount <= 0 ) continue;
9435
9436 amount *= light.intensity;
9437
9438 color.r += lightColor.r * amount;
9439 color.g += lightColor.g * amount;
9440 color.b += lightColor.b * amount;
9441
9442 } else if ( light instanceof THREE.PointLight ) {
9443
9444 lightPosition = light.matrixWorld.getPosition();
9445
9446 amount = normal.dot( _vector3.sub( lightPosition, position ).normalize() );
9447
9448 if ( amount <= 0 ) continue;
9449
9450 amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
9451
9452 if ( amount == 0 ) continue;
9453
9454 amount *= light.intensity;
9455
9456 color.r += lightColor.r * amount;
9457 color.g += lightColor.g * amount;
9458 color.b += lightColor.b * amount;
9459
9460 }
9461
9462 }
9463
9464 }
9465
9466 function renderParticle ( v1, element, material, scene ) {
9467

Callers 2

renderFace3Function · 0.70
renderFace4Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected