Ejemplo n.º 1
0
        public static bool NeedsMultiStageDefinition(this KeywordDescriptor keyword, ref List <KeywordShaderStage> dstStages)
        {
            dstStages.Clear();

            // All doesn't need special treatment.
            if (keyword.stages == KeywordShaderStage.All)
            {
                return(false);
            }

            if ((keyword.stages & KeywordShaderStage.Vertex) == KeywordShaderStage.Vertex)
            {
                dstStages.Add(KeywordShaderStage.Vertex);
            }
            if ((keyword.stages & KeywordShaderStage.Hull) == KeywordShaderStage.Hull)
            {
                dstStages.Add(KeywordShaderStage.Hull);
            }
            if ((keyword.stages & KeywordShaderStage.Domain) == KeywordShaderStage.Domain)
            {
                dstStages.Add(KeywordShaderStage.Domain);
            }
            if ((keyword.stages & KeywordShaderStage.Geometry) == KeywordShaderStage.Geometry)
            {
                dstStages.Add(KeywordShaderStage.Geometry);
            }
            if ((keyword.stages & KeywordShaderStage.RayTracing) == KeywordShaderStage.RayTracing)
            {
                dstStages.Add(KeywordShaderStage.RayTracing);
            }

            return(dstStages.Count > 1);
        }
Ejemplo n.º 2
0
        public static ShaderKeyword CreateBuiltInKeyword(KeywordDescriptor descriptor)
        {
            if (descriptor.entries != null)
            {
                for (int i = 0; i < descriptor.entries.Length; i++)
                {
                    if (descriptor.entries[i].id == -1)
                    {
                        descriptor.entries[i].id = i + 1;
                    }
                }
            }

            return(new ShaderKeyword()
            {
                isBuiltIn = true,
                displayName = descriptor.displayName,
                overrideReferenceName = descriptor.referenceName,
                keywordType = descriptor.type,
                keywordDefinition = descriptor.definition,
                keywordScope = descriptor.scope,
                value = descriptor.value,
                entries = descriptor.entries.ToList(),
            });
        }
Ejemplo n.º 3
0
        public static string ToDefineString(this KeywordDescriptor keyword, int value)
        {
            switch (keyword.type)
            {
            case KeywordType.Boolean:
                return(value == 1 ? $"#define {keyword.referenceName} 1" : string.Empty);

            case KeywordType.Enum:
                return($"#define {keyword.referenceName}_{keyword.entries[value].referenceName}");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 public static ShaderKeyword Create(KeywordDescriptor descriptor)
 {
     return(new ShaderKeyword()
     {
         m_IsExposable = false,
         m_IsEditable = false,
         displayName = descriptor.displayName,
         overrideReferenceName = descriptor.referenceName,
         keywordType = descriptor.type,
         keywordDefinition = descriptor.definition,
         keywordScope = descriptor.scope,
         value = descriptor.value,
         entries = descriptor.entries
     });
 }
Ejemplo n.º 5
0
        public static string ToDeclarationString(this KeywordDescriptor keyword)
        {
            // Get definition type using scope
            string scopeString      = keyword.scope == KeywordScope.Local ? "_local" : string.Empty;
            string definitionString = $"{keyword.definition.ToDeclarationString()}{scopeString}";

            switch (keyword.type)
            {
            case KeywordType.Boolean:
                return($"#pragma {definitionString} _ {keyword.referenceName}");

            case KeywordType.Enum:
                var    enumEntryDefinitions = keyword.entries.Select(x => $"{keyword.referenceName}_{x.referenceName}");
                string enumEntriesString    = string.Join(" ", enumEntryDefinitions);
                return($"#pragma {definitionString} {enumEntriesString}");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 6
0
 public void Add(KeywordDescriptor descriptor, int index, FieldCondition[] fieldConditions)
 {
     m_Items.Add(new Item(descriptor, index, fieldConditions));
 }
Ejemplo n.º 7
0
 public void Add(KeywordDescriptor descriptor, int index, FieldCondition fieldCondition)
 {
     m_Items.Add(new Item(descriptor, index, new FieldCondition[] { fieldCondition }));
 }
Ejemplo n.º 8
0
 public void Add(KeywordDescriptor descriptor, int index)
 {
     m_Items.Add(new Item(descriptor, index, null));
 }
Ejemplo n.º 9
0
 public Item(KeywordDescriptor descriptor, int index, FieldCondition[] fieldConditions)
 {
     this.descriptor      = descriptor;
     this.fieldConditions = fieldConditions;
     this.index           = index;
 }
Ejemplo n.º 10
0
 public void Add(KeywordDescriptor descriptor)
 {
     m_Items.Add(new Item(descriptor, null));
 }
Ejemplo n.º 11
0
 public Item(KeywordDescriptor descriptor, FieldCondition[] fieldConditions)
 {
     this.descriptor      = descriptor;
     this.fieldConditions = fieldConditions;
 }
Ejemplo n.º 12
0
 public DefineCollection Add(KeywordDescriptor descriptor, int index, FieldCondition[] fieldConditions)
 {
     m_Items.Add(new Item(descriptor, index, fieldConditions));
     return(this);
 }
Ejemplo n.º 13
0
 public DefineCollection Add(KeywordDescriptor descriptor, int index)
 {
     m_Items.Add(new Item(descriptor, index, null));
     return(this);
 }
Ejemplo n.º 14
0
 public KeywordCollection Add(KeywordDescriptor descriptor, FieldCondition[] fieldConditions)
 {
     m_Items.Add(new Item(descriptor, fieldConditions));
     return(this);
 }
Ejemplo n.º 15
0
 public KeywordCollection Add(KeywordDescriptor descriptor, FieldCondition fieldCondition)
 {
     m_Items.Add(new Item(descriptor, new FieldCondition[] { fieldCondition }));
     return(this);
 }
Ejemplo n.º 16
0
 public KeywordCollection Add(KeywordDescriptor descriptor)
 {
     m_Items.Add(new Item(descriptor, null));
     return(this);
 }