UserLutComponent.cs 1.5 KB

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