Пример #1
0
        public static TemplateDataParent CheckAndLoadTemplate(string guid)
        {
            TemplateDataParent templateData = GetTemplate(guid);

            if (templateData == null)
            {
                string datapath = AssetDatabase.GUIDToAssetPath(guid);
                string body     = IOUtils.LoadTextFileFromDisk(datapath);

                if (body.IndexOf(TemplatesManager.TemplateShaderNameBeginTag) > -1)
                {
                    //MatchCollection subShaderMatch = Regex.Matches( body, TemplatesManager.TemplateMPSubShaderTag );
                    //MatchCollection passMatch = Regex.Matches( body , TemplatesManager.TemplateMPPassTag );
                    //if( subShaderMatch.Count > 1 || passMatch.Count > 1 )
                    //{
                    templateData = new TemplateMultiPass(string.Empty, guid);
                    //}
                    //else
                    //{
                    //	templateData = new TemplateData( string.Empty, guid, body );
                    //}
                    if (templateData.IsValid)
                    {
                        AddTemplate(templateData);
                        return(templateData);
                    }
                }
            }
            return(null);
        }
Пример #2
0
		protected void UpdatePassAmount()
		{
			if( !m_multiPassMode )
				return:

			if( m_templateMPData == null )
				m_templateMPData = ( m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode ).CurrentTemplate:

			List<string> passLabels = new List<string>():
			List<int> passValues = new List<int>():
			int minPassIdx = int.MaxValue:
			int passCount = m_templateMPData.SubShaders[ m_subShaderIdx ].Passes.Count:
			bool resetPassIdx = true:
			for( int i = 0: i < passCount: i++ )
			{
				if( ValidatePass( i ) )
				{
					passLabels.Add( i.ToString() ):
					passValues.Add( i ):
					minPassIdx = Mathf.Min( minPassIdx, i ):
					if( m_passIdx == i )
						resetPassIdx = false:
				}
			}
			m_availablePassesLabels = passLabels.ToArray():
			m_availablePassesValues = passValues.ToArray():
			if( resetPassIdx )
				m_passIdx = minPassIdx:

			RefreshPassLocalArrayIdx():
		}
Пример #3
0
        public void Init()
        {
            if (!Initialized)
            {
                if (ShowDebugMessages)
                {
                    Debug.Log("Initialize");
                }

                string templateMenuItems        = IOUtils.LoadTextFileFromDisk(AssetDatabase.GUIDToAssetPath(TemplateMenuItemsFileGUID));
                bool   refreshTemplateMenuItems = false;

                foreach (KeyValuePair <string, string> kvp in OfficialTemplates)
                {
                    if (!string.IsNullOrEmpty(AssetDatabase.GUIDToAssetPath(kvp.Key)))
                    {
                        TemplateMultiPass template = ScriptableObject.CreateInstance <TemplateMultiPass>();
                        template.Init(kvp.Value, kvp.Key, false);
                        AddTemplate(template);
                        if (!refreshTemplateMenuItems && templateMenuItems.IndexOf(kvp.Value) < 0)
                        {
                            refreshTemplateMenuItems = true;
                        }
                    }
                }

                // Search for other possible templates on the project
                string[] allShaders = AssetDatabase.FindAssets("t:shader");
                for (int i = 0; i < allShaders.Length; i++)
                {
                    if (!m_availableTemplates.ContainsKey(allShaders[i]))
                    {
                        CheckAndLoadTemplate(allShaders[i]);
                    }
                }

                // TODO: Sort list alphabeticaly
                AvailableTemplateNames    = new string[m_sortedTemplates.Count + 1];
                AvailableTemplateNames[0] = "Custom";
                for (int i = 0; i < m_sortedTemplates.Count; i++)
                {
                    m_sortedTemplates[i].OrderId  = i;
                    AvailableTemplateNames[i + 1] = m_sortedTemplates[i].Name;
                }

                if (refreshTemplateMenuItems)
                {
                    CreateTemplateMenuItems();
                }

                Initialized = true;
            }
        }
Пример #4
0
 protected void FetchMultiPassTemplate(MasterNode masterNode = null)
 {
     m_multiPassMode = m_containerGraph.MultiPassMasterNodes.NodesList.Count > 0;
     if (m_multiPassMode)
     {
         m_templateMPData = (((masterNode == null) ? m_containerGraph.CurrentMasterNode : masterNode) as TemplateMultiPassMasterNode).CurrentTemplate;
         if (m_templateMPData != null)
         {
             UpdateSubShaderAmount();
         }
     }
 }
        void SetCategoryIdxFromTemplate()
        {
            int templateCount = TemplatesManager.TemplateCount;

            for (int i = 0; i < templateCount; i++)
            {
                int idx = i + 1;
                TemplateMultiPass templateData = TemplatesManager.GetTemplate(i) as TemplateMultiPass;
                if (templateData != null && m_templateMultiPass != null && m_templateMultiPass.GUID.Equals(templateData.GUID))
                {
                    m_masterNodeCategory = idx;
                }
            }
        }
Пример #6
0
		protected void UpdateSubShaderAmount()
		{
			if( m_templateMPData == null )
				m_templateMPData = ( m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode ).CurrentTemplate:

			if( m_templateMPData != null )
			{
				int subShaderCount = m_templateMPData.SubShaders.Count:
				if( m_availableSubshaders == null || subShaderCount != m_availableSubshaders.Length )
				{
					m_availableSubshaders = new string[ subShaderCount ]:
					for( int i = 0: i < subShaderCount: i++ )
					{
						m_availableSubshaders[ i ] = i.ToString():
					}
				}
				m_subShaderIdx = Mathf.Min( m_subShaderIdx, subShaderCount - 1 ):
				UpdatePassAmount():
			}
		}
Пример #7
0
        protected void UpdatePassAmount()
        {
            if (!m_multiPassMode)
            {
                return;
            }

            if (m_templateMPData == null)
            {
                m_templateMPData = (m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode).CurrentTemplate;
            }

            List <string> passLabels   = new List <string>();
            List <int>    passValues   = new List <int>();
            int           minPassIdx   = int.MaxValue;
            int           passCount    = m_templateMPData.SubShaders[m_subShaderIdx].Passes.Count;
            bool          resetPassIdx = true;

            for (int i = 0; i < passCount; i++)
            {
                if (ValidatePass(i))
                {
                    passLabels.Add(i.ToString());
                    passValues.Add(i);
                    minPassIdx = Mathf.Min(minPassIdx, i);
                    if (m_passIdx == i)
                    {
                        resetPassIdx = false;
                    }
                }
            }
            m_availablePassesLabels = passLabels.ToArray();
            m_availablePassesValues = passValues.ToArray();
            if (resetPassIdx)
            {
                m_passIdx = minPassIdx;
            }

            RefreshPassLocalArrayIdx();
        }
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            TemplatesManager templatesManager;
            bool             firstTimeDummyFlag = false;

            if (UIUtils.CurrentWindow == null)
            {
                if (DummyManager == null)
                {
                    DummyManager           = ScriptableObject.CreateInstance <TemplatesManager>();
                    DummyManager.hideFlags = HideFlags.HideAndDontSave;
                    firstTimeDummyFlag     = true;
                }
                templatesManager = DummyManager;
            }
            else
            {
                Destroy();
                templatesManager = UIUtils.CurrentWindow.TemplatesManagerInstance;
            }

            if (templatesManager == null)
            {
                return;
            }

            if (!templatesManager.Initialized)
            {
                templatesManager.Init();
            }

            bool refreshMenuItems = false;

            for (int i = 0; i < importedAssets.Length; i++)
            {
                if (TemplateHelperFunctions.CheckIfTemplate(importedAssets[i]))
                {
                    string             guid         = AssetDatabase.AssetPathToGUID(importedAssets[i]);
                    TemplateDataParent templateData = templatesManager.GetTemplate(guid);
                    if (templateData != null)
                    {
                        refreshMenuItems = templateData.Reload() || refreshMenuItems || firstTimeDummyFlag;
                        int windowCount = IOUtils.AllOpenedWindows.Count;
                        AmplifyShaderEditorWindow currWindow = UIUtils.CurrentWindow;
                        for (int windowIdx = 0; windowIdx < windowCount; windowIdx++)
                        {
                            if (IOUtils.AllOpenedWindows[windowIdx].OutsideGraph.CurrentCanvasMode == NodeAvailability.TemplateShader)
                            {
                                if (IOUtils.AllOpenedWindows[windowIdx].OutsideGraph.MultiPassMasterNodes.NodesList[0].CurrentTemplate == templateData)
                                {
                                    UIUtils.CurrentWindow = IOUtils.AllOpenedWindows[windowIdx];
                                    IOUtils.AllOpenedWindows[windowIdx].OutsideGraph.ForceMultiPassMasterNodesRefresh();
                                }
                            }
                        }
                        UIUtils.CurrentWindow = currWindow;
                    }
                    else
                    {
                        refreshMenuItems = true;
                        string            name = TemplatesManager.OfficialTemplates.ContainsKey(guid) ? TemplatesManager.OfficialTemplates[guid] : string.Empty;
                        TemplateMultiPass mp   = TemplateMultiPass.CreateInstance <TemplateMultiPass>();
                        mp.Init(name, guid, true);
                        templatesManager.AddTemplate(mp);
                    }
                }
            }

            if (deletedAssets.Length > 0)
            {
                if (deletedAssets[0].IndexOf(Constants.InvalidPostProcessDatapath) < 0)
                {
                    for (int i = 0; i < deletedAssets.Length; i++)
                    {
                        string             guid         = AssetDatabase.AssetPathToGUID(deletedAssets[i]);
                        TemplateDataParent templateData = templatesManager.GetTemplate(guid);
                        if (templateData != null)
                        {
                            // Close any window using that template
                            int windowCount = IOUtils.AllOpenedWindows.Count;
                            for (int windowIdx = 0; windowIdx < windowCount; windowIdx++)
                            {
                                TemplateMasterNode masterNode = IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.CurrentMasterNode as TemplateMasterNode;
                                if (masterNode != null && masterNode.CurrentTemplate.GUID.Equals(templateData.GUID))
                                {
                                    IOUtils.AllOpenedWindows[windowIdx].Close();
                                }
                            }

                            templatesManager.RemoveTemplate(templateData);
                            refreshMenuItems = true;
                        }
                    }
                }
            }

            //for ( int i = 0; i < movedAssets.Length; i++ )
            //{
            //	if ( TemplateHelperFunctions.CheckIfTemplate( movedAssets[ i ] ) )
            //	{
            //		refreshMenuItems = true;
            //		break;
            //	}
            //}

            //for ( int i = 0; i < movedFromAssetPaths.Length; i++ )
            //{
            //	if ( TemplateHelperFunctions.CheckIfTemplate( movedFromAssetPaths[ i ] ) )
            //	{
            //		refreshMenuItems = true;
            //		break;
            //	}
            //}

            if (refreshMenuItems)
            {
                //UnityEngine.Debug.Log( "Refresh Menu Items" );
                refreshMenuItems = false;
                templatesManager.CreateTemplateMenuItems();

                AmplifyShaderEditorWindow currWindow = UIUtils.CurrentWindow;

                int windowCount = IOUtils.AllOpenedWindows.Count;
                for (int windowIdx = 0; windowIdx < windowCount; windowIdx++)
                {
                    UIUtils.CurrentWindow = IOUtils.AllOpenedWindows[windowIdx];
                    IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.ForceCategoryRefresh();
                }
                UIUtils.CurrentWindow = currWindow;
            }
        }
Пример #9
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            if (UIUtils.CurrentWindow == null)
            {
                return;
            }

            TemplatesManager templatesManager = UIUtils.CurrentWindow.TemplatesManagerInstance;

            if (templatesManager == null)
            {
                return;
            }

            if (!templatesManager.Initialized)
            {
                templatesManager.Init();
            }

            bool refreshMenuItems = false;

            for (int i = 0; i < importedAssets.Length; i++)
            {
                if (TemplateHelperFunctions.CheckIfTemplate(importedAssets[i]))
                {
                    string             guid         = AssetDatabase.AssetPathToGUID(importedAssets[i]);
                    TemplateDataParent templateData = templatesManager.GetTemplate(guid);
                    if (templateData != null)
                    {
                        refreshMenuItems = templateData.Reload() || refreshMenuItems;
                    }
                    else
                    {
                        refreshMenuItems = true;
                        string            name = TemplatesManager.OfficialTemplates.ContainsKey(guid) ? TemplatesManager.OfficialTemplates[guid] : string.Empty;
                        TemplateMultiPass mp   = TemplateMultiPass.CreateInstance <TemplateMultiPass>();
                        mp.Init(name, guid, true);
                        templatesManager.AddTemplate(mp);
                    }
                }
            }

            if (deletedAssets.Length > 0)
            {
                if (deletedAssets[0].IndexOf(Constants.InvalidPostProcessDatapath) < 0)
                {
                    for (int i = 0; i < deletedAssets.Length; i++)
                    {
                        string             guid         = AssetDatabase.AssetPathToGUID(deletedAssets[i]);
                        TemplateDataParent templateData = templatesManager.GetTemplate(guid);
                        if (templateData != null)
                        {
                            // Close any window using that template
                            int windowCount = IOUtils.AllOpenedWindows.Count;
                            for (int windowIdx = 0; windowIdx < windowCount; windowIdx++)
                            {
                                TemplateMasterNode masterNode = IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.CurrentMasterNode as TemplateMasterNode;
                                if (masterNode != null && masterNode.CurrentTemplate.GUID.Equals(templateData.GUID))
                                {
                                    IOUtils.AllOpenedWindows[windowIdx].Close();
                                }
                            }

                            templatesManager.RemoveTemplate(templateData);
                            refreshMenuItems = true;
                        }
                    }
                }
            }

            //for ( int i = 0; i < movedAssets.Length; i++ )
            //{
            //	if ( TemplateHelperFunctions.CheckIfTemplate( movedAssets[ i ] ) )
            //	{
            //		refreshMenuItems = true;
            //		break;
            //	}
            //}

            //for ( int i = 0; i < movedFromAssetPaths.Length; i++ )
            //{
            //	if ( TemplateHelperFunctions.CheckIfTemplate( movedFromAssetPaths[ i ] ) )
            //	{
            //		refreshMenuItems = true;
            //		break;
            //	}
            //}

            if (refreshMenuItems)
            {
                //UnityEngine.Debug.Log( "Refresh Menu Items" );
                refreshMenuItems = false;
                templatesManager.CreateTemplateMenuItems();

                int windowCount = IOUtils.AllOpenedWindows.Count;
                for (int windowIdx = 0; windowIdx < windowCount; windowIdx++)
                {
                    IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.ForceCategoryRefresh();
                }
            }
        }
Пример #10
0
        public TemplatePass(TemplateMultiPass template, TemplateSubShader subShader, int subshaderIdx, int passIdx, TemplateIdManager idManager, string uniquePrefix, int offsetIdx, TemplatePassInfo passInfo, ref Dictionary <string, TemplateShaderPropertyData> duplicatesHelper)
        {
            m_idx = passIdx;

            m_uniquePrefix = uniquePrefix;
            idManager.RegisterPassId(passInfo.Data);
            m_isMainPass = passInfo.Data.Contains(TemplatesManager.TemplateMainPassTag);
            if (!m_isMainPass)
            {
                string id      = string.Empty;
                int    idIndex = 0;
                m_isInvisible = TemplateHelperFunctions.FetchInvisibleInfo(passInfo.Data, ref m_invisibleOptions, ref id, ref idIndex);
                if (m_isInvisible)
                {
                    idManager.RegisterId(idIndex, uniquePrefix + id, id, true);
                }
            }

            FetchPassName(offsetIdx, passInfo.Data);
            if (m_passNameContainer.Index > -1)
            {
                idManager.RegisterId(m_passNameContainer.Index, uniquePrefix + m_passNameContainer.Id, m_passNameContainer.Id);
            }
            else
            {
                m_passNameContainer.Data = string.Format(DefaultPassNameStr, subshaderIdx, passIdx);
            }

#if CUSTOM_OPTIONS_AVAILABLE
            m_customOptionsContainer = TemplateOptionsToolsHelper.GenerateOptionsContainer(false, passInfo.Data);
            if (m_customOptionsContainer.Enabled)
            {
                idManager.RegisterId(m_customOptionsContainer.Index, uniquePrefix + m_customOptionsContainer.Body, m_customOptionsContainer.Body, true);
            }
            //m_customOptionsContainer.CopyPortOptionsFrom( subShader.CustomOptionsContainer, m_passNameContainer.Data );
#endif
            m_modules = new TemplateModulesData(m_customOptionsContainer, idManager, m_templateProperties, uniquePrefix + "Module", offsetIdx, passInfo.Data, false);

            if (!m_modules.PassTag.IsValid)
            {
                m_modules.PassTag.StartIdx = passInfo.GlobalStartIdx;
                m_templateProperties.AddId(passInfo.Data, m_modules.PassTag.Id, passInfo.LocalStartIdx, false);
                //m_modules.PassTag.StartIdx -= m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].Indentation.Length;
                //m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].UseIndentationAtStart = false;
                idManager.RegisterId(m_modules.PassTag.StartIdx, m_modules.UniquePrefix + m_modules.PassTag.Id, string.Empty);
            }
            m_modules.SetPassUniqueNameIfUndefined(m_passNameContainer.Data);

            m_modules.SRPType = subShader.Modules.SRPType;
            if (m_modules.SRPType == TemplateSRPType.HD)
            {
                m_modules.SRPIsPBR = passInfo.Data.Contains(TemplateHelperFunctions.HDPBRTag);
            }

            Dictionary <string, TemplateShaderPropertyData> ownDuplicatesDict = new Dictionary <string, TemplateShaderPropertyData>(duplicatesHelper);
            TemplateHelperFunctions.CreateShaderGlobalsList(passInfo.Data, ref m_availableShaderGlobals, ref ownDuplicatesDict);

            // Vertex and Interpolator data
            FetchVertexAndInterpData(template, subShader.Modules, offsetIdx, passInfo.Data);
            if (m_vertexDataContainer != null)
            {
                idManager.RegisterId(m_vertexDataContainer.VertexDataStartIdx, uniquePrefix + m_vertexDataContainer.VertexDataId, m_vertexDataContainer.VertexDataId);
            }

            if (m_interpolatorDataContainer != null)
            {
                idManager.RegisterId(m_interpolatorDataContainer.InterpDataStartIdx, uniquePrefix + m_interpolatorDataContainer.InterpDataId, m_interpolatorDataContainer.InterpDataId);
            }

            //Fetch function code areas
            FetchCodeAreas(offsetIdx, TemplatesManager.TemplateVertexCodeBeginArea, MasterNodePortCategory.Vertex, passInfo.Data);
            if (m_vertexFunctionData != null)
            {
                idManager.RegisterId(m_vertexFunctionData.Position, uniquePrefix + m_vertexFunctionData.Id, m_vertexFunctionData.Id);
            }

            FetchCodeAreas(offsetIdx, TemplatesManager.TemplateFragmentCodeBeginArea, MasterNodePortCategory.Fragment, passInfo.Data);
            if (m_fragmentFunctionData != null)
            {
                idManager.RegisterId(m_fragmentFunctionData.Position, uniquePrefix + m_fragmentFunctionData.Id, m_fragmentFunctionData.Id);
            }

            //Fetching inputs, must be do
            if (m_fragmentFunctionData != null)
            {
                FetchInputs(offsetIdx, MasterNodePortCategory.Fragment, passInfo.Data);
            }

            if (m_vertexFunctionData != null)
            {
                FetchInputs(offsetIdx, MasterNodePortCategory.Vertex, passInfo.Data);
            }

            //Fetch local variables must be done after fetching code areas as it needs them to see is variable is on vertex or fragment
            TemplateHelperFunctions.FetchLocalVars(passInfo.Data, ref m_localVarsList, m_vertexFunctionData, m_fragmentFunctionData);

            int localVarCount = m_localVarsList.Count;
            if (localVarCount > 0)
            {
                idManager.RegisterTag(TemplatesManager.TemplateLocalVarTag);
                for (int i = 0; i < localVarCount; i++)
                {
                    if (m_localVarsList[i].IsSpecialVar)
                    {
                        idManager.RegisterTag(m_localVarsList[i].Id);
                    }
                }
            }

            int inputsCount = m_inputDataList.Count;
            for (int i = 0; i < inputsCount; i++)
            {
                if (m_inputDataList[i] != null)
                {
                    idManager.RegisterId(m_inputDataList[i].TagGlobalStartIdx, uniquePrefix + m_inputDataList[i].TagId, m_inputDataList[i].TagId);
                }
            }

            //int passEndIndex = passInfo.Data.LastIndexOf( "}" );
            //if( passEndIndex > 0 )
            //{
            //	int identationIndex = -1;
            //	for( int i = passEndIndex; i >= 0; i-- )
            //	{
            //		if( passInfo.Data[ i ] == TemplatesManager.TemplateNewLine )
            //		{
            //			identationIndex = i + 1;
            //			break;
            //		}

            //		if( i == 0 )
            //		{
            //			identationIndex = 0;
            //		}
            //	}

            //	if( identationIndex > -1 )
            //	{
            //		int length = passEndIndex - identationIndex;
            //		string indentation = ( length > 0 ) ? passInfo.Data.Substring( identationIndex, length ) : string.Empty;
            //		TemplateProperty templateProperty = new TemplateProperty( TemplatesManager.TemplateEndPassTag, indentation, false );
            //		m_templateProperties.AddId( templateProperty );
            //		idManager.RegisterId( offsetIdx + passEndIndex, uniquePrefix + TemplatesManager.TemplateEndPassTag, string.Empty );
            //	}
            //}

            ownDuplicatesDict.Clear();
            ownDuplicatesDict = null;
        }
Пример #11
0
        void FetchVertexAndInterpData(TemplateMultiPass template, TemplateModulesData subShaderModule, int offsetIdx, string body)
        {
            // Vertex Data
            try
            {
                int vertexDataTagBegin = body.IndexOf(TemplatesManager.TemplateVertexDataTag);
                if (vertexDataTagBegin > -1)
                {
                    m_vertexDataContainer = new VertexDataContainer();
                    m_vertexDataContainer.VertexDataStartIdx = offsetIdx + vertexDataTagBegin;
                    int vertexDataTagEnd = body.IndexOf(TemplatesManager.TemplateEndOfLine, vertexDataTagBegin);
                    m_vertexDataContainer.VertexDataId = body.Substring(vertexDataTagBegin, vertexDataTagEnd + TemplatesManager.TemplateEndOfLine.Length - vertexDataTagBegin);
                    int    dataBeginIdx = body.LastIndexOf('{', vertexDataTagBegin, vertexDataTagBegin);
                    string vertexData   = body.Substring(dataBeginIdx + 1, vertexDataTagBegin - dataBeginIdx);

                    int    parametersBegin = vertexDataTagBegin + TemplatesManager.TemplateVertexDataTag.Length;
                    string parameters      = body.Substring(parametersBegin, vertexDataTagEnd - parametersBegin);
                    m_vertexDataContainer.VertexData = TemplateHelperFunctions.CreateVertexDataList(vertexData, parameters);
                    m_templateProperties.AddId(body, m_vertexDataContainer.VertexDataId);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            // Available interpolators
            try
            {
                int interpDataBegin = body.IndexOf(TemplatesManager.TemplateInterpolatorBeginTag);
                if (interpDataBegin > -1)
                {
                    int    interpDataEnd = body.IndexOf(TemplatesManager.TemplateEndOfLine, interpDataBegin);
                    string interpDataId  = body.Substring(interpDataBegin, interpDataEnd + TemplatesManager.TemplateEndOfLine.Length - interpDataBegin);

                    int    dataBeginIdx = body.LastIndexOf('{', interpDataBegin, interpDataBegin);
                    string interpData   = body.Substring(dataBeginIdx + 1, interpDataBegin - dataBeginIdx);

                    int interpolatorAmount = TemplateHelperFunctions.AvailableInterpolators["2.5"];

                    if (m_modules.ShaderModel.IsValid)
                    {
                        interpolatorAmount = m_modules.ShaderModel.InterpolatorAmount;
                    }
                    else if (subShaderModule.ShaderModel.IsValid)
                    {
                        interpolatorAmount = subShaderModule.ShaderModel.InterpolatorAmount;
                    }
                    else if (template.GlobalShaderModel.IsValid)
                    {
                        interpolatorAmount = template.GlobalShaderModel.InterpolatorAmount;
                    }

                    m_interpolatorDataContainer = TemplateHelperFunctions.CreateInterpDataList(interpData, interpDataId, interpolatorAmount);
                    m_interpolatorDataContainer.InterpDataId       = interpDataId;
                    m_interpolatorDataContainer.InterpDataStartIdx = offsetIdx + interpDataBegin;
                    m_templateProperties.AddId(body, interpDataId);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
        void FetchTessellationData(TemplateMultiPass template, TemplateModulesData subShaderModule, int offsetIdx, string body)
        {
            // Tessellation VControl Tag
            try
            {
                int vcontrolcodeBegin = body.IndexOf(TemplatesManager.TemplateTessVControlTag);
                if (vcontrolcodeBegin > -1)
                {
                    m_tessVControlTag          = new TemplateTessVControlTag();
                    m_tessVControlTag.Id       = TemplatesManager.TemplateTessVControlTag;
                    m_tessVControlTag.StartIdx = offsetIdx + vcontrolcodeBegin;

                    m_templateProperties.AddId(body, m_tessVControlTag.Id);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            // Tessellation Control Data
            try
            {
                int controlCodeBegin = body.IndexOf(TemplatesManager.TemplateTessControlCodeArea);
                if (controlCodeBegin > -1)
                {
                    int beginIdx = controlCodeBegin + TemplatesManager.TemplateTessControlCodeArea.Length;
                    int endIdx   = body.IndexOf(TemplatesManager.TemplateEndOfLine, beginIdx);
                    int length   = endIdx - beginIdx;

                    string parameters = body.Substring(beginIdx, length);

                    string[] parametersArr = parameters.Split(IOUtils.FIELD_SEPARATOR);

                    string id            = body.Substring(controlCodeBegin, endIdx + TemplatesManager.TemplateEndOfLine.Length - controlCodeBegin);
                    string inParameters  = parametersArr[0];
                    string outParameters = (parametersArr.Length > 1) ? parametersArr[1] : string.Empty;

                    m_tessControlData = new TemplateTessControlData(offsetIdx + controlCodeBegin, id, inParameters, outParameters);

                    m_templateProperties.AddId(body, id);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            // Tessellation Domain Data
            try
            {
                int domainCodeBegin = body.IndexOf(TemplatesManager.TemplateTessDomainCodeArea);
                if (domainCodeBegin > -1)
                {
                    int beginIdx = domainCodeBegin + TemplatesManager.TemplateTessDomainCodeArea.Length;
                    int endIdx   = body.IndexOf(TemplatesManager.TemplateEndOfLine, beginIdx);
                    int length   = endIdx - beginIdx;

                    string parameters = body.Substring(beginIdx, length);

                    string[] parametersArr = parameters.Split(IOUtils.FIELD_SEPARATOR);

                    string id             = body.Substring(domainCodeBegin, endIdx + TemplatesManager.TemplateEndOfLine.Length - domainCodeBegin);
                    string inParameters   = (parametersArr.Length > 0) ? parametersArr[0] : string.Empty;
                    string outParameters  = (parametersArr.Length > 1) ? parametersArr[1] : string.Empty;
                    string baryParameters = (parametersArr.Length > 2) ? parametersArr[2] : string.Empty;

                    m_tessDomainData = new TemplateTessDomainData(offsetIdx + domainCodeBegin, id, inParameters, outParameters, baryParameters);

                    m_templateProperties.AddId(body, id);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
        public TemplateSubShader(TemplateMultiPass template, int subShaderIx, TemplateIdManager idManager, string uniquePrefix, TemplateSubShaderInfo subShaderInfo, ref Dictionary <string, TemplateShaderPropertyData> duplicatesHelper)
        {
            m_idx = subShaderIx;

            m_uniquePrefix = uniquePrefix;

            FetchLOD(subShaderInfo.StartIdx, subShaderInfo.Modules);
            if (m_LODContainer.Index > -1)
            {
                idManager.RegisterId(m_LODContainer.Index, uniquePrefix + "Module" + m_LODContainer.Id, m_LODContainer.Id);
            }

            m_customOptionsContainer = TemplateOptionsToolsHelper.GenerateOptionsContainer(true, subShaderInfo.Data);
            if (m_customOptionsContainer.Enabled)
            {
                idManager.RegisterId(m_customOptionsContainer.Index, uniquePrefix + m_customOptionsContainer.Body, m_customOptionsContainer.Body, true);
            }

            m_modules = new TemplateModulesData(m_customOptionsContainer, idManager, m_templateProperties, uniquePrefix + "Module", subShaderInfo.StartIdx, subShaderInfo.Modules, true);
            if (m_modules.SRPType == TemplateSRPType.HD)
            {
                m_modules.SRPIsPBR = subShaderInfo.Data.Contains(TemplateHelperFunctions.HDPBRTag);
            }

            Dictionary <string, TemplateShaderPropertyData> ownDuplicatesDict = new Dictionary <string, TemplateShaderPropertyData>(duplicatesHelper);

            TemplateHelperFunctions.CreateShaderGlobalsList(subShaderInfo.Modules, ref m_availableShaderGlobals, ref ownDuplicatesDict, subShaderIx, -1);
            if (m_modules.SRPType == TemplateSRPType.BuiltIn)
            {
                TemplateHelperFunctions.CheckUnityBuiltinGlobalMacros(subShaderInfo.Modules, ref m_availableShaderGlobals, ref ownDuplicatesDict, subShaderIx, -1);
            }

            m_passAmount = subShaderInfo.Passes.Count;

            //if( !m_modules.PassTag.IsValid )
            //{
            //	m_modules.PassTag.StartIdx = subShaderData.Passes[ 0 ].GlobalStartIdx;
            //	m_templateProperties.AddId( subShaderData.Data, m_modules.PassTag.Id, subShaderData.Passes[ 0 ].LocalStartIdx, m_modules.PassTag.SearchIndentation );
            //	m_modules.PassTag.StartIdx -= m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].Indentation.Length;
            //	m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].UseIndentationAtStart = true;
            //	idManager.RegisterId( m_modules.PassTag.StartIdx, m_modules.UniquePrefix + m_modules.PassTag.Id, string.Empty );
            //}

            int firstVisible     = -1;
            int currAddedPassIdx = 0;

            for (int passIdx = 0; passIdx < m_passAmount; passIdx++)
            {
                TemplatePass newPass = new TemplatePass(template, this, subShaderIx, passIdx, idManager, uniquePrefix + "Pass" + passIdx, subShaderInfo.Passes[passIdx].GlobalStartIdx, subShaderInfo.Passes[passIdx], ref ownDuplicatesDict);
                if (newPass.AddToList)
                {
                    if (newPass.IsMainPass && m_mainPass < 0)
                    {
                        m_mainPass         = currAddedPassIdx;
                        m_foundMainPassTag = true;
                    }
                    else if (!newPass.IsInvisible && firstVisible < 0)
                    {
                        firstVisible = currAddedPassIdx;
                    }

                    m_passes.Add(newPass);
                    currAddedPassIdx++;
                }
                else
                {
                    newPass.Destroy();
                    newPass = null;
                }
            }

            if (m_mainPass < 0)
            {
                // If no main pass was set then choose the first visible one
                m_mainPass = (firstVisible < 0) ? 0 : firstVisible;
                m_passes[m_mainPass].IsMainPass = true;
            }

            ownDuplicatesDict.Clear();
            ownDuplicatesDict = null;
        }
Пример #14
0
 public override void Destroy()
 {
     base.Destroy();
     m_templateMPData = null;
 }
        public override void ReadFromDeprecated(ref string[] nodeParams, Type oldType = null)
        {
            base.ReadFromString(ref nodeParams);
            try
            {
                string currShaderName = GetCurrentParam(ref nodeParams);
                if (currShaderName.Length > 0)
                {
                    currShaderName = UIUtils.RemoveShaderInvalidCharacters(currShaderName);
                }

                string templateGUID       = GetCurrentParam(ref nodeParams);
                string templateShaderName = string.Empty;
                if (UIUtils.CurrentShaderVersion() > 13601)
                {
                    templateShaderName = GetCurrentParam(ref nodeParams);
                }

                TemplateMultiPass template = TemplatesManager.GetTemplate(templateGUID) as TemplateMultiPass;
                if (template != null)
                {
                    m_templateGUID = templateGUID;
                    SetTemplate(null, false, true, 0, 0);
                }
                else
                {
                    template = TemplatesManager.GetTemplateByName(templateShaderName) as TemplateMultiPass;
                    if (template != null)
                    {
                        m_templateGUID = template.GUID;
                        SetTemplate(null, false, true, 0, 0);
                    }
                    else
                    {
                        m_masterNodeCategory = -1;
                    }
                }
                // only in here, after SetTemplate, we know if shader name is to be used as title or not
                ShaderName = currShaderName;
                if (UIUtils.CurrentShaderVersion() > 13902)
                {
                    //BLEND MODULE
                    if (m_templateMultiPass.SubShaders[0].Modules.BlendData.ValidBlendMode)
                    {
                        m_subShaderModule.BlendOpHelper.ReadBlendModeFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                    else if (m_templateMultiPass.SubShaders[0].Passes[0].Modules.BlendData.ValidBlendMode)
                    {
                        m_passModule.BlendOpHelper.ReadBlendModeFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }

                    if (m_templateMultiPass.SubShaders[0].Modules.BlendData.ValidBlendOp)
                    {
                        m_subShaderModule.BlendOpHelper.ReadBlendOpFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                    else if (m_templateMultiPass.SubShaders[0].Passes[0].Modules.BlendData.ValidBlendOp)
                    {
                        m_passModule.BlendOpHelper.ReadBlendOpFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }


                    //CULL MODE
                    if (m_templateMultiPass.SubShaders[0].Modules.CullModeData.DataCheck == TemplateDataCheck.Valid)
                    {
                        m_subShaderModule.CullModeHelper.ReadFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                    else if (m_templateMultiPass.SubShaders[0].Passes[0].Modules.CullModeData.DataCheck == TemplateDataCheck.Valid)
                    {
                        m_passModule.CullModeHelper.ReadFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }

                    //COLOR MASK
                    if (m_templateMultiPass.SubShaders[0].Modules.ColorMaskData.DataCheck == TemplateDataCheck.Valid)
                    {
                        m_subShaderModule.ColorMaskHelper.ReadFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                    else if (m_templateMultiPass.SubShaders[0].Passes[0].Modules.ColorMaskData.DataCheck == TemplateDataCheck.Valid)
                    {
                        m_passModule.ColorMaskHelper.ReadFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }

                    //STENCIL BUFFER
                    if (m_templateMultiPass.SubShaders[0].Modules.StencilData.DataCheck == TemplateDataCheck.Valid)
                    {
                        m_subShaderModule.StencilBufferHelper.ReadFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                    else if (m_templateMultiPass.SubShaders[0].Passes[0].Modules.StencilData.DataCheck == TemplateDataCheck.Valid)
                    {
                        m_passModule.StencilBufferHelper.ReadFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                }

                if (UIUtils.CurrentShaderVersion() > 14202)
                {
                    //DEPTH OPTIONS
                    if (m_templateMultiPass.SubShaders[0].Modules.DepthData.ValidZWrite)
                    {
                        m_subShaderModule.DepthOphelper.ReadZWriteFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                    else if (m_templateMultiPass.SubShaders[0].Passes[0].Modules.DepthData.ValidZWrite)
                    {
                        m_passModule.DepthOphelper.ReadZWriteFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }

                    if (m_templateMultiPass.SubShaders[0].Modules.DepthData.ValidZTest)
                    {
                        m_subShaderModule.DepthOphelper.ReadZTestFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                    else if (m_templateMultiPass.SubShaders[0].Passes[0].Modules.DepthData.ValidZTest)
                    {
                        m_subShaderModule.DepthOphelper.ReadZTestFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }

                    if (m_templateMultiPass.SubShaders[0].Modules.DepthData.ValidOffset)
                    {
                        m_subShaderModule.DepthOphelper.ReadOffsetFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                    else if (m_templateMultiPass.SubShaders[0].Passes[0].Modules.DepthData.ValidOffset)
                    {
                        m_passModule.DepthOphelper.ReadOffsetFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                }

                //TAGS
                if (UIUtils.CurrentShaderVersion() > 14301)
                {
                    if (m_templateMultiPass.SubShaders[0].Modules.TagData.DataCheck == TemplateDataCheck.Valid)
                    {
                        m_subShaderModule.TagsHelper.ReadFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                    else if (m_templateMultiPass.SubShaders[0].Passes[0].Modules.TagData.DataCheck == TemplateDataCheck.Valid)
                    {
                        m_passModule.TagsHelper.ReadFromString(ref m_currentReadParamIdx, ref nodeParams);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e, this);
            }
            m_containerGraph.CurrentCanvasMode = NodeAvailability.TemplateShader;
        }
        public void SetTemplate(TemplateMultiPass template, bool writeDefaultData, bool fetchMasterNodeCategory, int subShaderIdx, int passIdx)
        {
            if (subShaderIdx > -1)
            {
                m_subShaderIdx = subShaderIdx;
            }

            if (passIdx > -1)
            {
                m_passIdx = passIdx;
            }


            ReleaseResources();
            m_templateMultiPass = (template == null) ? TemplatesManager.GetTemplate(m_templateGUID) as TemplateMultiPass : template;
            if (m_templateMultiPass != null)
            {
                if (m_subShaderIdx >= m_templateMultiPass.SubShaders.Count ||
                    m_passIdx >= m_templateMultiPass.SubShaders[m_subShaderIdx].Passes.Count)
                {
                    if (DebugConsoleWindow.DeveloperMode)
                    {
                        Debug.LogFormat("Inexisting pass {0}. Cancelling template fetch", m_originalPassName);
                    }

                    return;
                }

                m_isMainOutputNode = m_templateMultiPass.SubShaders[m_subShaderIdx].Passes[m_passIdx].IsMainPass;
                if (m_isMainOutputNode)
                {
                    // We cannot use UIUtils.MasterNodeOnTexture.height since this method can be
                    // called before UIUtils is initialized
                    m_insideSize.y = 55;
                }
                else
                {
                    m_insideSize.y = 0;
                }

                //IsMainOutputNode = m_mainMPMasterNode;
                m_isInvisible = m_templateMultiPass.SubShaders[m_subShaderIdx].Passes[m_passIdx].IsInvisible;

                m_originalPassName = m_templateMultiPass.SubShaders[m_subShaderIdx].Passes[m_passIdx].PassNameContainer.Data;

                m_shaderNameIsTitle = (m_templateMultiPass.SubShaders[m_subShaderIdx].Passes.Count == 1);

                if (m_templateMultiPass.SubShaders[m_subShaderIdx].LODContainer.Index > -1)
                {
                    m_subShaderLODStr = m_templateMultiPass.SubShaders[m_subShaderIdx].LODContainer.Id;
                    m_subShaderLOD    = Convert.ToInt32(m_templateMultiPass.SubShaders[m_subShaderIdx].LODContainer.Data);
                }
                else
                {
                    m_subShaderLOD = -1;
                }
                m_fetchMasterNodeCategory = fetchMasterNodeCategory;
                m_templateGUID            = m_templateMultiPass.GUID;
                UpdatePortInfo();
                //bool updateInfofromTemplate = UpdatePortInfo();
                //if( updateInfofromTemplate )
                //{
                m_subShaderModule.FetchDataFromTemplate(m_templateMultiPass.SubShaders[m_subShaderIdx].Modules);
                m_passModule.FetchDataFromTemplate(m_templateMultiPass.SubShaders[m_subShaderIdx].Passes[m_passIdx].Modules);
                //}

                RegisterProperties();
                if (writeDefaultData)
                {
                    ShaderName = m_templateMultiPass.DefaultShaderName;
                    m_passName = m_templateMultiPass.SubShaders[m_subShaderIdx].Passes[m_passIdx].PassNameContainer.Data;
                    if (!m_templateMultiPass.IsSinglePass && !m_shaderNameIsTitle)
                    {
                        SetClippedTitle(m_passName);
                    }
                }

                UpdateSubShaderPassStr();

                if (m_isMainOutputNode)
                {
                    m_fireTemplateChange = true;
                }
            }
        }