public VFXExpressionSampleTexture2D(VFXExpression texture, VFXExpression uv, VFXExpression mipLevel)
     : base(Flags.InvalidOnCPU, new VFXExpression[3] {
     texture, uv, mipLevel
 })
 {
 }
예제 #2
0
 protected virtual VFXExpression[] ExpressionToChildren(VFXExpression exp)
 {
     return(null);
 }
예제 #3
0
 public void RegisterExpression(VFXExpression expression)
 {
     m_EndExpressions.Add(expression);
 }
예제 #4
0
 public VFXExpressionLogicalOr(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.LogicalOr)
 {
 }
예제 #5
0
 public VFXExpressionASin(VFXExpression parent) : base(parent, VFXExpressionOperation.ASin)
 {
 }
예제 #6
0
 public VFXExpressionATan2(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.ATan2)
 {
 }
예제 #7
0
 public VFXExpressionBitwiseXor(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.BitwiseXor)
 {
 }
예제 #8
0
 public List <string> GetNames(VFXExpression exp)
 {
     return(VFXExpression.IsTexture(exp.valueType) ? m_TextureToName[exp] : m_UniformToName[exp]);
 }
예제 #9
0
        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);
        }
예제 #11
0
 // 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());
 }
예제 #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++;
        }
예제 #13
0
 sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot)
 {
     return(ConvertExpressionToVector3(expression));
 }
예제 #14
0
 private void SetValueDesc <T>(VFXExpressionValueContainerDesc desc, VFXExpression exp)
 {
     ((VFXExpressionValueContainerDesc <T>)desc).value = exp.Get <T>();
 }
예제 #15
0
 public VFXExpressionPow(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Pow)
 {
 }
예제 #16
0
 public VFXExpressionLog2(VFXExpression parent) : base(parent, VFXExpressionOperation.Log2)
 {
 }
예제 #17
0
 public VFXExpressionACos(VFXExpression parent) : base(parent, VFXExpressionOperation.ACos)
 {
 }
예제 #18
0
 public VFXExpressionAdd(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Add)
 {
 }
예제 #19
0
 public VFXExpressionBitwiseRightShift(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.BitwiseRightShift)
 {
 }
예제 #20
0
 public VFXExpressionDivide(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Divide)
 {
 }
예제 #21
0
 public VFXExpressionBitwiseComplement(VFXExpression parent) : base(parent, VFXExpressionOperation.BitwiseComplement)
 {
 }
예제 #22
0
 public VFXExpressionSubtract(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Subtract)
 {
 }
예제 #23
0
 public VFXExpressionLogicalNot(VFXExpression parent) : base(parent, VFXExpressionOperation.LogicalNot)
 {
 }
예제 #24
0
 public VFXExpressionTan(VFXExpression parent) : base(parent, VFXExpressionOperation.Tan)
 {
 }
예제 #25
0
 protected virtual VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot)
 {
     return(expression);
 }
예제 #26
0
 public VFXExpressionMax(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Max)
 {
 }
예제 #27
0
 public void Invalidate(VFXExpression expression)
 {
     m_ReducedCache.Remove(expression);
 }
예제 #28
0
        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);
        }
예제 #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
 })
 {
 }