ViewDirectionNode.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. using UnityEditor.Graphing;
  3. using UnityEditor.ShaderGraph.Internal;
  4. namespace UnityEditor.ShaderGraph
  5. {
  6. [FormerName("UnityEngine.MaterialGraph.ViewDirectionNode")]
  7. [Title("Input", "Geometry", "View Direction")]
  8. class ViewDirectionNode : GeometryNode, IMayRequireViewDirection
  9. {
  10. private const int kOutputSlotId = 0;
  11. public const string kOutputSlotName = "Out";
  12. public ViewDirectionNode()
  13. {
  14. name = "View Direction";
  15. UpdateNodeAfterDeserialization();
  16. }
  17. public sealed override void UpdateNodeAfterDeserialization()
  18. {
  19. AddSlot(new Vector3MaterialSlot(
  20. kOutputSlotId,
  21. kOutputSlotName,
  22. kOutputSlotName,
  23. SlotType.Output,
  24. Vector4.zero));
  25. RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
  26. }
  27. public override string GetVariableNameForSlot(int slotId)
  28. {
  29. return string.Format("IN.{0}", space.ToVariableName(InterpolatorType.ViewDirection));
  30. }
  31. public NeededCoordinateSpace RequiresViewDirection(ShaderStageCapability stageCapability)
  32. {
  33. return space.ToNeededCoordinateSpace();
  34. }
  35. }
  36. }