Browse Source

Merge remote-tracking branch 'alteredq/dev' into dev

Mr.doob 12 years ago
parent
commit
359f4669a7

+ 9 - 4
build/three.js

@@ -1238,7 +1238,8 @@ THREE.Vector3.prototype = {
 
 
 	distanceToSquared: function ( v ) {
 	distanceToSquared: function ( v ) {
 
 
-		return new THREE.Vector3().sub( this, v ).lengthSq();
+		var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
+		return dx * dx + dy * dy + dz * dz;
 
 
 	},
 	},
 
 
@@ -2164,7 +2165,8 @@ THREE.Box2.prototype = {
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
 
 
-		return this.clampPoint( point ).subSelf( point ).length();
+		var clampedPoint = THREE.Box2.__v1.copy( point ).clampSelf( this.min, this.max );
+		return clampedPoint.subSelf( point ).length();
 
 
 	},
 	},
 
 
@@ -2422,6 +2424,7 @@ THREE.Box3.prototype = {
 
 
 		// This can potentially have a divide by zero if the box
 		// This can potentially have a divide by zero if the box
 		// has a size dimension of 0.
 		// has a size dimension of 0.
+
 		return new THREE.Vector3(
 		return new THREE.Vector3(
 			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
 			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
 			( point.y - this.min.y ) / ( this.max.y - this.min.y ),
 			( point.y - this.min.y ) / ( this.max.y - this.min.y ),
@@ -2454,7 +2457,8 @@ THREE.Box3.prototype = {
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
 
 
-		return this.clampPoint( point ).subSelf( point ).length();
+		var clampedPoint = THREE.Box3.__v1.copy( point ).clampSelf( this.min, this.max );
+		return clampedPoint.subSelf( point ).length();
 
 
 	},
 	},
 
 
@@ -3868,9 +3872,10 @@ THREE.Plane.prototype = {
 	setFromCoplanarPoints: function ( a, b, c ) {
 	setFromCoplanarPoints: function ( a, b, c ) {
 
 
 		var normal = THREE.Plane.__v1.sub( b, a ).cross(
 		var normal = THREE.Plane.__v1.sub( b, a ).cross(
-			THREE.Plane.__v2.sub( c, a ) );
+					 THREE.Plane.__v2.sub( c, a ) );
 
 
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
+
 		this.setFromNormalAndCoplanarPoint( normal, a );
 		this.setFromNormalAndCoplanarPoint( normal, a );
 
 
 		return this;
 		return this;

+ 10 - 10
build/three.min.js

@@ -27,12 +27,12 @@ THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(a,b,c){this.x=a;
 sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):
 sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):
 this.z=this.y=this.x=0;return this},minSelf:function(a){this.x>a.x&&(this.x=a.x);this.y>a.y&&(this.y=a.y);this.z>a.z&&(this.z=a.z);return this},maxSelf:function(a){this.x<a.x&&(this.x=a.x);this.y<a.y&&(this.y=a.y);this.z<a.z&&(this.z=a.z);return this},clampSelf:function(a,b){this.x<a.x?this.x=a.x:this.x>b.x&&(this.x=b.x);this.y<a.y?this.y=a.y:this.y>b.y&&(this.y=b.y);this.z<a.z?this.z=a.z:this.z>b.z&&(this.z=b.z);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*
 this.z=this.y=this.x=0;return this},minSelf:function(a){this.x>a.x&&(this.x=a.x);this.y>a.y&&(this.y=a.y);this.z>a.z&&(this.z=a.z);return this},maxSelf:function(a){this.x<a.x&&(this.x=a.x);this.y<a.y&&(this.y=a.y);this.z<a.z&&(this.z=a.z);return this},clampSelf:function(a,b){this.x<a.x?this.x=a.x:this.x>b.x&&(this.x=b.x);this.y<a.y?this.y=a.y:this.y>b.y&&(this.y=b.y);this.z<a.z?this.z=a.z:this.z>b.z&&(this.z=b.z);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*
 a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;return this},cross:function(a,b){this.x=a.y*b.z-
 a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;return this},cross:function(a,b){this.x=a.y*b.z-
-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,c=this.y,d=this.z;this.x=c*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-c*a.x;return this},angleTo:function(a){return Math.acos(this.dot(a)/this.length()/a.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this,a).lengthSq()},getPositionFromMatrix:function(a){this.x=a.elements[12];this.y=a.elements[13];this.z=a.elements[14];
-return this},setEulerFromRotationMatrix:function(a,b){function c(a){return Math.min(Math.max(a,-1),1)}var d=a.elements,e=d[0],f=d[4],g=d[8],h=d[1],i=d[5],j=d[9],l=d[2],p=d[6],d=d[10];void 0===b||"XYZ"===b?(this.y=Math.asin(c(g)),0.99999>Math.abs(g)?(this.x=Math.atan2(-j,d),this.z=Math.atan2(-f,e)):(this.x=Math.atan2(p,i),this.z=0)):"YXZ"===b?(this.x=Math.asin(-c(j)),0.99999>Math.abs(j)?(this.y=Math.atan2(g,d),this.z=Math.atan2(h,i)):(this.y=Math.atan2(-l,e),this.z=0)):"ZXY"===b?(this.x=Math.asin(c(p)),
-0.99999>Math.abs(p)?(this.y=Math.atan2(-l,d),this.z=Math.atan2(-f,i)):(this.y=0,this.z=Math.atan2(h,e))):"ZYX"===b?(this.y=Math.asin(-c(l)),0.99999>Math.abs(l)?(this.x=Math.atan2(p,d),this.z=Math.atan2(h,e)):(this.x=0,this.z=Math.atan2(-f,i))):"YZX"===b?(this.z=Math.asin(c(h)),0.99999>Math.abs(h)?(this.x=Math.atan2(-j,i),this.y=Math.atan2(-l,e)):(this.x=0,this.y=Math.atan2(g,d))):"XZY"===b&&(this.z=Math.asin(-c(f)),0.99999>Math.abs(f)?(this.x=Math.atan2(p,i),this.y=Math.atan2(g,e)):(this.x=Math.atan2(-j,
-d),this.y=0));return this},setEulerFromQuaternion:function(a,b){function c(a){return Math.min(Math.max(a,-1),1)}var d=a.x*a.x,e=a.y*a.y,f=a.z*a.z,g=a.w*a.w;void 0===b||"XYZ"===b?(this.x=Math.atan2(2*(a.x*a.w-a.y*a.z),g-d-e+f),this.y=Math.asin(c(2*(a.x*a.z+a.y*a.w))),this.z=Math.atan2(2*(a.z*a.w-a.x*a.y),g+d-e-f)):"YXZ"===b?(this.x=Math.asin(c(2*(a.x*a.w-a.y*a.z))),this.y=Math.atan2(2*(a.x*a.z+a.y*a.w),g-d-e+f),this.z=Math.atan2(2*(a.x*a.y+a.z*a.w),g-d+e-f)):"ZXY"===b?(this.x=Math.asin(c(2*(a.x*a.w+
-a.y*a.z))),this.y=Math.atan2(2*(a.y*a.w-a.z*a.x),g-d-e+f),this.z=Math.atan2(2*(a.z*a.w-a.x*a.y),g-d+e-f)):"ZYX"===b?(this.x=Math.atan2(2*(a.x*a.w+a.z*a.y),g-d-e+f),this.y=Math.asin(c(2*(a.y*a.w-a.x*a.z))),this.z=Math.atan2(2*(a.x*a.y+a.z*a.w),g+d-e-f)):"YZX"===b?(this.x=Math.atan2(2*(a.x*a.w-a.z*a.y),g-d+e-f),this.y=Math.atan2(2*(a.y*a.w-a.x*a.z),g+d-e-f),this.z=Math.asin(c(2*(a.x*a.y+a.z*a.w)))):"XZY"===b&&(this.x=Math.atan2(2*(a.x*a.w+a.y*a.z),g-d+e-f),this.y=Math.atan2(2*(a.x*a.z+a.y*a.w),g+d-
-e-f),this.z=Math.asin(c(2*(a.z*a.w-a.x*a.y))));return this},getScaleFromMatrix:function(a){var b=this.set(a.elements[0],a.elements[1],a.elements[2]).length(),c=this.set(a.elements[4],a.elements[5],a.elements[6]).length(),a=this.set(a.elements[8],a.elements[9],a.elements[10]).length();this.x=b;this.y=c;this.z=a;return this},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)}};THREE.Vector4=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=void 0!==d?d:1};
+a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,c=this.y,d=this.z;this.x=c*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-c*a.x;return this},angleTo:function(a){return Math.acos(this.dot(a)/this.length()/a.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,c=this.y-a.y,a=this.z-a.z;return b*b+c*c+a*a},getPositionFromMatrix:function(a){this.x=a.elements[12];this.y=a.elements[13];
+this.z=a.elements[14];return this},setEulerFromRotationMatrix:function(a,b){function c(a){return Math.min(Math.max(a,-1),1)}var d=a.elements,e=d[0],f=d[4],g=d[8],h=d[1],i=d[5],j=d[9],l=d[2],p=d[6],d=d[10];void 0===b||"XYZ"===b?(this.y=Math.asin(c(g)),0.99999>Math.abs(g)?(this.x=Math.atan2(-j,d),this.z=Math.atan2(-f,e)):(this.x=Math.atan2(p,i),this.z=0)):"YXZ"===b?(this.x=Math.asin(-c(j)),0.99999>Math.abs(j)?(this.y=Math.atan2(g,d),this.z=Math.atan2(h,i)):(this.y=Math.atan2(-l,e),this.z=0)):"ZXY"===
+b?(this.x=Math.asin(c(p)),0.99999>Math.abs(p)?(this.y=Math.atan2(-l,d),this.z=Math.atan2(-f,i)):(this.y=0,this.z=Math.atan2(h,e))):"ZYX"===b?(this.y=Math.asin(-c(l)),0.99999>Math.abs(l)?(this.x=Math.atan2(p,d),this.z=Math.atan2(h,e)):(this.x=0,this.z=Math.atan2(-f,i))):"YZX"===b?(this.z=Math.asin(c(h)),0.99999>Math.abs(h)?(this.x=Math.atan2(-j,i),this.y=Math.atan2(-l,e)):(this.x=0,this.y=Math.atan2(g,d))):"XZY"===b&&(this.z=Math.asin(-c(f)),0.99999>Math.abs(f)?(this.x=Math.atan2(p,i),this.y=Math.atan2(g,
+e)):(this.x=Math.atan2(-j,d),this.y=0));return this},setEulerFromQuaternion:function(a,b){function c(a){return Math.min(Math.max(a,-1),1)}var d=a.x*a.x,e=a.y*a.y,f=a.z*a.z,g=a.w*a.w;void 0===b||"XYZ"===b?(this.x=Math.atan2(2*(a.x*a.w-a.y*a.z),g-d-e+f),this.y=Math.asin(c(2*(a.x*a.z+a.y*a.w))),this.z=Math.atan2(2*(a.z*a.w-a.x*a.y),g+d-e-f)):"YXZ"===b?(this.x=Math.asin(c(2*(a.x*a.w-a.y*a.z))),this.y=Math.atan2(2*(a.x*a.z+a.y*a.w),g-d-e+f),this.z=Math.atan2(2*(a.x*a.y+a.z*a.w),g-d+e-f)):"ZXY"===b?(this.x=
+Math.asin(c(2*(a.x*a.w+a.y*a.z))),this.y=Math.atan2(2*(a.y*a.w-a.z*a.x),g-d-e+f),this.z=Math.atan2(2*(a.z*a.w-a.x*a.y),g-d+e-f)):"ZYX"===b?(this.x=Math.atan2(2*(a.x*a.w+a.z*a.y),g-d-e+f),this.y=Math.asin(c(2*(a.y*a.w-a.x*a.z))),this.z=Math.atan2(2*(a.x*a.y+a.z*a.w),g+d-e-f)):"YZX"===b?(this.x=Math.atan2(2*(a.x*a.w-a.z*a.y),g-d+e-f),this.y=Math.atan2(2*(a.y*a.w-a.x*a.z),g+d-e-f),this.z=Math.asin(c(2*(a.x*a.y+a.z*a.w)))):"XZY"===b&&(this.x=Math.atan2(2*(a.x*a.w+a.y*a.z),g-d+e-f),this.y=Math.atan2(2*
+(a.x*a.z+a.y*a.w),g+d-e-f),this.z=Math.asin(c(2*(a.z*a.w-a.x*a.y))));return this},getScaleFromMatrix:function(a){var b=this.set(a.elements[0],a.elements[1],a.elements[2]).length(),c=this.set(a.elements[4],a.elements[5],a.elements[6]).length(),a=this.set(a.elements[8],a.elements[9],a.elements[10]).length();this.x=b;this.y=c;this.z=a;return this},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)}};THREE.Vector4=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=void 0!==d?d:1};
 THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},setW:function(a){this.w=a;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=void 0!==a.w?a.w:1;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;this.w+=a;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+
 THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},setW:function(a){this.w=a;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=void 0!==a.w?a.w:1;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;this.w+=a;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+
 b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):(this.z=this.y=this.x=0,this.w=1);return this},minSelf:function(a){this.x>
 b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):(this.z=this.y=this.x=0,this.w=1);return this},minSelf:function(a){this.x>
 a.x&&(this.x=a.x);this.y>a.y&&(this.y=a.y);this.z>a.z&&(this.z=a.z);this.w>a.w&&(this.w=a.w);return this},maxSelf:function(a){this.x<a.x&&(this.x=a.x);this.y<a.y&&(this.y=a.y);this.z<a.z&&(this.z=a.z);this.w<a.w&&(this.w=a.w);return this},clampSelf:function(a,b){this.x<a.x?this.x=a.x:this.x>b.x&&(this.x=b.x);this.y<a.y?this.y=a.y:this.y>b.y&&(this.y=b.y);this.z<a.z?this.z=a.z:this.z>b.z&&(this.z=b.z);this.w<a.w?this.w=a.w:this.w>b.w&&(this.w=b.w);return this},negate:function(){return this.multiplyScalar(-1)},
 a.x&&(this.x=a.x);this.y>a.y&&(this.y=a.y);this.z>a.z&&(this.z=a.z);this.w>a.w&&(this.w=a.w);return this},maxSelf:function(a){this.x<a.x&&(this.x=a.x);this.y<a.y&&(this.y=a.y);this.z<a.z&&(this.z=a.z);this.w<a.w&&(this.w=a.w);return this},clampSelf:function(a,b){this.x<a.x?this.x=a.x:this.x>b.x&&(this.x=b.x);this.y<a.y?this.y=a.y:this.y>b.y&&(this.y=b.y);this.z<a.z?this.z=a.z:this.z>b.z&&(this.z=b.z);this.w<a.w?this.w=a.w:this.w>b.w&&(this.w=b.w);return this},negate:function(){return this.multiplyScalar(-1)},
@@ -43,14 +43,14 @@ g)&&0.01>Math.abs(f-c)&&0.01>Math.abs(i-b)){if(0.1>Math.abs(d+g)&&0.1>Math.abs(f
 THREE.Box2.prototype={constructor:THREE.Box2,set:function(a,b){this.min=a;this.max=b;return this},setFromPoints:function(a){if(0<a.length){var b=a[0];this.min.copy(b);this.max.copy(b);for(var c=1,d=a.length;c<d;c++)b=a[c],b.x<this.min.x?this.min.x=b.x:b.x>this.max.x&&(this.max.x=b.x),b.y<this.min.y?this.min.y=b.y:b.y>this.max.y&&(this.max.y=b.y)}else this.makeEmpty();return this},setFromCenterAndSize:function(a,b){var c=THREE.Box2.__v1.copy(b).multiplyScalar(0.5);this.min.copy(a).subSelf(c);this.max.copy(a).addSelf(c);
 THREE.Box2.prototype={constructor:THREE.Box2,set:function(a,b){this.min=a;this.max=b;return this},setFromPoints:function(a){if(0<a.length){var b=a[0];this.min.copy(b);this.max.copy(b);for(var c=1,d=a.length;c<d;c++)b=a[c],b.x<this.min.x?this.min.x=b.x:b.x>this.max.x&&(this.max.x=b.x),b.y<this.min.y?this.min.y=b.y:b.y>this.max.y&&(this.max.y=b.y)}else this.makeEmpty();return this},setFromCenterAndSize:function(a,b){var c=THREE.Box2.__v1.copy(b).multiplyScalar(0.5);this.min.copy(a).subSelf(c);this.max.copy(a).addSelf(c);
 return this},copy:function(a){this.min.copy(a.min);this.max.copy(a.max);return this},makeEmpty:function(){this.min.x=this.min.y=Infinity;this.max.x=this.max.y=-Infinity;return this},empty:function(){return this.max.x<this.min.x||this.max.y<this.min.y},volume:function(){return(this.max.x-this.min.x)*(this.max.y-this.min.y)},center:function(){return(new THREE.Vector2).add(this.min,this.max).multiplyScalar(0.5)},size:function(){return(new THREE.Vector2).sub(this.max,this.min)},expandByPoint:function(a){this.min.minSelf(a);
 return this},copy:function(a){this.min.copy(a.min);this.max.copy(a.max);return this},makeEmpty:function(){this.min.x=this.min.y=Infinity;this.max.x=this.max.y=-Infinity;return this},empty:function(){return this.max.x<this.min.x||this.max.y<this.min.y},volume:function(){return(this.max.x-this.min.x)*(this.max.y-this.min.y)},center:function(){return(new THREE.Vector2).add(this.min,this.max).multiplyScalar(0.5)},size:function(){return(new THREE.Vector2).sub(this.max,this.min)},expandByPoint:function(a){this.min.minSelf(a);
 this.max.maxSelf(a);return this},expandByVector:function(a){this.min.subSelf(a);this.max.addSelf(a);return this},expandByScalar:function(a){this.min.addScalar(-a);this.max.addScalar(a);return this},containsPoint:function(a){return this.min.x<=a.x&&a.x<=this.max.x&&this.min.y<=a.y&&a.y<=this.max.y?!0:!1},containsBox:function(a){return this.min.x<=a.min.x&&a.max.x<=this.max.x&&this.min.y<=a.min.y&&a.max.y<=this.max.y?!0:!1},getParameter:function(a){return new THREE.Vector2((a.x-this.min.x)/(this.max.x-
 this.max.maxSelf(a);return this},expandByVector:function(a){this.min.subSelf(a);this.max.addSelf(a);return this},expandByScalar:function(a){this.min.addScalar(-a);this.max.addScalar(a);return this},containsPoint:function(a){return this.min.x<=a.x&&a.x<=this.max.x&&this.min.y<=a.y&&a.y<=this.max.y?!0:!1},containsBox:function(a){return this.min.x<=a.min.x&&a.max.x<=this.max.x&&this.min.y<=a.min.y&&a.max.y<=this.max.y?!0:!1},getParameter:function(a){return new THREE.Vector2((a.x-this.min.x)/(this.max.x-
-this.min.x),(a.y-this.min.y)/(this.max.y-this.min.y))},isIntersection:function(a){return this.max.x<a.min.x||a.min.x>this.max.x||this.max.y<a.min.y||a.min.y>this.max.y?!1:!0},clampPoint:function(a){return(new THREE.Vector2).copy(a).clampSelf(this.min,this.max)},distanceToPoint:function(a){return this.clampPoint(a).subSelf(a).length()},intersect:function(a){this.min.maxSelf(a.min);this.max.minSelf(a.max);return this},union:function(a){this.min.minSelf(a.min);this.max.maxSelf(a.max);return this},translate:function(a){this.min.addSelf(a);
-this.max.addSelf(a);return this},scale:function(a){a=this.size().multiplyScalar(0.5*(1-a));this.expandByVector(a);return this},equals:function(a){return a.min.equals(this.min)&&a.max.equals(this.max)},clone:function(){return(new THREE.Box2).copy(this)}};THREE.Box2.__v1=new THREE.Vector2;THREE.Box3=function(a,b){void 0===a&&void 0===b?(this.min=new THREE.Vector3,this.max=new THREE.Vector3,this.makeEmpty()):(this.min=a||new THREE.Vector3,this.max=b||(new THREE.Vector3).copy(this.min))};
+this.min.x),(a.y-this.min.y)/(this.max.y-this.min.y))},isIntersection:function(a){return this.max.x<a.min.x||a.min.x>this.max.x||this.max.y<a.min.y||a.min.y>this.max.y?!1:!0},clampPoint:function(a){return(new THREE.Vector2).copy(a).clampSelf(this.min,this.max)},distanceToPoint:function(a){return THREE.Box2.__v1.copy(a).clampSelf(this.min,this.max).subSelf(a).length()},intersect:function(a){this.min.maxSelf(a.min);this.max.minSelf(a.max);return this},union:function(a){this.min.minSelf(a.min);this.max.maxSelf(a.max);
+return this},translate:function(a){this.min.addSelf(a);this.max.addSelf(a);return this},scale:function(a){a=this.size().multiplyScalar(0.5*(1-a));this.expandByVector(a);return this},equals:function(a){return a.min.equals(this.min)&&a.max.equals(this.max)},clone:function(){return(new THREE.Box2).copy(this)}};THREE.Box2.__v1=new THREE.Vector2;THREE.Box3=function(a,b){void 0===a&&void 0===b?(this.min=new THREE.Vector3,this.max=new THREE.Vector3,this.makeEmpty()):(this.min=a||new THREE.Vector3,this.max=b||(new THREE.Vector3).copy(this.min))};
 THREE.Box3.prototype={constructor:THREE.Box3,set:function(a,b){this.min=a;this.max=b;return this},setFromPoints:function(a){if(0<a.length){var b=a[0];this.min.copy(b);this.max.copy(b);for(var c=1,d=a.length;c<d;c++)b=a[c],b.x<this.min.x?this.min.x=b.x:b.x>this.max.x&&(this.max.x=b.x),b.y<this.min.y?this.min.y=b.y:b.y>this.max.y&&(this.max.y=b.y),b.z<this.min.z?this.min.z=b.z:b.z>this.max.z&&(this.max.z=b.z)}else this.makeEmpty();return this},setFromCenterAndSize:function(a,b){var c=THREE.Box3.__v1.copy(b).multiplyScalar(0.5);
 THREE.Box3.prototype={constructor:THREE.Box3,set:function(a,b){this.min=a;this.max=b;return this},setFromPoints:function(a){if(0<a.length){var b=a[0];this.min.copy(b);this.max.copy(b);for(var c=1,d=a.length;c<d;c++)b=a[c],b.x<this.min.x?this.min.x=b.x:b.x>this.max.x&&(this.max.x=b.x),b.y<this.min.y?this.min.y=b.y:b.y>this.max.y&&(this.max.y=b.y),b.z<this.min.z?this.min.z=b.z:b.z>this.max.z&&(this.max.z=b.z)}else this.makeEmpty();return this},setFromCenterAndSize:function(a,b){var c=THREE.Box3.__v1.copy(b).multiplyScalar(0.5);
 this.min.copy(a).subSelf(c);this.max.copy(a).addSelf(c);return this},copy:function(a){this.min.copy(a.min);this.max.copy(a.max);return this},makeEmpty:function(){this.min.x=this.min.y=this.min.z=Infinity;this.max.x=this.max.y=this.max.z=-Infinity;return this},empty:function(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z},volume:function(){return(this.max.x-this.min.x)*(this.max.y-this.min.y)*(this.max.z-this.min.z)},center:function(){return(new THREE.Vector3).add(this.min,
 this.min.copy(a).subSelf(c);this.max.copy(a).addSelf(c);return this},copy:function(a){this.min.copy(a.min);this.max.copy(a.max);return this},makeEmpty:function(){this.min.x=this.min.y=this.min.z=Infinity;this.max.x=this.max.y=this.max.z=-Infinity;return this},empty:function(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z},volume:function(){return(this.max.x-this.min.x)*(this.max.y-this.min.y)*(this.max.z-this.min.z)},center:function(){return(new THREE.Vector3).add(this.min,
 this.max).multiplyScalar(0.5)},size:function(){return(new THREE.Vector3).sub(this.max,this.min)},expandByPoint:function(a){this.min.minSelf(a);this.max.maxSelf(a);return this},expandByVector:function(a){this.min.subSelf(a);this.max.addSelf(a);return this},expandByScalar:function(a){this.min.addScalar(-a);this.max.addScalar(a);return this},containsPoint:function(a){return this.min.x<=a.x&&a.x<=this.max.x&&this.min.y<=a.y&&a.y<=this.max.y&&this.min.z<=a.z&&a.z<=this.max.z?!0:!1},containsBox:function(a){return this.min.x<=
 this.max).multiplyScalar(0.5)},size:function(){return(new THREE.Vector3).sub(this.max,this.min)},expandByPoint:function(a){this.min.minSelf(a);this.max.maxSelf(a);return this},expandByVector:function(a){this.min.subSelf(a);this.max.addSelf(a);return this},expandByScalar:function(a){this.min.addScalar(-a);this.max.addScalar(a);return this},containsPoint:function(a){return this.min.x<=a.x&&a.x<=this.max.x&&this.min.y<=a.y&&a.y<=this.max.y&&this.min.z<=a.z&&a.z<=this.max.z?!0:!1},containsBox:function(a){return this.min.x<=
 a.min.x&&a.max.x<=this.max.x&&this.min.y<=a.min.y&&a.max.y<=this.max.y&&this.min.z<=a.min.z&&a.max.z<=this.max.z?!0:!1},getParameter:function(a){return new THREE.Vector3((a.x-this.min.x)/(this.max.x-this.min.x),(a.y-this.min.y)/(this.max.y-this.min.y),(a.z-this.min.z)/(this.max.z-this.min.z))},isIntersection:function(a){return this.max.x<a.min.x||a.min.x>this.max.x||this.max.y<a.min.y||a.min.y>this.max.y||this.max.z<a.min.z||a.min.z>this.max.z?!1:!0},clampPoint:function(a){return(new THREE.Vector3).copy(a).clampSelf(this.min,
 a.min.x&&a.max.x<=this.max.x&&this.min.y<=a.min.y&&a.max.y<=this.max.y&&this.min.z<=a.min.z&&a.max.z<=this.max.z?!0:!1},getParameter:function(a){return new THREE.Vector3((a.x-this.min.x)/(this.max.x-this.min.x),(a.y-this.min.y)/(this.max.y-this.min.y),(a.z-this.min.z)/(this.max.z-this.min.z))},isIntersection:function(a){return this.max.x<a.min.x||a.min.x>this.max.x||this.max.y<a.min.y||a.min.y>this.max.y||this.max.z<a.min.z||a.min.z>this.max.z?!1:!0},clampPoint:function(a){return(new THREE.Vector3).copy(a).clampSelf(this.min,
-this.max)},distanceToPoint:function(a){return this.clampPoint(a).subSelf(a).length()},intersect:function(a){this.min.maxSelf(a.min);this.max.minSelf(a.max);return this},union:function(a){this.min.minSelf(a.min);this.max.maxSelf(a.max);return this},translate:function(a){this.min.addSelf(a);this.max.addSelf(a);return this},scale:function(a){a=this.size().multiplyScalar(0.5*(1-a));this.expandByVector(a);return this},equals:function(a){return a.min.equals(this.min)&&a.max.equals(this.max)},clone:function(){return(new THREE.Box3).copy(this)}};
-THREE.Box3.__v1=new THREE.Vector3;THREE.Matrix3=function(){this.elements=new Float32Array(9)};
+this.max)},distanceToPoint:function(a){return THREE.Box3.__v1.copy(a).clampSelf(this.min,this.max).subSelf(a).length()},intersect:function(a){this.min.maxSelf(a.min);this.max.minSelf(a.max);return this},union:function(a){this.min.minSelf(a.min);this.max.maxSelf(a.max);return this},translate:function(a){this.min.addSelf(a);this.max.addSelf(a);return this},scale:function(a){a=this.size().multiplyScalar(0.5*(1-a));this.expandByVector(a);return this},equals:function(a){return a.min.equals(this.min)&&
+a.max.equals(this.max)},clone:function(){return(new THREE.Box3).copy(this)}};THREE.Box3.__v1=new THREE.Vector3;THREE.Matrix3=function(){this.elements=new Float32Array(9)};
 THREE.Matrix3.prototype={constructor:THREE.Matrix3,multiplyVector3:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z;a.x=b[0]*c+b[3]*d+b[6]*e;a.y=b[1]*c+b[4]*d+b[7]*e;a.z=b[2]*c+b[5]*d+b[8]*e;return a},multiplyVector3Array:function(a){for(var b=THREE.Matrix3.__v1,c=0,d=a.length;c<d;c+=3)b.x=a[c],b.y=a[c+1],b.z=a[c+2],this.multiplyVector3(b),a[c]=b.x,a[c+1]=b.y,a[c+2]=b.z;return a},getInverse:function(a){var b=a.elements,a=b[10]*b[5]-b[6]*b[9],c=-b[10]*b[1]+b[2]*b[9],d=b[6]*b[1]-b[2]*b[5],e=-b[10]*
 THREE.Matrix3.prototype={constructor:THREE.Matrix3,multiplyVector3:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z;a.x=b[0]*c+b[3]*d+b[6]*e;a.y=b[1]*c+b[4]*d+b[7]*e;a.z=b[2]*c+b[5]*d+b[8]*e;return a},multiplyVector3Array:function(a){for(var b=THREE.Matrix3.__v1,c=0,d=a.length;c<d;c+=3)b.x=a[c],b.y=a[c+1],b.z=a[c+2],this.multiplyVector3(b),a[c]=b.x,a[c+1]=b.y,a[c+2]=b.z;return a},getInverse:function(a){var b=a.elements,a=b[10]*b[5]-b[6]*b[9],c=-b[10]*b[1]+b[2]*b[9],d=b[6]*b[1]-b[2]*b[5],e=-b[10]*
 b[4]+b[6]*b[8],f=b[10]*b[0]-b[2]*b[8],g=-b[6]*b[0]+b[2]*b[4],h=b[9]*b[4]-b[5]*b[8],i=-b[9]*b[0]+b[1]*b[8],j=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*e+b[2]*h;0===b&&console.warn("Matrix3.getInverse(): determinant == 0");var b=1/b,l=this.elements;l[0]=b*a;l[1]=b*c;l[2]=b*d;l[3]=b*e;l[4]=b*f;l[5]=b*g;l[6]=b*h;l[7]=b*i;l[8]=b*j;return this},transpose:function(){var a,b=this.elements;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.elements;
 b[4]+b[6]*b[8],f=b[10]*b[0]-b[2]*b[8],g=-b[6]*b[0]+b[2]*b[4],h=b[9]*b[4]-b[5]*b[8],i=-b[9]*b[0]+b[1]*b[8],j=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*e+b[2]*h;0===b&&console.warn("Matrix3.getInverse(): determinant == 0");var b=1/b,l=this.elements;l[0]=b*a;l[1]=b*c;l[2]=b*d;l[3]=b*e;l[4]=b*f;l[5]=b*g;l[6]=b*h;l[7]=b*i;l[8]=b*j;return this},transpose:function(){var a,b=this.elements;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.elements;
 a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix3.__v1=new THREE.Vector3;THREE.Matrix4=function(a,b,c,d,e,f,g,h,i,j,l,p,n,r,q,m){this.elements=new Float32Array(16);this.set(void 0!==a?a:1,b||0,c||0,d||0,e||0,void 0!==f?f:1,g||0,h||0,i||0,j||0,void 0!==l?l:1,p||0,n||0,r||0,q||0,void 0!==m?m:1)};
 a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix3.__v1=new THREE.Vector3;THREE.Matrix4=function(a,b,c,d,e,f,g,h,i,j,l,p,n,r,q,m){this.elements=new Float32Array(16);this.set(void 0!==a?a:1,b||0,c||0,d||0,e||0,void 0!==f?f:1,g||0,h||0,i||0,j||0,void 0!==l?l:1,p||0,n||0,r||0,q||0,void 0!==m?m:1)};

+ 53 - 28
examples/js/DeferredHelper.js → examples/js/renderers/WebGLDeferredRenderer.js

@@ -3,19 +3,39 @@
  * @author MPanknin / http://www.redplant.de/
  * @author MPanknin / http://www.redplant.de/
  */
  */
 
 
-THREE.DeferredHelper = function ( parameters ) {
+THREE.WebGLDeferredRenderer = function ( parameters ) {
+
+	var _this = this;
 
 
 	var width = parameters.width;
 	var width = parameters.width;
 	var height = parameters.height;
 	var height = parameters.height;
 	var scale = parameters.scale;
 	var scale = parameters.scale;
 
 
-	var renderer = parameters.renderer;
+	var scaledWidth = Math.floor( scale * width );
+	var scaledHeight = Math.floor( scale * height );
 
 
 	var additiveSpecular = parameters.additiveSpecular;
 	var additiveSpecular = parameters.additiveSpecular;
 	var multiply = parameters.multiply;
 	var multiply = parameters.multiply;
 
 
+	this.renderer = parameters.renderer;
+
+	if ( this.renderer === undefined ) {
+
+		this.renderer = new THREE.WebGLRenderer( { alpha: false } );
+		this.renderer.setSize( width, height );
+		this.renderer.setClearColorHex( 0x000000, 1 );
+
+		this.renderer.autoClear = false;
+
+	}
+
+	this.domElement = this.renderer.domElement;
+
+
 	//
 	//
 
 
+	var geometryLight = new THREE.SphereGeometry( 1, 16, 8 );
+
 	var black = new THREE.Color( 0x000000 );
 	var black = new THREE.Color( 0x000000 );
 
 
 	var colorShader = THREE.ShaderDeferred[ "color" ];
 	var colorShader = THREE.ShaderDeferred[ "color" ];
@@ -266,8 +286,8 @@ THREE.DeferredHelper = function ( parameters ) {
 		materialLight.uniforms[ "lightIntensity" ].value = light.intensity;
 		materialLight.uniforms[ "lightIntensity" ].value = light.intensity;
 		materialLight.uniforms[ "lightColor" ].value = light.color;
 		materialLight.uniforms[ "lightColor" ].value = light.color;
 
 
-		materialLight.uniforms[ "viewWidth" ].value = width;
-		materialLight.uniforms[ "viewHeight" ].value = height;
+		materialLight.uniforms[ "viewWidth" ].value = scaledWidth;
+		materialLight.uniforms[ "viewHeight" ].value = scaledHeight;
 
 
 		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
 		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
 		materialLight.uniforms[ 'samplerNormals' ].value = compNormal.renderTarget2;
 		materialLight.uniforms[ 'samplerNormals' ].value = compNormal.renderTarget2;
@@ -275,9 +295,9 @@ THREE.DeferredHelper = function ( parameters ) {
 
 
 		// create light proxy mesh
 		// create light proxy mesh
 
 
-		var geometryLight = new THREE.SphereGeometry( light.distance, 16, 8 );
 		var meshLight = new THREE.Mesh( geometryLight, materialLight );
 		var meshLight = new THREE.Mesh( geometryLight, materialLight );
 		meshLight.position = light.position;
 		meshLight.position = light.position;
+		meshLight.scale.multiplyScalar( light.distance );
 
 
 		// keep reference for size reset
 		// keep reference for size reset
 
 
@@ -308,8 +328,8 @@ THREE.DeferredHelper = function ( parameters ) {
 		materialLight.uniforms[ "lightIntensity" ].value = light.intensity;
 		materialLight.uniforms[ "lightIntensity" ].value = light.intensity;
 		materialLight.uniforms[ "lightColor" ].value = light.color;
 		materialLight.uniforms[ "lightColor" ].value = light.color;
 
 
-		materialLight.uniforms[ "viewWidth" ].value = width;
-		materialLight.uniforms[ "viewHeight" ].value = height;
+		materialLight.uniforms[ "viewWidth" ].value = scaledWidth;
+		materialLight.uniforms[ "viewHeight" ].value = scaledHeight;
 
 
 		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
 		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
 		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
 		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
@@ -343,8 +363,8 @@ THREE.DeferredHelper = function ( parameters ) {
 		} );
 		} );
 
 
 
 
-		materialLight.uniforms[ "viewWidth" ].value = width;
-		materialLight.uniforms[ "viewHeight" ].value = height;
+		materialLight.uniforms[ "viewWidth" ].value = scaledWidth;
+		materialLight.uniforms[ "viewHeight" ].value = scaledHeight;
 
 
 		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
 		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
 		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
 		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
@@ -408,18 +428,23 @@ THREE.DeferredHelper = function ( parameters ) {
 
 
 	this.setSize = function ( width, height ) {
 	this.setSize = function ( width, height ) {
 
 
-		compColor.setSize( width, height );
-		compNormal.setSize( width, height );
-		compDepth.setSize( width, height );
-		compLight.setSize( width, height );
-		compFinal.setSize( width, height );
+		this.renderer.setSize( width, height );
+
+		scaledWidth = Math.floor( scale * width );
+		scaledHeight = Math.floor( scale * height );
+
+		compColor.setSize( scaledWidth, scaledHeight );
+		compNormal.setSize( scaledWidth, scaledHeight );
+		compDepth.setSize( scaledWidth, scaledHeight );
+		compLight.setSize( scaledWidth, scaledHeight );
+		compFinal.setSize( scaledWidth, scaledHeight );
 
 
 		for ( var i = 0, il = lightMaterials.length; i < il; i ++ ) {
 		for ( var i = 0, il = lightMaterials.length; i < il; i ++ ) {
 
 
 			var uniforms = lightMaterials[ i ].uniforms;
 			var uniforms = lightMaterials[ i ].uniforms;
 
 
-			uniforms[ "viewWidth" ].value = width;
-			uniforms[ "viewHeight" ].value = height;
+			uniforms[ "viewWidth" ].value = scaledWidth;
+			uniforms[ "viewHeight" ].value = scaledHeight;
 
 
 			uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
 			uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
 			uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
 			uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
@@ -434,7 +459,7 @@ THREE.DeferredHelper = function ( parameters ) {
 
 
 		compositePass.uniforms[ 'samplerLight' ].value = compLight.renderTarget2;
 		compositePass.uniforms[ 'samplerLight' ].value = compLight.renderTarget2;
 
 
-		effectFXAA.uniforms[ 'resolution' ].value.set( scale / width, scale / height );
+		effectFXAA.uniforms[ 'resolution' ].value.set( 1 / width, 1 / height );
 
 
 	};
 	};
 
 
@@ -528,11 +553,11 @@ THREE.DeferredHelper = function ( parameters ) {
 
 
 		// g-buffers
 		// g-buffers
 
 
-		var rtColor   = new THREE.WebGLRenderTarget( width, height, rtParamsFloatNearest );
-		var rtNormal  = new THREE.WebGLRenderTarget( width, height, rtParamsFloatLinear );
-		var rtDepth   = new THREE.WebGLRenderTarget( width, height, rtParamsFloatLinear );
-		var rtLight   = new THREE.WebGLRenderTarget( width, height, rtParamsFloatLinear );
-		var rtFinal   = new THREE.WebGLRenderTarget( width, height, rtParamsUByte );
+		var rtColor   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatNearest );
+		var rtNormal  = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatLinear );
+		var rtDepth   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatLinear );
+		var rtLight   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatLinear );
+		var rtFinal   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsUByte );
 
 
 		rtColor.generateMipmaps = false;
 		rtColor.generateMipmaps = false;
 		rtNormal.generateMipmaps = false;
 		rtNormal.generateMipmaps = false;
@@ -543,22 +568,22 @@ THREE.DeferredHelper = function ( parameters ) {
 		// composers
 		// composers
 
 
 		passColor = new THREE.RenderPass();
 		passColor = new THREE.RenderPass();
-		compColor = new THREE.EffectComposer( renderer, rtColor );
+		compColor = new THREE.EffectComposer( _this.renderer, rtColor );
 		compColor.addPass( passColor );
 		compColor.addPass( passColor );
 
 
 		passNormal = new THREE.RenderPass();
 		passNormal = new THREE.RenderPass();
-		compNormal = new THREE.EffectComposer( renderer, rtNormal );
+		compNormal = new THREE.EffectComposer( _this.renderer, rtNormal );
 		compNormal.addPass( passNormal );
 		compNormal.addPass( passNormal );
 
 
 		passDepth = new THREE.RenderPass();
 		passDepth = new THREE.RenderPass();
-		compDepth = new THREE.EffectComposer( renderer, rtDepth );
+		compDepth = new THREE.EffectComposer( _this.renderer, rtDepth );
 		compDepth.addPass( passDepth );
 		compDepth.addPass( passDepth );
 
 
 		passLightFullscreen = new THREE.RenderPass();
 		passLightFullscreen = new THREE.RenderPass();
 		passLightProxy = new THREE.RenderPass();
 		passLightProxy = new THREE.RenderPass();
 		passLightProxy.clear = false;
 		passLightProxy.clear = false;
 
 
-		compLight = new THREE.EffectComposer( renderer, rtLight );
+		compLight = new THREE.EffectComposer( _this.renderer, rtLight );
 		compLight.addPass( passLightFullscreen );
 		compLight.addPass( passLightFullscreen );
 		compLight.addPass( passLightProxy );
 		compLight.addPass( passLightProxy );
 
 
@@ -571,12 +596,12 @@ THREE.DeferredHelper = function ( parameters ) {
 		// FXAA
 		// FXAA
 
 
 		effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
 		effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
-		effectFXAA.uniforms[ 'resolution' ].value.set( scale / width, scale / height );
+		effectFXAA.uniforms[ 'resolution' ].value.set( 1 / width, 1 / height );
 		effectFXAA.renderToScreen = true;
 		effectFXAA.renderToScreen = true;
 
 
 		//
 		//
 
 
-		compFinal = new THREE.EffectComposer( renderer, rtFinal );
+		compFinal = new THREE.EffectComposer( _this.renderer, rtFinal );
 		compFinal.addPass( compositePass );
 		compFinal.addPass( compositePass );
 		compFinal.addPass( effectFXAA );
 		compFinal.addPass( effectFXAA );
 
 

+ 5 - 18
examples/webgl_lights_deferred_morphs.html

@@ -51,8 +51,8 @@
 
 
 		<script src="js/Detector.js"></script>
 		<script src="js/Detector.js"></script>
 
 
+		<script src="js/renderers/WebGLDeferredRenderer.js"></script>
 		<script src="js/ShaderDeferred.js"></script>
 		<script src="js/ShaderDeferred.js"></script>
-		<script src="js/DeferredHelper.js"></script>
 
 
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/FXAAShader.js"></script>
 		<script src="js/shaders/FXAAShader.js"></script>
@@ -72,9 +72,6 @@
 			var WIDTH = window.innerWidth;
 			var WIDTH = window.innerWidth;
 			var HEIGHT = window.innerHeight - 2 * MARGIN;
 			var HEIGHT = window.innerHeight - 2 * MARGIN;
 
 
-			var SCALED_WIDTH = Math.floor( SCALE * WIDTH );
-			var SCALED_HEIGHT = Math.floor( SCALE * HEIGHT );
-
 			var NEAR = 1.0, FAR = 350.0;
 			var NEAR = 1.0, FAR = 350.0;
 			var VIEW_ANGLE = 45;
 			var VIEW_ANGLE = 45;
 
 
@@ -114,11 +111,7 @@
 
 
 				// renderer
 				// renderer
 
 
-				renderer = new THREE.WebGLRenderer( { alpha: false } );
-				renderer.setSize( WIDTH, HEIGHT );
-				renderer.setClearColorHex( 0x000000, 1 );
-
-				renderer.autoClear = false;
+				renderer = new THREE.WebGLDeferredRenderer( { width: WIDTH, height: HEIGHT, scale: SCALE, multiply: 2, additiveSpecular: true } );
 
 
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.top = MARGIN + "px";
 				renderer.domElement.style.top = MARGIN + "px";
@@ -149,10 +142,6 @@
 
 
 				clock = new THREE.Clock();
 				clock = new THREE.Clock();
 
 
-				// deferred helper
-
-				deferredHelper = new THREE.DeferredHelper( { renderer: renderer, width: SCALED_WIDTH, height: SCALED_HEIGHT, scale: SCALE, multiply: 2, additiveSpecular: true } );
-
 				// add lights
 				// add lights
 
 
 				initLights();
 				initLights();
@@ -328,11 +317,7 @@
 				WIDTH = window.innerWidth;
 				WIDTH = window.innerWidth;
 				HEIGHT = window.innerHeight - 2 * MARGIN;
 				HEIGHT = window.innerHeight - 2 * MARGIN;
 
 
-				SCALED_WIDTH = Math.floor( SCALE * WIDTH );
-				SCALED_HEIGHT = Math.floor( SCALE * HEIGHT );
-
 				renderer.setSize( WIDTH, HEIGHT );
 				renderer.setSize( WIDTH, HEIGHT );
-				deferredHelper.setSize( SCALED_WIDTH, SCALED_HEIGHT );
 
 
 				camera.aspect = WIDTH / HEIGHT;
 				camera.aspect = WIDTH / HEIGHT;
 				camera.updateProjectionMatrix();
 				camera.updateProjectionMatrix();
@@ -412,7 +397,9 @@
 
 
 				camera.lookAt( target );
 				camera.lookAt( target );
 
 
-				deferredHelper.render( scene, camera );
+				// render
+
+				renderer.render( scene, camera );
 
 
 			}
 			}
 
 

+ 7 - 18
examples/webgl_lights_deferred_pointlights.html

@@ -50,8 +50,8 @@
 		<script src="js/Detector.js"></script>
 		<script src="js/Detector.js"></script>
 		<script src="js/libs/stats.min.js"></script>
 		<script src="js/libs/stats.min.js"></script>
 
 
+		<script src="js/renderers/WebGLDeferredRenderer.js"></script>
 		<script src="js/ShaderDeferred.js"></script>
 		<script src="js/ShaderDeferred.js"></script>
-		<script src="js/DeferredHelper.js"></script>
 
 
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/FXAAShader.js"></script>
 		<script src="js/shaders/FXAAShader.js"></script>
@@ -76,9 +76,6 @@
 			var WIDTH = window.innerWidth;
 			var WIDTH = window.innerWidth;
 			var HEIGHT = window.innerHeight - 2 * MARGIN;
 			var HEIGHT = window.innerHeight - 2 * MARGIN;
 
 
-			var SCALED_WIDTH = Math.floor( SCALE * WIDTH );
-			var SCALED_HEIGHT = Math.floor( SCALE * HEIGHT );
-
 			var NEAR = 1.0, FAR = 350.0;
 			var NEAR = 1.0, FAR = 350.0;
 			var VIEW_ANGLE = 45;
 			var VIEW_ANGLE = 45;
 
 
@@ -114,11 +111,7 @@
 
 
 				// renderer
 				// renderer
 
 
-				renderer = new THREE.WebGLRenderer( { alpha: false } );
-				renderer.setSize( WIDTH, HEIGHT );
-				renderer.setClearColorHex( 0x000000, 1 );
-
-				renderer.autoClear = false;
+				renderer = new THREE.WebGLDeferredRenderer( { width: WIDTH, height: HEIGHT, scale: SCALE, additiveSpecular: false, multiply: 2 } );
 
 
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.top = MARGIN + "px";
 				renderer.domElement.style.top = MARGIN + "px";
@@ -149,10 +142,6 @@
 
 
 				clock = new THREE.Clock();
 				clock = new THREE.Clock();
 
 
-				// deferred helper
-
-				deferredHelper = new THREE.DeferredHelper( { renderer: renderer, width: SCALED_WIDTH, height: SCALED_HEIGHT, scale: SCALE, additiveSpecular: false, multiply: 2 } );
-
 				// add lights
 				// add lights
 
 
 				initLights();
 				initLights();
@@ -375,11 +364,7 @@
 				WIDTH = window.innerWidth;
 				WIDTH = window.innerWidth;
 				HEIGHT = window.innerHeight - 2 * MARGIN;
 				HEIGHT = window.innerHeight - 2 * MARGIN;
 
 
-				SCALED_WIDTH = Math.floor( SCALE * WIDTH );
-				SCALED_HEIGHT = Math.floor( SCALE * HEIGHT );
-
 				renderer.setSize( WIDTH, HEIGHT );
 				renderer.setSize( WIDTH, HEIGHT );
-				deferredHelper.setSize( SCALED_WIDTH, SCALED_HEIGHT );
 
 
 				camera.aspect = WIDTH / HEIGHT;
 				camera.aspect = WIDTH / HEIGHT;
 				camera.updateProjectionMatrix();
 				camera.updateProjectionMatrix();
@@ -433,6 +418,8 @@
 
 
 				}
 				}
 
 
+				// update camera
+
 				var delta = clock.getDelta();
 				var delta = clock.getDelta();
 
 
 				targetX = mouseX * .001;
 				targetX = mouseX * .001;
@@ -445,7 +432,9 @@
 
 
 				camera.lookAt( target );
 				camera.lookAt( target );
 
 
-				deferredHelper.render( scene, camera );
+				// render
+
+				renderer.render( scene, camera );
 
 
 			}
 			}
 
 

+ 2 - 1
src/core/Box2.js

@@ -215,7 +215,8 @@ THREE.Box2.prototype = {
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
 
 
-		return this.clampPoint( point ).subSelf( point ).length();
+		var clampedPoint = THREE.Box2.__v1.copy( point ).clampSelf( this.min, this.max );
+		return clampedPoint.subSelf( point ).length();
 
 
 	},
 	},
 
 

+ 3 - 1
src/core/Box3.js

@@ -201,6 +201,7 @@ THREE.Box3.prototype = {
 
 
 		// This can potentially have a divide by zero if the box
 		// This can potentially have a divide by zero if the box
 		// has a size dimension of 0.
 		// has a size dimension of 0.
+
 		return new THREE.Vector3(
 		return new THREE.Vector3(
 			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
 			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
 			( point.y - this.min.y ) / ( this.max.y - this.min.y ),
 			( point.y - this.min.y ) / ( this.max.y - this.min.y ),
@@ -233,7 +234,8 @@ THREE.Box3.prototype = {
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
 
 
-		return this.clampPoint( point ).subSelf( point ).length();
+		var clampedPoint = THREE.Box3.__v1.copy( point ).clampSelf( this.min, this.max );
+		return clampedPoint.subSelf( point ).length();
 
 
 	},
 	},
 
 

+ 2 - 1
src/core/Plane.js

@@ -43,9 +43,10 @@ THREE.Plane.prototype = {
 	setFromCoplanarPoints: function ( a, b, c ) {
 	setFromCoplanarPoints: function ( a, b, c ) {
 
 
 		var normal = THREE.Plane.__v1.sub( b, a ).cross(
 		var normal = THREE.Plane.__v1.sub( b, a ).cross(
-			THREE.Plane.__v2.sub( c, a ) );
+					 THREE.Plane.__v2.sub( c, a ) );
 
 
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
+
 		this.setFromNormalAndCoplanarPoint( normal, a );
 		this.setFromNormalAndCoplanarPoint( normal, a );
 
 
 		return this;
 		return this;

+ 2 - 1
src/core/Vector3.js

@@ -348,7 +348,8 @@ THREE.Vector3.prototype = {
 
 
 	distanceToSquared: function ( v ) {
 	distanceToSquared: function ( v ) {
 
 
-		return new THREE.Vector3().sub( this, v ).lengthSq();
+		var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
+		return dx * dx + dy * dy + dz * dz;
 
 
 	},
 	},