public Node CreateEmptyParameterNode(ParamSourceType sourceType, String archiveName, String title) { var node = new Node(title); node.Tag = new ShaderParameterNodeTag(archiveName); var enumList = AsEnumList(sourceType, ParamSourceTypeNames); var typeSelection = new HyperGraph.Items.NodeDropDownItem(enumList.Item1.ToArray(), enumList.Item2, false, false); node.AddItem(typeSelection); typeSelection.SelectionChanged += ParameterNodeTypeChanged; return(node); }
public static String AsString(ShaderFragmentArchive.Parameter.SourceType input) { switch (input) { case ShaderFragmentArchive.Parameter.SourceType.Material: return("Material Parameter"); case ShaderFragmentArchive.Parameter.SourceType.InterpolatorIntoVertex: return("Interpolator Into Vertex Shader"); case ShaderFragmentArchive.Parameter.SourceType.InterpolatorIntoPixel: return("Interpolator Into Pixel Shader"); case ShaderFragmentArchive.Parameter.SourceType.System: return("System Parameter"); case ShaderFragmentArchive.Parameter.SourceType.Output: return("Output"); case ShaderFragmentArchive.Parameter.SourceType.Constant: return("Constant"); } return("Unknown Parameter"); }
private static ShaderPatcherLayer.Node.Type AsNodeType(ShaderFragmentArchive.Parameter.SourceType input) { switch (input) { case ShaderFragmentArchive.Parameter.SourceType.Material: return(ShaderPatcherLayer.Node.Type.MaterialCBuffer); case ShaderFragmentArchive.Parameter.SourceType.InterpolatorIntoVertex: return(ShaderPatcherLayer.Node.Type.InterpolatorIntoVertex); case ShaderFragmentArchive.Parameter.SourceType.InterpolatorIntoPixel: return(ShaderPatcherLayer.Node.Type.InterpolatorIntoPixel); case ShaderFragmentArchive.Parameter.SourceType.System: return(ShaderPatcherLayer.Node.Type.SystemCBuffer); case ShaderFragmentArchive.Parameter.SourceType.Output: return(ShaderPatcherLayer.Node.Type.Output); case ShaderFragmentArchive.Parameter.SourceType.Constant: return(ShaderPatcherLayer.Node.Type.Constants); default: return(ShaderPatcherLayer.Node.Type.Procedure); } }
public static Node CreateEmptyParameterNode(ShaderFragmentArchive.Parameter.SourceType sourceType, String archiveName, String title) { var node = new Node(title); node.Tag = new ShaderParameterNodeTag(archiveName); int selectedIndex = 0; List <String> typeNames = new List <String>(); foreach (var e in Enum.GetValues(typeof(ShaderFragmentArchive.Parameter.SourceType)).Cast <ShaderFragmentArchive.Parameter.SourceType>()) { if (e == sourceType) { selectedIndex = typeNames.Count; } typeNames.Add(AsString(e)); } var typeSelection = new HyperGraph.Items.NodeDropDownItem(typeNames.ToArray(), selectedIndex, false, false); node.AddItem(typeSelection); typeSelection.SelectionChanged += ParameterNodeTypeChanged; return(node); }
public Node CreateParameterNode(ShaderFragmentArchive.ParameterStruct parameter, String archiveName, ParamSourceType type) { var node = CreateEmptyParameterNode(type, archiveName, (parameter != null) ? parameter.Name : VisibleName(archiveName)); if (parameter != null) { foreach (var param in parameter.Parameters) { bool isOutput = type == ParamSourceType.Output; node.AddItem(new ShaderFragmentNodeItem( param.Name, param.Type, archiveName + ":" + param.Name, isOutput ? true : false, isOutput ? false : true)); } } return(node); }
public static bool FillInMaterialParameters(ShaderDiagram.Document document, HyperGraph.GraphControl graphControl) { // // Look for new or removed material parameters // and update the material parameters dictionary // Dictionary <String, String> newMaterialParameters = new Dictionary <String, String>(); foreach (Node n in graphControl.Nodes) { if (n.Tag is ShaderParameterNodeTag && n.Items.Count() > 0) { // look for a drop down list element -- this will tell us the type ShaderFragmentArchive.Parameter.SourceType type = ShaderFragmentArchive.Parameter.SourceType.System; foreach (var i in n.Items) { if (i is HyperGraph.Items.NodeDropDownItem) { var dropDown = (HyperGraph.Items.NodeDropDownItem)i; var stringForm = dropDown.Items[dropDown.SelectedIndex]; type = ShaderFragmentNodeCreator.AsSourceType(stringForm); break; } } if (type == ShaderFragmentArchive.Parameter.SourceType.Material) { foreach (var i in n.Items) { if (i is ShaderFragmentNodeItem) { ShaderFragmentNodeItem item = (ShaderFragmentNodeItem)i; if (item.Output != null) { if (!newMaterialParameters.ContainsKey(item.ArchiveName)) { var param = ShaderFragmentArchive.Archive.GetParameter(item.ArchiveName); if (param != null) { newMaterialParameters.Add(item.ArchiveName, param.Type); } else { newMaterialParameters.Add(item.ArchiveName, "<<unknown>>"); } } } } } } } } bool didSomething = false; List <String> entriesToRemove = new List <String>(); foreach (String s in document.PreviewMaterialState.Keys) { if (!newMaterialParameters.ContainsKey(s)) { entriesToRemove.Add(s); } } foreach (String s in entriesToRemove) { document.PreviewMaterialState.Remove(s); // does this invalidate the iteration? didSomething = true; } foreach (KeyValuePair <String, String> s in newMaterialParameters) { if (!document.PreviewMaterialState.ContainsKey(s.Key)) { var parameter = ShaderFragmentArchive.Archive.GetParameter(s.Key); System.Object def = null; if (parameter != null && parameter.Default != null && parameter.Default.Length > 0) { def = ShaderPatcherLayer.TypeRules.CreateFromString(parameter.Default, parameter.Type); } var parameterName = s.Key; if (parameter != null) { parameterName = parameter.Name; } if (def != null) { document.PreviewMaterialState.Add(parameterName, def); } else { document.PreviewMaterialState.Add(parameterName, ShaderPatcherLayer.TypeRules.CreateDefaultObject(s.Value)); } didSomething = true; } } return(didSomething); }
public static Node CreateParameterNode(ShaderFragmentArchive.ParameterStruct parameter, String archiveName, ShaderFragmentArchive.Parameter.SourceType type) { var node = CreateEmptyParameterNode(type, archiveName, parameter.Name); foreach (var param in parameter.Parameters) { bool isOutput = type == ShaderFragmentArchive.Parameter.SourceType.Output; node.AddItem(new ShaderFragmentNodeItem( param.Name, param.Type, archiveName + ":" + param.Name, isOutput ? true : false, isOutput ? false : true)); } return(node); }