protected override void OnAssetPropertyChanged(string propertyName, IGraphNode node, NodeIndex index, object oldValue, object newValue) { base.OnAssetPropertyChanged(propertyName, node, index, oldValue, newValue); var memberNode = node as IMemberNode; if (memberNode != null && !PropertyGraph.UpdatingPropertyFromBase && !UndoRedoService.UndoRedoInProgress) { // If Dither changed, clamp Quality to the new valid range // Note: other part of the behavior is in GraphicsCompositorAssetNodeUpdater (hide Quality if Dither set to None) // TODO: This should be moved to FXAA-specific code to be plugin-ready (asset property changed works only at asset level) var ownerNode = memberNode.Parent; if (typeof(FXAAEffect).IsAssignableFrom(ownerNode.Type) && propertyName == nameof(FXAAEffect.Dither)) { var qualityNode = ownerNode[nameof(FXAAEffect.Quality)]; var dither = (FXAAEffect.DitherType)memberNode.Retrieve(); // Get new valid quality range var(minQuality, maxQuality) = FXAAEffect.GetQualityRange(dither); // Clamp and set it back (if different) var quality = (int)qualityNode.Retrieve(); if (quality < minQuality) { qualityNode.Update(minQuality); } else if (quality > maxQuality) { qualityNode.Update(maxQuality); } } } }
public override void UpdateNode(INodePresenter node) { // Adjust Quality range depending on Dither mode // Note: other part of the behavior is in GraphicsCompositorViewModel.OnAssetPropertyChanged (clamp Quality based on Dither) var fxaaEffect = node.Value as FXAAEffect; if (fxaaEffect != null) { var ditherNode = node[nameof(FXAAEffect.Dither)]; // If dither type changes, we will need to update quality sliders again node.AddDependency(ditherNode, false); // Adjust quality range according to dither level var(minQuality, maxQuality) = FXAAEffect.GetQualityRange(fxaaEffect.Dither); node[nameof(FXAAEffect.Quality)].AttachedProperties[NumericData.MinimumKey] = minQuality; node[nameof(FXAAEffect.Quality)].AttachedProperties[NumericData.MaximumKey] = maxQuality; // FXAA: Hide Quality if Dither is set to None (only 9 is a valid value) if (fxaaEffect.Dither == FXAAEffect.DitherType.None) { node[nameof(FXAAEffect.Quality)].IsVisible = false; } } }
private void CreateEffect() { Viewport viewport = _graphicsDevice.Viewport; try // try to create a 9_3 shader. { fxaaGreenLumaLowEffect = new FXAAGreenLumaLowEffect(_graphicsDevice); SetEffectParameters(fxaaGreenLumaLowEffect, 0.5f, viewport); } catch (Exception ex1) { } #if (WINDOWS || W8_1 || W10) try { if (_graphicsDevice.GraphicsProfile >= GraphicsProfile.HiDef) { fxaaGreenLumaMediumEffect = new FXAAGreenLumaMediumEffect(_graphicsDevice); fxaaGreenLumaHighEffect = new FXAAGreenLumaHighEffect(_graphicsDevice); SetEffectParameters(fxaaGreenLumaMediumEffect, 0.5f, viewport); SetEffectParameters(fxaaGreenLumaHighEffect, 0.5f, viewport); } } catch (Exception ex2) {} #endif return; }
public void DrawRenderTarget(int antiAliasingLevel, Viewport viewport, bool clearRenderTarget) { FXAAEffect fxaaEffect = fxaaGreenLumaLowEffect; #if (WINDOWS || W8_1 || W10) if (antiAliasingLevel == 1) { fxaaEffect = fxaaGreenLumaLowEffect; } if (antiAliasingLevel == 2) { fxaaEffect = fxaaGreenLumaMediumEffect; } if (antiAliasingLevel == 3) { fxaaEffect = fxaaGreenLumaHighEffect; } #endif fxaaEffect.AntialiasingEnabled = (antiAliasingLevel != 0); if (clearRenderTarget) { _graphicsDevice.SetRenderTarget(null); } Rectangle srcRect; srcRect = new Rectangle(0, 0, (int)(_renderTarget.Width), (int)(_renderTarget.Height)); Viewport oldViewport = _graphicsDevice.Viewport; _graphicsDevice.Viewport = viewport; Rectangle destRect = new Rectangle(0, 0, viewport.Width, viewport.Height); fxaaEffect.CurrentTechnique.Passes[0].Apply(); _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearClamp, null, null, fxaaEffect); _spriteBatch.Draw(_renderTarget, destRect, srcRect, Color.White); _spriteBatch.End(); _graphicsDevice.Viewport = oldViewport; }
private void SetEffectParameters(FXAAEffect effect, float N, Viewport viewport) { effect.SetDefaultParameters(viewport.Width, viewport.Height); effect.AntialiasingEnabled = true; }