2 using System.Collections.Generic;
3 using UnityEditor.Graphing;
4 using UnityEditor.ShaderGraph.Drawing.Slots;
7 using UnityEngine.UIElements;
9 namespace UnityEditor.ShaderGraph
11 class ColorRGBAMaterialSlot : Vector4MaterialSlot
13 public ColorRGBAMaterialSlot() {}
15 public ColorRGBAMaterialSlot(
18 string shaderOutputName,
21 ShaderStageCapability stageCapability = ShaderStageCapability.All,
23 : base(slotId, displayName, shaderOutputName, slotType, value, stageCapability, hidden: hidden)
27 public override VisualElement InstantiateControl()
29 return new ColorRGBASlotControlView(this);
32 protected override string ConcreteSlotValueAsVariable()
34 return string.Format("IsGammaSpace() ? $precision4({0}, {1}, {2}, {3}) : $precision4 (SRGBToLinear($precision3({0}, {1}, {2})), {3})"
35 , NodeUtils.FloatToShaderValue(value.x)
36 , NodeUtils.FloatToShaderValue(value.y)
37 , NodeUtils.FloatToShaderValue(value.z)
38 , NodeUtils.FloatToShaderValue(value.w));
41 public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
43 if (!generationMode.IsPreview())
46 var matOwner = owner as AbstractMaterialNode;
48 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
50 var property = new ColorShaderProperty()
52 overrideReferenceName = matOwner.GetVariableNameForSlot(id),
53 generatePropertyBlock = false,
56 properties.AddShaderProperty(property);
59 public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
61 var pp = new PreviewProperty(PropertyType.Color)
64 colorValue = new Color(value.x, value.x, value.z, value.w),