Browse Source

WebGLRenderer: Update materials when light setup changes.

Mr.doob 9 years ago
parent
commit
d3958d0624
1 changed files with 18 additions and 0 deletions
  1. 18 0
      src/renderers/WebGLRenderer.js

+ 18 - 0
src/renderers/WebGLRenderer.js

@@ -2563,9 +2563,16 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		viewMatrix = camera.matrixWorldInverse,
 
+		directionalCurrent = _lights.directional.length;
 		directionalLength = 0,
+
+		pointCurrent = _lights.point.length;
 		pointLength = 0,
+
+		spotCurrent = _lights.spot.length;
 		spotLength = 0,
+
+		hemiCurrent = _lights.hemi.length;
 		hemiLength = 0;
 
 		for ( l = 0, ll = lights.length; l < ll; l ++ ) {
@@ -2685,6 +2692,17 @@ THREE.WebGLRenderer = function ( parameters ) {
 		_lights.ambient[ 1 ] = g;
 		_lights.ambient[ 2 ] = b;
 
+		// Reset materials if light setup changes
+
+		if ( directionalCurrent !== directionalLength ||
+				pointCurrent !== pointLength ||
+				spotCurrent !== spotLength ||
+				hemiCurrent !== hemiLength ) {
+
+			materialsCache.clear();
+
+		}
+
 		_lights.directional.length = directionalLength;
 		_lights.point.length = pointLength;
 		_lights.spot.length = spotLength;