Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

SamplerStateMaterialSlot.cs 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using UnityEditor.Graphing;
  3. using UnityEngine;
  4. namespace UnityEditor.ShaderGraph
  5. {
  6. [Serializable]
  7. class SamplerStateMaterialSlot : MaterialSlot
  8. {
  9. public SamplerStateMaterialSlot()
  10. {
  11. }
  12. public SamplerStateMaterialSlot(
  13. int slotId,
  14. string displayName,
  15. string shaderOutputName,
  16. SlotType slotType,
  17. ShaderStageCapability stageCapability = ShaderStageCapability.All,
  18. bool hidden = false)
  19. : base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
  20. {
  21. }
  22. [SerializeField]
  23. bool m_BareResource = false;
  24. internal override bool bareResource
  25. {
  26. get { return m_BareResource; }
  27. set { m_BareResource = value; }
  28. }
  29. // NOT serialized -- this is always set by the parent node if they care about it
  30. public TextureSamplerState defaultSamplerState { get; set; }
  31. public string defaultSamplerStateName => defaultSamplerState?.defaultPropertyName ?? "SamplerState_Linear_Repeat";
  32. public override void AppendHLSLParameterDeclaration(ShaderStringBuilder sb, string paramName)
  33. {
  34. if (m_BareResource)
  35. {
  36. // we have to use our modified macro declaration here
  37. // (the standard SAMPLER macro doesn't declare anything, so the commas will be messed up in the parameter list)
  38. sb.Append("SAMPLER(");
  39. sb.Append(paramName);
  40. sb.Append(")");
  41. }
  42. else
  43. base.AppendHLSLParameterDeclaration(sb, paramName);
  44. }
  45. public override string GetDefaultValue(GenerationMode generationMode)
  46. {
  47. var nodeOwner = owner as AbstractMaterialNode;
  48. if (nodeOwner == null)
  49. throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
  50. return $"UnityBuildSamplerStateStruct({defaultSamplerStateName})";
  51. }
  52. public override SlotValueType valueType { get { return SlotValueType.SamplerState; } }
  53. public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.SamplerState; } }
  54. public override bool isDefaultValue => true;
  55. public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
  56. {
  57. var nodeOwner = owner as AbstractMaterialNode;
  58. if (nodeOwner == null)
  59. throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
  60. properties.AddShaderProperty(new SamplerStateShaderProperty()
  61. {
  62. value = defaultSamplerState ?? new TextureSamplerState()
  63. {
  64. filter = TextureSamplerState.FilterMode.Linear,
  65. wrap = TextureSamplerState.WrapMode.Repeat
  66. },
  67. overrideReferenceName = defaultSamplerStateName,
  68. generatePropertyBlock = false,
  69. });
  70. }
  71. public override void CopyValuesFrom(MaterialSlot foundSlot)
  72. { }
  73. public override void CopyDefaultValue(MaterialSlot other)
  74. {
  75. base.CopyDefaultValue(other);
  76. if (other is SamplerStateMaterialSlot ms)
  77. {
  78. defaultSamplerState = ms.defaultSamplerState;
  79. }
  80. }
  81. }
  82. }