AbstractShaderProperty.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.ShaderGraph.Internal
  4. {
  5. [Serializable]
  6. public abstract class AbstractShaderProperty : ShaderInput
  7. {
  8. public abstract PropertyType propertyType { get; }
  9. internal override ConcreteSlotValueType concreteShaderValueType => propertyType.ToConcreteShaderValueType();
  10. [SerializeField]
  11. Precision m_Precision = Precision.Inherit;
  12. [SerializeField]
  13. private bool m_GPUInstanced = false;
  14. public bool gpuInstanced
  15. {
  16. get { return m_GPUInstanced; }
  17. set { m_GPUInstanced = value; }
  18. }
  19. ConcretePrecision m_ConcretePrecision = ConcretePrecision.Float;
  20. internal Precision precision
  21. {
  22. get => m_Precision;
  23. set => m_Precision = value;
  24. }
  25. public ConcretePrecision concretePrecision => m_ConcretePrecision;
  26. internal void ValidateConcretePrecision(ConcretePrecision graphPrecision)
  27. {
  28. m_ConcretePrecision = (precision == Precision.Inherit) ? graphPrecision : precision.ToConcrete();
  29. }
  30. internal abstract bool isBatchable { get; }
  31. [SerializeField]
  32. bool m_Hidden = false;
  33. public bool hidden
  34. {
  35. get => m_Hidden;
  36. set => m_Hidden = value;
  37. }
  38. internal string hideTagString => hidden ? "[HideInInspector]" : "";
  39. internal virtual string GetPropertyBlockString()
  40. {
  41. return string.Empty;
  42. }
  43. internal virtual string GetPropertyDeclarationString(string delimiter = ";")
  44. {
  45. SlotValueType type = ConcreteSlotValueType.Vector4.ToSlotValueType();
  46. return $"{concreteShaderValueType.ToShaderString(concretePrecision.ToShaderString())} {referenceName}{delimiter}";
  47. }
  48. internal virtual string GetPropertyAsArgumentString()
  49. {
  50. return GetPropertyDeclarationString(string.Empty);
  51. }
  52. internal abstract AbstractMaterialNode ToConcreteNode();
  53. internal abstract PreviewProperty GetPreviewMaterialProperty();
  54. internal virtual bool isGpuInstanceable => false;
  55. }
  56. [Serializable]
  57. public abstract class AbstractShaderProperty<T> : AbstractShaderProperty
  58. {
  59. [SerializeField]
  60. T m_Value;
  61. public virtual T value
  62. {
  63. get => m_Value;
  64. set => m_Value = value;
  65. }
  66. }
  67. }