public void UpdateAutoParamsLightsOnly( AutoParamDataSource source )
{
// return if no constants
if ( !this.HasAutoConstantType )
{
return;
}
PassIterationNumberIndex = int.MaxValue;
// loop through and update all constants based on their type
for ( int i = 0; i < autoConstantList.Count; i++ )
{
AutoConstantEntry entry = autoConstantList[ i ];
Vector3 vec3;
switch ( entry.Type )
{
case AutoConstantType.LightDiffuseColor:
SetConstant( entry.PhysicalIndex, source.GetLight( entry.Data ).Diffuse );
break;
case AutoConstantType.LightSpecularColor:
SetConstant( entry.PhysicalIndex, source.GetLight( entry.Data ).Specular );
break;
case AutoConstantType.LightPosition:
// Fix from Multiverse to enable Normal Mapping Sample Material from OGRE
SetConstant( entry.PhysicalIndex, source.GetLight( entry.Data ).GetAs4DVector() );
break;
case AutoConstantType.LightDirection:
vec3 = source.GetLight( 1 ).DerivedDirection;
SetConstant( entry.PhysicalIndex, vec3.x, vec3.y, vec3.z, 1.0f );
break;
case AutoConstantType.LightPositionObjectSpace:
SetConstant( entry.PhysicalIndex, source.InverseWorldMatrix * source.GetLight( entry.Data ).GetAs4DVector() );
break;
case AutoConstantType.LightDirectionObjectSpace:
vec3 = source.InverseWorldMatrix * source.GetLight( entry.Data ).DerivedDirection;
vec3.Normalize();
SetConstant( entry.PhysicalIndex, vec3.x, vec3.y, vec3.z, 1.0f );
break;
case AutoConstantType.LightDistanceObjectSpace:
vec3 = source.InverseWorldMatrix * source.GetLight( entry.Data ).DerivedPosition;
SetConstant( entry.PhysicalIndex, vec3.Length, 0f, 0f, 0f );
break;
case AutoConstantType.ShadowExtrusionDistance:
SetConstant( entry.PhysicalIndex, source.ShadowExtrusionDistance, 0f, 0f, 0f );
break;
case AutoConstantType.LightAttenuation:
Light light = source.GetLight( entry.Data );
SetConstant( entry.PhysicalIndex, light.AttenuationRange, light.AttenuationConstant, light.AttenuationLinear, light.AttenuationQuadratic );
break;
case AutoConstantType.LightPowerScale:
SetConstant( entry.PhysicalIndex, source.GetLightPowerScale( entry.Data ) );
break;
case AutoConstantType.WorldMatrix:
SetConstant( entry.PhysicalIndex, source.WorldMatrix );
break;
//case AutoConstantType.ViewProjMatrix:
// SetConstant( entry.PhysicalIndex, source.ViewProjectionMatrix );
// break;
case AutoConstantType.PassIterationNumber:
SetConstant(entry.PhysicalIndex, 0.0f);
PassIterationNumberIndex = entry.PhysicalIndex;
break;
}
}
}