A game about forced loneliness, made by TACStudios
1using System;
2using UnityEditor.ShaderGraph.Drawing.Controls;
3using UnityEngine;
4using UnityEditor.Graphing;
5using UnityEditor.ShaderGraph.Internal;
6
7namespace UnityEditor.ShaderGraph
8{
9 [Title("Input", "Texture", "Sampler State")]
10 class SamplerStateNode : AbstractMaterialNode, IPropertyFromNode
11 {
12 [SerializeField]
13 private TextureSamplerState.FilterMode m_filter = TextureSamplerState.FilterMode.Linear;
14
15 [EnumControl]
16 public TextureSamplerState.FilterMode filter
17 {
18 get { return m_filter; }
19 set
20 {
21 if (m_filter == value)
22 return;
23
24 m_filter = value;
25 Dirty(ModificationScope.Graph);
26 }
27 }
28
29 [SerializeField]
30 private TextureSamplerState.WrapMode m_wrap = TextureSamplerState.WrapMode.Repeat;
31
32 [EnumControl]
33 public TextureSamplerState.WrapMode wrap
34 {
35 get { return m_wrap; }
36 set
37 {
38 if (m_wrap == value)
39 return;
40
41 m_wrap = value;
42 Dirty(ModificationScope.Graph);
43 }
44 }
45
46 [SerializeField]
47 private TextureSamplerState.Anisotropic m_aniso = TextureSamplerState.Anisotropic.None;
48
49 public TextureSamplerState.Anisotropic anisotropic
50 {
51 get { return m_aniso; }
52 set
53 {
54 if (m_aniso == value)
55 return;
56
57 m_aniso = value;
58 Dirty(ModificationScope.Graph);
59 }
60 }
61
62 public SamplerStateNode()
63 {
64 name = "Sampler State";
65 UpdateNodeAfterDeserialization();
66 }
67
68 public override bool hasPreview { get { return false; } }
69
70 private const int kOutputSlotId = 0;
71 private const string kOutputSlotName = "Out";
72
73 public sealed override void UpdateNodeAfterDeserialization()
74 {
75 AddSlot(new SamplerStateMaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
76 RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
77 }
78
79 string GetSamplerStatePropertyName()
80 {
81 return GetVariableNameForNode();
82 }
83
84 string GetSamplerStateVariableName()
85 {
86 return $"UnityBuildSamplerStateStruct({GetSamplerStatePropertyName()})";
87 }
88
89 public override string GetVariableNameForSlot(int slotId)
90 {
91 return GetSamplerStateVariableName();
92 }
93
94 public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
95 {
96 properties.AddShaderProperty(new SamplerStateShaderProperty()
97 {
98 overrideReferenceName = GetSamplerStatePropertyName(),
99 generatePropertyBlock = false,
100
101 value = new TextureSamplerState()
102 {
103 filter = m_filter,
104 wrap = m_wrap,
105 anisotropic = m_aniso
106 }
107 });
108 }
109
110 public override string GetVariableNameForNode()
111 {
112 return TextureSamplerState.BuildSamplerStateName(filter, wrap, anisotropic);
113 }
114
115 public AbstractShaderProperty AsShaderProperty()
116 {
117 return new SamplerStateShaderProperty
118 {
119 value = new TextureSamplerState()
120 {
121 filter = this.filter,
122 wrap = this.wrap,
123 anisotropic = this.anisotropic
124 }
125 };
126 }
127
128 public int outputSlotId { get { return kOutputSlotId; } }
129 }
130}