private void CreateEffect(DynamicEffectInstance effectInstance) { var compilerParameters = new CompilerParameters(); parameterCollections.Clear(true); effectInstance.FillParameterCollections(parameterCollections); foreach (var parameterCollection in parameterCollections) { if (parameterCollection != null) { foreach (var parameter in parameterCollection.InternalValues) { compilerParameters.SetObject(parameter.Key, parameter.Value.Object); } } } foreach (var parameter in GraphicsDevice.Parameters.InternalValues) { compilerParameters.SetObject(parameter.Key, parameter.Value.Object); } // Compile shader // possible exception in LoadEffect var effect = EffectSystem.LoadEffect(EffectName, compilerParameters); if (!ReferenceEquals(effect, effectInstance.Effect)) { // Copy back parameters set on previous effect to new effect if (effectInstance.Effect != null) { foreach (var parameter in effectInstance.Effect.Parameters.InternalValues) { effect.Parameters.SetObject(parameter.Key, parameter.Value.Object); } } effectInstance.Effect = effect; effectInstance.UpdaterDefinition = new EffectParameterUpdaterDefinition(effect); } else { // Same effect than previous one effectInstance.UpdaterDefinition.UpdateCounter(effect.CompilationParameters); } UpdateLevels(effectInstance); updater.UpdateCounters(effectInstance.UpdaterDefinition); }
/// <summary> /// Creates an effect. /// </summary> /// <param name="effectSystem">The effect system.</param> /// <param name="effectName">Name of the effect.</param> /// <returns>A new instance of an effect.</returns> public static Effect LoadEffect(this EffectSystem effectSystem, string effectName) { var compilerParameters = new CompilerParameters(); return(effectSystem.LoadEffect(effectName, compilerParameters)); }