Exemple #1
0
		void FetchCommonTags()
		{
			// Name
			try
			{
				int nameBegin = m_templateBody.IndexOf( TemplatesManager.TemplateShaderNameBeginTag ):
				if( nameBegin < 0 )
				{
					// Not a template
					return:
				}

				int nameEnd = m_templateBody.IndexOf( TemplatesManager.TemplateFullEndTag, nameBegin ):
				int defaultBegin = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length:
				int defaultLength = nameEnd - defaultBegin:
				m_defaultShaderName = m_templateBody.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 = m_templateBody.Substring( nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin ):
				AddId( m_shaderNameId, false ):

			}
			catch( Exception e )
			{
				Debug.LogException( e ):
				m_isValid = false:
			}

			FetchSubShaderProperties():
			// Vertex Data
			{
				int vertexDataTagBegin = m_templateBody.IndexOf( TemplatesManager.TemplateVertexDataTag ):
				if( vertexDataTagBegin > -1 )
				{
					m_vertexDataContainer.VertexDataStartIdx = vertexDataTagBegin:
					int vertexDataTagEnd = m_templateBody.IndexOf( TemplatesManager.TemplateEndOfLine, vertexDataTagBegin ):
					m_vertexDataContainer.VertexDataId = m_templateBody.Substring( vertexDataTagBegin, vertexDataTagEnd + TemplatesManager.TemplateEndOfLine.Length - vertexDataTagBegin ):
					int dataBeginIdx = m_templateBody.LastIndexOf( '{', vertexDataTagBegin, vertexDataTagBegin ):
					string vertexData = m_templateBody.Substring( dataBeginIdx + 1, vertexDataTagBegin - dataBeginIdx ):

					int parametersBegin = vertexDataTagBegin + TemplatesManager.TemplateVertexDataTag.Length:
					string parameters = m_templateBody.Substring( parametersBegin, vertexDataTagEnd - parametersBegin ):
					m_vertexDataContainer.VertexData = TemplateHelperFunctions.CreateVertexDataList( vertexData, parameters ):
					AddId( m_vertexDataContainer.VertexDataId ):
				}
			}

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

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

					m_interpolatorDataContainer = TemplateHelperFunctions.CreateInterpDataList( interpData, interpDataId, 8 ):
					m_interpolatorDataContainer.InterpDataId = interpDataId:
					m_interpolatorDataContainer.InterpDataStartIdx = interpDataBegin:
					AddId( interpDataId ):
				}
			}
			catch( Exception e )
			{
				Debug.LogException( e ):
				m_isValid = false:
			}


			try
			{
				Dictionary<string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary<string, TemplateShaderPropertyData>():
				m_availableShaderProperties = new List<TemplateShaderPropertyData>():

				// Common Tags
				for( int i = 0: i < TemplatesManager.CommonTags.Length: i++ )
				{
					int idx = m_templateBody.IndexOf( TemplatesManager.CommonTags[ i ].Id ):
					if( idx > -1 )
					{
						string currentId = TemplatesManager.CommonTags[ i ].Id:

						TemplateCommonTagId commonTagId = (TemplateCommonTagId)i:
						switch( commonTagId )
						{
							// Properties
							case TemplateCommonTagId.Property:
							{
								TemplateHelperFunctions.CreateShaderPropertiesList( m_templateBody.Substring( 0, idx + TemplatesManager.CommonTags[ i ].Id.Length ), ref m_availableShaderProperties, ref duplicatesHelper ):
							}
							break:
							// Globals
							case TemplateCommonTagId.Global:
							{
								TemplateHelperFunctions.CreateShaderGlobalsList( m_templateBody.Substring( 0, idx + TemplatesManager.CommonTags[ i ].Id.Length ), ref m_availableShaderProperties, ref duplicatesHelper ):
							}
							break:

							//Tags
							//case TemplateCommonTagId.Tag:
							//{
							//	m_propertyList[ m_propertyList.Count - 1 ].Indentation = " ":
							//}
							//break:
							//case TemplateCommonTagId.CullMode:
							//{
							//	int newId = idx + TemplatesManager.CommonTags[ i ].Id.Length:
							//	int end = m_templateBody.IndexOf( TemplatesManager.TemplateNewLine, newId ):
							//	string cullParams = m_templateBody.Substring( newId, end - newId ):
							//	currentId = m_templateBody.Substring( idx, end - idx ):
							//	m_cullModeData.CullModeId = currentId:
							//	TemplateHelperFunctions.CreateCullMode( cullParams, ref m_cullModeData ):
							//}
							//break:
							//Blend Mode
							//case TemplateCommonTagId.BlendMode:
							//{
							//	int newId = idx + TemplatesManager.CommonTags[ i ].Id.Length:
							//	int end = m_templateBody.IndexOf( TemplatesManager.TemplateNewLine, newId ):
							//	string blendParams = m_templateBody.Substring( newId, end - newId ):
							//	currentId = m_templateBody.Substring( idx, end - idx ):
							//	m_blendData.BlendModeId = currentId:
							//	TemplateHelperFunctions.CreateBlendMode( blendParams, ref m_blendData ):
							//}break:
							//case TemplateCommonTagId.BlendOp:
							//{
							//	int newId = idx + TemplatesManager.CommonTags[ i ].Id.Length:
							//	int end = m_templateBody.IndexOf( TemplatesManager.TemplateNewLine, newId ):
							//	currentId = m_templateBody.Substring( idx, end - idx ):
							//	BlendData.BlendOpId = currentId:
							//	TemplateHelperFunctions.CreateBlendOp( m_templateBody.Substring( newId, end - newId ), ref m_blendData ):
							//}break:
							//case TemplateCommonTagId.ColorMask:
							//{
							//	int newId = idx + TemplatesManager.CommonTags[ i ].Id.Length:
							//	int end = m_templateBody.IndexOf( TemplatesManager.TemplateNewLine, newId ):
							//	string colorMaskParams = m_templateBody.Substring( newId, end - newId ):
							//	currentId = m_templateBody.Substring( idx, end - idx ):
							//	m_colorMaskData.ColorMaskId = currentId:
							//	TemplateHelperFunctions.CreateColorMask( colorMaskParams, ref m_colorMaskData ):
							//}
							//break:
							//case TemplateCommonTagId.StencilOp:
							//{
							//    int id = m_templateBody.LastIndexOf( "Stencil" ):
							//    if( id > -1 )
							//    {
							//        string stencilParams = m_templateBody.Substring( id, idx - id ):
							//        currentId = stencilParams + TemplatesManager.TemplateStencilOpTag:
							//        m_stencilData.StencilBufferId = currentId:
							//        TemplateHelperFunctions.CreateStencilOps( stencilParams, ref m_stencilData ):
							//    }

							//}
							//break:
							default:
							break:
						}

						//AddId( TemplatesManager.CommonTags[ i ] ):
						AddId( currentId, TemplatesManager.CommonTags[ i ].SearchIndentation, TemplatesManager.CommonTags[ i ].CustomIndentation ):
					}
				}

				duplicatesHelper.Clear():
				duplicatesHelper = null:
			}
			catch( Exception e )
			{
				Debug.LogException( e ):
				m_isValid = false:
			}
		}
Exemple #2
0
        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;
        }
Exemple #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;
        }
        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;
        }
		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:
		}
Exemple #6
0
        void FetchCommonTags()
        {
            // Name
            try
            {
                int nameBegin = m_templateBody.IndexOf(TemplatesManager.TemplateShaderNameBeginTag);
                if (nameBegin < 0)
                {
                    // Not a template
                    return;
                }

                int nameEnd       = m_templateBody.IndexOf(TemplatesManager.TemplateFullEndTag, nameBegin);
                int defaultBegin  = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length;
                int defaultLength = nameEnd - defaultBegin;
                m_defaultShaderName = m_templateBody.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      = m_templateBody.Substring(nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin);
                AddId(m_shaderNameId, false);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }
            // Vertex Data
            {
                int vertexDataTagBegin = m_templateBody.IndexOf(TemplatesManager.TemplateVertexDataTag);
                if (vertexDataTagBegin > -1)
                {
                    int vertexDataTagEnd = m_templateBody.IndexOf(TemplatesManager.TemplateEndOfLine, vertexDataTagBegin);
                    m_vertexDataId = m_templateBody.Substring(vertexDataTagBegin, vertexDataTagEnd + TemplatesManager.TemplateEndOfLine.Length - vertexDataTagBegin);
                    int    dataBeginIdx = m_templateBody.LastIndexOf('{', vertexDataTagBegin, vertexDataTagBegin);
                    string vertexData   = m_templateBody.Substring(dataBeginIdx + 1, vertexDataTagBegin - dataBeginIdx);

                    int    parametersBegin = vertexDataTagBegin + TemplatesManager.TemplateVertexDataTag.Length;
                    string parameters      = m_templateBody.Substring(parametersBegin, vertexDataTagEnd - parametersBegin);
                    m_vertexData = TemplateHelperFunctions.CreateVertexDataList(vertexData, parameters);
                    AddId(m_vertexDataId);
                }
            }

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

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

                    m_interpolatorData = TemplateHelperFunctions.CreateInterpDataList(interpData, m_interpDataId);
                    AddId(m_interpDataId);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }

            try
            {
                Dictionary <string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary <string, TemplateShaderPropertyData>();
                m_availableShaderProperties = new List <TemplateShaderPropertyData>();

                // Common Tags
                for (int i = 0; i < TemplatesManager.CommonTags.Length; i++)
                {
                    int idx = m_templateBody.IndexOf(TemplatesManager.CommonTags[i].Id);
                    if (idx > -1)
                    {
                        TemplateCommonTagId commonTagId = (TemplateCommonTagId)i;
                        switch (commonTagId)
                        {
                        // Properties
                        case TemplateCommonTagId.Property:
                        {
                            TemplateHelperFunctions.CreateShaderPropertiesList(m_templateBody.Substring(0, idx + TemplatesManager.CommonTags[i].Id.Length), ref m_availableShaderProperties, ref duplicatesHelper);
                        }
                        break;

                        // Globals
                        case TemplateCommonTagId.Global:
                        {
                            TemplateHelperFunctions.CreateShaderGlobalsList(m_templateBody.Substring(0, idx + TemplatesManager.CommonTags[i].Id.Length), ref m_availableShaderProperties, ref duplicatesHelper);
                        }
                        break;

                        //Tags
                        case TemplateCommonTagId.Tag:
                        {
                            m_propertyList[m_propertyList.Count - 1].Indentation = " ";
                        }
                        break;

                        case TemplateCommonTagId.CullMode:
                            break;

                        //Blend Mode
                        case TemplateCommonTagId.BlendMode:
                        {
                            int newId = idx + TemplatesManager.CommonTags[i].Id.Length;
                            int end   = m_templateBody.IndexOf(TemplatesManager.TemplateNewLine, newId);
                            TemplateHelperFunctions.CreateBlendMode(m_templateBody.Substring(newId, end - newId), ref m_blendData);
                        }
                        break;

                        case TemplateCommonTagId.BlendOp:
                        {
                            int newId = idx + TemplatesManager.CommonTags[i].Id.Length;
                            int end   = m_templateBody.IndexOf(TemplatesManager.TemplateNewLine, newId);
                            TemplateHelperFunctions.CreateBlendOp(m_templateBody.Substring(newId, end - newId), ref m_blendData);
                        }
                        break;

                        case TemplateCommonTagId.ColorMask:
                            break;

                        default:
                            break;
                        }

                        AddId(TemplatesManager.CommonTags[i]);
                    }
                }
                duplicatesHelper.Clear();
                duplicatesHelper = null;
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }
        }