public override VFXExpressionMapper GetExpressionMapper(VFXDeviceTarget target)
        {
            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);
                return(mapper);
            }

            default:
                return(null);
            }
        }
        public override VFXExpressionMapper GetExpressionMapper(VFXDeviceTarget target)
        {
            // GPU
            if (target == VFXDeviceTarget.GPU)
            {
                var gpuMapper = VFXExpressionMapper.FromBlocks(activeFlattenedChildrenWithImplicit);
                if (ownedType == VFXDataType.ParticleStrip)
                {
                    gpuMapper.AddExpressionsFromSlot(inputSlots[1], -1); // strip index
                }
                return(gpuMapper);
            }

            // CPU
            var cpuMapper = new VFXExpressionMapper();

            cpuMapper.AddExpressionsFromSlot(inputSlots[0], -1); // bounds
            return(cpuMapper);
        }
Exemple #3
0
        public override VFXExpressionMapper GetExpressionMapper(VFXDeviceTarget target)
        {
            var  particleData     = GetData() as VFXDataParticle;
            bool isRecordedBounds = particleData && particleData.boundsSettingMode == BoundsSettingMode.Recorded;

            // GPU
            if (target == VFXDeviceTarget.GPU)
            {
                var gpuMapper = VFXExpressionMapper.FromBlocks(activeFlattenedChildrenWithImplicit);
                if (ownedType == VFXDataType.ParticleStrip && !hasGPUSpawner)
                {
                    gpuMapper.AddExpressionsFromSlot(inputSlots[(isRecordedBounds ? 2 : 1)], -1); // strip index
                }
                return(gpuMapper);
            }

            // CPU
            var cpuMapper = new VFXExpressionMapper();

            if (particleData)
            {
                switch (particleData.boundsSettingMode)
                {
                case BoundsSettingMode.Manual:
                    cpuMapper.AddExpressionsFromSlot(inputSlots[0], -1);     // bounds
                    break;

                case BoundsSettingMode.Recorded:
                    cpuMapper.AddExpressionsFromSlot(inputSlots[0], -1);     // bounds
                    cpuMapper.AddExpressionsFromSlot(inputSlots[1], -1);     //bounds padding
                    break;

                case BoundsSettingMode.Automatic:
                    cpuMapper.AddExpressionsFromSlot(inputSlots[0], -1);     //bounds padding
                    break;
                }
            }

            return(cpuMapper);
        }
Exemple #4
0
        public override VFXExpressionMapper GetExpressionMapper(VFXDeviceTarget target)
        {
            var localSpace = ((VFXDataParticle)GetData()).space == VFXCoordinateSpace.Local;

            if (localSpace && target == VFXDeviceTarget.GPU) // Needs to add locaToWorld matrix
            {
                var gpuMapper = new VFXExpressionMapper();
                if (IsPerCamera(sortCriterion))
                {
                    gpuMapper.AddExpression(VFXBuiltInExpression.LocalToWorld, "unity_ObjectToWorld", -1);
                    gpuMapper.AddExpression(VFXBuiltInExpression.WorldToLocal, "unity_WorldToObject", -1);
                }

                if (sortCriterion == SortCriteria.Custom)
                {
                    var sortKeyExp = customSortingSlot.GetExpression();
                    gpuMapper.AddExpression(sortKeyExp, "sortKey", -1);
                }
                return(gpuMapper);
            }

            return(null); // cpu
        }
Exemple #5
0
        public void WriteBlockFunction(VFXExpressionMapper mapper, string functionName, string source, IEnumerable <FunctionParameter> parameters, string commentMethod)
        {
            var parametersCode = new List <string>();

            foreach (var parameter in parameters)
            {
                var inputModifier = GetInputModifier(parameter.mode);
                var parameterType = GetFunctionParameterType(parameter.expression.valueType);
                parametersCode.Add(string.Format("{0}{1} {2}", inputModifier, parameterType, parameter.name));
            }

            WriteFormat("void {0}({1})", functionName, AggregateParameters(parametersCode));
            if (!string.IsNullOrEmpty(commentMethod))
            {
                WriteFormat(" /*{0}*/", commentMethod);
            }
            WriteLine();
            EnterScope();
            if (source != null)
            {
                WriteMultilineWithIndent(source);
            }
            ExitScope();
        }
        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);
            }
        }
Exemple #7
0
        public void WriteCallFunction(string functionName, IEnumerable <FunctionParameter> parameters, VFXExpressionMapper mapper, Dictionary <VFXExpression, string> variableNames)
        {
            var parametersCode = new List <string>();

            foreach (var parameter in parameters)
            {
                var inputModifier = GetInputModifier(parameter.mode);
                parametersCode.Add(string.Format("{1}{0}", GetFunctionParameterName(parameter.expression, variableNames), string.IsNullOrEmpty(inputModifier) ? string.Empty : string.Format(" /*{0}*/", inputModifier)));
            }

            WriteLineFormat("{0}({1});", functionName, AggregateParameters(parametersCode));
        }
 public VFXUniformMapper(VFXExpressionMapper mapper, bool filterOutConstants)
 {
     m_FilterOutConstants = filterOutConstants;
     Init(mapper);
 }