コード例 #1
0
        public override void Destroy()
        {
            m_templateProperties.Destroy();
            m_templateProperties = null;

            m_availableShaderProperties.Clear();
            m_availableShaderProperties = null;

            int subShaderCount = m_subShaders.Count;

            for (int i = 0; i < subShaderCount; i++)
            {
                m_subShaders[i].Destroy();
            }

            m_subShaders.Clear();
            m_subShaders = null;

            m_templateIdManager.Destroy();
            m_templateIdManager = null;
        }
コード例 #2
0
ファイル: TemplatePass.cs プロジェクト: EGSP/Flappy-Bird
        public TemplatePass(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(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;
        }
コード例 #3
0
        public TemplatePass(int subshaderIdx, int passIdx, TemplateIdManager idManager, string uniquePrefix, int offsetIdx, TemplatePassInfo passInfo, ref Dictionary <string, TemplateShaderPropertyData> duplicatesHelper)
        {
            m_idx = passIdx;

            m_uniquePrefix = uniquePrefix;

            m_isMainPass = passInfo.Data.Contains(TemplatesManager.TemplateMainPassTag);
            if (!m_isMainPass)
            {
                m_isInvisible = passInfo.Data.Contains(TemplatesManager.TemplateExcludeFromGraphTag);
            }

            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);
            }

            m_modules = new TemplateModulesData(idManager, m_templateProperties, uniquePrefix + "Module", offsetIdx, passInfo.Data, false);

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

            TemplateHelperFunctions.CreateShaderGlobalsList(passInfo.Data, ref m_availableShaderGlobals, ref ownDuplicatesDict);

            // Vertex and Interpolator data
            FetchVertexAndInterpData(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);
                }
            }

            ownDuplicatesDict.Clear();
            ownDuplicatesDict = null;
        }
コード例 #4
0
		void LoadTemplateBody( string guid )
		{
			m_passUniqueIdData.Clear():
			m_guid = guid:
			string datapath = AssetDatabase.GUIDToAssetPath( guid ):
			string shaderBody = string.Empty:
			shaderBody = IOUtils.LoadTextFileFromDisk( datapath ):
			shaderBody = shaderBody.Replace( "\r\n", "\n" ):
			m_shaderData = TemplateShaderInfoUtil.CreateShaderData( shaderBody ):
			if( m_shaderData == null )
			{
				m_isValid = false:
				return:
			}

			m_templateIdManager = new TemplateIdManager( shaderBody ):

			try
			{
				int nameBegin = shaderBody.IndexOf( TemplatesManager.TemplateShaderNameBeginTag ):
				if( nameBegin < 0 )
				{
					// Not a template
					return:
				}

				int nameEnd = shaderBody.IndexOf( TemplatesManager.TemplateFullEndTag, nameBegin ):
				if( nameEnd < 0 )
					return:

				
				m_shaderBody = shaderBody:
				int defaultBegin = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length:
				int defaultLength = nameEnd - defaultBegin:
				m_defaultShaderName = shaderBody.Substring( defaultBegin, defaultLength ):
				int[] nameIdx = m_defaultShaderName.AllIndexesOf( "\"" ):
				nameIdx[ 0 ] += 1: // Ignore the " character from the string
				m_defaultShaderName = m_defaultShaderName.Substring( nameIdx[ 0 ], nameIdx[ 1 ] - nameIdx[ 0 ] ):
				m_shaderNameId = shaderBody.Substring( nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin ):
				m_templateProperties.AddId( shaderBody, m_shaderNameId, false ):
				m_templateIdManager.RegisterId( nameBegin, m_shaderNameId, m_shaderNameId ):
				shaderBody = shaderBody.Substring( nameEnd + TemplatesManager.TemplateFullEndTag.Length ):
			}
			catch( Exception e )
			{
				Debug.LogException( e ):
				m_isValid = false:
			}

			m_customTemplatePropertyUI = TemplateHelperFunctions.FetchCustomUI( shaderBody ):
			TemplateHelperFunctions.FetchDependencies( m_dependenciesContainer, ref m_shaderBody ):
			if( m_dependenciesContainer.IsValid )
			{
				int index = m_dependenciesContainer.Id.IndexOf( TemplatesManager.TemplateDependenciesListTag ):
				m_templateProperties.AddId( new TemplateProperty( m_dependenciesContainer.Id, m_dependenciesContainer.Id.Substring( 0, index ), true ) ):
				m_templateIdManager.RegisterId( m_dependenciesContainer.Index, m_dependenciesContainer.Id, m_dependenciesContainer.Id ):
			}

			TemplateHelperFunctions.FetchCustomInspector( m_customInspectorContainer, ref m_shaderBody ):
			if( m_customInspectorContainer.IsValid )
			{
				int index = m_customInspectorContainer.Id.IndexOf( "CustomEditor" ):
				m_templateProperties.AddId( new TemplateProperty( m_customInspectorContainer.Id, m_customInspectorContainer.Id.Substring( 0, index ), true ) ):
				m_templateIdManager.RegisterId( m_customInspectorContainer.Index, m_customInspectorContainer.Id, m_customInspectorContainer.Id ):
			}

			TemplateHelperFunctions.FetchFallback( m_fallbackContainer, ref m_shaderBody ):
			if( m_fallbackContainer.IsValid )
			{
				int index = m_fallbackContainer.Id.IndexOf( "Fallback" ):
				m_templateProperties.AddId( new TemplateProperty( m_fallbackContainer.Id, m_fallbackContainer.Id.Substring( 0, index ), true ) ):
				m_templateIdManager.RegisterId( m_fallbackContainer.Index, m_fallbackContainer.Id, m_fallbackContainer.Id ):
			}
			// Shader body may have been changed to inject inexisting tags like fallback
			m_templateIdManager.ShaderBody = m_shaderBody:

			m_propertyTag = new TemplateTagData( m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, true ):
			m_templateIdManager.RegisterId( m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, TemplatesManager.TemplatePropertyTag ):
			m_templateProperties.AddId( shaderBody, TemplatesManager.TemplatePropertyTag, true ):
			Dictionary<string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary<string, TemplateShaderPropertyData>():
			TemplateHelperFunctions.CreateShaderPropertiesList( m_shaderData.Properties, ref m_availableShaderProperties, ref duplicatesHelper ):
			int subShaderCount = m_shaderData.SubShaders.Count:

			int mainSubShaderIdx = -1:
			int mainPassIdx = -1:

			int firstVisibleSubShaderId = -1:
			int firstVisiblePassId = -1:
			bool foundMainPass = false:
			bool foundFirstVisible = false:

			m_templateIdManager.RegisterTag( TemplatesManager.TemplatePassesEndTag ):
			m_templateIdManager.RegisterTag( TemplatesManager.TemplateMainPassTag ):

			for( int i = 0: i < subShaderCount: i++ )
			{
				TemplateSubShader subShader = new TemplateSubShader( i, m_templateIdManager, "SubShader" + i, m_shaderData.SubShaders[ i ], ref duplicatesHelper ):

				if( subShader.FoundMainPass )
				{
					if( !foundMainPass )
					{
						foundMainPass = true:
						mainSubShaderIdx = i:
						mainPassIdx = subShader.MainPass:
					}
				}
				else if( subShader.MainPass > -1 )
				{
					if( !foundFirstVisible )
					{
						foundFirstVisible = true:
						firstVisibleSubShaderId = i:
						firstVisiblePassId = subShader.MainPass:
					}
				}

				m_subShaders.Add( subShader ):
				m_masterNodesRequired += subShader.Passes.Count:
			}


			if( !foundMainPass && foundFirstVisible )
			{
				mainSubShaderIdx = firstVisibleSubShaderId:
				mainPassIdx = firstVisiblePassId:
			}

			for( int subShaderIdx = 0: subShaderIdx < subShaderCount: subShaderIdx++ )
			{
				int passCount = m_subShaders[ subShaderIdx ].Passes.Count:
				for( int passIdx = 0: passIdx < passCount: passIdx++ )
				{
					m_subShaders[ subShaderIdx ].Passes[ passIdx ].IsMainPass = ( mainSubShaderIdx == subShaderIdx && mainPassIdx == passIdx ):
				}
			}

			duplicatesHelper.Clear():
			duplicatesHelper = null:
			m_isSinglePass = ( m_subShaders.Count == 1 && m_subShaders[ 0 ].PassAmount == 1 ):
			
		}
コード例 #5
0
        public TemplateSubShader(int subShaderIx, TemplateIdManager idManager, string uniquePrefix, TemplateSubShaderInfo subShaderData, ref Dictionary <string, TemplateShaderPropertyData> duplicatesHelper)
        {
            m_idx = subShaderIx;

            m_uniquePrefix = uniquePrefix;

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

            m_modules = new TemplateModulesData(idManager, m_templateProperties, uniquePrefix + "Module", subShaderData.StartIdx, subShaderData.Modules, true);

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

            TemplateHelperFunctions.CreateShaderGlobalsList(subShaderData.Modules, ref m_availableShaderGlobals, ref ownDuplicatesDict);

            m_passAmount = subShaderData.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(m_modules, subShaderIx, passIdx, idManager, uniquePrefix + "Pass" + passIdx, subShaderData.Passes[passIdx].GlobalStartIdx, subShaderData.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;
        }
コード例 #6
0
        void LoadTemplateBody(string guid)
        {
            m_guid = guid;
            string datapath   = AssetDatabase.GUIDToAssetPath(guid);
            string shaderBody = string.Empty;

            shaderBody   = IOUtils.LoadTextFileFromDisk(datapath);
            shaderBody   = shaderBody.Replace("\r\n", "\n");
            m_shaderData = TemplateShaderInfoUtil.CreateShaderData(shaderBody);
            if (m_shaderData == null)
            {
                m_isValid = false;
                return;
            }

            m_templateIdManager = new TemplateIdManager(shaderBody);

            try
            {
                int nameBegin = shaderBody.IndexOf(TemplatesManager.TemplateShaderNameBeginTag);
                if (nameBegin < 0)
                {
                    // Not a template
                    return;
                }

                int nameEnd = shaderBody.IndexOf(TemplatesManager.TemplateFullEndTag, nameBegin);
                if (nameEnd < 0)
                {
                    return;
                }

                m_shaderBody = shaderBody;
                int defaultBegin  = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length;
                int defaultLength = nameEnd - defaultBegin;
                m_defaultShaderName = shaderBody.Substring(defaultBegin, defaultLength);
                int[] nameIdx = m_defaultShaderName.AllIndexesOf("\"");
                nameIdx[0]         += 1;           // Ignore the " character from the string
                m_defaultShaderName = m_defaultShaderName.Substring(nameIdx[0], nameIdx[1] - nameIdx[0]);
                m_shaderNameId      = shaderBody.Substring(nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin);
                m_templateProperties.AddId(shaderBody, m_shaderNameId, false);
                m_templateIdManager.RegisterId(nameBegin, m_shaderNameId, m_shaderNameId);
                shaderBody = shaderBody.Substring(nameEnd + TemplatesManager.TemplateFullEndTag.Length);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }

            m_propertyTag = new TemplateTagData(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, true);
            m_templateIdManager.RegisterId(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, TemplatesManager.TemplatePropertyTag);
            m_templateProperties.AddId(shaderBody, TemplatesManager.TemplatePropertyTag, true);
            Dictionary <string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary <string, TemplateShaderPropertyData>();

            TemplateHelperFunctions.CreateShaderPropertiesList(m_shaderData.Properties, ref m_availableShaderProperties, ref duplicatesHelper);
            int subShaderCount = m_shaderData.SubShaders.Count;

            int mainSubShaderIdx = -1;
            int mainPassIdx      = -1;

            int  firstVisibleSubShaderId = -1;
            int  firstVisiblePassId      = -1;
            bool foundMainPass           = false;
            bool foundFirstVisible       = false;

            for (int i = 0; i < subShaderCount; i++)
            {
                TemplateSubShader subShader = new TemplateSubShader(i, m_templateIdManager, "SubShader" + i, m_shaderData.SubShaders[i], ref duplicatesHelper);

                if (subShader.FoundMainPass)
                {
                    if (!foundMainPass)
                    {
                        foundMainPass    = true;
                        mainSubShaderIdx = i;
                        mainPassIdx      = subShader.MainPass;
                    }
                }
                else if (subShader.MainPass > -1)
                {
                    if (!foundFirstVisible)
                    {
                        foundFirstVisible       = true;
                        firstVisibleSubShaderId = i;
                        firstVisiblePassId      = subShader.MainPass;
                    }
                }

                m_subShaders.Add(subShader);
                m_masterNodesRequired += subShader.Passes.Count;
            }


            if (!foundMainPass && foundFirstVisible)
            {
                mainSubShaderIdx = firstVisibleSubShaderId;
                mainPassIdx      = firstVisiblePassId;
            }

            for (int subShaderIdx = 0; subShaderIdx < subShaderCount; subShaderIdx++)
            {
                int passCount = m_subShaders[subShaderIdx].Passes.Count;
                for (int passIdx = 0; passIdx < passCount; passIdx++)
                {
                    m_subShaders[subShaderIdx].Passes[passIdx].IsMainPass = (mainSubShaderIdx == subShaderIdx && mainPassIdx == passIdx);
                }
            }
            duplicatesHelper.Clear();
            duplicatesHelper = null;
            m_isSinglePass   = (m_subShaders.Count == 1 && m_subShaders[0].PassAmount == 1);
            TemplateHelperFunctions.FetchCustomInspector(m_customInspectorContainer, m_shaderBody);
            if (m_customInspectorContainer.IsValid)
            {
                int index = m_customInspectorContainer.Id.IndexOf("CustomEditor");
                m_templateProperties.AddId(new TemplateProperty(m_customInspectorContainer.Id, m_customInspectorContainer.Id.Substring(0, index), true));
                m_templateIdManager.RegisterId(m_customInspectorContainer.Index, m_customInspectorContainer.Id, m_customInspectorContainer.Id);
            }
        }
コード例 #7
0
		public TemplateSubShader( 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 ):

			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( 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:
		}
コード例 #8
0
        public TemplateModulesData(TemplateIdManager idManager, TemplatePropertyContainer propertyContainer, string uniquePrefix, int offsetIdx, string subBody, bool isSubShader)
        {
            if (string.IsNullOrEmpty(subBody))
            {
                return;
            }

            m_uniquePrefix = uniquePrefix;
            //PRAGMAS AND INCLUDES
            TemplateHelperFunctions.CreatePragmaIncludeList(subBody, m_includePragmaContainer);

            //COMMON TAGS
            ConfigureCommonTag(m_globalsTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_functionsTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_pragmaTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_passTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_inputsVertTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_inputsFragTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);

            //BlEND MODE
            {
                Match blendModeMatch = Regex.Match(subBody, TemplateHelperFunctions.BlendWholeWordPattern);
                if (blendModeMatch.Success)
                {
                    int blendModeIdx = blendModeMatch.Index;

                    int    end         = subBody.IndexOf(TemplatesManager.TemplateNewLine, blendModeIdx);
                    string blendParams = subBody.Substring(blendModeIdx, end - blendModeIdx);
                    m_blendData.BlendModeId         = blendParams;
                    m_blendData.BlendModeStartIndex = offsetIdx + blendModeIdx;
                    idManager.RegisterId(m_blendData.BlendModeStartIndex, uniquePrefix + m_blendData.BlendModeId, m_blendData.BlendModeId);

                    TemplateHelperFunctions.CreateBlendMode(blendParams, ref m_blendData);
                    if (m_blendData.ValidBlendMode)
                    {
                        propertyContainer.AddId(subBody, blendParams, false);
                    }
                }
            }
            //BLEND OP
            {
                Match blendOpMatch = Regex.Match(subBody, TemplateHelperFunctions.BlendOpWholeWordPattern);
                if (blendOpMatch.Success)
                {
                    int    blendOpIdx    = blendOpMatch.Index;
                    int    end           = subBody.IndexOf(TemplatesManager.TemplateNewLine, blendOpIdx);
                    string blendOpParams = subBody.Substring(blendOpIdx, end - blendOpIdx);
                    m_blendData.BlendOpId       = blendOpParams;
                    BlendData.BlendOpStartIndex = offsetIdx + blendOpIdx;
                    idManager.RegisterId(m_blendData.BlendOpStartIndex, uniquePrefix + m_blendData.BlendOpId, m_blendData.BlendOpId);
                    TemplateHelperFunctions.CreateBlendOp(blendOpParams, ref m_blendData);
                    if (m_blendData.ValidBlendOp)
                    {
                        propertyContainer.AddId(subBody, blendOpParams, false);
                    }
                }
            }

            //ALPHA TO MASK
            {
                Match alphaToMaskMatch = Regex.Match(subBody, TemplateHelperFunctions.ALphaToMaskPattern);
                if (alphaToMaskMatch.Success)
                {
                    m_blendData.ValidAlphaToMask = true;
                    m_blendData.AlphaToMaskId    = alphaToMaskMatch.Groups[0].Value;
                    if (alphaToMaskMatch.Groups.Count > 1)
                    {
                        m_blendData.AlphaToMaskValue = alphaToMaskMatch.Groups[1].Value.Equals("On") ? true : false;
                    }
                    m_blendData.IndependentAlphaToMask = true;
                    idManager.RegisterId(offsetIdx + alphaToMaskMatch.Index, uniquePrefix + m_blendData.AlphaToMaskId, m_blendData.AlphaToMaskId);
                    propertyContainer.AddId(subBody, m_blendData.AlphaToMaskId, false);
                }

                m_blendData.DataCheck = (m_blendData.ValidBlendMode || m_blendData.ValidBlendOp || m_blendData.ValidAlphaToMask) ? TemplateDataCheck.Valid : TemplateDataCheck.Invalid;
            }

            //CULL MODE
            {
                Match cullMatch = Regex.Match(subBody, TemplateHelperFunctions.CullWholeWordPattern);
                if (cullMatch.Success)
                {
                    int    cullIdx    = cullMatch.Index;
                    int    end        = subBody.IndexOf(TemplatesManager.TemplateNewLine, cullIdx);
                    string cullParams = subBody.Substring(cullIdx, end - cullIdx);
                    m_cullModeData.CullModeId = cullParams;
                    m_cullModeData.StartIdx   = offsetIdx + cullIdx;
                    idManager.RegisterId(m_cullModeData.StartIdx, uniquePrefix + m_cullModeData.CullModeId, m_cullModeData.CullModeId);
                    TemplateHelperFunctions.CreateCullMode(cullParams, ref m_cullModeData);
                    if (m_cullModeData.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, cullParams, false, string.Empty);
                    }
                }
            }
            //COLOR MASK
            {
                Match colorMaskMatch = Regex.Match(subBody, TemplateHelperFunctions.ColorMaskWholeWordPattern);
                if (colorMaskMatch.Success)
                {
                    int    colorMaskIdx    = colorMaskMatch.Index;
                    int    end             = subBody.IndexOf(TemplatesManager.TemplateNewLine, colorMaskIdx);
                    string colorMaskParams = subBody.Substring(colorMaskIdx, end - colorMaskIdx);
                    m_colorMaskData.ColorMaskId = colorMaskParams;
                    m_colorMaskData.StartIdx    = offsetIdx + colorMaskIdx;
                    idManager.RegisterId(m_colorMaskData.StartIdx, uniquePrefix + m_colorMaskData.ColorMaskId, m_colorMaskData.ColorMaskId);
                    TemplateHelperFunctions.CreateColorMask(colorMaskParams, ref m_colorMaskData);
                    if (m_colorMaskData.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, colorMaskParams, false);
                    }
                }
            }
            //STENCIL
            {
                Match stencilMatch = Regex.Match(subBody, TemplateHelperFunctions.StencilWholeWordPattern);
                if (stencilMatch.Success)
                {
                    int stencilIdx    = stencilMatch.Index;
                    int stencilEndIdx = subBody.IndexOf("}", stencilIdx);
                    if (stencilEndIdx > 0)
                    {
                        string stencilParams = subBody.Substring(stencilIdx, stencilEndIdx + 1 - stencilIdx);
                        m_stencilData.StencilBufferId = stencilParams;
                        m_stencilData.StartIdx        = offsetIdx + stencilIdx;
                        idManager.RegisterId(m_stencilData.StartIdx, uniquePrefix + m_stencilData.StencilBufferId, m_stencilData.StencilBufferId);
                        TemplateHelperFunctions.CreateStencilOps(stencilParams, ref m_stencilData);
                        if (m_stencilData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, stencilParams, true);
                        }
                    }
                }
                else
                {
                    int stencilTagIdx = subBody.IndexOf(TemplatesManager.TemplateStencilTag);
                    if (stencilTagIdx > -1)
                    {
                        m_stencilData.SetIndependentDefault();
                        m_stencilData.StencilBufferId = TemplatesManager.TemplateStencilTag;
                        m_stencilData.StartIdx        = offsetIdx + stencilTagIdx;
                        idManager.RegisterId(m_stencilData.StartIdx, uniquePrefix + m_stencilData.StencilBufferId, m_stencilData.StencilBufferId);
                        propertyContainer.AddId(subBody, m_stencilData.StencilBufferId, true);
                    }
                }
            }
            //ZWRITE
            {
                Match zWriteMatch = Regex.Match(subBody, TemplateHelperFunctions.ZWriteWholeWordPattern);
                if (zWriteMatch.Success)
                {
                    int zWriteOpIdx  = zWriteMatch.Index;
                    int zWriteEndIdx = subBody.IndexOf(TemplatesManager.TemplateNewLine, zWriteOpIdx);
                    if (zWriteEndIdx > 0)
                    {
                        m_depthData.ZWriteModeId     = subBody.Substring(zWriteOpIdx, zWriteEndIdx + 1 - zWriteOpIdx);
                        m_depthData.ZWriteStartIndex = offsetIdx + zWriteOpIdx;
                        idManager.RegisterId(m_depthData.ZWriteStartIndex, uniquePrefix + m_depthData.ZWriteModeId, m_depthData.ZWriteModeId);
                        TemplateHelperFunctions.CreateZWriteMode(m_depthData.ZWriteModeId, ref m_depthData);
                        if (m_depthData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, m_depthData.ZWriteModeId, true);
                        }
                    }
                }
            }

            //ZTEST
            {
                Match zTestMatch = Regex.Match(subBody, TemplateHelperFunctions.ZTestWholeWordPattern);
                if (zTestMatch.Success)
                {
                    int zTestOpIdx  = zTestMatch.Index;
                    int zTestEndIdx = subBody.IndexOf(TemplatesManager.TemplateNewLine, zTestOpIdx);
                    if (zTestEndIdx > 0)
                    {
                        m_depthData.ZTestModeId     = subBody.Substring(zTestOpIdx, zTestEndIdx + 1 - zTestOpIdx);
                        m_depthData.ZTestStartIndex = offsetIdx + zTestOpIdx;
                        idManager.RegisterId(m_depthData.ZTestStartIndex, uniquePrefix + m_depthData.ZTestModeId, m_depthData.ZTestModeId);
                        TemplateHelperFunctions.CreateZTestMode(m_depthData.ZTestModeId, ref m_depthData);
                        if (m_depthData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, m_depthData.ZTestModeId, true);
                        }
                    }
                }
            }

            //ZOFFSET
            {
                Match zOffsetMatch = Regex.Match(subBody, TemplateHelperFunctions.ZOffsetWholeWordPattern);
                if (zOffsetMatch.Success)
                {
                    int zOffsetIdx    = zOffsetMatch.Index;
                    int zOffsetEndIdx = subBody.IndexOf(TemplatesManager.TemplateNewLine, zOffsetIdx);
                    if (zOffsetEndIdx > 0)
                    {
                        m_depthData.OffsetId         = subBody.Substring(zOffsetIdx, zOffsetEndIdx + 1 - zOffsetIdx);
                        m_depthData.OffsetStartIndex = offsetIdx + zOffsetIdx;
                        idManager.RegisterId(m_depthData.OffsetStartIndex, uniquePrefix + m_depthData.OffsetId, m_depthData.OffsetId);
                        TemplateHelperFunctions.CreateZOffsetMode(m_depthData.OffsetId, ref m_depthData);
                        if (m_depthData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, m_depthData.OffsetId, true);
                        }
                    }
                }
            }
            //TAGS
            {
                Match tagsMatch = Regex.Match(subBody, TemplateHelperFunctions.TagsWholeWordPattern);
                if (tagsMatch.Success)
                {
                    int tagsIdx    = tagsMatch.Index;
                    int tagsEndIdx = subBody.IndexOf("}", tagsIdx);
                    if (tagsEndIdx > -1)
                    {
                        m_tagData.Reset();
                        m_tagData.TagsId   = subBody.Substring(tagsIdx, tagsEndIdx + 1 - tagsIdx);
                        m_tagData.StartIdx = offsetIdx + tagsIdx;
                        idManager.RegisterId(m_tagData.StartIdx, uniquePrefix + m_tagData.TagsId, m_tagData.TagsId);
                        m_srpType = TemplateHelperFunctions.CreateTags(ref m_tagData, isSubShader);

                        propertyContainer.AddId(subBody, m_tagData.TagsId, false);
                        m_tagData.DataCheck = TemplateDataCheck.Valid;
                    }
                    else
                    {
                        m_tagData.DataCheck = TemplateDataCheck.Invalid;
                    }
                }
                else
                {
                    m_tagData.DataCheck = TemplateDataCheck.Invalid;
                }
            }

            //SHADER MODEL
            {
                Match match = Regex.Match(subBody, TemplateHelperFunctions.ShaderModelPattern);
                if (match != null && match.Groups.Count > 1)
                {
                    if (TemplateHelperFunctions.AvailableInterpolators.ContainsKey(match.Groups[1].Value))
                    {
                        m_shaderModel.Id                 = match.Groups[0].Value;
                        m_shaderModel.StartIdx           = offsetIdx + match.Index;
                        m_shaderModel.Value              = match.Groups[1].Value;
                        m_shaderModel.InterpolatorAmount = TemplateHelperFunctions.AvailableInterpolators[match.Groups[1].Value];
                        m_shaderModel.DataCheck          = TemplateDataCheck.Valid;
                        idManager.RegisterId(m_shaderModel.StartIdx, uniquePrefix + m_shaderModel.Id, m_shaderModel.Id);
                    }
                    else
                    {
                        m_shaderModel.DataCheck = TemplateDataCheck.Invalid;
                    }
                }
            }

            // ALL MODULES
            int allModulesIndex = subBody.IndexOf(TemplatesManager.TemplateAllModulesTag);

            if (allModulesIndex > 0)
            {
                //ONLY REGISTER MISSING TAGS
                ConfigureCommonTag(m_allModulesTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
                m_allModulesMode = true;

                m_blendData.SetAllModulesDefault();

                if (!m_cullModeData.IsValid)
                {
                    m_cullModeData.SetAllModulesDefault();
                }

                if (!m_colorMaskData.IsValid)
                {
                    m_colorMaskData.SetAllModulesDefault();
                }

                if (!m_stencilData.IsValid)
                {
                    m_stencilData.SetAllModulesDefault();
                }

                if (!m_depthData.IsValid)
                {
                    m_depthData.SetAllModulesDefault();
                }

                if (!m_shaderModel.IsValid)
                {
                    m_shaderModel.SetAllModulesDefault();
                }
            }
        }
コード例 #9
0
        public void ConfigureCommonTag(TemplateTagData tagData, TemplatePropertyContainer propertyContainer, TemplateIdManager idManager, string uniquePrefix, int offsetIdx, string subBody)
        {
            int id = subBody.IndexOf(tagData.Id);

            if (id >= 0)
            {
                tagData.StartIdx = offsetIdx + id;
                idManager.RegisterId(tagData.StartIdx, uniquePrefix + tagData.Id, tagData.Id);
                propertyContainer.AddId(subBody, tagData.Id, tagData.SearchIndentation);
            }
        }
コード例 #10
0
ファイル: TemplatePass.cs プロジェクト: InVale/AmongTheWave
        public TemplateModules(TemplateIdManager idManager, TemplatePropertyContainer propertyContainer, string uniquePrefix, int offsetIdx, string subBody, bool isSubShader)
        {
            if (string.IsNullOrEmpty(subBody))
            {
                return;
            }

            m_uniquePrefix = uniquePrefix;

            //COMMON TAGS
            ConfigureCommonTag(m_globalsTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_functionsTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_pragmaTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_passTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_inputsVertTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_inputsFragTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);

            //BlEND MODE
            {
                int blendModeIdx = subBody.IndexOf("Blend");
                if (blendModeIdx > 0)
                {
                    int    end         = subBody.IndexOf(TemplatesManager.TemplateNewLine, blendModeIdx);
                    string blendParams = subBody.Substring(blendModeIdx, end - blendModeIdx);
                    m_blendData.BlendModeId         = blendParams;
                    m_blendData.BlendModeStartIndex = offsetIdx + blendModeIdx;
                    idManager.RegisterId(m_blendData.BlendModeStartIndex, uniquePrefix + m_blendData.BlendModeId, m_blendData.BlendModeId);

                    TemplateHelperFunctions.CreateBlendMode(blendParams, ref m_blendData);
                    if (m_blendData.ValidBlendMode)
                    {
                        propertyContainer.AddId(subBody, blendParams, false);
                    }
                }
            }
            //BLEND OP
            {
                int blendOpIdx = subBody.IndexOf("BlendOp");
                if (blendOpIdx > 0)
                {
                    int    end           = subBody.IndexOf(TemplatesManager.TemplateNewLine, blendOpIdx);
                    string blendOpParams = subBody.Substring(blendOpIdx, end - blendOpIdx);
                    m_blendData.BlendOpId       = blendOpParams;
                    BlendData.BlendOpStartIndex = offsetIdx + blendOpIdx;
                    idManager.RegisterId(m_blendData.BlendOpStartIndex, uniquePrefix + m_blendData.BlendOpId, m_blendData.BlendOpId);
                    TemplateHelperFunctions.CreateBlendOp(blendOpParams, ref m_blendData);
                    if (m_blendData.ValidBlendOp)
                    {
                        propertyContainer.AddId(subBody, blendOpParams, false);
                    }
                }

                m_blendData.DataCheck = (m_blendData.ValidBlendMode || m_blendData.ValidBlendOp) ? TemplateDataCheck.Valid : TemplateDataCheck.Invalid;
            }
            //CULL MODE
            {
                int cullIdx = subBody.IndexOf("Cull");
                if (cullIdx > 0)
                {
                    int    end        = subBody.IndexOf(TemplatesManager.TemplateNewLine, cullIdx);
                    string cullParams = subBody.Substring(cullIdx, end - cullIdx);
                    m_cullModeData.CullModeId = cullParams;
                    m_cullModeData.StartIdx   = offsetIdx + cullIdx;
                    idManager.RegisterId(m_cullModeData.StartIdx, uniquePrefix + m_cullModeData.CullModeId, m_cullModeData.CullModeId);
                    TemplateHelperFunctions.CreateCullMode(cullParams, ref m_cullModeData);
                    if (m_cullModeData.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, cullParams, false, string.Empty);
                    }
                }
            }
            //COLOR MASK
            {
                int colorMaskIdx = subBody.IndexOf("ColorMask");
                if (colorMaskIdx > 0)
                {
                    int    end             = subBody.IndexOf(TemplatesManager.TemplateNewLine, colorMaskIdx);
                    string colorMaskParams = subBody.Substring(colorMaskIdx, end - colorMaskIdx);
                    m_colorMaskData.ColorMaskId = colorMaskParams;
                    m_colorMaskData.StartIdx    = offsetIdx + colorMaskIdx;
                    idManager.RegisterId(m_colorMaskData.StartIdx, uniquePrefix + m_colorMaskData.ColorMaskId, m_colorMaskData.ColorMaskId);
                    TemplateHelperFunctions.CreateColorMask(colorMaskParams, ref m_colorMaskData);
                    if (m_colorMaskData.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, colorMaskParams, false);
                    }
                }
            }
            //STENCIL
            {
                int stencilIdx = subBody.IndexOf("Stencil");
                if (stencilIdx > -1)
                {
                    int stencilEndIdx = subBody.IndexOf("}", stencilIdx);
                    if (stencilEndIdx > 0)
                    {
                        string stencilParams = subBody.Substring(stencilIdx, stencilEndIdx + 1 - stencilIdx);
                        m_stencilData.StencilBufferId = stencilParams;
                        m_stencilData.StartIdx        = offsetIdx + stencilIdx;
                        idManager.RegisterId(m_stencilData.StartIdx, uniquePrefix + m_stencilData.StencilBufferId, m_stencilData.StencilBufferId);
                        TemplateHelperFunctions.CreateStencilOps(stencilParams, ref m_stencilData);
                        if (m_stencilData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, stencilParams, true);
                        }
                    }
                }
            }
            //ZWRITE
            {
                int zWriteOpIdx = subBody.IndexOf("ZWrite");
                if (zWriteOpIdx > -1)
                {
                    int zWriteEndIdx = subBody.IndexOf(TemplatesManager.TemplateNewLine, zWriteOpIdx);
                    if (zWriteEndIdx > 0)
                    {
                        m_depthData.ZWriteModeId     = subBody.Substring(zWriteOpIdx, zWriteEndIdx + 1 - zWriteOpIdx);
                        m_depthData.ZWriteStartIndex = offsetIdx + zWriteOpIdx;
                        idManager.RegisterId(m_depthData.ZWriteStartIndex, uniquePrefix + m_depthData.ZWriteModeId, m_depthData.ZWriteModeId);
                        TemplateHelperFunctions.CreateZWriteMode(m_depthData.ZWriteModeId, ref m_depthData);
                        if (m_depthData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, m_depthData.ZWriteModeId, true);
                        }
                    }
                }
            }

            //ZTEST
            {
                int zTestOpIdx = subBody.IndexOf("ZTest");
                if (zTestOpIdx > -1)
                {
                    int zTestEndIdx = subBody.IndexOf(TemplatesManager.TemplateNewLine, zTestOpIdx);
                    if (zTestEndIdx > 0)
                    {
                        m_depthData.ZTestModeId     = subBody.Substring(zTestOpIdx, zTestEndIdx + 1 - zTestOpIdx);
                        m_depthData.ZTestStartIndex = offsetIdx + zTestOpIdx;
                        idManager.RegisterId(m_depthData.ZTestStartIndex, uniquePrefix + m_depthData.ZTestModeId, m_depthData.ZTestModeId);
                        TemplateHelperFunctions.CreateZTestMode(m_depthData.ZTestModeId, ref m_depthData);
                        if (m_depthData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, m_depthData.ZTestModeId, true);
                        }
                    }
                }
            }

            //ZOFFSET
            {
                int zOffsetIdx = subBody.IndexOf("Offset");
                if (zOffsetIdx > -1)
                {
                    int zOffsetEndIdx = subBody.IndexOf(TemplatesManager.TemplateNewLine, zOffsetIdx);
                    if (zOffsetEndIdx > 0)
                    {
                        m_depthData.OffsetId         = subBody.Substring(zOffsetIdx, zOffsetEndIdx + 1 - zOffsetIdx);
                        m_depthData.OffsetStartIndex = offsetIdx + zOffsetIdx;
                        idManager.RegisterId(m_depthData.OffsetStartIndex, uniquePrefix + m_depthData.OffsetId, m_depthData.OffsetId);
                        TemplateHelperFunctions.CreateZOffsetMode(m_depthData.OffsetId, ref m_depthData);
                        if (m_depthData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, m_depthData.OffsetId, true);
                        }
                    }
                }
            }
            //TAGS
            {
                int tagsIdx = subBody.IndexOf("Tags");
                if (tagsIdx > -1)
                {
                    int tagsEndIdx = subBody.IndexOf("}", tagsIdx);
                    if (tagsEndIdx > -1)
                    {
                        m_tagData.Reset();
                        m_tagData.TagsId   = subBody.Substring(tagsIdx, tagsEndIdx + 1 - tagsIdx);
                        m_tagData.StartIdx = offsetIdx + tagsIdx;
                        idManager.RegisterId(m_tagData.StartIdx, uniquePrefix + m_tagData.TagsId, m_tagData.TagsId);
                        m_srpType = TemplateHelperFunctions.CreateTags(ref m_tagData, isSubShader);
                        propertyContainer.AddId(subBody, m_tagData.TagsId, false);
                        m_tagData.DataCheck = TemplateDataCheck.Valid;
                    }
                    else
                    {
                        m_tagData.DataCheck = TemplateDataCheck.Invalid;
                    }
                }
                else
                {
                    m_tagData.DataCheck = TemplateDataCheck.Invalid;
                }
            }

            //SHADER MODEL
            {
                Match match = Regex.Match(subBody, TemplateHelperFunctions.ShaderModelPattern);
                if (match != null && match.Groups.Count > 1)
                {
                    if (TemplateHelperFunctions.AvailableInterpolators.ContainsKey(match.Groups[1].Value))
                    {
                        m_shaderModel.Id                 = match.Groups[0].Value;
                        m_shaderModel.StartIdx           = offsetIdx + match.Index;
                        m_shaderModel.Value              = match.Groups[1].Value;
                        m_shaderModel.InterpolatorAmount = TemplateHelperFunctions.AvailableInterpolators[match.Groups[1].Value];
                        m_shaderModel.DataCheck          = TemplateDataCheck.Valid;
                        idManager.RegisterId(m_shaderModel.StartIdx, uniquePrefix + m_shaderModel.Id, m_shaderModel.Id);
                    }
                    else
                    {
                        m_shaderModel.DataCheck = TemplateDataCheck.Invalid;
                    }
                }
            }
        }
コード例 #11
0
        public TemplateModulesData(TemplateOptionsContainer optionsContainer, TemplateIdManager idManager, TemplatePropertyContainer propertyContainer, string uniquePrefix, int offsetIdx, string subBody, bool isSubShader)
        {
            if (string.IsNullOrEmpty(subBody))
            {
                return;
            }

            m_uniquePrefix = uniquePrefix;

            //RENDERING PLATFORMS
            m_renderPlatformHelper = new TemplateRenderPlatformHelper();
            TemplateHelperFunctions.FillRenderingPlatform(m_renderPlatformHelper, subBody);
            if (m_renderPlatformHelper.IsValid)
            {
                m_renderPlatformHelper.Index = offsetIdx + m_renderPlatformHelper.Index;
                idManager.RegisterId(m_renderPlatformHelper.Index, uniquePrefix + m_renderPlatformHelper.ID, m_renderPlatformHelper.ID);
            }

            //PRAGMAS AND INCLUDES
            TemplateHelperFunctions.CreatePragmaIncludeList(subBody, m_includePragmaContainer);

            //COMMON TAGS
            ConfigureCommonTag(m_globalsTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_srpBatcherTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_functionsTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_pragmaTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_pragmaBeforeTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            if (!TemplateHelperFunctions.GetPassUniqueId(m_passTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody, ref m_passUniqueName))
            {
                ConfigureCommonTag(m_passTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            }
            ConfigureCommonTag(m_inputsVertTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
            ConfigureCommonTag(m_inputsFragTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);

            // If Options are enabled then remove them so they won't influence Regex matches
            if (optionsContainer.Enabled && optionsContainer.EndIndex > 0)
            {
                offsetIdx += optionsContainer.EndIndex;
                subBody    = subBody.Substring(optionsContainer.EndIndex);
            }
            //BlEND MODE
            {
                Match blendModeMatch = Regex.Match(subBody, TemplateHelperFunctions.BlendModePattern1);
                if (blendModeMatch.Success)
                {
                    int    blendModeIdx = blendModeMatch.Index;
                    int    end          = blendModeMatch.Length + blendModeIdx;
                    string blendParams  = subBody.Substring(blendModeIdx, end - blendModeIdx);
                    m_blendData1.BlendModeId         = blendParams;
                    m_blendData1.BlendModeStartIndex = offsetIdx + blendModeIdx;
                    idManager.RegisterId(m_blendData1.BlendModeStartIndex, uniquePrefix + m_blendData1.BlendModeId, m_blendData1.BlendModeId);

                    TemplateHelperFunctions.CreateBlendMode(blendParams, ref m_blendData1, TemplateHelperFunctions.BlendModePattern1);
                    if (m_blendData1.ValidBlendMode)
                    {
                        propertyContainer.AddId(subBody, blendParams, false);
                    }
                }
            }
            {
                Match blendModeMatch = Regex.Match(subBody, TemplateHelperFunctions.BlendModePattern2);
                if (blendModeMatch.Success)
                {
                    int    blendModeIdx = blendModeMatch.Index;
                    int    end          = blendModeMatch.Length + blendModeIdx;
                    string blendParams  = subBody.Substring(blendModeIdx, end - blendModeIdx);
                    m_blendData2.BlendModeId         = blendParams;
                    m_blendData2.BlendModeStartIndex = offsetIdx + blendModeIdx;
                    idManager.RegisterId(m_blendData2.BlendModeStartIndex, uniquePrefix + m_blendData2.BlendModeId, m_blendData2.BlendModeId);

                    TemplateHelperFunctions.CreateBlendMode(blendParams, ref m_blendData2, TemplateHelperFunctions.BlendModePattern2);
                    if (m_blendData2.ValidBlendMode)
                    {
                        propertyContainer.AddId(subBody, blendParams, false);
                    }
                }
            }
            {
                Match blendModeMatch = Regex.Match(subBody, TemplateHelperFunctions.BlendModePattern3);
                if (blendModeMatch.Success)
                {
                    int    blendModeIdx = blendModeMatch.Index;
                    int    end          = blendModeMatch.Length + blendModeIdx;
                    string blendParams  = subBody.Substring(blendModeIdx, end - blendModeIdx);
                    m_blendData3.BlendModeId         = blendParams;
                    m_blendData3.BlendModeStartIndex = offsetIdx + blendModeIdx;
                    idManager.RegisterId(m_blendData3.BlendModeStartIndex, uniquePrefix + m_blendData3.BlendModeId, m_blendData3.BlendModeId);

                    TemplateHelperFunctions.CreateBlendMode(blendParams, ref m_blendData3, TemplateHelperFunctions.BlendModePattern3);
                    if (m_blendData3.ValidBlendMode)
                    {
                        propertyContainer.AddId(subBody, blendParams, false);
                    }
                }
            }
            {
                string pattern        = TemplateHelperFunctions.BlendModePattern;
                Match  blendModeMatch = Regex.Match(subBody, pattern);
                if (!blendModeMatch.Success && !m_blendData1.ValidBlendMode && !m_blendData2.ValidBlendMode && !m_blendData3.ValidBlendMode)
                {
                    pattern        = TemplateHelperFunctions.BlendModePatternFirst;
                    blendModeMatch = Regex.Match(subBody, pattern);
                }
                if (blendModeMatch.Success)
                {
                    int    blendModeIdx = blendModeMatch.Index;
                    int    end          = blendModeMatch.Length + blendModeIdx;
                    string blendParams  = subBody.Substring(blendModeIdx, end - blendModeIdx);
                    m_blendData.BlendModeId         = blendParams;
                    m_blendData.BlendModeStartIndex = offsetIdx + blendModeIdx;
                    idManager.RegisterId(m_blendData.BlendModeStartIndex, uniquePrefix + m_blendData.BlendModeId, m_blendData.BlendModeId);

                    TemplateHelperFunctions.CreateBlendMode(blendParams, ref m_blendData, pattern);
                    if (m_blendData.ValidBlendMode)
                    {
                        propertyContainer.AddId(subBody, blendParams, false);
                    }
                }
            }
            //BLEND OP
            {
                Match blendOpMatch = Regex.Match(subBody, TemplateHelperFunctions.BlendOpPattern1);
                if (blendOpMatch.Success)
                {
                    int    blendOpIdx    = blendOpMatch.Index;
                    int    end           = blendOpMatch.Length + blendOpIdx;
                    string blendOpParams = subBody.Substring(blendOpIdx, end - blendOpIdx);
                    m_blendData1.BlendOpId         = blendOpParams;
                    m_blendData1.BlendOpStartIndex = offsetIdx + blendOpIdx;
                    idManager.RegisterId(m_blendData1.BlendOpStartIndex, uniquePrefix + m_blendData1.BlendOpId, m_blendData1.BlendOpId);
                    TemplateHelperFunctions.CreateBlendOp(blendOpParams, ref m_blendData1, TemplateHelperFunctions.BlendOpPattern1);
                    if (m_blendData1.ValidBlendOp)
                    {
                        propertyContainer.AddId(subBody, blendOpParams, false);
                    }
                }

                m_blendData1.DataCheck = (m_blendData1.ValidBlendMode || m_blendData1.ValidBlendOp) ? TemplateDataCheck.Valid : TemplateDataCheck.Invalid;
            }
            {
                Match blendOpMatch = Regex.Match(subBody, TemplateHelperFunctions.BlendOpPattern2);
                if (blendOpMatch.Success)
                {
                    int    blendOpIdx    = blendOpMatch.Index;
                    int    end           = blendOpMatch.Length + blendOpIdx;
                    string blendOpParams = subBody.Substring(blendOpIdx, end - blendOpIdx);
                    m_blendData2.BlendOpId         = blendOpParams;
                    m_blendData2.BlendOpStartIndex = offsetIdx + blendOpIdx;
                    idManager.RegisterId(m_blendData2.BlendOpStartIndex, uniquePrefix + m_blendData2.BlendOpId, m_blendData2.BlendOpId);
                    TemplateHelperFunctions.CreateBlendOp(blendOpParams, ref m_blendData2, TemplateHelperFunctions.BlendOpPattern2);
                    if (m_blendData2.ValidBlendOp)
                    {
                        propertyContainer.AddId(subBody, blendOpParams, false);
                    }
                }

                m_blendData2.DataCheck = (m_blendData2.ValidBlendMode || m_blendData2.ValidBlendOp) ? TemplateDataCheck.Valid : TemplateDataCheck.Invalid;
            }
            {
                Match blendOpMatch = Regex.Match(subBody, TemplateHelperFunctions.BlendOpPattern3);
                if (blendOpMatch.Success)
                {
                    int    blendOpIdx    = blendOpMatch.Index;
                    int    end           = blendOpMatch.Length + blendOpIdx;
                    string blendOpParams = subBody.Substring(blendOpIdx, end - blendOpIdx);
                    m_blendData3.BlendOpId         = blendOpParams;
                    m_blendData3.BlendOpStartIndex = offsetIdx + blendOpIdx;
                    idManager.RegisterId(m_blendData3.BlendOpStartIndex, uniquePrefix + m_blendData3.BlendOpId, m_blendData3.BlendOpId);
                    TemplateHelperFunctions.CreateBlendOp(blendOpParams, ref m_blendData3, TemplateHelperFunctions.BlendOpPattern3);
                    if (m_blendData3.ValidBlendOp)
                    {
                        propertyContainer.AddId(subBody, blendOpParams, false);
                    }
                }

                m_blendData3.DataCheck = (m_blendData3.ValidBlendMode || m_blendData3.ValidBlendOp) ? TemplateDataCheck.Valid : TemplateDataCheck.Invalid;
            }
            {
                string pattern      = TemplateHelperFunctions.BlendOpPattern;
                Match  blendOpMatch = Regex.Match(subBody, pattern);
                if (!blendOpMatch.Success && !m_blendData1.ValidBlendOp && !m_blendData2.ValidBlendOp && !m_blendData3.ValidBlendOp)
                {
                    pattern      = TemplateHelperFunctions.BlendOpPatternFirst;
                    blendOpMatch = Regex.Match(subBody, pattern);
                }

                if (blendOpMatch.Success)
                {
                    int    blendOpIdx    = blendOpMatch.Index;
                    int    end           = blendOpMatch.Length + blendOpIdx;
                    string blendOpParams = subBody.Substring(blendOpIdx, end - blendOpIdx);
                    m_blendData.BlendOpId         = blendOpParams;
                    m_blendData.BlendOpStartIndex = offsetIdx + blendOpIdx;
                    idManager.RegisterId(m_blendData.BlendOpStartIndex, uniquePrefix + m_blendData.BlendOpId, m_blendData.BlendOpId);
                    TemplateHelperFunctions.CreateBlendOp(blendOpParams, ref m_blendData, pattern);
                    if (m_blendData.ValidBlendOp)
                    {
                        propertyContainer.AddId(subBody, blendOpParams, false);
                    }
                }

                m_blendData.DataCheck = (m_blendData.ValidBlendMode || m_blendData.ValidBlendOp) ? TemplateDataCheck.Valid : TemplateDataCheck.Invalid;
            }

            //ALPHA TO MASK
            {
                Match alphaToMaskMatch = Regex.Match(subBody, TemplateHelperFunctions.AlphaToMaskPattern);
                if (alphaToMaskMatch.Success)
                {
                    int    alphaIdx    = alphaToMaskMatch.Index;
                    int    end         = subBody.IndexOf(TemplatesManager.TemplateNewLine, alphaIdx);
                    string alphaParams = subBody.Substring(alphaIdx, end - alphaIdx);
                    m_alphaToMaskData.AlphaToMaskId = alphaParams;
                    m_alphaToMaskData.StartIdx      = offsetIdx + alphaIdx;
                    idManager.RegisterId(m_alphaToMaskData.StartIdx, uniquePrefix + m_alphaToMaskData.AlphaToMaskId, m_alphaToMaskData.AlphaToMaskId);
                    TemplateHelperFunctions.CreateAlphaToMask(alphaParams, ref m_alphaToMaskData);
                    if (m_alphaToMaskData.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, alphaParams, false, string.Empty);
                    }
                }
            }

            //CULL MODE
            {
                Match cullMatch = Regex.Match(subBody, TemplateHelperFunctions.CullWholeWordPattern);
                if (cullMatch.Success)
                {
                    int    cullIdx    = cullMatch.Index;
                    int    end        = subBody.IndexOf(TemplatesManager.TemplateNewLine, cullIdx);
                    string cullParams = subBody.Substring(cullIdx, end - cullIdx);
                    m_cullModeData.CullModeId = cullParams;
                    m_cullModeData.StartIdx   = offsetIdx + cullIdx;
                    idManager.RegisterId(m_cullModeData.StartIdx, uniquePrefix + m_cullModeData.CullModeId, m_cullModeData.CullModeId);
                    TemplateHelperFunctions.CreateCullMode(cullParams, ref m_cullModeData);
                    if (m_cullModeData.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, cullParams, false, string.Empty);
                    }
                }
            }
            //COLOR MASK
            {
                Match colorMaskMatch = Regex.Match(subBody, TemplateHelperFunctions.ColorMask1Pattern);
                if (colorMaskMatch.Success)
                {
                    int    colorMaskIdx    = colorMaskMatch.Index;
                    int    end             = colorMaskMatch.Length + colorMaskIdx;     // subBody.IndexOf( TemplatesManager.TemplateNewLine, colorMaskIdx );
                    string colorMaskParams = subBody.Substring(colorMaskIdx, end - colorMaskIdx);
                    m_colorMaskData1.ColorMaskId = colorMaskParams;
                    m_colorMaskData1.StartIdx    = offsetIdx + colorMaskIdx;
                    idManager.RegisterId(m_colorMaskData1.StartIdx, uniquePrefix + m_colorMaskData1.ColorMaskId, m_colorMaskData1.ColorMaskId);
                    TemplateHelperFunctions.CreateColorMask(colorMaskParams, ref m_colorMaskData1, TemplateHelperFunctions.ColorMask1Pattern);
                    if (m_colorMaskData1.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, colorMaskParams, false);
                    }
                }
            }
            {
                Match colorMaskMatch = Regex.Match(subBody, TemplateHelperFunctions.ColorMask2Pattern);
                if (colorMaskMatch.Success)
                {
                    int    colorMaskIdx    = colorMaskMatch.Index;
                    int    end             = colorMaskMatch.Length + colorMaskIdx;     // subBody.IndexOf( TemplatesManager.TemplateNewLine, colorMaskIdx );
                    string colorMaskParams = subBody.Substring(colorMaskIdx, end - colorMaskIdx);
                    m_colorMaskData2.ColorMaskId = colorMaskParams;
                    m_colorMaskData2.StartIdx    = offsetIdx + colorMaskIdx;
                    idManager.RegisterId(m_colorMaskData2.StartIdx, uniquePrefix + m_colorMaskData2.ColorMaskId, m_colorMaskData2.ColorMaskId);
                    TemplateHelperFunctions.CreateColorMask(colorMaskParams, ref m_colorMaskData2, TemplateHelperFunctions.ColorMask2Pattern);
                    if (m_colorMaskData2.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, colorMaskParams, false);
                    }
                }
            }
            {
                Match colorMaskMatch = Regex.Match(subBody, TemplateHelperFunctions.ColorMask3Pattern);
                if (colorMaskMatch.Success)
                {
                    int    colorMaskIdx    = colorMaskMatch.Index;
                    int    end             = colorMaskMatch.Length + colorMaskIdx;     // subBody.IndexOf( TemplatesManager.TemplateNewLine, colorMaskIdx );
                    string colorMaskParams = subBody.Substring(colorMaskIdx, end - colorMaskIdx);
                    m_colorMaskData3.ColorMaskId = colorMaskParams;
                    m_colorMaskData3.StartIdx    = offsetIdx + colorMaskIdx;
                    idManager.RegisterId(m_colorMaskData3.StartIdx, uniquePrefix + m_colorMaskData3.ColorMaskId, m_colorMaskData3.ColorMaskId);
                    TemplateHelperFunctions.CreateColorMask(colorMaskParams, ref m_colorMaskData3, TemplateHelperFunctions.ColorMask3Pattern);
                    if (m_colorMaskData3.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, colorMaskParams, false);
                    }
                }
            }
            {
                string pattern        = TemplateHelperFunctions.ColorMaskPattern;
                Match  colorMaskMatch = Regex.Match(subBody, pattern);
                if (!colorMaskMatch.Success && m_colorMaskData1.DataCheck == TemplateDataCheck.Invalid && m_colorMaskData2.DataCheck == TemplateDataCheck.Invalid && m_colorMaskData3.DataCheck == TemplateDataCheck.Invalid)
                {
                    pattern        = TemplateHelperFunctions.ColorMaskPatternFirst;
                    colorMaskMatch = Regex.Match(subBody, pattern);
                }

                if (colorMaskMatch.Success)
                {
                    int    colorMaskIdx    = colorMaskMatch.Index;
                    int    end             = colorMaskMatch.Length + colorMaskIdx;      //subBody.IndexOf( TemplatesManager.TemplateNewLine, colorMaskIdx );
                    string colorMaskParams = subBody.Substring(colorMaskIdx, end - colorMaskIdx);
                    m_colorMaskData.ColorMaskId = colorMaskParams;
                    m_colorMaskData.StartIdx    = offsetIdx + colorMaskIdx;
                    idManager.RegisterId(m_colorMaskData.StartIdx, uniquePrefix + m_colorMaskData.ColorMaskId, m_colorMaskData.ColorMaskId);
                    TemplateHelperFunctions.CreateColorMask(colorMaskParams, ref m_colorMaskData, pattern);
                    if (m_colorMaskData.DataCheck == TemplateDataCheck.Valid)
                    {
                        propertyContainer.AddId(subBody, colorMaskParams, false);
                    }
                }
            }
            //STENCIL
            {
                Match stencilMatch = Regex.Match(subBody, TemplateHelperFunctions.StencilWholeWordPattern);
                if (stencilMatch.Success)
                {
                    int stencilIdx    = stencilMatch.Index;
                    int stencilEndIdx = subBody.IndexOf("}", stencilIdx);
                    if (stencilEndIdx > 0)
                    {
                        string stencilParams = subBody.Substring(stencilIdx, stencilEndIdx + 1 - stencilIdx);
                        m_stencilData.StencilBufferId = stencilParams;
                        m_stencilData.StartIdx        = offsetIdx + stencilIdx;
                        idManager.RegisterId(m_stencilData.StartIdx, uniquePrefix + m_stencilData.StencilBufferId, m_stencilData.StencilBufferId);
                        TemplateHelperFunctions.CreateStencilOps(stencilParams, ref m_stencilData);
                        if (m_stencilData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, stencilParams, true);
                        }
                    }
                }
                else
                {
                    int stencilTagIdx = subBody.IndexOf(TemplatesManager.TemplateStencilTag);
                    if (stencilTagIdx > -1)
                    {
                        m_stencilData.SetIndependentDefault();
                        m_stencilData.StencilBufferId = TemplatesManager.TemplateStencilTag;
                        m_stencilData.StartIdx        = offsetIdx + stencilTagIdx;
                        idManager.RegisterId(m_stencilData.StartIdx, uniquePrefix + m_stencilData.StencilBufferId, m_stencilData.StencilBufferId);
                        propertyContainer.AddId(subBody, m_stencilData.StencilBufferId, true);
                    }
                }
            }
            //ZWRITE
            {
                Match zWriteMatch = Regex.Match(subBody, TemplateHelperFunctions.ZWriteWholeWordPattern);
                if (zWriteMatch.Success)
                {
                    int zWriteOpIdx  = zWriteMatch.Index;
                    int zWriteEndIdx = subBody.IndexOf(TemplatesManager.TemplateNewLine, zWriteOpIdx);
                    if (zWriteEndIdx > 0)
                    {
                        m_depthData.ZWriteModeId     = subBody.Substring(zWriteOpIdx, zWriteEndIdx + 1 - zWriteOpIdx);
                        m_depthData.ZWriteStartIndex = offsetIdx + zWriteOpIdx;
                        idManager.RegisterId(m_depthData.ZWriteStartIndex, uniquePrefix + m_depthData.ZWriteModeId, m_depthData.ZWriteModeId);
                        TemplateHelperFunctions.CreateZWriteMode(m_depthData.ZWriteModeId, ref m_depthData);
                        if (m_depthData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, m_depthData.ZWriteModeId, true);
                        }
                    }
                }
            }

            //ZTEST
            {
                Match zTestMatch = Regex.Match(subBody, TemplateHelperFunctions.ZTestWholeWordPattern);
                if (zTestMatch.Success)
                {
                    int zTestOpIdx  = zTestMatch.Index;
                    int zTestEndIdx = subBody.IndexOf(TemplatesManager.TemplateNewLine, zTestOpIdx);
                    if (zTestEndIdx > 0)
                    {
                        m_depthData.ZTestModeId     = subBody.Substring(zTestOpIdx, zTestEndIdx + 1 - zTestOpIdx);
                        m_depthData.ZTestStartIndex = offsetIdx + zTestOpIdx;
                        idManager.RegisterId(m_depthData.ZTestStartIndex, uniquePrefix + m_depthData.ZTestModeId, m_depthData.ZTestModeId);
                        TemplateHelperFunctions.CreateZTestMode(m_depthData.ZTestModeId, ref m_depthData);
                        if (m_depthData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, m_depthData.ZTestModeId, true);
                        }
                    }
                }
            }

            //ZOFFSET
            {
                Match zOffsetMatch = Regex.Match(subBody, TemplateHelperFunctions.ZOffsetWholeWordPattern);
                if (zOffsetMatch.Success)
                {
                    int zOffsetIdx    = zOffsetMatch.Index;
                    int zOffsetEndIdx = subBody.IndexOf(TemplatesManager.TemplateNewLine, zOffsetIdx);
                    if (zOffsetEndIdx > 0)
                    {
                        m_depthData.OffsetId         = subBody.Substring(zOffsetIdx, zOffsetEndIdx + 1 - zOffsetIdx);
                        m_depthData.OffsetStartIndex = offsetIdx + zOffsetIdx;
                        idManager.RegisterId(m_depthData.OffsetStartIndex, uniquePrefix + m_depthData.OffsetId, m_depthData.OffsetId);
                        TemplateHelperFunctions.CreateZOffsetMode(m_depthData.OffsetId, ref m_depthData);
                        if (m_depthData.DataCheck == TemplateDataCheck.Valid)
                        {
                            propertyContainer.AddId(subBody, m_depthData.OffsetId, true);
                        }
                    }
                }
                m_depthData.SetDataCheck();
            }
            //TAGS
            {
                Match tagsMatch = Regex.Match(subBody, TemplateHelperFunctions.TagsWholeWordPattern);
                if (tagsMatch.Success)
                {
                    int tagsIdx    = tagsMatch.Index;
                    int tagsEndIdx = subBody.IndexOf("}", tagsIdx);
                    if (tagsEndIdx > -1)
                    {
                        m_tagData.Reset();
                        m_tagData.TagsId   = subBody.Substring(tagsIdx, tagsEndIdx + 1 - tagsIdx);
                        m_tagData.StartIdx = offsetIdx + tagsIdx;
                        idManager.RegisterId(m_tagData.StartIdx, uniquePrefix + m_tagData.TagsId, m_tagData.TagsId);
                        m_srpType = TemplateHelperFunctions.CreateTags(ref m_tagData, isSubShader);

                        propertyContainer.AddId(subBody, m_tagData.TagsId, false);
                        m_tagData.DataCheck = TemplateDataCheck.Valid;
                    }
                    else
                    {
                        m_tagData.DataCheck = TemplateDataCheck.Invalid;
                    }
                }
                else
                {
                    m_tagData.DataCheck = TemplateDataCheck.Invalid;
                }
            }

            //SHADER MODEL
            {
                Match match = Regex.Match(subBody, TemplateHelperFunctions.ShaderModelPattern);
                if (match != null && match.Groups.Count > 1)
                {
                    if (TemplateHelperFunctions.AvailableInterpolators.ContainsKey(match.Groups[1].Value))
                    {
                        m_shaderModel.Id                 = match.Groups[0].Value;
                        m_shaderModel.StartIdx           = offsetIdx + match.Index;
                        m_shaderModel.Value              = match.Groups[1].Value;
                        m_shaderModel.InterpolatorAmount = TemplateHelperFunctions.AvailableInterpolators[match.Groups[1].Value];
                        m_shaderModel.DataCheck          = TemplateDataCheck.Valid;
                        idManager.RegisterId(m_shaderModel.StartIdx, uniquePrefix + m_shaderModel.Id, m_shaderModel.Id);
                    }
                    else
                    {
                        m_shaderModel.DataCheck = TemplateDataCheck.Invalid;
                    }
                }
            }

            // ALL MODULES
            int allModulesIndex = subBody.IndexOf(TemplatesManager.TemplateAllModulesTag);

            if (allModulesIndex > 0)
            {
                //ONLY REGISTER MISSING TAGS
                ConfigureCommonTag(m_allModulesTag, propertyContainer, idManager, uniquePrefix, offsetIdx, subBody);
                m_allModulesMode = true;

                m_blendData.SetAllModulesDefault();

                if (!m_alphaToMaskData.IsValid)
                {
                    m_alphaToMaskData.SetAllModulesDefault();
                }

                if (!m_cullModeData.IsValid)
                {
                    m_cullModeData.SetAllModulesDefault();
                }

                if (!m_colorMaskData.IsValid)
                {
                    m_colorMaskData.SetAllModulesDefault();
                }

                if (!m_stencilData.IsValid)
                {
                    m_stencilData.SetAllModulesDefault();
                }

                if (!m_depthData.IsValid)
                {
                    m_depthData.SetAllModulesDefault();
                }

                if (!m_shaderModel.IsValid)
                {
                    m_shaderModel.SetAllModulesDefault();
                }
            }
        }
コード例 #12
0
        void LoadTemplateBody(string guid)
        {
            m_guid = guid;
            string datapath   = AssetDatabase.GUIDToAssetPath(guid);
            string shaderBody = string.Empty;

            shaderBody   = IOUtils.LoadTextFileFromDisk(datapath);
            shaderBody   = shaderBody.Replace("\r\n", "\n");
            m_shaderData = TemplateShaderInfoUtil.CreateShaderData(shaderBody);
            if (m_shaderData == null)
            {
                m_isValid = false;
                return;
            }

            m_templateIdManager = new TemplateIdManager(shaderBody);

            try
            {
                int nameBegin = shaderBody.IndexOf(TemplatesManager.TemplateShaderNameBeginTag);
                if (nameBegin < 0)
                {
                    // Not a template
                    return;
                }

                m_shaderBody = shaderBody;
                int nameEnd       = shaderBody.IndexOf(TemplatesManager.TemplateFullEndTag, nameBegin);
                int defaultBegin  = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length;
                int defaultLength = nameEnd - defaultBegin;
                m_defaultShaderName = shaderBody.Substring(defaultBegin, defaultLength);
                int[] nameIdx = m_defaultShaderName.AllIndexesOf("\"");
                nameIdx[0]         += 1;           // Ignore the " character from the string
                m_defaultShaderName = m_defaultShaderName.Substring(nameIdx[0], nameIdx[1] - nameIdx[0]);
                m_shaderNameId      = shaderBody.Substring(nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin);
                m_templateProperties.AddId(shaderBody, m_shaderNameId, false);
                m_templateIdManager.RegisterId(nameBegin, m_shaderNameId, m_shaderNameId);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }

            m_propertyTag = new TemplateTagData(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, true);
            m_templateIdManager.RegisterId(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, TemplatesManager.TemplatePropertyTag);
            m_templateProperties.AddId(shaderBody, TemplatesManager.TemplatePropertyTag, true);
            Dictionary <string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary <string, TemplateShaderPropertyData>();

            TemplateHelperFunctions.CreateShaderPropertiesList(m_shaderData.Properties, ref m_availableShaderProperties, ref duplicatesHelper);
            int subShaderCount = m_shaderData.SubShaders.Count;

            for (int i = 0; i < subShaderCount; i++)
            {
                TemplateSubShader subShader = new TemplateSubShader(i, m_templateIdManager, "SubShader" + i, m_shaderData.SubShaders[i], ref duplicatesHelper);
                m_subShaders.Add(subShader);
                m_masterNodesRequired += subShader.Passes.Count;
            }

            duplicatesHelper.Clear();
            duplicatesHelper = null;
            m_isSinglePass   = (m_subShaders.Count == 1 && m_subShaders[0].PassAmount == 1);
        }