SpriteUnlitMasterNode.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using UnityEditor.Graphing;
  5. using UnityEditor.ShaderGraph.Drawing;
  6. using UnityEditor.ShaderGraph.Drawing.Controls;
  7. using UnityEngine;
  8. using UnityEngine.UIElements;
  9. using UnityEditor.ShaderGraph;
  10. using UnityEditor.ShaderGraph.Internal;
  11. namespace UnityEditor.Experimental.Rendering.Universal
  12. {
  13. [Serializable]
  14. [Title("Master", "Sprite Unlit (Experimental)")]
  15. [FormerName("UnityEditor.Experimental.Rendering.LWRP.SpriteUnlitMasterNode")]
  16. class SpriteUnlitMasterNode : MasterNode<ISpriteUnlitSubShader>, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent
  17. {
  18. public const string PositionName = "Vertex Position";
  19. public const string NormalName = "Vertex Normal";
  20. public const string TangentName = "Vertex Tangent";
  21. public const string ColorSlotName = "Color";
  22. public const int PositionSlotId = 9;
  23. public const int ColorSlotId = 0;
  24. public const int VertNormalSlotId = 10;
  25. public const int VertTangentSlotId = 11;
  26. public SpriteUnlitMasterNode()
  27. {
  28. UpdateNodeAfterDeserialization();
  29. }
  30. public sealed override void UpdateNodeAfterDeserialization()
  31. {
  32. base.UpdateNodeAfterDeserialization();
  33. name = "Sprite Unlit Master";
  34. AddSlot(new PositionMaterialSlot(PositionSlotId, PositionName, PositionName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
  35. AddSlot(new NormalMaterialSlot(VertNormalSlotId, NormalName, NormalName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
  36. AddSlot(new TangentMaterialSlot(VertTangentSlotId, TangentName, TangentName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
  37. AddSlot(new ColorRGBAMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.white, ShaderStageCapability.Fragment));
  38. RemoveSlotsNameNotMatching(
  39. new[]
  40. {
  41. PositionSlotId,
  42. VertNormalSlotId,
  43. VertTangentSlotId,
  44. ColorSlotId,
  45. });
  46. }
  47. public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability)
  48. {
  49. List<MaterialSlot> slots = new List<MaterialSlot>();
  50. GetSlots(slots);
  51. List<MaterialSlot> validSlots = new List<MaterialSlot>();
  52. for (int i = 0; i < slots.Count; i++)
  53. {
  54. if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability)
  55. continue;
  56. validSlots.Add(slots[i]);
  57. }
  58. return validSlots.OfType<IMayRequireNormal>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability));
  59. }
  60. public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability)
  61. {
  62. List<MaterialSlot> slots = new List<MaterialSlot>();
  63. GetSlots(slots);
  64. List<MaterialSlot> validSlots = new List<MaterialSlot>();
  65. for (int i = 0; i < slots.Count; i++)
  66. {
  67. if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability)
  68. continue;
  69. validSlots.Add(slots[i]);
  70. }
  71. return validSlots.OfType<IMayRequirePosition>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability));
  72. }
  73. public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability)
  74. {
  75. List<MaterialSlot> slots = new List<MaterialSlot>();
  76. GetSlots(slots);
  77. List<MaterialSlot> validSlots = new List<MaterialSlot>();
  78. for (int i = 0; i < slots.Count; i++)
  79. {
  80. if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability)
  81. continue;
  82. validSlots.Add(slots[i]);
  83. }
  84. return validSlots.OfType<IMayRequireTangent>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability));
  85. }
  86. }
  87. }