No Description
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.

CubemapInputMaterialSlot.cs 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor.Graphing;
  4. using UnityEditor.ShaderGraph.Drawing.Slots;
  5. using UnityEditor.ShaderGraph.Internal;
  6. using UnityEngine;
  7. using UnityEngine.UIElements;
  8. namespace UnityEditor.ShaderGraph
  9. {
  10. [Serializable]
  11. [HasDependencies(typeof(MinimalCubemapInputMaterialSlot))]
  12. class CubemapInputMaterialSlot : CubemapMaterialSlot
  13. {
  14. [SerializeField]
  15. private SerializableCubemap m_Cubemap = new SerializableCubemap();
  16. public Cubemap cubemap
  17. {
  18. get { return m_Cubemap.cubemap; }
  19. set { m_Cubemap.cubemap = value; }
  20. }
  21. public override bool isDefaultValue => cubemap == null;
  22. public CubemapInputMaterialSlot()
  23. { }
  24. public CubemapInputMaterialSlot(
  25. int slotId,
  26. string displayName,
  27. string shaderOutputName,
  28. ShaderStageCapability stageCapability = ShaderStageCapability.All,
  29. bool hidden = false)
  30. : base(slotId, displayName, shaderOutputName, SlotType.Input, stageCapability, hidden)
  31. { }
  32. public override VisualElement InstantiateControl()
  33. {
  34. return new CubemapSlotControlView(this);
  35. }
  36. public override string GetDefaultValue(GenerationMode generationMode)
  37. {
  38. var nodeOwner = owner as AbstractMaterialNode;
  39. if (nodeOwner == null)
  40. throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
  41. return $"UnityBuildTextureCubeStruct({nodeOwner.GetVariableNameForSlot(id)})";
  42. }
  43. public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
  44. {
  45. var nodeOwner = owner as AbstractMaterialNode;
  46. if (nodeOwner == null)
  47. throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
  48. var prop = new CubemapShaderProperty();
  49. prop.overrideReferenceName = nodeOwner.GetVariableNameForSlot(id);
  50. prop.modifiable = false;
  51. prop.generatePropertyBlock = true;
  52. prop.value.cubemap = cubemap;
  53. properties.AddShaderProperty(prop);
  54. }
  55. public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
  56. {
  57. var pp = new PreviewProperty(PropertyType.Cubemap)
  58. {
  59. name = name,
  60. cubemapValue = cubemap
  61. };
  62. properties.Add(pp);
  63. }
  64. public override void CopyValuesFrom(MaterialSlot foundSlot)
  65. {
  66. var slot = foundSlot as CubemapInputMaterialSlot;
  67. if (slot != null)
  68. {
  69. m_Cubemap = slot.m_Cubemap;
  70. bareResource = slot.bareResource;
  71. }
  72. }
  73. }
  74. class MinimalCubemapInputMaterialSlot : IHasDependencies
  75. {
  76. [SerializeField]
  77. private SerializableCubemap m_Cubemap = null;
  78. public void GetSourceAssetDependencies(AssetCollection assetCollection)
  79. {
  80. var guidString = m_Cubemap.guid;
  81. if (!string.IsNullOrEmpty(guidString) && GUID.TryParse(guidString, out var guid))
  82. {
  83. assetCollection.AddAssetDependency(guid, AssetCollection.Flags.IncludeInExportPackage);
  84. }
  85. }
  86. }
  87. }