FxaaComponent.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace UnityEngine.PostProcessing
  2. {
  3. public sealed class FxaaComponent : PostProcessingComponentRenderTexture<AntialiasingModel>
  4. {
  5. static class Uniforms
  6. {
  7. internal static readonly int _QualitySettings = Shader.PropertyToID("_QualitySettings");
  8. internal static readonly int _ConsoleSettings = Shader.PropertyToID("_ConsoleSettings");
  9. }
  10. public override bool active
  11. {
  12. get
  13. {
  14. return model.enabled
  15. && model.settings.method == AntialiasingModel.Method.Fxaa
  16. && !context.interrupted;
  17. }
  18. }
  19. public void Render(RenderTexture source, RenderTexture destination)
  20. {
  21. var settings = model.settings.fxaaSettings;
  22. var material = context.materialFactory.Get("Hidden/Post FX/FXAA");
  23. var qualitySettings = AntialiasingModel.FxaaQualitySettings.presets[(int)settings.preset];
  24. var consoleSettings = AntialiasingModel.FxaaConsoleSettings.presets[(int)settings.preset];
  25. material.SetVector(Uniforms._QualitySettings,
  26. new Vector3(
  27. qualitySettings.subpixelAliasingRemovalAmount,
  28. qualitySettings.edgeDetectionThreshold,
  29. qualitySettings.minimumRequiredLuminance
  30. )
  31. );
  32. material.SetVector(Uniforms._ConsoleSettings,
  33. new Vector4(
  34. consoleSettings.subpixelSpreadAmount,
  35. consoleSettings.edgeSharpnessAmount,
  36. consoleSettings.edgeDetectionThreshold,
  37. consoleSettings.minimumRequiredLuminance
  38. )
  39. );
  40. Graphics.Blit(source, destination, material, 0);
  41. }
  42. }
  43. }