暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VFXURPLitQuadStripOutput.cs 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #if HAS_VFX_GRAPH
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace UnityEditor.VFX.URP
  6. {
  7. [VFXHelpURL("Context-OutputPrimitive")]
  8. [VFXInfo(name = "Output ParticleStrip|URP Lit|Quad", category = "#3Output Strip", experimental = true)]
  9. class VFXURPLitQuadStripOutput : VFXAbstractParticleURPLitOutput
  10. {
  11. protected VFXURPLitQuadStripOutput() : base(true) {} // strips
  12. public override string name => "Output ParticleStrip".AppendLabel("URP Lit").AppendLabel("Quad");
  13. public override string codeGeneratorTemplate => RenderPipeTemplate("VFXParticleLitPlanarPrimitive");
  14. public override VFXTaskType taskType => VFXTaskType.ParticleQuadOutput;
  15. public override bool supportsUV => true;
  16. [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), SerializeField, Tooltip("When enabled, a Normal Bending Factor slider becomes available in the output which can be used to adjust the curvature of the normals.")]
  17. protected bool normalBending = false;
  18. [VFXSetting, SerializeField, Tooltip("Specifies the way the UVs are interpolated along the strip. They can either be stretched or repeated per segment.")]
  19. private StripTilingMode tilingMode = StripTilingMode.Stretch;
  20. [VFXSetting, SerializeField, Tooltip("When enabled, uvs for the strips are swapped.")]
  21. protected bool swapUV = false;
  22. public class NormalBendingProperties
  23. {
  24. [Range(0, 1), Tooltip("Controls the amount by which the normals will be bent, creating a rounder look.")]
  25. public float normalBendingFactor = 0.1f;
  26. }
  27. public class CustomUVInputProperties
  28. {
  29. [Tooltip("Specifies the texture coordinate value (u or v depending on swap UV being enabled) used along the strip.")]
  30. public float texCoord = 0.0f;
  31. }
  32. protected override IEnumerable<VFXPropertyWithValue> inputProperties
  33. {
  34. get
  35. {
  36. var properties = base.inputProperties;
  37. if (normalBending)
  38. properties = properties.Concat(PropertiesFromType(nameof(NormalBendingProperties)));
  39. if (tilingMode == StripTilingMode.Custom)
  40. properties = properties.Concat(PropertiesFromType(nameof(CustomUVInputProperties)));
  41. return properties;
  42. }
  43. }
  44. public override IEnumerable<VFXAttributeInfo> attributes
  45. {
  46. get
  47. {
  48. yield return new VFXAttributeInfo(VFXAttribute.Position, VFXAttributeMode.Read);
  49. if (colorMode != ColorMode.None)
  50. yield return new VFXAttributeInfo(VFXAttribute.Color, VFXAttributeMode.Read);
  51. yield return new VFXAttributeInfo(VFXAttribute.Alpha, VFXAttributeMode.Read);
  52. yield return new VFXAttributeInfo(VFXAttribute.AxisX, VFXAttributeMode.Read);
  53. yield return new VFXAttributeInfo(VFXAttribute.AxisY, VFXAttributeMode.Read);
  54. yield return new VFXAttributeInfo(VFXAttribute.AxisZ, VFXAttributeMode.Read);
  55. yield return new VFXAttributeInfo(VFXAttribute.AngleX, VFXAttributeMode.Read);
  56. yield return new VFXAttributeInfo(VFXAttribute.AngleY, VFXAttributeMode.Read);
  57. yield return new VFXAttributeInfo(VFXAttribute.AngleZ, VFXAttributeMode.Read);
  58. yield return new VFXAttributeInfo(VFXAttribute.PivotX, VFXAttributeMode.Read);
  59. yield return new VFXAttributeInfo(VFXAttribute.PivotY, VFXAttributeMode.Read);
  60. yield return new VFXAttributeInfo(VFXAttribute.PivotZ, VFXAttributeMode.Read);
  61. yield return new VFXAttributeInfo(VFXAttribute.Size, VFXAttributeMode.Read);
  62. foreach (var attribute in flipbookAttributes)
  63. yield return attribute;
  64. }
  65. }
  66. protected override IEnumerable<VFXNamedExpression> CollectGPUExpressions(IEnumerable<VFXNamedExpression> slotExpressions)
  67. {
  68. foreach (var exp in base.CollectGPUExpressions(slotExpressions))
  69. yield return exp;
  70. if (normalBending)
  71. yield return slotExpressions.First(o => o.name == nameof(NormalBendingProperties.normalBendingFactor));
  72. if (tilingMode == StripTilingMode.Custom)
  73. yield return slotExpressions.First(o => o.name == nameof(CustomUVInputProperties.texCoord));
  74. }
  75. public override IEnumerable<string> additionalDefines
  76. {
  77. get
  78. {
  79. foreach (var d in base.additionalDefines)
  80. yield return d;
  81. if (normalBending)
  82. yield return "USE_NORMAL_BENDING";
  83. if (tilingMode == StripTilingMode.Stretch)
  84. yield return "VFX_STRIPS_UV_STRECHED";
  85. else if (tilingMode == StripTilingMode.RepeatPerSegment)
  86. yield return "VFX_STRIPS_UV_PER_SEGMENT";
  87. if (swapUV)
  88. yield return "VFX_STRIPS_SWAP_UV";
  89. yield return "FORCE_NORMAL_VARYING"; // To avoid discrepancy between depth and color pass which could cause glitch with ztest
  90. yield return VFXPlanarPrimitiveHelper.GetShaderDefine(VFXPrimitiveType.Quad);
  91. }
  92. }
  93. }
  94. }
  95. #endif