Ejemplo n.º 1
0
        // HACK: This is very implementation-specific :(
        protected string CallFunction()
        {
            var data            = GetData();
            var context         = (VFXContext)GetParent();
            var expressionGraph = GetGraph()
                                  .GetPropertyValue <VFXGraphCompiledData>("compiledData")
                                  .GetFieldValue <VFXExpressionGraph>("m_ExpressionGraph");

            var gpuMapper     = expressionGraph.BuildGPUMapper(context);
            var uniformMapper = new VFXUniformMapper(gpuMapper, context.doesGenerateShader);
            var blockIndex    = context.activeChildrenWithImplicit
                                .Select((value, index) => new
            {
                value,
                index
            })
                                .Where(pair => pair.value == this)
                                .Select(pair => pair.index + 1)
                                .FirstOrDefault() - 1;

            var writer           = new VFXShaderWriter();
            var expressionToName = data
                                   .GetAttributes()
                                   .ToDictionary(o =>
                                                 new VFXAttributeExpression(o.attrib) as VFXExpression,
                                                 o => (new VFXAttributeExpression(o.attrib)).GetCodeString(null));

            expressionToName = expressionToName
                               .Union(uniformMapper.expressionToCode).ToDictionary(s => s.Key, s => s.Value);

            var blockParameters = mergedAttributes.Select(o => new VFXShaderWriter.FunctionParameter
            {
                name = o.attrib.name, expression = new VFXAttributeExpression(o.attrib) as VFXExpression, mode = o.mode
            }).ToList();

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

            var scoped = blockParameters.Any(o => !expressionToName.ContainsKey(o.expression));

            if (scoped)
            {
                expressionToName = new Dictionary <VFXExpression, string>(expressionToName);
                writer.EnterScope();
                foreach (var exp in blockParameters.Select(o => o.expression))
                {
                    if (expressionToName.ContainsKey(exp))
                    {
                        continue;
                    }
                    writer.WriteVariable(exp, expressionToName);
                }
            }

            writer.WriteCallFunction(GetMethodName(), blockParameters, gpuMapper, expressionToName);

            if (scoped)
            {
                writer.ExitScope();
            }

            return(writer.builder.ToString());
        }
Ejemplo n.º 2
0
        protected VFXShaderWriter GetDecalMaskColor(int maskIndex)
        {
            var rs         = new VFXShaderWriter();
            var maskString = "";

            switch (maskIndex)
            {
            case 0:
                rs.Write(affectBaseColor ? "RBGA" : "0");
                break;

            case 1:
                rs.Write(useNormalMap ? "RGBA" : "0");
                break;

            case 2:
            {
                if (affectMetal)
                {
                    maskString += "R";
                }

                if (affectAmbientOcclusion)
                {
                    maskString += "G";
                }

                if (affectSmoothness)
                {
                    maskString += "BA";
                }

                if (String.IsNullOrEmpty(maskString))
                {
                    maskString = "0";
                }
                rs.Write(maskString);
                break;
            }

            case 3:
                if (affectMetal)
                {
                    maskString += "R";
                }

                if (affectAmbientOcclusion)
                {
                    maskString += "G";
                }

                if (String.IsNullOrEmpty(maskString))
                {
                    maskString = "0";
                }
                rs.Write(maskString);
                break;
            }

            return(rs);
        }