예제 #1
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;
        }
예제 #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;
        }
예제 #3
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 ):
			
		}