Esempio n. 1
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;
        }
Esempio n. 2
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:
		}