Texture2DShaderProperty.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Text;
  3. using UnityEditor.Graphing;
  4. using UnityEngine;
  5. namespace UnityEditor.ShaderGraph.Internal
  6. {
  7. [Serializable]
  8. [FormerName("UnityEditor.ShaderGraph.TextureShaderProperty")]
  9. public sealed class Texture2DShaderProperty : AbstractShaderProperty<SerializableTexture>
  10. {
  11. public enum DefaultType { White, Black, Grey, Bump }
  12. internal Texture2DShaderProperty()
  13. {
  14. displayName = "Texture2D";
  15. value = new SerializableTexture();
  16. }
  17. public override PropertyType propertyType => PropertyType.Texture2D;
  18. internal override bool isBatchable => false;
  19. internal override bool isExposable => true;
  20. internal override bool isRenamable => true;
  21. internal string modifiableTagString => modifiable ? "" : "[NonModifiableTextureData]";
  22. internal override string GetPropertyBlockString()
  23. {
  24. return $"{hideTagString}{modifiableTagString}[NoScaleOffset]{referenceName}(\"{displayName}\", 2D) = \"{defaultType.ToString().ToLower()}\" {{}}";
  25. }
  26. internal override string GetPropertyDeclarationString(string delimiter = ";")
  27. {
  28. return $"TEXTURE2D({referenceName}){delimiter} SAMPLER(sampler{referenceName}){delimiter} {concretePrecision.ToShaderString()}4 {referenceName}_TexelSize{delimiter}";
  29. }
  30. internal override string GetPropertyAsArgumentString()
  31. {
  32. return $"TEXTURE2D_PARAM({referenceName}, sampler{referenceName}), {concretePrecision.ToShaderString()}4 {referenceName}_TexelSize";
  33. }
  34. [SerializeField]
  35. bool m_Modifiable = true;
  36. internal bool modifiable
  37. {
  38. get => m_Modifiable;
  39. set => m_Modifiable = value;
  40. }
  41. [SerializeField]
  42. DefaultType m_DefaultType = DefaultType.White;
  43. public DefaultType defaultType
  44. {
  45. get { return m_DefaultType; }
  46. set { m_DefaultType = value; }
  47. }
  48. internal override AbstractMaterialNode ToConcreteNode()
  49. {
  50. return new Texture2DAssetNode { texture = value.texture };
  51. }
  52. internal override PreviewProperty GetPreviewMaterialProperty()
  53. {
  54. return new PreviewProperty(propertyType)
  55. {
  56. name = referenceName,
  57. textureValue = value.texture
  58. };
  59. }
  60. internal override ShaderInput Copy()
  61. {
  62. return new Texture2DShaderProperty()
  63. {
  64. displayName = displayName,
  65. hidden = hidden,
  66. value = value
  67. };
  68. }
  69. }
  70. }