|
@@ -358,12 +358,16 @@ THREE.CanvasRenderer = function () {
|
|
|
|
|
|
} else if ( light instanceof THREE.DirectionalLight ) {
|
|
|
|
|
|
+ // for particles
|
|
|
+
|
|
|
_directionalLights.r += lightColor.r;
|
|
|
_directionalLights.g += lightColor.g;
|
|
|
_directionalLights.b += lightColor.b;
|
|
|
|
|
|
} else if ( light instanceof THREE.PointLight ) {
|
|
|
|
|
|
+ // for particles
|
|
|
+
|
|
|
_pointLights.r += lightColor.r;
|
|
|
_pointLights.g += lightColor.g;
|
|
|
_pointLights.b += lightColor.b;
|
|
@@ -376,41 +380,41 @@ THREE.CanvasRenderer = function () {
|
|
|
|
|
|
function calculateLight( scene, position, normal, color ) {
|
|
|
|
|
|
- var l, ll, light, lightColor, lightIntensity,
|
|
|
+ var l, ll, light, lightColor,
|
|
|
amount, lights = scene.lights;
|
|
|
|
|
|
for ( l = 0, ll = lights.length; l < ll; l ++ ) {
|
|
|
|
|
|
light = lights[ l ];
|
|
|
lightColor = light.color;
|
|
|
- lightIntensity = light.intensity;
|
|
|
|
|
|
if ( light instanceof THREE.DirectionalLight ) {
|
|
|
|
|
|
- amount = normal.dot( light.position ) * lightIntensity;
|
|
|
+ amount = normal.dot( light.position );
|
|
|
|
|
|
- if ( amount > 0 ) {
|
|
|
+ if ( amount <= 0 ) continue;
|
|
|
|
|
|
- color.r += lightColor.r * amount;
|
|
|
- color.g += lightColor.g * amount;
|
|
|
- color.b += lightColor.b * amount;
|
|
|
+ amount *= light.intensity;
|
|
|
|
|
|
- }
|
|
|
+ color.r += lightColor.r * amount;
|
|
|
+ color.g += lightColor.g * amount;
|
|
|
+ color.b += lightColor.b * amount;
|
|
|
|
|
|
} else if ( light instanceof THREE.PointLight ) {
|
|
|
|
|
|
- _vector3.sub( light.position, position );
|
|
|
- _vector3.normalize();
|
|
|
+ amount = normal.dot( _vector3.sub( light.position, position ).normalize() );
|
|
|
|
|
|
- amount = normal.dot( _vector3 ) * lightIntensity;
|
|
|
+ if ( amount <= 0 ) continue;
|
|
|
|
|
|
- if ( amount > 0 ) {
|
|
|
+ amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( light.position ) / light.distance, 1 );
|
|
|
|
|
|
- color.r += lightColor.r * amount;
|
|
|
- color.g += lightColor.g * amount;
|
|
|
- color.b += lightColor.b * amount;
|
|
|
+ if ( amount == 0 ) continue;
|
|
|
|
|
|
- }
|
|
|
+ amount *= light.intensity;
|
|
|
+
|
|
|
+ color.r += lightColor.r * amount;
|
|
|
+ color.g += lightColor.g * amount;
|
|
|
+ color.b += lightColor.b * amount;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -475,24 +479,6 @@ THREE.CanvasRenderer = function () {
|
|
|
|
|
|
} else if ( material instanceof THREE.ParticleCanvasMaterial ) {
|
|
|
|
|
|
- if ( _enableLighting ) {
|
|
|
-
|
|
|
- _light.r = _ambientLight.r + _directionalLights.r + _pointLights.r;
|
|
|
- _light.g = _ambientLight.g + _directionalLights.g + _pointLights.g;
|
|
|
- _light.b = _ambientLight.b + _directionalLights.b + _pointLights.b;
|
|
|
-
|
|
|
- _color.r = material.color.r * _light.r;
|
|
|
- _color.g = material.color.g * _light.g;
|
|
|
- _color.b = material.color.b * _light.b;
|
|
|
-
|
|
|
- _color.updateStyleString();
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- _color.__styleString = material.color.__styleString;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
width = element.scale.x * _canvasWidthHalf;
|
|
|
height = element.scale.y * _canvasHeightHalf;
|
|
|
|
|
@@ -504,12 +490,15 @@ THREE.CanvasRenderer = function () {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ setStrokeStyle( material.color.__styleString );
|
|
|
+ setFillStyle( material.color.__styleString );
|
|
|
+
|
|
|
_context.save();
|
|
|
_context.translate( v1.x, v1.y );
|
|
|
_context.rotate( - element.rotation );
|
|
|
_context.scale( width, height );
|
|
|
|
|
|
- material.program( _context, _color );
|
|
|
+ material.program( _context );
|
|
|
|
|
|
_context.restore();
|
|
|
|