VignetteComponent.cs 2.0 KB

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