예제 #1
0
        public override void Destroy()
        {
            m_mainPreviewNode = null;

            base.Destroy();

            if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface != null)
            {
                for (int i = 0; i < m_includes.Count; i++)
                {
                    if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Contains(m_includes[i]))
                    {
                        ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Remove(m_includes[i]);
                    }
                }
            }

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            if (m_allFunctionInputs != null)
            {
                m_allFunctionInputs.Clear();
            }
            m_allFunctionInputs = null;

            if (m_allFunctionOutputs != null)
            {
                m_allFunctionOutputs.Clear();
            }
            m_allFunctionOutputs = null;

            if (m_functionGraph != null)
            {
                m_functionGraph.Destroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;
        }
예제 #2
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            OutputPort     outputPort     = GetOutputPortByUniqueId(outputId);
            FunctionOutput functionOutput = GetFunctionOutputByUniqueId(outputId);

            if (outputPort.IsLocalValue(dataCollector.PortCategory))
            {
                return(outputPort.LocalValue(dataCollector.PortCategory));
            }

            m_functionGraph.CurrentPrecision = ContainerGraph.ParentWindow.CurrentGraph.CurrentPrecision;
            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            m_outsideGraph = cachedGraph;
            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;
#if ADD_SHADER_FUNCTION_HEADERS
            if (m_reordenator != null && m_reordenator.RecursiveCount() > 0 && m_reordenator.HasTitle)
            {
                dataCollector.AddToProperties(UniqueId, "[Header(" + m_reordenator.HeaderTitle.Replace("-", " ") + ")]", m_reordenator.OrderIndex);
            }
#endif
            string result = string.Empty;
            for (int i = 0; i < m_allFunctionInputs.Count; i++)
            {
                if (!m_allFunctionInputs[i].InputPorts[0].IsConnected || m_inputPorts[i].IsConnected)
                {
                    m_allFunctionInputs[i].OnPortGeneration += FunctionNodeOnPortGeneration;
                }
            }

            result += functionOutput.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar);

            for (int i = 0; i < m_allFunctionInputs.Count; i++)
            {
                if (!m_allFunctionInputs[i].InputPorts[0].IsConnected || m_inputPorts[i].IsConnected)
                {
                    m_allFunctionInputs[i].OnPortGeneration -= FunctionNodeOnPortGeneration;
                }
            }

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            if (outputPort.ConnectionCount > 1)
            {
                RegisterLocalVariable(outputId, result, ref dataCollector);
            }
            else
            {
                outputPort.SetLocalValue(result, dataCollector.PortCategory);
            }

            return(outputPort.LocalValue(dataCollector.PortCategory));
        }
예제 #3
0
        public void DrawFunctionOutputs()
        {
            List <ParentNode> nodes = UIUtils.FunctionOutputList();

            if (m_functionOutputsReordableList == null || nodes.Count != m_functionOutputsLastCount)
            {
                List <FunctionOutput> functionOutputNodes = new List <FunctionOutput>();
                for (int i = 0; i < nodes.Count; i++)
                {
                    FunctionOutput node = nodes[i] as FunctionOutput;
                    if (node != null)
                    {
                        functionOutputNodes.Add(node);
                    }
                }

                functionOutputNodes.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

                m_functionOutputsReordableList = new ReorderableList(functionOutputNodes, typeof(FunctionOutput), true, false, false, false);
                m_functionOutputsReordableList.headerHeight          = 0;
                m_functionOutputsReordableList.footerHeight          = 0;
                m_functionOutputsReordableList.showDefaultBackground = false;

                m_functionOutputsReordableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
                {
                    EditorGUI.LabelField(rect, functionOutputNodes[index].OutputName);
                };

                m_functionOutputsReordableList.onChangedCallback = (list) =>
                {
                    for (int i = 0; i < functionOutputNodes.Count; i++)
                    {
                        functionOutputNodes[i].OrderIndex = i;
                    }
                };

                m_functionOutputsLastCount = m_functionOutputsReordableList.count;
            }

            if (m_functionOutputsReordableList != null)
            {
                if (m_propertyAdjustment == null)
                {
                    m_propertyAdjustment = new GUIStyle();
                    m_propertyAdjustment.padding.left = 17;
                }
                EditorGUILayout.BeginVertical(m_propertyAdjustment);
                m_functionOutputsReordableList.DoLayoutList();
                EditorGUILayout.EndVertical();
            }
        }
예제 #4
0
        public void CommonInit(AmplifyShaderFunction function, int uniqueId)
        {
            SetBaseUniqueId(uniqueId);

            if (function == null)
            {
                return;
            }

            m_refreshIdsRequired = UIUtils.IsLoading && (UIUtils.CurrentShaderVersion() < 14004);

            m_function = function;

            if (Function.FunctionName.Length > 1)
            {
                bool lastIsUpper = Char.IsUpper(Function.FunctionName, 0);
                System.Text.StringBuilder title = new System.Text.StringBuilder();
                title.Append(Function.FunctionName[0]);
                for (int i = 1; i < Function.FunctionName.Length; i++)
                {
                    bool currIsUpper = Char.IsUpper(Function.FunctionName, i);
                    if (currIsUpper && !lastIsUpper && Char.IsLetter(Function.FunctionName[i - 1]))
                    {
                        title.Append(" ");
                    }
                    lastIsUpper = currIsUpper;
                    title.Append(Function.FunctionName[i]);
                    SetTitleText(title.ToString());
                }
            }
            else
            {
                SetTitleText(Function.FunctionName);
            }
            m_tooltipText    = Function.Description;
            m_hasTooltipLink = false;
            if (m_functionGraph == null)
            {
                //m_functionGraph = new ParentGraph();
                m_functionGraph = CreateInstance <ParentGraph>();
                m_functionGraph.Init();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            if (string.IsNullOrEmpty(m_functionGUID))
            {
                m_functionGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_function));
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, Function.FunctionInfo);
            //m_functionCheckSum = LastLine( m_function.FunctionInfo );
            m_functionCheckSum = AssetDatabase.GetAssetDependencyHash(AssetDatabase.GetAssetPath(m_function)).ToString();
            List <PropertyNode> propertyList = UIUtils.PropertyNodesList();

            m_allFunctionInputs   = UIUtils.FunctionInputList();
            m_allFunctionOutputs  = UIUtils.FunctionOutputList();
            m_allFunctionSwitches = UIUtils.FunctionSwitchList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionSwitches.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                if (m_refreshIdsRequired)
                {
                    AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                }
                else
                {
                    AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName, -1, MasterNodePortCategory.Fragment, m_allFunctionInputs[i].UniqueId);
                }
                InputPortSwitchRestriction(m_inputPorts[i]);

                if (!m_allFunctionInputs[i].InputPorts[0].IsConnected)
                {
                    m_inputPorts[i].AutoDrawInternalData = true;
                    m_inputPorts[i].InternalData         = m_allFunctionInputs[i].InputPorts[0].InternalData;
                }
            }

            int            outputCount = m_allFunctionOutputs.Count;
            FunctionOutput first       = null;

            for (int i = 0; i < outputCount; i++)
            {
                if (i == 0)
                {
                    first = m_allFunctionOutputs[i];
                }

                if (m_allFunctionOutputs[i].PreviewNode)
                {
                    m_mainPreviewNode = m_allFunctionOutputs[i];
                }

                if (m_refreshIdsRequired)
                {
                    AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                }
                else
                {
                    AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName, m_allFunctionOutputs[i].UniqueId);
                }
                OutputPortSwitchRestriction(m_outputPorts[i]);
            }

            // make sure to hide the ports properly
            CheckPortVisibility();

            if (m_mainPreviewNode == null)
            {
                m_mainPreviewNode = first;
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList, false);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 120;

            UIUtils.RegisterFunctionNode(this);

            m_previewShaderGUID   = "aca70c900c50c004e8ef0b47c4fac4d4";
            m_useInternalPortData = false;
            m_selectedLocation    = function.PreviewPosition;
        }
예제 #5
0
        public override void Destroy()
        {
            m_mainPreviewNode = null;
            base.Destroy();

            if (m_functionGraph != null && ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph)
            {
                ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount -= m_functionGraph.InstancePropertyCount;
            }

            if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface != null)
            {
                //for( int i = 0; i < m_includes.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Contains( m_includes[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Remove( m_includes[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Include, m_includes[ i ] );
                //}

                //for( int i = 0; i < m_pragmas.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Contains( m_pragmas[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Remove( m_pragmas[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Pragma, m_pragmas[ i ] );
                //}
                ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItems(m_directives);
            }
            else
            {
                if (ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.Count > 0)
                {
                    List <TemplateMultiPassMasterNode> nodes = ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.NodesList;
                    int count = nodes.Count;
                    for (int i = 0; i < count; i++)
                    {
                        nodes[i].PassModule.AdditionalDirectives.RemoveShaderFunctionItems(m_directives);
                    }
                }
            }

            // Cannot GameObject.Destroy(m_directives[i]) since we would be removing them from
            // the shader function asset itself

            m_directives.Clear();
            m_directives = null;

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            if (m_allFunctionInputs != null)
            {
                m_allFunctionInputs.Clear();
            }
            m_allFunctionInputs = null;

            if (m_allFunctionOutputs != null)
            {
                m_allFunctionOutputs.Clear();
            }
            m_allFunctionOutputs = null;

            if (m_functionGraph != null)
            {
                m_functionGraph.SoftDestroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;

            m_allFunctionOutputsDict.Clear();
            m_allFunctionOutputsDict = null;

            m_allFunctionSwitchesDict.Clear();
            m_allFunctionSwitchesDict = null;

            m_allFunctionInputsDict.Clear();
            m_allFunctionInputsDict = null;
        }
예제 #6
0
        public void CommonInit(AmplifyShaderFunction function, int uniqueId)
        {
            SetBaseUniqueId(uniqueId);

            if (function == null)
            {
                return;
            }

            m_function = function;
            SetTitleText(Function.FunctionName);
            m_tooltipText = Function.Description;
            if (m_functionGraph == null)
            {
                m_functionGraph = new ParentGraph();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            if (string.IsNullOrEmpty(m_functionGUID))
            {
                m_functionGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_function));
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, ContainerGraph.ParentWindow.CurrentVersionInfo, Function.FunctionInfo);
            //m_functionCheckSum = LastLine( m_function.FunctionInfo );
            m_functionCheckSum = AssetDatabase.GetAssetDependencyHash(AssetDatabase.GetAssetPath(m_function)).ToString();
            List <PropertyNode> propertyList = UIUtils.PropertyNodesList();

            m_allFunctionInputs  = UIUtils.FunctionInputList();
            m_allFunctionOutputs = UIUtils.FunctionOutputList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                PortSwitchRestriction(m_inputPorts[i]);
            }

            int            outputCount = m_allFunctionOutputs.Count;
            FunctionOutput first       = null;

            for (int i = 0; i < outputCount; i++)
            {
                if (i == 0)
                {
                    first = m_allFunctionOutputs[i];
                }

                if (m_allFunctionOutputs[i].PreviewNode)
                {
                    m_mainPreviewNode = m_allFunctionOutputs[i];
                }

                AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                PortSwitchRestriction(m_outputPorts[i]);
            }

            if (m_mainPreviewNode == null)
            {
                m_mainPreviewNode = first;
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList, false);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 100;

            UIUtils.RegisterFunctionNode(this);

            m_previewShaderGUID = "aca70c900c50c004e8ef0b47c4fac4d4";
        }
예제 #7
0
        public override void Destroy()
        {
            m_mainPreviewNode = null;
            base.Destroy();

            if (m_functionGraph != null && ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph)
            {
                ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount -= m_functionGraph.InstancePropertyCount;
            }

            if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface != null)
            {
                //for( int i = 0; i < m_includes.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Contains( m_includes[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Remove( m_includes[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Include, m_includes[ i ] );
                //}

                //for( int i = 0; i < m_pragmas.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Contains( m_pragmas[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Remove( m_pragmas[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Pragma, m_pragmas[ i ] );
                //}
                ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItems(m_directives);
                m_directives.Clear();
                m_directives = null;
            }

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            if (m_allFunctionInputs != null)
            {
                m_allFunctionInputs.Clear();
            }
            m_allFunctionInputs = null;

            if (m_allFunctionOutputs != null)
            {
                m_allFunctionOutputs.Clear();
            }
            m_allFunctionOutputs = null;

            if (m_functionGraph != null)
            {
                m_functionGraph.SoftDestroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;

            m_allFunctionOutputsDict.Clear();
            m_allFunctionOutputsDict = null;

            m_allFunctionSwitchesDict.Clear();
            m_allFunctionSwitchesDict = null;

            m_allFunctionInputsDict.Clear();
            m_allFunctionInputsDict = null;
        }