|
@@ -4291,6 +4291,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
var refreshProgram = false;
|
|
var refreshProgram = false;
|
|
var refreshMaterial = false;
|
|
var refreshMaterial = false;
|
|
|
|
+ var refreshLights = false;
|
|
|
|
|
|
var program = material.program,
|
|
var program = material.program,
|
|
p_uniforms = program.uniforms,
|
|
p_uniforms = program.uniforms,
|
|
@@ -4303,12 +4304,15 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
refreshProgram = true;
|
|
refreshProgram = true;
|
|
refreshMaterial = true;
|
|
refreshMaterial = true;
|
|
|
|
+ refreshLights = true;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if ( material.id !== _currentMaterialId ) {
|
|
if ( material.id !== _currentMaterialId ) {
|
|
|
|
|
|
|
|
+ if ( _currentMaterialId === -1 ) refreshLights = true;
|
|
_currentMaterialId = material.id;
|
|
_currentMaterialId = material.id;
|
|
|
|
+
|
|
refreshMaterial = true;
|
|
refreshMaterial = true;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -4414,12 +4418,17 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
if ( _lightsNeedUpdate ) {
|
|
if ( _lightsNeedUpdate ) {
|
|
|
|
|
|
- setupLights( program, lights );
|
|
|
|
|
|
+ refreshLights = true;
|
|
|
|
+ setupLights( lights );
|
|
_lightsNeedUpdate = false;
|
|
_lightsNeedUpdate = false;
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- refreshUniformsLights( m_uniforms, _lights );
|
|
|
|
|
|
+ if ( refreshLights ) {
|
|
|
|
+ refreshUniformsLights( m_uniforms, _lights );
|
|
|
|
+ markUniformsLightsNeedsUpdate( m_uniforms, true );
|
|
|
|
+ } else {
|
|
|
|
+ markUniformsLightsNeedsUpdate( m_uniforms, false );
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4700,6 +4709,32 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ // If uniforms are marked as clean, they don't need to be loaded to the GPU.
|
|
|
|
+
|
|
|
|
+ function markUniformsLightsNeedsUpdate ( uniforms, boolean ) {
|
|
|
|
+
|
|
|
|
+ uniforms.ambientLightColor.needsUpdate = boolean;
|
|
|
|
+
|
|
|
|
+ uniforms.directionalLightColor.needsUpdate = boolean;
|
|
|
|
+ uniforms.directionalLightDirection.needsUpdate = boolean;
|
|
|
|
+
|
|
|
|
+ uniforms.pointLightColor.needsUpdate = boolean;
|
|
|
|
+ uniforms.pointLightPosition.needsUpdate = boolean;
|
|
|
|
+ uniforms.pointLightDistance.needsUpdate = boolean;
|
|
|
|
+
|
|
|
|
+ uniforms.spotLightColor.needsUpdate = boolean;
|
|
|
|
+ uniforms.spotLightPosition.needsUpdate = boolean;
|
|
|
|
+ uniforms.spotLightDistance.needsUpdate = boolean;
|
|
|
|
+ uniforms.spotLightDirection.needsUpdate = boolean;
|
|
|
|
+ uniforms.spotLightAngleCos.needsUpdate = boolean;
|
|
|
|
+ uniforms.spotLightExponent.needsUpdate = boolean;
|
|
|
|
+
|
|
|
|
+ uniforms.hemisphereLightSkyColor.needsUpdate = boolean;
|
|
|
|
+ uniforms.hemisphereLightGroundColor.needsUpdate = boolean;
|
|
|
|
+ uniforms.hemisphereLightDirection.needsUpdate = boolean;
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
function refreshUniformsShadow ( uniforms, lights ) {
|
|
function refreshUniformsShadow ( uniforms, lights ) {
|
|
|
|
|
|
if ( uniforms.shadowMatrix ) {
|
|
if ( uniforms.shadowMatrix ) {
|
|
@@ -4772,6 +4807,9 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
var uniform = uniforms[ j ][ 0 ];
|
|
var uniform = uniforms[ j ][ 0 ];
|
|
|
|
|
|
|
|
+ // needsUpdate property is not added to all uniforms.
|
|
|
|
+ if ( uniform.needsUpdate === false ) continue;
|
|
|
|
+
|
|
var type = uniform.type;
|
|
var type = uniform.type;
|
|
var value = uniform.value;
|
|
var value = uniform.value;
|
|
|
|
|
|
@@ -5001,7 +5039,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
- function setupLights ( program, lights ) {
|
|
|
|
|
|
+ function setupLights ( lights ) {
|
|
|
|
|
|
var l, ll, light, n,
|
|
var l, ll, light, n,
|
|
r = 0, g = 0, b = 0,
|
|
r = 0, g = 0, b = 0,
|