using System.Text.Json.Serialization; namespace Editor.ShaderGraph; public enum TextureExtension { Color, Normal, Rough, AO, Metal, Trans, SelfIllum, Mask, } public enum TextureProcessor { None, Mod2XCenter, NormalizeNormals, FillToPowerOfTwo, FillToMultipleOfFour, ScaleToPowerOfTwo, HeightToNormal, Inverse, ConvertToYCoCg, DilateColorInTransparentPixels, EncodeRGBM, } public enum TextureColorSpace { Srgb, Linear, } public enum TextureFormat { DXT5, DXT1, RGBA8888, BC7, } public enum TextureType { Tex2D, TexCube, } public struct UIGroup { /// /// Name of this group /// [Editor( "shadergraphgroup" )] public string Name { get; set; } /// /// Priority of this group /// public int Priority { get; set; } } public struct TextureInput { /// /// Name that shows up in material editor /// public string Name { get; set; } /// /// If true, this parameter can be modified with . /// public bool IsAttribute { get; set; } /// /// Default color that shows up in material editor when using color control /// public Color Default { get; set; } /// /// Default texture that shows up in material editor /// [Hide, JsonIgnore] public string DefaultTexture { get; set; } /// /// Default texture that shows up in material editor (_color, _normal, _rough, etc..) /// [ShowIf( nameof( ShowExtension ), true )] public TextureExtension Extension { get; set; } /// /// Default texture that shows up in material editor (_color, _normal, _rough, etc..) /// public string CustomExtension { get; set; } [Hide] public readonly bool ShowExtension => string.IsNullOrWhiteSpace( CustomExtension ); [JsonIgnore, Hide] public string ExtensionString { get { if ( !string.IsNullOrWhiteSpace( CustomExtension ) ) { var ext = CustomExtension.Trim(); if ( ext.StartsWith( "_" ) ) ext = ext[1..]; if ( !string.IsNullOrWhiteSpace( ext ) ) return ext; } return Extension.ToString(); } } /// /// Processor used when compiling this texture /// public TextureProcessor Processor { get; set; } /// /// Color space used when compiling this texture /// public TextureColorSpace ColorSpace { get; set; } /// /// Format used when compiling this texture /// public TextureFormat ImageFormat { get; set; } /// /// Sample this texture as srgb /// public bool SrgbRead { get; set; } /// /// Priority of this value in the group /// public int Priority { get; set; } /// /// Primary group /// [InlineEditor( Label = false ), Group( "Group" )] public UIGroup PrimaryGroup { get; set; } /// /// Group within the primary group /// [InlineEditor( Label = false ), Group( "Sub Group" )] public UIGroup SecondaryGroup { get; set; } [JsonIgnore, Hide] public readonly string UIGroup => $"{PrimaryGroup.Name},{PrimaryGroup.Priority}/{SecondaryGroup.Name},{SecondaryGroup.Priority}/{Priority}"; [JsonIgnore, Hide] public TextureType Type { get; set; } public readonly string CreateTexture( string name ) { if ( Type == TextureType.Tex2D ) return $"Texture2D g_t{name}"; if ( Type == TextureType.TexCube ) return $"TextureCube g_t{name}"; return default; } [JsonIgnore, Hide] public readonly string CreateInput { get { if ( Type == TextureType.Tex2D ) return "CreateInputTexture2D"; if ( Type == TextureType.TexCube ) return "CreateInputTextureCube"; return default; } } }