Light2DBlendStyle.cs 4.2 KB

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