暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CodeFunctionNode.cs 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using JetBrains.Annotations;
  6. using UnityEngine;
  7. using UnityEditor.Graphing;
  8. using UnityEditor.ShaderGraph.Internal;
  9. namespace UnityEditor.ShaderGraph
  10. {
  11. abstract class CodeFunctionNode : AbstractMaterialNode
  12. , IGeneratesBodyCode
  13. , IGeneratesFunction
  14. , IMayRequireNormal
  15. , IMayRequireTangent
  16. , IMayRequireBitangent
  17. , IMayRequireMeshUV
  18. , IMayRequireScreenPosition
  19. , IMayRequireNDCPosition
  20. , IMayRequirePixelPosition
  21. , IMayRequireViewDirection
  22. , IMayRequirePosition
  23. , IMayRequirePositionPredisplacement
  24. , IMayRequireVertexColor
  25. {
  26. [NonSerialized]
  27. private List<SlotAttribute> m_Slots = new List<SlotAttribute>();
  28. public override bool hasPreview
  29. {
  30. get { return true; }
  31. }
  32. protected CodeFunctionNode()
  33. {
  34. UpdateNodeAfterDeserialization();
  35. }
  36. protected struct Boolean
  37. { }
  38. protected struct Vector1
  39. { }
  40. protected struct Texture2D
  41. { }
  42. protected struct Texture2DArray
  43. { }
  44. protected struct Texture3D
  45. { }
  46. protected struct SamplerState
  47. { }
  48. protected struct Gradient
  49. { }
  50. protected struct DynamicDimensionVector
  51. { }
  52. protected struct ColorRGBA
  53. { }
  54. protected struct ColorRGB
  55. { }
  56. protected struct Matrix3x3
  57. { }
  58. protected struct Matrix2x2
  59. { }
  60. protected struct DynamicDimensionMatrix
  61. { }
  62. protected struct PropertyConnectionState
  63. { }
  64. protected enum Binding
  65. {
  66. None,
  67. ObjectSpaceNormal,
  68. ObjectSpaceTangent,
  69. ObjectSpaceBitangent,
  70. ObjectSpacePosition,
  71. ViewSpaceNormal,
  72. ViewSpaceTangent,
  73. ViewSpaceBitangent,
  74. ViewSpacePosition,
  75. WorldSpaceNormal,
  76. WorldSpaceTangent,
  77. WorldSpaceBitangent,
  78. WorldSpacePosition,
  79. TangentSpaceNormal,
  80. TangentSpaceTangent,
  81. TangentSpaceBitangent,
  82. TangentSpacePosition,
  83. MeshUV0,
  84. MeshUV1,
  85. MeshUV2,
  86. MeshUV3,
  87. ScreenPosition,
  88. ObjectSpaceViewDirection,
  89. ViewSpaceViewDirection,
  90. WorldSpaceViewDirection,
  91. TangentSpaceViewDirection,
  92. VertexColor,
  93. }
  94. [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
  95. protected class SlotAttribute : Attribute
  96. {
  97. public int slotId { get; private set; }
  98. public Binding binding { get; private set; }
  99. public bool hidden { get; private set; }
  100. public Vector4? defaultValue { get; private set; }
  101. public ShaderStageCapability stageCapability { get; private set; }
  102. public SlotAttribute(int mSlotId, Binding mImplicitBinding, ShaderStageCapability mStageCapability = ShaderStageCapability.All)
  103. {
  104. slotId = mSlotId;
  105. binding = mImplicitBinding;
  106. defaultValue = null;
  107. stageCapability = mStageCapability;
  108. }
  109. public SlotAttribute(int mSlotId, Binding mImplicitBinding, bool mHidden, ShaderStageCapability mStageCapability = ShaderStageCapability.All)
  110. {
  111. slotId = mSlotId;
  112. binding = mImplicitBinding;
  113. hidden = mHidden;
  114. defaultValue = null;
  115. stageCapability = mStageCapability;
  116. }
  117. public SlotAttribute(int mSlotId, Binding mImplicitBinding, float defaultX, float defaultY, float defaultZ, float defaultW, ShaderStageCapability mStageCapability = ShaderStageCapability.All)
  118. {
  119. slotId = mSlotId;
  120. binding = mImplicitBinding;
  121. defaultValue = new Vector4(defaultX, defaultY, defaultZ, defaultW);
  122. stageCapability = mStageCapability;
  123. }
  124. }
  125. protected abstract MethodInfo GetFunctionToConvert();
  126. private static SlotValueType ConvertTypeToSlotValueType(ParameterInfo p)
  127. {
  128. Type t = p.ParameterType;
  129. if (p.ParameterType.IsByRef)
  130. t = p.ParameterType.GetElementType();
  131. if (t == typeof(Boolean))
  132. {
  133. return SlotValueType.Boolean;
  134. }
  135. if (t == typeof(Vector1))
  136. {
  137. return SlotValueType.Vector1;
  138. }
  139. if (t == typeof(Vector2))
  140. {
  141. return SlotValueType.Vector2;
  142. }
  143. if (t == typeof(Vector3))
  144. {
  145. return SlotValueType.Vector3;
  146. }
  147. if (t == typeof(Vector4))
  148. {
  149. return SlotValueType.Vector4;
  150. }
  151. if (t == typeof(Color))
  152. {
  153. return SlotValueType.Vector4;
  154. }
  155. if (t == typeof(ColorRGBA))
  156. {
  157. return SlotValueType.Vector4;
  158. }
  159. if (t == typeof(ColorRGB))
  160. {
  161. return SlotValueType.Vector3;
  162. }
  163. if (t == typeof(Texture2D))
  164. {
  165. return SlotValueType.Texture2D;
  166. }
  167. if (t == typeof(Texture2DArray))
  168. {
  169. return SlotValueType.Texture2DArray;
  170. }
  171. if (t == typeof(Texture3D))
  172. {
  173. return SlotValueType.Texture3D;
  174. }
  175. if (t == typeof(Cubemap))
  176. {
  177. return SlotValueType.Cubemap;
  178. }
  179. if (t == typeof(Gradient))
  180. {
  181. return SlotValueType.Gradient;
  182. }
  183. if (t == typeof(SamplerState))
  184. {
  185. return SlotValueType.SamplerState;
  186. }
  187. if (t == typeof(DynamicDimensionVector))
  188. {
  189. return SlotValueType.DynamicVector;
  190. }
  191. if (t == typeof(Matrix4x4))
  192. {
  193. return SlotValueType.Matrix4;
  194. }
  195. if (t == typeof(Matrix3x3))
  196. {
  197. return SlotValueType.Matrix3;
  198. }
  199. if (t == typeof(Matrix2x2))
  200. {
  201. return SlotValueType.Matrix2;
  202. }
  203. if (t == typeof(DynamicDimensionMatrix))
  204. {
  205. return SlotValueType.DynamicMatrix;
  206. }
  207. if (t == typeof(PropertyConnectionState))
  208. {
  209. return SlotValueType.PropertyConnectionState;
  210. }
  211. throw new ArgumentException("Unsupported type " + t);
  212. }
  213. public sealed override void UpdateNodeAfterDeserialization()
  214. {
  215. var method = GetFunctionToConvert();
  216. if (method == null)
  217. throw new ArgumentException("Mapped method is null on node" + this);
  218. if (method.ReturnType != typeof(string))
  219. throw new ArgumentException("Mapped function should return string");
  220. // validate no duplicates
  221. var slotAtributes = method.GetParameters().Select(GetSlotAttribute).ToList();
  222. if (slotAtributes.Any(x => x == null))
  223. throw new ArgumentException("Missing SlotAttribute on " + method.Name);
  224. if (slotAtributes.GroupBy(x => x.slotId).Any(x => x.Count() > 1))
  225. throw new ArgumentException("Duplicate SlotAttribute on " + method.Name);
  226. List<MaterialSlot> slots = new List<MaterialSlot>();
  227. foreach (var par in method.GetParameters())
  228. {
  229. var attribute = GetSlotAttribute(par);
  230. var name = GraphUtil.ConvertCamelCase(par.Name, true);
  231. MaterialSlot s;
  232. if (attribute.binding == Binding.None && !par.IsOut && par.ParameterType == typeof(Color))
  233. s = new ColorRGBAMaterialSlot(attribute.slotId, name, par.Name, SlotType.Input, attribute.defaultValue ?? Vector4.zero, stageCapability: attribute.stageCapability, hidden: attribute.hidden);
  234. else if (attribute.binding == Binding.None && !par.IsOut && par.ParameterType == typeof(ColorRGBA))
  235. s = new ColorRGBAMaterialSlot(attribute.slotId, name, par.Name, SlotType.Input, attribute.defaultValue ?? Vector4.zero, stageCapability: attribute.stageCapability, hidden: attribute.hidden);
  236. else if (attribute.binding == Binding.None && !par.IsOut && par.ParameterType == typeof(ColorRGB))
  237. s = new ColorRGBMaterialSlot(attribute.slotId, name, par.Name, SlotType.Input, attribute.defaultValue ?? Vector4.zero, ColorMode.Default, stageCapability: attribute.stageCapability, hidden: attribute.hidden);
  238. else if (attribute.binding == Binding.None || par.IsOut)
  239. s = MaterialSlot.CreateMaterialSlot(
  240. ConvertTypeToSlotValueType(par),
  241. attribute.slotId,
  242. name,
  243. par.Name,
  244. par.IsOut ? SlotType.Output : SlotType.Input,
  245. attribute.defaultValue ?? Vector4.zero,
  246. shaderStageCapability: attribute.stageCapability,
  247. hidden: attribute.hidden);
  248. else
  249. s = CreateBoundSlot(attribute.binding, attribute.slotId, name, par.Name, attribute.stageCapability, attribute.hidden);
  250. slots.Add(s);
  251. m_Slots.Add(attribute);
  252. }
  253. foreach (var slot in slots)
  254. {
  255. AddSlot(slot);
  256. }
  257. RemoveSlotsNameNotMatching(slots.Select(x => x.id), true);
  258. }
  259. private static MaterialSlot CreateBoundSlot(Binding attributeBinding, int slotId, string displayName, string shaderOutputName, ShaderStageCapability shaderStageCapability, bool hidden = false)
  260. {
  261. switch (attributeBinding)
  262. {
  263. case Binding.ObjectSpaceNormal:
  264. return new NormalMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object, shaderStageCapability, hidden);
  265. case Binding.ObjectSpaceTangent:
  266. return new TangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object, shaderStageCapability, hidden);
  267. case Binding.ObjectSpaceBitangent:
  268. return new BitangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object, shaderStageCapability, hidden);
  269. case Binding.ObjectSpacePosition:
  270. return new PositionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object, shaderStageCapability, hidden);
  271. case Binding.ViewSpaceNormal:
  272. return new NormalMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View, shaderStageCapability, hidden);
  273. case Binding.ViewSpaceTangent:
  274. return new TangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View, shaderStageCapability, hidden);
  275. case Binding.ViewSpaceBitangent:
  276. return new BitangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View, shaderStageCapability, hidden);
  277. case Binding.ViewSpacePosition:
  278. return new PositionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View, shaderStageCapability, hidden);
  279. case Binding.WorldSpaceNormal:
  280. return new NormalMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World, shaderStageCapability, hidden);
  281. case Binding.WorldSpaceTangent:
  282. return new TangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World, shaderStageCapability, hidden);
  283. case Binding.WorldSpaceBitangent:
  284. return new BitangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World, shaderStageCapability, hidden);
  285. case Binding.WorldSpacePosition:
  286. return new PositionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World, shaderStageCapability, hidden);
  287. case Binding.TangentSpaceNormal:
  288. return new NormalMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent, shaderStageCapability, hidden);
  289. case Binding.TangentSpaceTangent:
  290. return new TangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent, shaderStageCapability, hidden);
  291. case Binding.TangentSpaceBitangent:
  292. return new BitangentMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent, shaderStageCapability, hidden);
  293. case Binding.TangentSpacePosition:
  294. return new PositionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent, shaderStageCapability, hidden);
  295. case Binding.MeshUV0:
  296. return new UVMaterialSlot(slotId, displayName, shaderOutputName, UVChannel.UV0, shaderStageCapability, hidden);
  297. case Binding.MeshUV1:
  298. return new UVMaterialSlot(slotId, displayName, shaderOutputName, UVChannel.UV1, shaderStageCapability, hidden);
  299. case Binding.MeshUV2:
  300. return new UVMaterialSlot(slotId, displayName, shaderOutputName, UVChannel.UV2, shaderStageCapability, hidden);
  301. case Binding.MeshUV3:
  302. return new UVMaterialSlot(slotId, displayName, shaderOutputName, UVChannel.UV3, shaderStageCapability, hidden);
  303. case Binding.ScreenPosition:
  304. return new ScreenPositionMaterialSlot(slotId, displayName, shaderOutputName, ScreenSpaceType.Default, shaderStageCapability, hidden);
  305. case Binding.ObjectSpaceViewDirection:
  306. return new ViewDirectionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Object, shaderStageCapability, hidden);
  307. case Binding.ViewSpaceViewDirection:
  308. return new ViewDirectionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.View, shaderStageCapability, hidden);
  309. case Binding.WorldSpaceViewDirection:
  310. return new ViewDirectionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.World, shaderStageCapability, hidden);
  311. case Binding.TangentSpaceViewDirection:
  312. return new ViewDirectionMaterialSlot(slotId, displayName, shaderOutputName, CoordinateSpace.Tangent, shaderStageCapability, hidden);
  313. case Binding.VertexColor:
  314. return new VertexColorMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden);
  315. default:
  316. throw new ArgumentOutOfRangeException("attributeBinding", attributeBinding, null);
  317. }
  318. }
  319. public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
  320. {
  321. using (var tempSlots = PooledList<MaterialSlot>.Get())
  322. {
  323. GetOutputSlots(tempSlots);
  324. foreach (var outSlot in tempSlots)
  325. {
  326. sb.AppendLine(outSlot.concreteValueType.ToShaderString(PrecisionUtil.Token) + " " + GetVariableNameForSlot(outSlot.id) + ";");
  327. }
  328. string call = GetFunctionName() + "(";
  329. bool first = true;
  330. tempSlots.Clear();
  331. GetSlots(tempSlots);
  332. tempSlots.Sort((slot1, slot2) => slot1.id.CompareTo(slot2.id));
  333. foreach (var slot in tempSlots)
  334. {
  335. if (!first)
  336. {
  337. call += ", ";
  338. }
  339. first = false;
  340. if (slot.isInputSlot)
  341. call += GetSlotValue(slot.id, generationMode);
  342. else
  343. call += GetVariableNameForSlot(slot.id);
  344. }
  345. call += ");";
  346. sb.AppendLine(call);
  347. }
  348. }
  349. private string GetFunctionName()
  350. {
  351. var function = GetFunctionToConvert();
  352. return function.Name + (function.IsStatic ? string.Empty : "_" + objectId) + "_$precision"
  353. + (this.GetSlots<DynamicVectorMaterialSlot>().Select(s => NodeUtils.GetSlotDimension(s.concreteValueType)).FirstOrDefault() ?? "")
  354. + (this.GetSlots<DynamicMatrixMaterialSlot>().Select(s => NodeUtils.GetSlotDimension(s.concreteValueType)).FirstOrDefault() ?? "");
  355. }
  356. private string GetFunctionHeader()
  357. {
  358. string header = "void " + GetFunctionName() + "(";
  359. using (var tempSlots = PooledList<MaterialSlot>.Get())
  360. {
  361. GetSlots(tempSlots);
  362. tempSlots.Sort((slot1, slot2) => slot1.id.CompareTo(slot2.id));
  363. var first = true;
  364. foreach (var slot in tempSlots)
  365. {
  366. if (!first)
  367. header += ", ";
  368. first = false;
  369. if (slot.isOutputSlot)
  370. header += "out ";
  371. // always use generic precisions for parameters, they will get concretized by the system
  372. header += slot.concreteValueType.ToShaderString(PrecisionUtil.Token) + " " + slot.shaderOutputName;
  373. }
  374. header += ")";
  375. }
  376. return header;
  377. }
  378. private static object GetDefault(Type type)
  379. {
  380. return type.IsValueType ? Activator.CreateInstance(type) : null;
  381. }
  382. private string GetFunctionBody(MethodInfo info)
  383. {
  384. var args = new List<object>();
  385. foreach (var param in info.GetParameters())
  386. args.Add(GetDefault(param.ParameterType));
  387. var result = info.Invoke(this, args.ToArray()) as string;
  388. if (string.IsNullOrEmpty(result))
  389. return string.Empty;
  390. // stomp any newline differences that might try to sneak in via this path
  391. result = result.Replace("\r\n", "\n");
  392. using (var tempSlots = PooledList<MaterialSlot>.Get())
  393. {
  394. GetSlots(tempSlots);
  395. foreach (var slot in tempSlots)
  396. {
  397. var toReplace = string.Format("{{slot{0}dimension}}", slot.id);
  398. var replacement = NodeUtils.GetSlotDimension(slot.concreteValueType);
  399. result = result.Replace(toReplace, replacement);
  400. }
  401. }
  402. return result;
  403. }
  404. public virtual void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
  405. {
  406. registry.ProvideFunction(GetFunctionName(), s =>
  407. {
  408. s.AppendLine(GetFunctionHeader());
  409. var functionBody = GetFunctionBody(GetFunctionToConvert());
  410. var lines = functionBody.Trim('\r', '\n', '\t', ' ');
  411. s.AppendLines(lines);
  412. });
  413. }
  414. private static SlotAttribute GetSlotAttribute([NotNull] ParameterInfo info)
  415. {
  416. var attrs = info.GetCustomAttributes(typeof(SlotAttribute), false).OfType<SlotAttribute>().ToList();
  417. return attrs.FirstOrDefault();
  418. }
  419. public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability)
  420. {
  421. var binding = NeededCoordinateSpace.None;
  422. using (var tempSlots = PooledList<MaterialSlot>.Get())
  423. {
  424. GetInputSlots(tempSlots);
  425. foreach (var slot in tempSlots)
  426. binding |= slot.RequiresNormal();
  427. return binding;
  428. }
  429. }
  430. public NeededCoordinateSpace RequiresViewDirection(ShaderStageCapability stageCapability)
  431. {
  432. var binding = NeededCoordinateSpace.None;
  433. using (var tempSlots = PooledList<MaterialSlot>.Get())
  434. {
  435. GetInputSlots(tempSlots);
  436. foreach (var slot in tempSlots)
  437. binding |= slot.RequiresViewDirection();
  438. return binding;
  439. }
  440. }
  441. public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability)
  442. {
  443. using (var tempSlots = PooledList<MaterialSlot>.Get())
  444. {
  445. GetInputSlots(tempSlots);
  446. var binding = NeededCoordinateSpace.None;
  447. foreach (var slot in tempSlots)
  448. binding |= slot.RequiresPosition();
  449. return binding;
  450. }
  451. }
  452. public NeededCoordinateSpace RequiresPositionPredisplacement(ShaderStageCapability stageCapability)
  453. {
  454. using (var tempSlots = PooledList<MaterialSlot>.Get())
  455. {
  456. GetInputSlots(tempSlots);
  457. var binding = NeededCoordinateSpace.None;
  458. foreach (var slot in tempSlots)
  459. binding |= slot.RequiresPositionPredisplacement();
  460. return binding;
  461. }
  462. }
  463. public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability)
  464. {
  465. using (var tempSlots = PooledList<MaterialSlot>.Get())
  466. {
  467. GetInputSlots(tempSlots);
  468. var binding = NeededCoordinateSpace.None;
  469. foreach (var slot in tempSlots)
  470. binding |= slot.RequiresTangent();
  471. return binding;
  472. }
  473. }
  474. public NeededCoordinateSpace RequiresBitangent(ShaderStageCapability stageCapability)
  475. {
  476. using (var tempSlots = PooledList<MaterialSlot>.Get())
  477. {
  478. GetInputSlots(tempSlots);
  479. var binding = NeededCoordinateSpace.None;
  480. foreach (var slot in tempSlots)
  481. binding |= slot.RequiresBitangent();
  482. return binding;
  483. }
  484. }
  485. public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
  486. {
  487. using (var tempSlots = PooledList<MaterialSlot>.Get())
  488. {
  489. GetInputSlots(tempSlots);
  490. foreach (var slot in tempSlots)
  491. {
  492. if (slot.RequiresMeshUV(channel))
  493. return true;
  494. }
  495. return false;
  496. }
  497. }
  498. public bool RequiresScreenPosition(ShaderStageCapability stageCapability)
  499. {
  500. using (var tempSlots = PooledList<MaterialSlot>.Get())
  501. {
  502. GetInputSlots(tempSlots);
  503. foreach (var slot in tempSlots)
  504. {
  505. if (slot.RequiresScreenPosition(stageCapability))
  506. return true;
  507. }
  508. return false;
  509. }
  510. }
  511. public bool RequiresNDCPosition(ShaderStageCapability stageCapability)
  512. {
  513. using (var tempSlots = PooledList<MaterialSlot>.Get())
  514. {
  515. GetInputSlots(tempSlots);
  516. foreach (var slot in tempSlots)
  517. {
  518. if (slot.RequiresNDCPosition(stageCapability))
  519. return true;
  520. }
  521. return false;
  522. }
  523. }
  524. public bool RequiresPixelPosition(ShaderStageCapability stageCapability)
  525. {
  526. using (var tempSlots = PooledList<MaterialSlot>.Get())
  527. {
  528. GetInputSlots(tempSlots);
  529. foreach (var slot in tempSlots)
  530. {
  531. if (slot.RequiresPixelPosition(stageCapability))
  532. return true;
  533. }
  534. return false;
  535. }
  536. }
  537. public bool RequiresVertexColor(ShaderStageCapability stageCapability)
  538. {
  539. using (var tempSlots = PooledList<MaterialSlot>.Get())
  540. {
  541. GetInputSlots(tempSlots);
  542. foreach (var slot in tempSlots)
  543. {
  544. if (slot.RequiresVertexColor())
  545. return true;
  546. }
  547. return false;
  548. }
  549. }
  550. }
  551. }