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.

SamplerStateShaderProperty.cs 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using UnityEditor.Graphing;
  3. using UnityEditor.ShaderGraph.Internal;
  4. using UnityEngine;
  5. namespace UnityEditor.ShaderGraph
  6. {
  7. [BlackboardInputInfo(80)]
  8. class SamplerStateShaderProperty : AbstractShaderProperty<TextureSamplerState>
  9. {
  10. public SamplerStateShaderProperty()
  11. {
  12. displayName = "SamplerState";
  13. value = new TextureSamplerState();
  14. }
  15. public override PropertyType propertyType => PropertyType.SamplerState;
  16. // Sampler States cannot be exposed on a Material
  17. internal override bool isExposable => false;
  18. // subgraph Sampler States can be renamed
  19. // just the actual properties they create will always have fixed names
  20. internal override bool isRenamable => true;
  21. internal override bool isReferenceRenamable => false;
  22. // this is the fixed naming scheme for actual samplerstates properties
  23. string propertyReferenceName => value.defaultPropertyName;
  24. public override string referenceNameForEditing => propertyReferenceName;
  25. internal override bool AllowHLSLDeclaration(HLSLDeclaration decl) => false; // disable UI, nothing to choose
  26. internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
  27. {
  28. action(new HLSLProperty(HLSLType._SamplerState, propertyReferenceName, HLSLDeclaration.Global));
  29. }
  30. internal override string GetPropertyAsArgumentString(string precisionString)
  31. {
  32. return $"UnitySamplerState {referenceName}";
  33. }
  34. internal override string GetHLSLVariableName(bool isSubgraphProperty, GenerationMode mode)
  35. {
  36. if (isSubgraphProperty)
  37. return referenceName;
  38. else
  39. return $"UnityBuildSamplerStateStruct({propertyReferenceName})";
  40. }
  41. internal override AbstractMaterialNode ToConcreteNode()
  42. {
  43. return new SamplerStateNode()
  44. {
  45. filter = value.filter,
  46. wrap = value.wrap
  47. };
  48. }
  49. internal override PreviewProperty GetPreviewMaterialProperty()
  50. {
  51. return default(PreviewProperty);
  52. }
  53. internal override ShaderInput Copy()
  54. {
  55. return new SamplerStateShaderProperty()
  56. {
  57. displayName = displayName,
  58. value = value,
  59. };
  60. }
  61. public override int latestVersion => 1;
  62. public override void OnAfterDeserialize(string json)
  63. {
  64. if (sgVersion == 0)
  65. {
  66. // we no longer require forced reference names on sampler state properties
  67. // as we enforce custom property naming by simply not using the reference name
  68. // this allows us to use the real reference name for subgraph parameters
  69. // however we must clear out the old reference name first (as it was always hard-coded)
  70. // this will fallback to the default ref name
  71. overrideReferenceName = null;
  72. var unused = referenceName;
  73. ChangeVersion(1);
  74. }
  75. }
  76. }
  77. }