예제 #1
0
        sealed protected override void ConvertExpressionsFromLink(VFXSlot fromSlot)
        {
            if (fromSlot.property.type == typeof(TSphere))
            {
                var destSlots = GetVFXValueTypeSlots();
                var fromSlots = fromSlot.GetVFXValueTypeSlots();

                var sourceRadius   = fromSlots.FirstOrDefault(o => o.name == nameof(TSphere.radius)).GetExpression();
                var sourceScale    = fromSlots.FirstOrDefault(o => o.name == nameof(TSphere.transform.scale)).GetExpression();
                var computedRadius = sourceRadius * VFXOperatorUtility.Max3(sourceScale);
                UpdateLinkedInExpression(destSlots.FirstOrDefault(o => o.name == nameof(Sphere.radius)), computedRadius, null);

                var sourcePosition = fromSlots.FirstOrDefault(o => o.name == nameof(TSphere.transform.position));
                UpdateLinkedInExpression(destSlots.FirstOrDefault(o => o.name == nameof(Sphere.center)), sourcePosition.GetExpression(), sourcePosition);
            }
            else
            {
                throw new InvalidOperationException("Unexpected manual conversion from slot type : " + fromSlot.property.type);
            }
        }
        static private VFXExpression ApplyAddressingMode(VFXExpression index, VFXExpression count, SequentialAddressingMode mode)
        {
            VFXExpression r = null;

            if (mode == SequentialAddressingMode.Wrap)
            {
                r = VFXOperatorUtility.Modulo(index, count);
            }
            else if (mode == SequentialAddressingMode.Clamp)
            {
                r = VFXOperatorUtility.Clamp(index, ZeroExpression[VFXValueType.Uint32], count, false);
            }
            else if (mode == SequentialAddressingMode.Mirror)
            {
                var direction = VFXOperatorUtility.Modulo(index / count, VFXOperatorUtility.TwoExpression[VFXValueType.Uint32]);
                var modulo    = VFXOperatorUtility.Modulo(index, count);
                r = VFXOperatorUtility.Lerp(modulo, count - modulo, direction);
            }
            return(r);
        }
예제 #3
0
        sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot)
        {
            if (sourceSlot != null)
            {
                if (sourceSlot.GetType() == typeof(VFXSlotDirection))
                {
                    return(expression); //avoid multiple normalization
                }
                if (sourceSlot.property.attributes != null && sourceSlot.property.attributes.OfType <NormalizeAttribute>().Any())
                {
                    return(expression); //avoid multiple normalization from Normalize attribute (rarely used for output slot)
                }
            }

            if (expression.valueType == VFXValueType.Float4)
            {
                expression = VFXOperatorUtility.CastFloat(expression, VFXValueType.Float3);
            }

            return(ApplyPatchExpression(expression));
        }
        public static VFXExpression ApplyToExpressionGraph(VFXPropertyAttribute[] attributes, VFXExpression exp)
        {
            if (attributes != null)
            {
                foreach (VFXPropertyAttribute attribute in attributes)
                {
                    switch (attribute.m_Type)
                    {
                    case Type.kRange:
                        exp = VFXOperatorUtility.Clamp(exp, VFXValue.Constant(attribute.m_Min), VFXValue.Constant(attribute.m_Max));
                        break;

                    case Type.kMin:
                        exp = new VFXExpressionMax(exp, VFXOperatorUtility.CastFloat(VFXValue.Constant(attribute.m_Min), 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);
        }
예제 #5
0
        static public VFXExpression SequentialCircle(VFXExpression center, VFXExpression radius, VFXExpression normal, VFXExpression up, VFXExpression index, VFXExpression count, SequentialAddressingMode mode)
        {
            VFXExpression countForAddressing = count;

            if (mode == SequentialAddressingMode.Clamp || mode == SequentialAddressingMode.Mirror)
            {
                //Explicitly close the circle loop, if `index` equals to `count`, adds an extra step.
                countForAddressing = count + OneExpression[VFXValueType.Uint32];
            }
            VFXExpression dt = ApplyAddressingMode(index, countForAddressing, mode);

            dt = new VFXExpressionCastUintToFloat(dt);
            dt = dt / new VFXExpressionCastUintToFloat(count);

            var cos  = new VFXExpressionCos(dt * VFXOperatorUtility.TauExpression[VFXValueType.Float]) as VFXExpression;
            var sin  = new VFXExpressionSin(dt * VFXOperatorUtility.TauExpression[VFXValueType.Float]) as VFXExpression;
            var left = VFXOperatorUtility.Normalize(VFXOperatorUtility.Cross(normal, up));

            radius = new VFXExpressionCombine(radius, radius, radius);
            sin    = new VFXExpressionCombine(sin, sin, sin);
            cos    = new VFXExpressionCombine(cos, cos, cos);

            return(center + (cos * up + sin * left) * radius);
        }
예제 #6
0
        public override VFXExpressionMapper GetExpressionMapper(VFXDeviceTarget target)
        {
            var meshData = (VFXDataMesh)GetData();

            switch (target)
            {
            case VFXDeviceTarget.GPU:
            {
                var mapper = new VFXExpressionMapper();
                for (int i = 2; i < GetNbInputSlots(); ++i)
                {
                    VFXExpression exp  = GetInputSlot(i).GetExpression();
                    VFXProperty   prop = GetInputSlot(i).property;

                    // As there's not shader generation here, we need expressions that can be evaluated on CPU
                    if (exp.IsAny(VFXExpression.Flags.NotCompilableOnCPU))
                    {
                        throw new InvalidOperationException(string.Format("Expression for slot {0} must be evaluable on CPU: {1}", prop.name, exp));
                    }

                    // needs to convert to srgb as color are linear in vfx graph
                    // This should not be performed for colors with the attribute [HDR] and be performed for vector4 with the attribute [Gamma]
                    // But property attributes cannot seem to be accessible from C# :(
                    if (prop.type == typeof(Color))
                    {
                        exp = VFXOperatorUtility.LinearToGamma(exp);
                    }

                    mapper.AddExpression(exp, prop.name, -1);
                }
                return(mapper);
            }

            case VFXDeviceTarget.CPU:
            {
                var mapper = new VFXExpressionMapper();
                mapper.AddExpression(GetInputSlot(0).GetExpression(), "mesh", -1);
                mapper.AddExpression(GetInputSlot(1).GetExpression(), "transform", -1);
                mapper.AddExpression(GetInputSlot(2).GetExpression(), "subMeshMask", -1);

                // TODO Remove this once material are serialized
                // Add material properties
                if (shader != null)
                {
                    var mat = meshData.GetOrCreateMaterial();
                    for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); ++i)
                    {
                        if (ShaderUtil.IsShaderPropertyHidden(shader, i))
                        {
                            var name   = ShaderUtil.GetPropertyName(shader, i);
                            var nameId = Shader.PropertyToID(name);
                            if (!mat.HasProperty(nameId))
                            {
                                continue;
                            }

                            VFXExpression expr = null;
                            switch (ShaderUtil.GetPropertyType(shader, i))
                            {
                            case ShaderUtil.ShaderPropertyType.Float:
                                expr = VFXValue.Constant <float>(mat.GetFloat(nameId));
                                break;

                            default:
                                break;
                            }

                            if (expr != null)
                            {
                                mapper.AddExpression(expr, name, -1);
                            }
                        }
                    }
                }

                return(mapper);
            }

            default:
                return(null);
            }
        }
예제 #7
0
 static VFXExpression RandomFromVector2(VFXExpression input)
 {
     return(VFXOperatorUtility.Lerp(input.x, input.y, new VFXExpressionRandom()));
 }
예제 #8
0
        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);
        }
 static VFXExpression RandomFromVector2(VFXExpression input, RandId randId)
 {
     return(VFXOperatorUtility.Lerp(input.x, input.y, new VFXExpressionRandom(false, randId)));
 }
예제 #10
0
 protected override VFXExpression ApplyPatchExpression(VFXExpression expression)
 {
     return(VFXOperatorUtility.Normalize(expression));
 }
예제 #11
0
        public VFXExpression ApplyToExpressionGraph(VFXExpression exp)
        {
            if (m_GraphAttributes == null)
            {
                return(exp);
            }

            foreach (PropertyAttribute attribute in m_GraphAttributes)
            {
                if (attribute is RangeAttribute)
                {
                    var rangeAttribute = (RangeAttribute)attribute;
                    switch (exp.valueType)
                    {
                    case VFXValueType.Int32:
                        exp = VFXOperatorUtility.Clamp(exp, VFXValue.Constant((int)rangeAttribute.min), VFXValue.Constant((int)rangeAttribute.max), false);
                        break;

                    case VFXValueType.Uint32:
                        exp = VFXOperatorUtility.Clamp(exp, VFXValue.Constant((uint)rangeAttribute.min), VFXValue.Constant((uint)rangeAttribute.max), false);
                        break;

                    case VFXValueType.Float:
                    case VFXValueType.Float2:
                    case VFXValueType.Float3:
                    case VFXValueType.Float4:
                        exp = VFXOperatorUtility.Clamp(exp, VFXValue.Constant(rangeAttribute.min), VFXValue.Constant(rangeAttribute.max));
                        break;

                    default:
                        throw new NotImplementedException(string.Format("Cannot use RangeAttribute on value of type: {0}", exp.valueType));
                    }
                }
                else if (attribute is MinAttribute)
                {
                    var minAttribute = (MinAttribute)attribute;
                    switch (exp.valueType)
                    {
                    case VFXValueType.Int32:
                        exp = new VFXExpressionMax(exp, VFXValue.Constant((int)minAttribute.min));
                        break;

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

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

                    default:
                        throw new NotImplementedException(string.Format("Cannot use MinAttribute on value of type: {0}", exp.valueType));
                    }
                }
                else if (attribute is NormalizeAttribute)
                {
                    exp = VFXOperatorUtility.Normalize(exp);
                }
                else if (attribute is EnumAttribute)
                {
                    var enumAttribute = (EnumAttribute)attribute;
                    exp = new VFXExpressionMin(exp, VFXValue.Constant((uint)enumAttribute.values.Length - 1));
                }
                else
                {
                    throw new NotImplementedException("Unrecognized expression attribute: " + attribute);
                }
            }

            return(exp);
        }
예제 #12
0
 //Convert automatically input expression with diverging floatN size to floatMax
 protected override IEnumerable <VFXExpression> ApplyPatchInputExpression(IEnumerable <VFXExpression> inputExpression)
 {
     return(VFXOperatorUtility.UpcastAllFloatN(inputExpression, m_FallbackValue));
 }