UserLutComponent.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. namespace UnityEngine.PostProcessing
  3. {
  4. public sealed class UserLutComponent : PostProcessingComponentRenderTexture<UserLutModel>
  5. {
  6. public override bool active
  7. {
  8. get
  9. {
  10. UserLutModel.Settings settings = base.model.settings;
  11. return base.model.enabled && settings.lut != null && settings.contribution > 0f && settings.lut.height == (int)Mathf.Sqrt((float)settings.lut.width) && !this.context.interrupted;
  12. }
  13. }
  14. public override void Prepare(Material uberMaterial)
  15. {
  16. UserLutModel.Settings settings = base.model.settings;
  17. uberMaterial.EnableKeyword("USER_LUT");
  18. uberMaterial.SetTexture(UserLutComponent.Uniforms._UserLut, settings.lut);
  19. uberMaterial.SetVector(UserLutComponent.Uniforms._UserLut_Params, new Vector4(1f / (float)settings.lut.width, 1f / (float)settings.lut.height, (float)settings.lut.height - 1f, settings.contribution));
  20. }
  21. public void OnGUI()
  22. {
  23. UserLutModel.Settings settings = base.model.settings;
  24. Rect position = new Rect(this.context.viewport.x * (float)Screen.width + 8f, 8f, (float)settings.lut.width, (float)settings.lut.height);
  25. GUI.DrawTexture(position, settings.lut);
  26. }
  27. private static class Uniforms
  28. {
  29. internal static readonly int _UserLut = Shader.PropertyToID("_UserLut");
  30. internal static readonly int _UserLut_Params = Shader.PropertyToID("_UserLut_Params");
  31. }
  32. }
  33. }