static private VFXShaderWriter GenerateLoadAttribute(string matching, VFXContext context)
        {
            var r = new VFXShaderWriter();

            var regex = new Regex(matching);
            var attributesFromContext = context.GetData().GetAttributes().Where(o => regex.IsMatch(o.attrib.name)).ToArray();
            var attributesSource      = attributesFromContext.Where(o => (o.mode & VFXAttributeMode.ReadSource) != 0).ToArray();
            var attributesCurrent     = attributesFromContext.Where(o => o.mode != VFXAttributeMode.ReadSource).Where(a => context.GetData().IsAttributeUsed(a.attrib, context) || (context.contextType == VFXContextType.kInit && context.GetData().IsAttributeStored(a.attrib))).ToArray();

            //< Current Attribute
            foreach (var attribute in attributesCurrent.Select(o => o.attrib))
            {
                var name = attribute.name;
                if (name != VFXAttribute.EventCount.name)
                {
                    if (context.contextType != VFXContextType.kInit && context.GetData().IsAttributeStored(attribute))
                    {
                        r.WriteVariable(attribute.type, name, context.GetData().GetLoadAttributeCode(attribute, VFXAttributeLocation.Current));
                    }
                    else
                    {
                        r.WriteVariable(attribute.type, name, attribute.value.GetCodeString(null));
                    }
                }
                else
                {
                    var linkedOutCount = context.allLinkedOutputSlot.Count();
                    for (uint i = 0; i < linkedOutCount; ++i)
                    {
                        r.WriteLineFormat("uint {0}_{1} = 0u;", name, VFXCodeGeneratorHelper.GeneratePrefix(i));
                    }
                    r.WriteVariable(attribute.type, name, attribute.value.GetCodeString(null));
                }
                r.WriteLine();
            }

            //< Source Attribute (default temporary behavior, source is always the initial current value except for init context)
            foreach (var attribute in attributesSource.Select(o => o.attrib))
            {
                var name = string.Format("{0}_source", attribute.name);
                if (context.contextType == VFXContextType.kInit)
                {
                    r.WriteVariable(attribute.type, name, context.GetData().GetLoadAttributeCode(attribute, VFXAttributeLocation.Source));
                }
                else
                {
                    if (attributesCurrent.Any(o => o.attrib.name == attribute.name))
                    {
                        var reference = new VFXAttributeExpression(new VFXAttribute(attribute.name, attribute.value), VFXAttributeLocation.Current);
                        r.WriteVariable(reference.valueType, name, reference.GetCodeString(null));
                    }
                    else
                    {
                        r.WriteVariable(attribute.type, name, attribute.value.GetCodeString(null));
                    }
                }
                r.WriteLine();
            }
            return(r);
        }
Exemplo n.º 2
0
        protected override VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            var attribute = VFXAttribute.Find(this.attribute);

            if (attribute.variadic == VFXVariadic.True)
            {
                var attributes  = new VFXAttribute[] { VFXAttribute.Find(attribute.name + "X"), VFXAttribute.Find(attribute.name + "Y"), VFXAttribute.Find(attribute.name + "Z") };
                var expressions = attributes.Select(a => new VFXAttributeExpression(a, location)).ToArray();

                var componentStack = new Stack <VFXExpression>();
                int outputSize     = mask.Length;
                for (int iComponent = 0; iComponent < outputSize; iComponent++)
                {
                    char componentChar    = char.ToLower(mask[iComponent]);
                    int  currentComponent = Math.Min(componentChar - 'x', 2);
                    componentStack.Push(expressions[currentComponent]);
                }

                VFXExpression finalExpression = null;
                if (componentStack.Count == 1)
                {
                    finalExpression = componentStack.Pop();
                }
                else
                {
                    finalExpression = new VFXExpressionCombine(componentStack.Reverse().ToArray());
                }
                return(new[] { finalExpression });
            }
            else
            {
                var expression = new VFXAttributeExpression(attribute, location);
                return(new VFXExpression[] { expression });
            }
        }
        protected override VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            var attribute = currentAttribute;

            var expression = new VFXAttributeExpression(attribute, VFXAttributeLocation.Current);

            return(new VFXExpression[] { expression });
        }