提交 1cdc0957 编写于 作者: M Mr.doob

WebGLRenderer: Create lights hash so material remembers the light setup it was...

WebGLRenderer: Create lights hash so material remembers the light setup it was created for. See #7440.
上级 982b28f5
......@@ -108,6 +108,8 @@ THREE.WebGLRenderer = function ( parameters ) {
_lights = {
hash: '',
ambient: [ 0, 0, 0 ],
directional: [],
point: [],
......@@ -1496,6 +1498,8 @@ THREE.WebGLRenderer = function ( parameters ) {
material instanceof THREE.MeshPhysicalMaterial ||
material.lights ) {
materialProperties.lightsHash = _lights.hash;
// wire up the material to this renderer's lighting state
uniforms.ambientLightColor.value = _lights.ambient;
......@@ -1543,7 +1547,20 @@ THREE.WebGLRenderer = function ( parameters ) {
var materialProperties = materialsCache.get( material );
if ( material.needsUpdate || ! materialProperties.program ) {
if ( materialProperties.program === undefined ) {
material.needsUpdate = true;
}
if ( materialProperties.lightsHash !== undefined &&
materialProperties.lightsHash !== _lights.hash ) {
material.needsUpdate = true;
}
if ( material.needsUpdate ) {
initMaterial( material, lights, fog, object );
material.needsUpdate = false;
......@@ -2564,11 +2581,6 @@ THREE.WebGLRenderer = function ( parameters ) {
viewMatrix = camera.matrixWorldInverse,
directionalCurrent = _lights.directional.length,
pointCurrent = _lights.point.length,
spotCurrent = _lights.spot.length,
hemiCurrent = _lights.hemi.length,
directionalLength = 0,
pointLength = 0,
spotLength = 0,
......@@ -2691,22 +2703,13 @@ 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;
_lights.hemi.length = hemiLength;
_lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength;
}
// GL state setting
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册