VignetteComponent.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. namespace UnityEngine.PostProcessing
  3. {
  4. public sealed class VignetteComponent : PostProcessingComponentRenderTexture<VignetteModel>
  5. {
  6. public override bool active
  7. {
  8. get
  9. {
  10. return base.model.enabled && !this.context.interrupted;
  11. }
  12. }
  13. public override void Prepare(Material uberMaterial)
  14. {
  15. VignetteModel.Settings settings = base.model.settings;
  16. uberMaterial.SetColor(VignetteComponent.Uniforms._Vignette_Color, settings.color);
  17. if (settings.mode == VignetteModel.Mode.Classic)
  18. {
  19. uberMaterial.SetVector(VignetteComponent.Uniforms._Vignette_Center, settings.center);
  20. uberMaterial.EnableKeyword("VIGNETTE_CLASSIC");
  21. float z = (1f - settings.roundness) * 6f + settings.roundness;
  22. uberMaterial.SetVector(VignetteComponent.Uniforms._Vignette_Settings, new Vector4(settings.intensity * 3f, settings.smoothness * 5f, z, (!settings.rounded) ? 0f : 1f));
  23. }
  24. else if (settings.mode == VignetteModel.Mode.Masked && settings.mask != null && settings.opacity > 0f)
  25. {
  26. uberMaterial.EnableKeyword("VIGNETTE_MASKED");
  27. uberMaterial.SetTexture(VignetteComponent.Uniforms._Vignette_Mask, settings.mask);
  28. uberMaterial.SetFloat(VignetteComponent.Uniforms._Vignette_Opacity, settings.opacity);
  29. }
  30. }
  31. private static class Uniforms
  32. {
  33. internal static readonly int _Vignette_Color = Shader.PropertyToID("_Vignette_Color");
  34. internal static readonly int _Vignette_Center = Shader.PropertyToID("_Vignette_Center");
  35. internal static readonly int _Vignette_Settings = Shader.PropertyToID("_Vignette_Settings");
  36. internal static readonly int _Vignette_Mask = Shader.PropertyToID("_Vignette_Mask");
  37. internal static readonly int _Vignette_Opacity = Shader.PropertyToID("_Vignette_Opacity");
  38. }
  39. }
  40. }