/// <summary>
/// Lazily recomputes the world inverse transpose matrix and
/// eye position based on the current effect parameter settings.
/// </summary>
internal static EffectDirtyFlags SetLightingMatrices(EffectDirtyFlags dirtyFlags, ref Matrix world, ref Matrix view,
EffectParameter worldParam, EffectParameter worldInverseTransposeParam, EffectParameter eyePositionParam)
{
// Set the world and world inverse transpose matrices.
if ((dirtyFlags & EffectDirtyFlags.World) != 0)
{
Matrix worldTranspose;
Matrix worldInverseTranspose;
Matrix.Invert(ref world, out worldTranspose);
Matrix.Transpose(ref worldTranspose, out worldInverseTranspose);
worldParam.SetValue(world);
worldInverseTransposeParam.SetValue(worldInverseTranspose);
dirtyFlags &= ~EffectDirtyFlags.World;
}
// Set the eye position.
if ((dirtyFlags & EffectDirtyFlags.EyePosition) != 0)
{
Matrix viewInverse;
Matrix.Invert(ref view, out viewInverse);
eyePositionParam.SetValue(viewInverse.Translation);
dirtyFlags &= ~EffectDirtyFlags.EyePosition;
}
return dirtyFlags;
}