Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

SpriteSubTargetUtility.cs 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Linq;
  3. using UnityEditor.ShaderGraph;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.Rendering.Universal.ShaderGraph
  6. {
  7. internal static class SpriteSubTargetUtility
  8. {
  9. public static void AddDefaultFields(ref TargetFieldContext context, UniversalTarget target)
  10. {
  11. // Only support SpriteColor legacy block if BaseColor/Alpha are not active
  12. var descs = context.blocks.Select(x => x.descriptor);
  13. bool useLegacyBlocks = !descs.Contains(BlockFields.SurfaceDescription.BaseColor) && !descs.Contains(BlockFields.SurfaceDescription.Alpha);
  14. context.AddField(CoreFields.UseLegacySpriteBlocks, useLegacyBlocks);
  15. // Surface Type
  16. context.AddField(UniversalFields.SurfaceTransparent);
  17. context.AddField(Fields.DoubleSided);
  18. // Blend Mode
  19. switch (target.alphaMode)
  20. {
  21. case AlphaMode.Premultiply:
  22. context.AddField(UniversalFields.BlendPremultiply);
  23. break;
  24. case AlphaMode.Additive:
  25. context.AddField(UniversalFields.BlendAdd);
  26. break;
  27. case AlphaMode.Multiply:
  28. context.AddField(UniversalFields.BlendMultiply);
  29. break;
  30. default:
  31. context.AddField(Fields.BlendAlpha);
  32. break;
  33. }
  34. }
  35. public static void GetDefaultActiveBlocks(ref TargetActiveBlockContext context, UniversalTarget target)
  36. {
  37. // Only support SpriteColor legacy block if BaseColor/Alpha are not active
  38. bool useLegacyBlocks = !context.currentBlocks.Contains(BlockFields.SurfaceDescription.BaseColor) && !context.currentBlocks.Contains(BlockFields.SurfaceDescription.Alpha);
  39. context.AddBlock(BlockFields.SurfaceDescriptionLegacy.SpriteColor, useLegacyBlocks);
  40. context.AddBlock(BlockFields.SurfaceDescription.Alpha);
  41. context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, target.alphaClip);
  42. }
  43. public static void AddDefaultPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo, UniversalTarget target)
  44. {
  45. context.AddProperty("Blending Mode", new UnityEngine.UIElements.EnumField(AlphaMode.Alpha) { value = target.alphaMode }, (evt) =>
  46. {
  47. if (Equals(target.alphaMode, evt.newValue))
  48. return;
  49. registerUndo("Change Blend");
  50. target.alphaMode = (AlphaMode)evt.newValue;
  51. onChange();
  52. });
  53. context.AddProperty("Alpha Clipping", new Toggle() { value = target.alphaClip }, (evt) =>
  54. {
  55. if (Equals(target.alphaClip, evt.newValue))
  56. return;
  57. registerUndo("Change Alpha Clip");
  58. target.alphaClip = evt.newValue;
  59. onChange();
  60. });
  61. context.AddProperty("Disable Color Tint", new Toggle() { value = target.disableTint }, (evt) =>
  62. {
  63. if (Equals(target.disableTint, evt.newValue))
  64. return;
  65. registerUndo("Change Disable Tint");
  66. target.disableTint = evt.newValue;
  67. onChange();
  68. });
  69. }
  70. public static void AddAlphaClipControlToPass(ref PassDescriptor pass, UniversalTarget target)
  71. {
  72. if (target.alphaClip)
  73. pass.defines.Add(CoreKeywordDescriptors.AlphaClipThreshold, 1);
  74. }
  75. }
  76. }