説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BlockNodeTests.cs 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System.Collections.Generic;
  2. using NUnit.Framework;
  3. using UnityEngine;
  4. using UnityEditor.Graphing;
  5. using UnityEditor.ShaderGraph.Internal;
  6. namespace UnityEditor.ShaderGraph.UnitTests
  7. {
  8. [TestFixture]
  9. class BlockNodeTests
  10. {
  11. static BlockFieldDescriptor s_DescriptorA = new BlockFieldDescriptor("Test", "BlockA", string.Empty, new FloatControl(0.5f), ShaderStage.Fragment, true);
  12. static BlockFieldDescriptor s_DescriptorB = new BlockFieldDescriptor("Test", "BlockB", string.Empty, new NormalControl(CoordinateSpace.World), ShaderStage.Fragment, true);
  13. static Vector3MaterialSlot s_MaterialSlot = new Vector3MaterialSlot(0, "Test", "BlockB", SlotType.Input, Vector3.one);
  14. static CustomSlotBlockFieldDescriptor s_CustomSlotDescriptor = new CustomSlotBlockFieldDescriptor("Test", "CustomBlock", string.Empty,
  15. () => { return new Vector3MaterialSlot(0, "Test", "BlockB", SlotType.Input, Vector3.one); });
  16. [OneTimeSetUp]
  17. public void RunBeforeAnyTests()
  18. {
  19. Debug.unityLogger.logHandler = new ConsoleLogHandler();
  20. }
  21. [Test]
  22. public void CanGatherBlockDescriptors()
  23. {
  24. GraphData graph = new GraphData();
  25. graph.AddContexts();
  26. Assert.IsNotNull(graph.blockFieldDescriptors);
  27. Assert.AreNotEqual(0, graph.blockFieldDescriptors.Count);
  28. }
  29. [Test]
  30. public void CanInitializeBlockNode()
  31. {
  32. var node = new BlockNode();
  33. node.Init(s_DescriptorA);
  34. Assert.IsNotNull(node.descriptor);
  35. Assert.AreEqual(s_DescriptorA, node.descriptor);
  36. Assert.AreEqual("Test.BlockA", $"{node.descriptor.tag}.{node.descriptor.name}");
  37. }
  38. [Test]
  39. public void CanCreateSlotFromBlockDescriptor()
  40. {
  41. var node = new BlockNode();
  42. node.Init(s_DescriptorA);
  43. List<MaterialSlot> slots = new List<MaterialSlot>();
  44. node.GetSlots(slots);
  45. Assert.IsNotNull(slots);
  46. Assert.AreEqual(1, slots.Count);
  47. var vector3Slot = slots[0] as Vector1MaterialSlot;
  48. Assert.IsNotNull(vector3Slot);
  49. Assert.AreEqual(0, vector3Slot.id);
  50. Assert.AreEqual(s_DescriptorA.displayName, vector3Slot.RawDisplayName());
  51. Assert.AreEqual(s_DescriptorA.name, vector3Slot.shaderOutputName);
  52. Assert.AreEqual(SlotType.Input, vector3Slot.slotType);
  53. Assert.AreEqual(((FloatControl)s_DescriptorA.control).value, vector3Slot.value);
  54. Assert.AreEqual(s_DescriptorA.shaderStage.GetShaderStageCapability(), vector3Slot.stageCapability);
  55. }
  56. [Test]
  57. public void CanCreateSlotFromCustomSlotBlockDescriptor()
  58. {
  59. var node = new BlockNode();
  60. node.Init(s_CustomSlotDescriptor);
  61. List<MaterialSlot> slots = new List<MaterialSlot>();
  62. node.GetSlots(slots);
  63. Assert.IsNotNull(slots);
  64. Assert.AreEqual(1, slots.Count);
  65. Assert.AreNotEqual(s_MaterialSlot, slots[0]); //We actually WANT to create a new slot in this case
  66. Assert.AreEqual(s_MaterialSlot.displayName, slots[0].displayName);
  67. Assert.AreEqual(s_MaterialSlot.valueType, slots[0].valueType);
  68. Assert.AreEqual(s_MaterialSlot.value, ((Vector3MaterialSlot)slots[0]).value);
  69. }
  70. [Test]
  71. public void CanGetRequirementsFromBlockNode()
  72. {
  73. var node = new BlockNode();
  74. node.Init(s_DescriptorB);
  75. var iMayRequireNormals = node as IMayRequireNormal;
  76. Assert.IsNotNull(iMayRequireNormals);
  77. var neededCoordinateSpace = iMayRequireNormals.RequiresNormal(ShaderStageCapability.Fragment);
  78. Assert.AreEqual(NeededCoordinateSpace.World, neededCoordinateSpace);
  79. }
  80. [Test]
  81. public void CanSerializeDescriptor()
  82. {
  83. var node = new BlockNode();
  84. node.Init(s_DescriptorA);
  85. node.OnBeforeSerialize();
  86. Assert.AreEqual("Test.BlockA", node.serializedDescriptor);
  87. }
  88. [Test]
  89. public void CanGetBlockIndex()
  90. {
  91. GraphData graph = new GraphData();
  92. graph.AddContexts();
  93. var node = new BlockNode();
  94. node.Init(s_DescriptorA);
  95. graph.AddBlock(node, graph.fragmentContext, 0);
  96. Assert.AreEqual(0, node.index);
  97. }
  98. }
  99. }