VFXURPLitMeshOutput.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #if HAS_VFX_GRAPH
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace UnityEditor.VFX.URP
  6. {
  7. [VFXInfo]
  8. class VFXURPLitMeshOutput : VFXAbstractParticleURPLitOutput, IVFXMultiMeshOutput
  9. {
  10. public override string name
  11. {
  12. get
  13. {
  14. return !string.IsNullOrEmpty(shaderName)
  15. ? $"Output Particle {shaderName} Mesh"
  16. : "Output Particle URP Lit Mesh";
  17. }
  18. }
  19. public override string codeGeneratorTemplate { get { return RenderPipeTemplate("VFXParticleLitMesh"); } }
  20. public override VFXTaskType taskType { get { return VFXTaskType.ParticleMeshOutput; } }
  21. public override bool supportsUV { get { return GetOrRefreshShaderGraphObject() == null; } }
  22. public override bool implementsMotionVector { get { return true; } }
  23. public override CullMode defaultCullMode { get { return CullMode.Back; } }
  24. [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), Range(1, 4), Tooltip("Specifies the number of different meshes (up to 4). Mesh per particle can be specified with the meshIndex attribute."), SerializeField]
  25. private uint MeshCount = 1;
  26. [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), Tooltip("When enabled, screen space LOD is used to determine with meshIndex to use per particle."), SerializeField]
  27. private bool lod = false;
  28. public uint meshCount => HasStrips(true) ? 1 : MeshCount;
  29. public override VFXOutputUpdate.Features outputUpdateFeatures
  30. {
  31. get
  32. {
  33. VFXOutputUpdate.Features features = base.outputUpdateFeatures;
  34. if (!HasStrips(true)) // TODO make it compatible with strips
  35. {
  36. if (MeshCount > 1)
  37. features |= VFXOutputUpdate.Features.MultiMesh;
  38. if (lod)
  39. features |= VFXOutputUpdate.Features.LOD;
  40. if (HasSorting() && VFXOutputUpdate.HasFeature(features, VFXOutputUpdate.Features.IndirectDraw))
  41. features |= VFXOutputUpdate.Features.Sort;
  42. }
  43. return features;
  44. }
  45. }
  46. public override IEnumerable<VFXAttributeInfo> attributes
  47. {
  48. get
  49. {
  50. yield return new VFXAttributeInfo(VFXAttribute.Position, VFXAttributeMode.Read);
  51. if (colorMode != ColorMode.None)
  52. yield return new VFXAttributeInfo(VFXAttribute.Color, VFXAttributeMode.Read);
  53. yield return new VFXAttributeInfo(VFXAttribute.Alpha, VFXAttributeMode.Read);
  54. yield return new VFXAttributeInfo(VFXAttribute.Alive, VFXAttributeMode.Read);
  55. yield return new VFXAttributeInfo(VFXAttribute.AxisX, VFXAttributeMode.Read);
  56. yield return new VFXAttributeInfo(VFXAttribute.AxisY, VFXAttributeMode.Read);
  57. yield return new VFXAttributeInfo(VFXAttribute.AxisZ, VFXAttributeMode.Read);
  58. yield return new VFXAttributeInfo(VFXAttribute.AngleX, VFXAttributeMode.Read);
  59. yield return new VFXAttributeInfo(VFXAttribute.AngleY, VFXAttributeMode.Read);
  60. yield return new VFXAttributeInfo(VFXAttribute.AngleZ, VFXAttributeMode.Read);
  61. yield return new VFXAttributeInfo(VFXAttribute.PivotX, VFXAttributeMode.Read);
  62. yield return new VFXAttributeInfo(VFXAttribute.PivotY, VFXAttributeMode.Read);
  63. yield return new VFXAttributeInfo(VFXAttribute.PivotZ, VFXAttributeMode.Read);
  64. yield return new VFXAttributeInfo(VFXAttribute.Size, VFXAttributeMode.Read);
  65. yield return new VFXAttributeInfo(VFXAttribute.ScaleX, VFXAttributeMode.Read);
  66. yield return new VFXAttributeInfo(VFXAttribute.ScaleY, VFXAttributeMode.Read);
  67. yield return new VFXAttributeInfo(VFXAttribute.ScaleZ, VFXAttributeMode.Read);
  68. if (usesFlipbook)
  69. yield return new VFXAttributeInfo(VFXAttribute.TexIndex, VFXAttributeMode.Read);
  70. }
  71. }
  72. protected override IEnumerable<VFXPropertyWithValue> inputProperties
  73. {
  74. get
  75. {
  76. foreach (var property in base.inputProperties)
  77. yield return property;
  78. foreach (var property in VFXMultiMeshHelper.GetInputProperties(MeshCount, outputUpdateFeatures))
  79. yield return property;
  80. }
  81. }
  82. protected override IEnumerable<string> filteredOutSettings
  83. {
  84. get
  85. {
  86. foreach (var s in base.filteredOutSettings)
  87. yield return s;
  88. // TODO Add a experimental bool to setting attribute
  89. if (!VFXViewPreference.displayExperimentalOperator)
  90. {
  91. yield return "MeshCount";
  92. yield return "lod";
  93. }
  94. }
  95. }
  96. public override VFXExpressionMapper GetExpressionMapper(VFXDeviceTarget target)
  97. {
  98. var mapper = base.GetExpressionMapper(target);
  99. switch (target)
  100. {
  101. case VFXDeviceTarget.CPU:
  102. {
  103. foreach (var name in VFXMultiMeshHelper.GetCPUExpressionNames(MeshCount))
  104. mapper.AddExpression(inputSlots.First(s => s.name == name).GetExpression(), name, -1);
  105. break;
  106. }
  107. default:
  108. {
  109. break;
  110. }
  111. }
  112. return mapper;
  113. }
  114. }
  115. }
  116. #endif