Light2DBlendStyle.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using UnityEngine.Scripting.APIUpdating;
  3. namespace UnityEngine.Rendering.Universal
  4. {
  5. /// <summary>
  6. /// Controls how the light texture is used when rendering Sprites and other 2D renderers.
  7. /// </summary>
  8. [Serializable]
  9. [MovedFrom("UnityEngine.Experimental.Rendering.Universal")]
  10. public struct Light2DBlendStyle
  11. {
  12. internal enum TextureChannel
  13. {
  14. None = 0,
  15. R = 1,
  16. G = 2,
  17. B = 3,
  18. A = 4,
  19. OneMinusR = 5,
  20. OneMinusG = 6,
  21. OneMinusB = 7,
  22. OneMinusA = 8
  23. }
  24. internal struct MaskChannelFilter
  25. {
  26. public Vector4 mask { get; private set; }
  27. public Vector4 inverted { get; private set; }
  28. public MaskChannelFilter(Vector4 m, Vector4 i)
  29. {
  30. mask = m;
  31. inverted = i;
  32. }
  33. }
  34. internal enum BlendMode
  35. {
  36. Additive = 0,
  37. Multiply = 1,
  38. Subtractive = 2
  39. }
  40. [Serializable]
  41. internal struct BlendFactors
  42. {
  43. public float multiplicative;
  44. public float additive;
  45. }
  46. /// <summary>
  47. /// Returns the name of the blend style
  48. /// </summary>
  49. public string name;
  50. [SerializeField]
  51. internal TextureChannel maskTextureChannel;
  52. [SerializeField]
  53. internal BlendMode blendMode;
  54. internal Vector2 blendFactors
  55. {
  56. get
  57. {
  58. var result = new Vector2();
  59. switch (blendMode)
  60. {
  61. case BlendMode.Additive:
  62. result.x = 0.0f;
  63. result.y = 1.0f;
  64. break;
  65. case BlendMode.Multiply:
  66. result.x = 1.0f;
  67. result.y = 0.0f;
  68. break;
  69. case BlendMode.Subtractive:
  70. result.x = 0.0f;
  71. result.y = -1.0f;
  72. break;
  73. default:
  74. result.x = 1.0f;
  75. result.y = 0.0f;
  76. break;
  77. }
  78. return result;
  79. }
  80. }
  81. internal MaskChannelFilter maskTextureChannelFilter
  82. {
  83. get
  84. {
  85. switch (maskTextureChannel)
  86. {
  87. case TextureChannel.R:
  88. return new MaskChannelFilter(new Vector4(1, 0, 0, 0), new Vector4(0, 0, 0, 0));
  89. case TextureChannel.OneMinusR:
  90. return new MaskChannelFilter(new Vector4(1, 0, 0, 0), new Vector4(1, 0, 0, 0));
  91. case TextureChannel.G:
  92. return new MaskChannelFilter(new Vector4(0, 1, 0, 0), new Vector4(0, 0, 0, 0));
  93. case TextureChannel.OneMinusG:
  94. return new MaskChannelFilter(new Vector4(0, 1, 0, 0), new Vector4(0, 1, 0, 0));
  95. case TextureChannel.B:
  96. return new MaskChannelFilter(new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 0));
  97. case TextureChannel.OneMinusB:
  98. return new MaskChannelFilter(new Vector4(0, 0, 1, 0), new Vector4(0, 0, 1, 0));
  99. case TextureChannel.A:
  100. return new MaskChannelFilter(new Vector4(0, 0, 0, 1), new Vector4(0, 0, 0, 0));
  101. case TextureChannel.OneMinusA:
  102. return new MaskChannelFilter(new Vector4(0, 0, 0, 1), new Vector4(0, 0, 0, 1));
  103. case TextureChannel.None:
  104. default:
  105. return new MaskChannelFilter(Vector4.zero, Vector4.zero);
  106. }
  107. }
  108. }
  109. // Transient data
  110. internal bool isDirty { get; set; }
  111. internal bool hasRenderTarget { get; set; }
  112. internal RenderTargetHandle renderTargetHandle;
  113. }
  114. }