Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VFXTarget.cs 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #if VFX_GRAPH_10_0_0_OR_NEWER
  2. using System;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.Rendering;
  7. using UnityEngine.UIElements;
  8. using UnityEditor.UIElements;
  9. using UnityEditor.ShaderGraph;
  10. using UnityEditor.ShaderGraph.Drawing;
  11. using UnityEditor.Graphing.Util;
  12. using UnityEditor.ShaderGraph.Internal;
  13. using UnityEditor.ShaderGraph.Legacy;
  14. namespace UnityEditor.ShaderGraph
  15. {
  16. sealed class VFXTarget : Target, ILegacyTarget, IMaySupportVFX, IMayObsolete
  17. {
  18. public const string kVisualEffectTargetListedKey = "VFX.VisualEffectTargetListed";
  19. [SerializeField]
  20. bool m_Lit;
  21. [SerializeField]
  22. bool m_AlphaTest = false;
  23. public VFXTarget()
  24. {
  25. displayName = "Visual Effect (deprecated)";
  26. }
  27. public bool lit
  28. {
  29. get => m_Lit;
  30. set => m_Lit = value;
  31. }
  32. public bool alphaTest
  33. {
  34. get => m_AlphaTest;
  35. set => m_AlphaTest = value;
  36. }
  37. public override bool IsActive() => true;
  38. public override void Setup(ref TargetSetupContext context)
  39. {
  40. }
  41. public override void GetFields(ref TargetFieldContext context)
  42. {
  43. }
  44. public override bool IsNodeAllowedByTarget(Type nodeType)
  45. {
  46. return base.IsNodeAllowedByTarget(nodeType);
  47. }
  48. public override void GetActiveBlocks(ref TargetActiveBlockContext context)
  49. {
  50. context.AddBlock(BlockFields.SurfaceDescription.BaseColor);
  51. context.AddBlock(BlockFields.SurfaceDescription.Alpha);
  52. context.AddBlock(BlockFields.SurfaceDescription.Metallic, lit);
  53. context.AddBlock(BlockFields.SurfaceDescription.Smoothness, lit);
  54. context.AddBlock(BlockFields.SurfaceDescription.NormalTS, lit);
  55. context.AddBlock(BlockFields.SurfaceDescription.Emission);
  56. context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, alphaTest);
  57. }
  58. enum MaterialMode
  59. {
  60. Unlit,
  61. Lit
  62. }
  63. public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
  64. {
  65. context.AddProperty("Material", new EnumField(MaterialMode.Unlit) { value = m_Lit ? MaterialMode.Lit : MaterialMode.Unlit }, evt =>
  66. {
  67. var newLit = (MaterialMode)evt.newValue == MaterialMode.Lit;
  68. if (Equals(m_Lit, newLit))
  69. return;
  70. registerUndo("Change Material Lit");
  71. m_Lit = newLit;
  72. onChange();
  73. });
  74. context.AddProperty("Alpha Clipping", new Toggle() { value = m_AlphaTest }, (evt) =>
  75. {
  76. if (Equals(m_AlphaTest, evt.newValue))
  77. return;
  78. registerUndo("Change Alpha Test");
  79. m_AlphaTest = evt.newValue;
  80. onChange();
  81. });
  82. }
  83. public static Dictionary<BlockFieldDescriptor, int> s_BlockMap = new Dictionary<BlockFieldDescriptor, int>()
  84. {
  85. { BlockFields.SurfaceDescription.BaseColor, ShaderGraphVfxAsset.ColorSlotId },
  86. { BlockFields.SurfaceDescription.Metallic, ShaderGraphVfxAsset.MetallicSlotId },
  87. { BlockFields.SurfaceDescription.Smoothness, ShaderGraphVfxAsset.SmoothnessSlotId },
  88. { BlockFields.SurfaceDescription.NormalTS, ShaderGraphVfxAsset.NormalSlotId },
  89. { BlockFields.SurfaceDescription.Emission, ShaderGraphVfxAsset.EmissiveSlotId },
  90. { BlockFields.SurfaceDescription.Alpha, ShaderGraphVfxAsset.AlphaSlotId },
  91. { BlockFields.SurfaceDescription.AlphaClipThreshold, ShaderGraphVfxAsset.AlphaThresholdSlotId },
  92. };
  93. public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<BlockFieldDescriptor, int> blockMap)
  94. {
  95. blockMap = null;
  96. if (!(masterNode is VisualEffectMasterNode1 vfxMasterNode))
  97. return false;
  98. lit = vfxMasterNode.m_Lit;
  99. alphaTest = vfxMasterNode.m_AlphaTest;
  100. blockMap = new Dictionary<BlockFieldDescriptor, int>();
  101. if (lit)
  102. {
  103. blockMap.Add(BlockFields.SurfaceDescription.BaseColor, ShaderGraphVfxAsset.BaseColorSlotId);
  104. blockMap.Add(BlockFields.SurfaceDescription.Metallic, ShaderGraphVfxAsset.MetallicSlotId);
  105. blockMap.Add(BlockFields.SurfaceDescription.Smoothness, ShaderGraphVfxAsset.SmoothnessSlotId);
  106. blockMap.Add(BlockFields.SurfaceDescription.NormalTS, ShaderGraphVfxAsset.NormalSlotId);
  107. blockMap.Add(BlockFields.SurfaceDescription.Emission, ShaderGraphVfxAsset.EmissiveSlotId);
  108. }
  109. else
  110. {
  111. blockMap.Add(BlockFields.SurfaceDescription.BaseColor, ShaderGraphVfxAsset.ColorSlotId);
  112. }
  113. blockMap.Add(BlockFields.SurfaceDescription.Alpha, ShaderGraphVfxAsset.AlphaSlotId);
  114. if (alphaTest)
  115. {
  116. blockMap.Add(BlockFields.SurfaceDescription.AlphaClipThreshold, ShaderGraphVfxAsset.AlphaThresholdSlotId);
  117. }
  118. return true;
  119. }
  120. public override bool WorksWithSRP(RenderPipelineAsset scriptableRenderPipeline)
  121. {
  122. return GraphicsSettings.currentRenderPipeline != null && scriptableRenderPipeline?.GetType() == GraphicsSettings.currentRenderPipeline.GetType();
  123. }
  124. public bool SupportsVFX() => true;
  125. public bool CanSupportVFX() => true;
  126. public bool IsObsolete()
  127. {
  128. var isObsolete = !EditorPrefs.GetBool(kVisualEffectTargetListedKey, false);
  129. return isObsolete;
  130. }
  131. }
  132. }
  133. #endif