public VFXExpressionSampleTexture2D(VFXExpression texture, VFXExpression uv, VFXExpression mipLevel)
     : base(Flags.InvalidOnCPU, new VFXExpression[3] {
     texture, uv, mipLevel
 })
 {
 }
Example #2
0
 protected virtual VFXExpression[] ExpressionToChildren(VFXExpression exp)
 {
     return(null);
 }
Example #3
0
 public void RegisterExpression(VFXExpression expression)
 {
     m_EndExpressions.Add(expression);
 }
 public VFXExpressionLogicalOr(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.LogicalOr)
 {
 }
 public VFXExpressionASin(VFXExpression parent) : base(parent, VFXExpressionOperation.ASin)
 {
 }
 public VFXExpressionATan2(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.ATan2)
 {
 }
 public VFXExpressionBitwiseXor(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.BitwiseXor)
 {
 }
 public List <string> GetNames(VFXExpression exp)
 {
     return(VFXExpression.IsTexture(exp.valueType) ? m_TextureToName[exp] : m_UniformToName[exp]);
 }
        private void CollectAndAddUniforms(VFXExpression exp, IEnumerable <string> names, HashSet <VFXExpression> processedExp)
        {
            if (!exp.IsAny(VFXExpression.Flags.NotCompilableOnCPU))
            {
                string prefix;
                Dictionary <VFXExpression, List <string> > expressions;

                if (VFXExpression.IsUniform(exp.valueType))
                {
                    if (m_FilterOutConstants && exp.Is(VFXExpression.Flags.Constant)) // Filter out constant uniform that should be patched directly in shader
                    {
                        return;
                    }

                    prefix      = "uniform_";
                    expressions = m_UniformToName;
                }
                else if (VFXExpression.IsTexture(exp.valueType))
                {
                    prefix      = "texture_";
                    expressions = m_TextureToName;
                }
                else
                {
                    if (VFXExpression.IsTypeValidOnGPU(exp.valueType))
                    {
                        throw new InvalidOperationException(string.Format("Missing handling for type: {0}", exp.valueType));
                    }
                    return;
                }

                List <string> previousNames;
                expressions.TryGetValue(exp, out previousNames);

                if (previousNames == null)
                {
                    previousNames    = new List <string>();
                    expressions[exp] = previousNames;
                }

                if (names == null)
                {
                    previousNames.Add(prefix + VFXCodeGeneratorHelper.GeneratePrefix((uint)expressions.Count()));
                }
                else
                {
                    previousNames.AddRange(names);
                }
            }
            else
            {
                foreach (var parent in exp.parents)
                {
                    if (processedExp.Contains(parent))
                    {
                        continue;
                    }

                    processedExp.Add(parent);
                    CollectAndAddUniforms(parent, null, processedExp);
                }
            }
        }
        public static VFXExpression ApplyToExpressionGraph(VFXPropertyAttribute[] attributes, VFXExpression exp)
        {
            if (attributes != null)
            {
                foreach (VFXPropertyAttribute attribute in attributes)
                {
                    switch (attribute.m_Type)
                    {
                    case Type.kRange:
                        switch (exp.valueType)
                        {
                        case VFXValueType.Int32:
                            exp = VFXOperatorUtility.Clamp(exp, VFXValue.Constant((int)attribute.m_Min), VFXValue.Constant((int)attribute.m_Max), false);
                            break;

                        case VFXValueType.Uint32:
                            exp = VFXOperatorUtility.Clamp(exp, VFXValue.Constant((uint)attribute.m_Min), VFXValue.Constant((uint)attribute.m_Max), false);
                            break;

                        case VFXValueType.Float:
                        case VFXValueType.Float2:
                        case VFXValueType.Float3:
                        case VFXValueType.Float4:
                            exp = VFXOperatorUtility.Clamp(exp, VFXValue.Constant(attribute.m_Min), VFXValue.Constant(attribute.m_Max));
                            break;

                        default:
                            throw new NotImplementedException(string.Format("Cannot use RangeAttribute on value of type: {0}", exp.valueType));
                        }
                        break;

                    case Type.kMin:
                        switch (exp.valueType)
                        {
                        case VFXValueType.Int32:
                            exp = new VFXExpressionMax(exp, VFXValue.Constant((int)attribute.m_Min));
                            break;

                        case VFXValueType.Uint32:
                            exp = new VFXExpressionMax(exp, VFXValue.Constant((uint)attribute.m_Min));
                            break;

                        case VFXValueType.Float:
                        case VFXValueType.Float2:
                        case VFXValueType.Float3:
                        case VFXValueType.Float4:
                            exp = new VFXExpressionMax(exp, VFXOperatorUtility.CastFloat(VFXValue.Constant(attribute.m_Min), exp.valueType));
                            break;

                        default:
                            throw new NotImplementedException(string.Format("Cannot use MinAttribute on value of type: {0}", exp.valueType));
                        }
                        break;

                    case Type.kNormalize:
                        exp = VFXOperatorUtility.Normalize(exp);
                        break;

                    case Type.kTooltip:
                    case Type.kAngle:
                    case Type.kColor:
                    case Type.kRegex:
                    case Type.kDelayed:
                    case Type.kBitField:
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }

            return(exp);
        }
 // Get only the first name of a uniform (For generated code, we collapse all uniforms using the same expression into a single one)
 public string GetName(VFXExpression exp)
 {
     return(VFXExpression.IsTexture(exp.valueType) ? m_TextureToName[exp].First() : m_UniformToName[exp].First());
 }
Example #12
0
        private static void BuildBlock(VFXContextCompiledData contextData, List <VFXSlot> linkedEventOut, VFXShaderWriter blockFunction, VFXShaderWriter blockCallFunction, HashSet <string> blockDeclared, Dictionary <VFXExpression, string> expressionToName, VFXBlock block, ref int blockIndex)
        {
            var parameters = block.mergedAttributes.Select(o =>
            {
                return(new VFXShaderWriter.FunctionParameter
                {
                    name = o.attrib.name,
                    expression = new VFXAttributeExpression(o.attrib) as VFXExpression,
                    mode = o.mode
                });
            }).ToList();

            foreach (var parameter in block.parameters)
            {
                var expReduced = contextData.gpuMapper.FromNameAndId(parameter.name, blockIndex);
                if (VFXExpression.IsTypeValidOnGPU(expReduced.valueType))
                {
                    parameters.Add(new VFXShaderWriter.FunctionParameter
                    {
                        name       = parameter.name,
                        expression = expReduced,
                        mode       = VFXAttributeMode.None
                    });
                }
            }

            string methodName, commentMethod;

            GetFunctionName(block, out methodName, out commentMethod);
            if (!blockDeclared.Contains(methodName))
            {
                blockDeclared.Add(methodName);
                blockFunction.WriteBlockFunction(contextData.gpuMapper,
                                                 methodName,
                                                 block.source,
                                                 parameters,
                                                 commentMethod);
            }

            //< Parameters (computed and/or extracted from uniform)
            var  expressionToNameLocal = expressionToName;
            bool needScope             = parameters.Any(o => !expressionToNameLocal.ContainsKey(o.expression));

            if (needScope)
            {
                expressionToNameLocal = new Dictionary <VFXExpression, string>(expressionToNameLocal);
                blockCallFunction.EnterScope();
                foreach (var exp in parameters.Select(o => o.expression))
                {
                    if (expressionToNameLocal.ContainsKey(exp))
                    {
                        continue;
                    }
                    blockCallFunction.WriteVariable(exp, expressionToNameLocal);
                }
            }

            var indexEventCount = parameters.FindIndex(o => o.name == VFXAttribute.EventCount.name);

            if (indexEventCount != -1)
            {
                if ((parameters[indexEventCount].mode & VFXAttributeMode.Read) != 0)
                {
                    throw new InvalidOperationException(string.Format("{0} isn't expected as read (special case)", VFXAttribute.EventCount.name));
                }
                blockCallFunction.WriteLine(string.Format("{0} = 0u;", VFXAttribute.EventCount.GetNameInCode(VFXAttributeLocation.Current)));
            }

            blockCallFunction.WriteCallFunction(methodName,
                                                parameters,
                                                contextData.gpuMapper,
                                                expressionToNameLocal);

            if (indexEventCount != -1)
            {
                foreach (var outputSlot in block.outputSlots.SelectMany(o => o.LinkedSlots))
                {
                    var eventIndex = linkedEventOut.IndexOf(outputSlot);
                    if (eventIndex != -1)
                    {
                        blockCallFunction.WriteLineFormat("{0}_{1} += {2};", VFXAttribute.EventCount.name, VFXCodeGeneratorHelper.GeneratePrefix((uint)eventIndex), VFXAttribute.EventCount.GetNameInCode(VFXAttributeLocation.Current));
                    }
                }
            }
            if (needScope)
            {
                blockCallFunction.ExitScope();
            }

            blockIndex++;
        }
Example #13
0
 sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot)
 {
     return(ConvertExpressionToVector3(expression));
 }
Example #14
0
 private void SetValueDesc <T>(VFXExpressionValueContainerDesc desc, VFXExpression exp)
 {
     ((VFXExpressionValueContainerDesc <T>)desc).value = exp.Get <T>();
 }
 public VFXExpressionPow(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Pow)
 {
 }
 public VFXExpressionLog2(VFXExpression parent) : base(parent, VFXExpressionOperation.Log2)
 {
 }
 public VFXExpressionACos(VFXExpression parent) : base(parent, VFXExpressionOperation.ACos)
 {
 }
 public VFXExpressionAdd(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Add)
 {
 }
 public VFXExpressionBitwiseRightShift(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.BitwiseRightShift)
 {
 }
 public VFXExpressionDivide(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Divide)
 {
 }
 public VFXExpressionBitwiseComplement(VFXExpression parent) : base(parent, VFXExpressionOperation.BitwiseComplement)
 {
 }
 public VFXExpressionSubtract(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Subtract)
 {
 }
 public VFXExpressionLogicalNot(VFXExpression parent) : base(parent, VFXExpressionOperation.LogicalNot)
 {
 }
 public VFXExpressionTan(VFXExpression parent) : base(parent, VFXExpressionOperation.Tan)
 {
 }
Example #25
0
 protected virtual VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot)
 {
     return(expression);
 }
 public VFXExpressionMax(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Max)
 {
 }
Example #27
0
 public void Invalidate(VFXExpression expression)
 {
     m_ReducedCache.Remove(expression);
 }
        static public bool CanBeReducedToSaturate(VFXExpression current, VFXExpression[] reducedParents, out VFXExpression inputValueRef)
        {
            inputValueRef = null;
            var valueType = current.valueType;

            if (reducedParents.Length != 2 || !VFXExpression.IsFloatValueType(valueType))
            {
                return(false);
            }

            var one  = VFXOperatorUtility.OneExpression[valueType];
            var zero = VFXOperatorUtility.ZeroExpression[valueType];

            Type          searchInnerFunctionType     = null;
            VFXExpression searchInnerValueFirstLevel  = null;
            VFXExpression searchInnerValueSecondLevel = null;

            if (current is VFXExpressionMax)
            {
                searchInnerFunctionType     = typeof(VFXExpressionMin);
                searchInnerValueFirstLevel  = zero;
                searchInnerValueSecondLevel = one;
            }
            else if (current is VFXExpressionMin)
            {
                searchInnerFunctionType     = typeof(VFXExpressionMax);
                searchInnerValueFirstLevel  = one;
                searchInnerValueSecondLevel = zero;
            }
            else
            {
                return(false);
            }

            var minReferenceExpected = reducedParents.FirstOrDefault(o => o.GetType() == searchInnerFunctionType);
            var firstValueExpected   = reducedParents.FirstOrDefault(o => o == searchInnerValueFirstLevel);

            if (minReferenceExpected != null && firstValueExpected != null)
            {
                var indexOf = Array.IndexOf(minReferenceExpected.parents, searchInnerValueSecondLevel);
                if (indexOf != -1)
                {
                    var otherIndexOf = (indexOf + 1) % 2;
                    inputValueRef = minReferenceExpected.parents[otherIndexOf];
                    return(true);
                }
            }
            return(false);
        }
Example #29
0
 public void UnregisterExpression(VFXExpression expression)
 {
     Invalidate(expression);
     m_EndExpressions.Remove(expression);
 }
 public VFXExpressionLoadTexture2DArray(VFXExpression texture, VFXExpression location)
     : base(Flags.InvalidOnCPU, new VFXExpression[2] {
     texture, location
 })
 {
 }