public static string GetLoadAttributeCode(VFXBlock block, VFXAttribute attribute, string name, string index) { var r = new VFXShaderWriter(); var layout = new StructureOfArrayProvider(); r.WriteVariable(attribute.type, name, block.GetData().GetLoadAttributeCode(attribute, VFXAttributeLocation.Current)); var result = r.builder.ToString().Replace("(index *", $"({index} *"); return(result); }
public static string GetLoadAttributeCode(this VFXData data, VFXAttribute attribute, string name, string index) { var r = new VFXShaderWriter(); r.WriteVariable( attribute.type, name, data.GetLoadAttributeCode(attribute, VFXAttributeLocation.Current)); var result = r.builder.ToString().Replace("(index *", $"({index} *"); return(result); }
// 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()); }