void UpdateFromId() { if (m_interpolatorData != null) { if (m_interpolatorData.Count == 0) { for (int i = 0; i < 4; i++) { m_containerGraph.DeleteConnection(false, UniqueId, i, false, true); } m_headerColor = UIUtils.GetColorFromCategory("Default"); m_content.text = "None"; m_additionalContent.text = string.Empty; m_outputPorts[0].ChangeProperties("None", WirePortDataType.OBJECT, false); ConfigurePorts(); return; } bool areCompatible = TemplateHelperFunctions.CheckIfCompatibles(m_outputPorts[0].DataType, m_interpolatorData[m_currentDataIdx].DataType); switch (m_interpolatorData[m_currentDataIdx].DataType) { default: case WirePortDataType.INT: case WirePortDataType.FLOAT: m_outputPorts[0].ChangeProperties(Constants.EmptyPortValue, m_interpolatorData[m_currentDataIdx].DataType, false); break; case WirePortDataType.FLOAT2: m_outputPorts[0].ChangeProperties("XY", m_interpolatorData[m_currentDataIdx].DataType, false); break; case WirePortDataType.FLOAT3: m_outputPorts[0].ChangeProperties("XYZ", m_interpolatorData[m_currentDataIdx].DataType, false); break; case WirePortDataType.FLOAT4: m_outputPorts[0].ChangeProperties("XYZW", m_interpolatorData[m_currentDataIdx].DataType, false); break; case WirePortDataType.COLOR: m_outputPorts[0].ChangeProperties("RGBA", m_interpolatorData[m_currentDataIdx].DataType, false); break; } ConfigurePorts(); if (!areCompatible) { m_containerGraph.DeleteConnection(false, UniqueId, 0, false, true); } m_dataName = m_interpolatorData[m_currentDataIdx].VarName; m_content.text = m_dataName; m_sizeIsDirty = true; CheckWarningState(); } }
void UpdateFromId() { if (m_shaderProperties != null) { bool areCompatible = TemplateHelperFunctions.CheckIfCompatibles(m_outputPorts[0].DataType, m_shaderProperties[m_currentPropertyIdx].PropertyDataType); m_outputPorts[0].ChangeType(m_shaderProperties[m_currentPropertyIdx].PropertyDataType, false); if (!areCompatible) { m_containerGraph.DeleteConnection(false, UniqueId, 0, false, true); } m_propertyName = m_shaderProperties[m_currentPropertyIdx].PropertyName; m_content.text = m_shaderProperties[m_currentPropertyIdx].PropertyInspectorName; m_propertyNameId = Shader.PropertyToID(m_propertyName); m_typeName = TypeLabelStr + m_shaderProperties[m_currentPropertyIdx].PropertyType.ToString(); m_sizeIsDirty = true; Material currMat = m_containerGraph.CurrentMaterial; if (currMat != null) { if (m_shaderProperties[m_currentPropertyIdx].PropertyType == PropertyType.Global) { m_previewMaterialPassId = 0; if (!m_showErrorMessage) { ShowTab(NodeMessageType.Info, WarningStr); } } else { if (m_showErrorMessage && m_errorMessageTypeIsError != NodeMessageType.Error) { HideTab(); } switch (m_shaderProperties[m_currentPropertyIdx].PropertyDataType) { case WirePortDataType.INT: m_previewMaterialPassId = 0; break; case WirePortDataType.FLOAT: m_previewMaterialPassId = 1; break; case WirePortDataType.FLOAT4: case WirePortDataType.COLOR: m_previewMaterialPassId = 2; break; case WirePortDataType.SAMPLER2D: m_previewMaterialPassId = 3; break; case WirePortDataType.SAMPLER3D: m_previewMaterialPassId = 4; break; case WirePortDataType.SAMPLERCUBE: m_previewMaterialPassId = 5; break; default: PreviewMaterial.SetPass(0); break; } } } CheckWarningState(); } }
void UpdateFromId() { if( m_localVarsData != null ) { if( m_localVarsData.Count == 0 ) { for( int i = 0: i < 4: i++ ) m_containerGraph.DeleteConnection( false, UniqueId, i, false, true ): m_headerColor = UIUtils.GetColorFromCategory( "Default" ): m_content.text = "None": m_additionalContent.text = string.Empty: m_outputPorts[ 0 ].ChangeProperties( "None", WirePortDataType.OBJECT, false ): ConfigurePorts(): return: } bool areCompatible = TemplateHelperFunctions.CheckIfCompatibles( m_outputPorts[ 0 ].DataType, m_localVarsData[ m_currentDataIdx ].DataType ): string category = m_localVarsData[ m_currentDataIdx ].Category == MasterNodePortCategory.Fragment ? "Surface Data" : "Vertex Data": m_headerColor = UIUtils.GetColorFromCategory( category ): switch( m_localVarsData[ m_currentDataIdx ].DataType ) { default: case WirePortDataType.INT: case WirePortDataType.FLOAT: m_outputPorts[ 0 ].ChangeProperties( Constants.EmptyPortValue, m_localVarsData[ m_currentDataIdx ].DataType, false ): break: case WirePortDataType.FLOAT2: m_outputPorts[ 0 ].ChangeProperties( "XY", m_localVarsData[ m_currentDataIdx ].DataType, false ): break: case WirePortDataType.FLOAT3: m_outputPorts[ 0 ].ChangeProperties( "XYZ", m_localVarsData[ m_currentDataIdx ].DataType, false ): break: case WirePortDataType.FLOAT4: m_outputPorts[ 0 ].ChangeProperties( "XYZW", m_localVarsData[ m_currentDataIdx ].DataType, false ): break: case WirePortDataType.COLOR: m_outputPorts[ 0 ].ChangeProperties( "RGBA", m_localVarsData[ m_currentDataIdx ].DataType, false ): break: } ConfigurePorts(): if( !areCompatible ) { m_containerGraph.DeleteConnection( false, UniqueId, 0, false, true ): } m_dataName = m_localVarsData[ m_currentDataIdx ].LocalVarName: m_content.text = m_dataName: m_sizeIsDirty = true: CheckWarningState(): } }
public string GetVertexPosition(WirePortDataType type, bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { if (HasInfo(TemplateInfoOnSematics.POSITION, useMasterNodeCategory, customCategory)) { InterpDataHelper info = GetInfo(TemplateInfoOnSematics.POSITION, useMasterNodeCategory, customCategory); return(TemplateHelperFunctions.AutoSwizzleData(info.VarName, info.VarType, type)); } else { MasterNodePortCategory portCategory = useMasterNodeCategory ? m_currentDataCollector.PortCategory : customCategory; string name = "ase_vertex_pos"; return(RegisterInfoOnSemantic(portCategory, TemplateInfoOnSematics.POSITION, TemplateSemantics.POSITION, name, type, true)); } }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { string src = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); bool isScaledNormal = false; if (m_inputPorts[1].IsConnected) { isScaledNormal = true; } else { if (m_inputPorts[1].FloatInternalData != 1) { isScaledNormal = true; } } string normalMapUnpackMode = string.Empty; string scaleValue = isScaledNormal?m_inputPorts[1].GeneratePortInstructions(ref dataCollector):"1.0"; normalMapUnpackMode = string.Format(TemplateHelperFunctions.CreateUnpackNormalStr(dataCollector, isScaledNormal, scaleValue), src); if (isScaledNormal && !(dataCollector.IsTemplate && dataCollector.IsSRP)) { dataCollector.AddToIncludes(UniqueId, Constants.UnityStandardUtilsLibFuncs); } int outputUsage = 0; for (int i = 0; i < m_outputPorts.Count; i++) { if (m_outputPorts[i].IsConnected) { outputUsage += 1; } } if (outputUsage > 1) { string varName = "localUnpackNormal" + OutputId; dataCollector.AddLocalVariable(UniqueId, "float3 " + varName + " = " + normalMapUnpackMode + ";"); return(GetOutputVectorItem(0, outputId, varName)); } else { return(GetOutputVectorItem(0, outputId, normalMapUnpackMode)); } }
public string GetVertexNormal(bool useMasterNodeCategory = true, MasterNodePortCategory customCategory = MasterNodePortCategory.Fragment) { if (HasInfo(TemplateInfoOnSematics.NORMAL, useMasterNodeCategory, customCategory)) { InterpDataHelper info = GetInfo(TemplateInfoOnSematics.NORMAL, useMasterNodeCategory, customCategory); return(TemplateHelperFunctions.AutoSwizzleData(info.VarName, info.VarType, WirePortDataType.FLOAT3)); } else { MasterNodePortCategory category = useMasterNodeCategory ? m_currentDataCollector.PortCategory : customCategory; string name = "ase_normal"; return(RegisterInfoOnSemantic(category, TemplateInfoOnSematics.NORMAL, TemplateSemantics.NORMAL, name, WirePortDataType.FLOAT3, false)); } }
void FetchVertexAndInterpData(int offsetIdx, string body) { // Vertex Data try { int vertexDataTagBegin = body.IndexOf(TemplatesManager.TemplateVertexDataTag); if (vertexDataTagBegin > -1) { m_vertexDataContainer = new VertexDataContainer(); m_vertexDataContainer.VertexDataStartIdx = offsetIdx + vertexDataTagBegin; int vertexDataTagEnd = body.IndexOf(TemplatesManager.TemplateEndOfLine, vertexDataTagBegin); m_vertexDataContainer.VertexDataId = body.Substring(vertexDataTagBegin, vertexDataTagEnd + TemplatesManager.TemplateEndOfLine.Length - vertexDataTagBegin); int dataBeginIdx = body.LastIndexOf('{', vertexDataTagBegin, vertexDataTagBegin); string vertexData = body.Substring(dataBeginIdx + 1, vertexDataTagBegin - dataBeginIdx); int parametersBegin = vertexDataTagBegin + TemplatesManager.TemplateVertexDataTag.Length; string parameters = body.Substring(parametersBegin, vertexDataTagEnd - parametersBegin); m_vertexDataContainer.VertexData = TemplateHelperFunctions.CreateVertexDataList(vertexData, parameters); m_templateProperties.AddId(body, m_vertexDataContainer.VertexDataId); } } catch (Exception e) { Debug.LogException(e); } // Available interpolators try { int interpDataBegin = body.IndexOf(TemplatesManager.TemplateInterpolatorBeginTag); if (interpDataBegin > -1) { int interpDataEnd = body.IndexOf(TemplatesManager.TemplateEndOfLine, interpDataBegin); string interpDataId = body.Substring(interpDataBegin, interpDataEnd + TemplatesManager.TemplateEndOfLine.Length - interpDataBegin); int dataBeginIdx = body.LastIndexOf('{', interpDataBegin, interpDataBegin); string interpData = body.Substring(dataBeginIdx + 1, interpDataBegin - dataBeginIdx); m_interpolatorDataContainer = TemplateHelperFunctions.CreateInterpDataList(interpData, interpDataId, m_modules.ShaderModel.InterpolatorAmount); m_interpolatorDataContainer.InterpDataId = interpDataId; m_interpolatorDataContainer.InterpDataStartIdx = offsetIdx + interpDataBegin; m_templateProperties.AddId(body, interpDataId); } } catch (Exception e) { Debug.LogException(e); } }
void UpdateFromId() { if (m_localVarsData != null) { bool areCompatible = TemplateHelperFunctions.CheckIfCompatibles(m_outputPorts[0].DataType, m_localVarsData[m_currentDataIdx].DataType); string category = m_localVarsData[m_currentDataIdx].InputData.PortCategory == MasterNodePortCategory.Fragment ? "Surface Data" : "Vertex Data"; m_headerColor = UIUtils.GetColorFromCategory(category); switch (m_localVarsData[m_currentDataIdx].DataType) { default: case WirePortDataType.INT: case WirePortDataType.FLOAT: m_outputPorts[0].ChangeProperties(Constants.EmptyPortValue, m_localVarsData[m_currentDataIdx].DataType, false); break; case WirePortDataType.FLOAT2: m_outputPorts[0].ChangeProperties("XY", m_localVarsData[m_currentDataIdx].DataType, false); break; case WirePortDataType.FLOAT3: m_outputPorts[0].ChangeProperties("XYZ", m_localVarsData[m_currentDataIdx].DataType, false); break; case WirePortDataType.FLOAT4: m_outputPorts[0].ChangeProperties("XYZW", m_localVarsData[m_currentDataIdx].DataType, false); break; case WirePortDataType.COLOR: m_outputPorts[0].ChangeProperties("RGBA", m_localVarsData[m_currentDataIdx].DataType, false); break; } ConfigurePorts(); if (!areCompatible) { m_containerGraph.DeleteConnection(false, UniqueId, 0, false, true); } m_dataName = m_localVarsData[m_currentDataIdx].LocalVarName; m_content.text = m_dataName; m_sizeIsDirty = true; CheckWarningState(); } }
void UpdateFromId() { if (m_interpolatorData != null) { bool areCompatible = TemplateHelperFunctions.CheckIfCompatibles(m_outputPorts[0].DataType, m_interpolatorData[m_currentDataIdx].DataType); switch (m_interpolatorData[m_currentDataIdx].DataType) { default: case WirePortDataType.INT: case WirePortDataType.FLOAT: m_outputPorts[0].ChangeProperties(Constants.EmptyPortValue, m_interpolatorData[m_currentDataIdx].DataType, false); break; case WirePortDataType.FLOAT2: m_outputPorts[0].ChangeProperties("XY", m_interpolatorData[m_currentDataIdx].DataType, false); break; case WirePortDataType.FLOAT3: m_outputPorts[0].ChangeProperties("XYZ", m_interpolatorData[m_currentDataIdx].DataType, false); break; case WirePortDataType.FLOAT4: m_outputPorts[0].ChangeProperties("XYZW", m_interpolatorData[m_currentDataIdx].DataType, false); break; case WirePortDataType.COLOR: m_outputPorts[0].ChangeProperties("RGBA", m_interpolatorData[m_currentDataIdx].DataType, false); break; } ConfigurePorts(); if (!areCompatible) { m_containerGraph.DeleteConnection(false, UniqueId, 0, false, true); } m_dataName = m_interpolatorData[m_currentDataIdx].VarName; m_content.text = m_dataName; m_sizeIsDirty = true; CheckWarningState(); } }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (m_proceduralMaterial == null) { return("(0).xxxx"); } if (m_outputPorts[outputId].IsLocalValue(dataCollector.PortCategory)) { return(m_outputPorts[outputId].LocalValue(dataCollector.PortCategory)); } Texture[] textures = m_proceduralMaterial.GetGeneratedTextures(); string uvPropertyName = string.Empty; for (int i = 0; i < m_outputPorts.Count; i++) { if (m_outputPorts[i].IsConnected) { uvPropertyName = textures[i].name; break; } } string name = textures[outputId].name + OutputId; dataCollector.AddToUniforms(UniqueId, string.Format(GlobalVarDecStr, textures[outputId].name)); dataCollector.AddToProperties(UniqueId, string.Format(PropertyDecStr, textures[outputId].name) + "{}", -1); bool isVertex = (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation); string value = string.Format("tex2D{0}({1}, {2})", (isVertex ? "lod" : string.Empty), textures[outputId].name, GetUVCoords(ref dataCollector, ignoreLocalvar, uvPropertyName)); if (m_autoNormal && m_textureTypes[outputId] == ProceduralOutputType.Normal) { value = string.Format(TemplateHelperFunctions.CreateUnpackNormalStr(dataCollector, false, "1.0"), value); } dataCollector.AddPropertyNode(this); RegisterLocalVariable(outputId, value, ref dataCollector, name); return(m_outputPorts[outputId].LocalValue(dataCollector.PortCategory)); }
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; } } } }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation) { UIUtils.ShowNoVertexModeNodeMessage(this); return("0"); } if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory)) { return(GetOutputColorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); } if (!(dataCollector.IsTemplate && dataCollector.IsSRP)) { dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs); } if (!dataCollector.IsTemplate || dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.HD) { dataCollector.AddToUniforms(UniqueId, "uniform sampler2D _CameraDepthTexture;"); } string screenPos = string.Empty; string screenPosNorm = string.Empty; InputPort vertexPosPort = GetInputPortByUniqueId(1); if (vertexPosPort.IsConnected) { string vertexPosVar = "vertexPos" + OutputId; GenerateInputInVertex(ref dataCollector, 1, vertexPosVar, false); screenPos = GeneratorUtils.GenerateScreenPositionForValue(vertexPosVar, OutputId, ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalizedForValue(vertexPosVar, OutputId, ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); } else { screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); } string screenDepth = TemplateHelperFunctions.CreateDepthFetch(dataCollector, screenPos); if (m_convertToLinear) { if (dataCollector.IsTemplate && dataCollector.IsSRP) { screenDepth = string.Format("LinearEyeDepth({0},_ZBufferParams)", screenDepth); } else { screenDepth = string.Format("LinearEyeDepth({0})", screenDepth); } } else { screenDepth = string.Format("({0}*( _ProjectionParams.z - _ProjectionParams.y ))", screenDepth); } string distance = GetInputPortByUniqueId(0).GeneratePortInstructions(ref dataCollector); dataCollector.AddLocalVariable(UniqueId, "float screenDepth" + OutputId + " = " + screenDepth + ";"); string finalVarName = "distanceDepth" + OutputId; string finalVarValue = string.Empty; if (dataCollector.IsTemplate && dataCollector.IsSRP) { finalVarValue = "abs( ( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z,_ZBufferParams ) ) / ( " + distance + " ) )"; } else { finalVarValue = "abs( ( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z ) ) / ( " + distance + " ) )"; } if (m_saturate) { finalVarValue = string.Format("saturate( {0} )", finalVarValue); } dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, finalVarName, finalVarValue); m_outputPorts[0].SetLocalValue(finalVarName, dataCollector.PortCategory); return(GetOutputColorItem(0, outputId, finalVarName)); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { TemplatesManager templatesManager; bool firstTimeDummyFlag = false; if (UIUtils.CurrentWindow == null) { if (DummyManager == null) { DummyManager = ScriptableObject.CreateInstance <TemplatesManager>(); DummyManager.hideFlags = HideFlags.HideAndDontSave; firstTimeDummyFlag = true; } templatesManager = DummyManager; } else { Destroy(); templatesManager = UIUtils.CurrentWindow.TemplatesManagerInstance; } if (templatesManager == null) { return; } if (!templatesManager.Initialized) { templatesManager.Init(); } bool refreshMenuItems = false; for (int i = 0; i < importedAssets.Length; i++) { if (TemplateHelperFunctions.CheckIfTemplate(importedAssets[i])) { string guid = AssetDatabase.AssetPathToGUID(importedAssets[i]); TemplateDataParent templateData = templatesManager.GetTemplate(guid); if (templateData != null) { refreshMenuItems = templateData.Reload() || refreshMenuItems || firstTimeDummyFlag; int windowCount = IOUtils.AllOpenedWindows.Count; AmplifyShaderEditorWindow currWindow = UIUtils.CurrentWindow; for (int windowIdx = 0; windowIdx < windowCount; windowIdx++) { if (IOUtils.AllOpenedWindows[windowIdx].OutsideGraph.CurrentCanvasMode == NodeAvailability.TemplateShader) { if (IOUtils.AllOpenedWindows[windowIdx].OutsideGraph.MultiPassMasterNodes.NodesList[0].CurrentTemplate == templateData) { UIUtils.CurrentWindow = IOUtils.AllOpenedWindows[windowIdx]; IOUtils.AllOpenedWindows[windowIdx].OutsideGraph.ForceMultiPassMasterNodesRefresh(); } } } UIUtils.CurrentWindow = currWindow; } else { refreshMenuItems = true; string name = TemplatesManager.OfficialTemplates.ContainsKey(guid) ? TemplatesManager.OfficialTemplates[guid] : string.Empty; TemplateMultiPass mp = TemplateMultiPass.CreateInstance <TemplateMultiPass>(); mp.Init(name, guid, true); templatesManager.AddTemplate(mp); } } } if (deletedAssets.Length > 0) { if (deletedAssets[0].IndexOf(Constants.InvalidPostProcessDatapath) < 0) { for (int i = 0; i < deletedAssets.Length; i++) { string guid = AssetDatabase.AssetPathToGUID(deletedAssets[i]); TemplateDataParent templateData = templatesManager.GetTemplate(guid); if (templateData != null) { // Close any window using that template int windowCount = IOUtils.AllOpenedWindows.Count; for (int windowIdx = 0; windowIdx < windowCount; windowIdx++) { TemplateMasterNode masterNode = IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.CurrentMasterNode as TemplateMasterNode; if (masterNode != null && masterNode.CurrentTemplate.GUID.Equals(templateData.GUID)) { IOUtils.AllOpenedWindows[windowIdx].Close(); } } templatesManager.RemoveTemplate(templateData); refreshMenuItems = true; } } } } //for ( int i = 0; i < movedAssets.Length; i++ ) //{ // if ( TemplateHelperFunctions.CheckIfTemplate( movedAssets[ i ] ) ) // { // refreshMenuItems = true; // break; // } //} //for ( int i = 0; i < movedFromAssetPaths.Length; i++ ) //{ // if ( TemplateHelperFunctions.CheckIfTemplate( movedFromAssetPaths[ i ] ) ) // { // refreshMenuItems = true; // break; // } //} if (refreshMenuItems) { //UnityEngine.Debug.Log( "Refresh Menu Items" ); refreshMenuItems = false; templatesManager.CreateTemplateMenuItems(); AmplifyShaderEditorWindow currWindow = UIUtils.CurrentWindow; int windowCount = IOUtils.AllOpenedWindows.Count; for (int windowIdx = 0; windowIdx < windowCount; windowIdx++) { UIUtils.CurrentWindow = IOUtils.AllOpenedWindows[windowIdx]; IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.ForceCategoryRefresh(); } UIUtils.CurrentWindow = currWindow; } }
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 ): }
// This should only be used to semantics outside the text coord set public string RegisterInfoOnSemantic(MasterNodePortCategory portCategory, TemplateInfoOnSematics info, TemplateSemantics semantic, string name, WirePortDataType dataType, bool requestNewInterpolator) { if (portCategory == MasterNodePortCategory.Vertex) { if (m_vertexDataDict.ContainsKey(semantic)) { return(m_vertexDataDict[semantic].VarName); } m_availableVertData.Add(info, new InterpDataHelper(WirePortDataType.FLOAT4, string.Format(TemplateHelperFunctions.TemplateVarFormat, m_currentTemplateData.VertexFunctionData.InVarName, name))); m_currentDataCollector.AddToVertexInput( string.Format(TemplateHelperFunctions.TexFullSemantic, name, semantic)); RegisterOnVertexData(semantic, dataType, name); return(m_availableVertData[info].VarName); } else { //search if the correct vertex data is set ... TemplateSemantics vertexSemantics = TemplateSemantics.NONE; foreach (KeyValuePair <TemplateSemantics, TemplateVertexData> kvp in m_vertexDataDict) { if (kvp.Value.DataInfo == info) { vertexSemantics = kvp.Key; break; } } // if not, add vertex data and create interpolator if (vertexSemantics == TemplateSemantics.NONE) { vertexSemantics = semantic; if (!m_vertexDataDict.ContainsKey(vertexSemantics)) { m_availableVertData.Add(info, new InterpDataHelper(WirePortDataType.FLOAT4, string.Format(TemplateHelperFunctions.TemplateVarFormat, m_currentTemplateData.VertexFunctionData.InVarName, name))); m_currentDataCollector.AddToVertexInput( string.Format(TemplateHelperFunctions.TexFullSemantic, name, vertexSemantics)); RegisterOnVertexData(vertexSemantics, dataType, name); } } // either way create interpolator TemplateVertexData availableInterp = null; if (requestNewInterpolator || IsSemanticUsedOnInterpolator(semantic)) { availableInterp = RequestNewInterpolator(dataType, false); } else { availableInterp = RegisterOnInterpolator(semantic, dataType); } if (availableInterp != null) { string interpVarName = m_currentTemplateData.VertexFunctionData.OutVarName + "." + availableInterp.VarNameWithSwizzle; string interpDecl = string.Format(TemplateHelperFunctions.TemplateVariableDecl, interpVarName, TemplateHelperFunctions.AutoSwizzleData(m_availableVertData[info].VarName, m_availableVertData[info].VarType, dataType)); m_currentDataCollector.AddToVertexInterpolatorsDecl(interpDecl); string finalVarName = m_currentTemplateData.FragFunctionData.InVarName + "." + availableInterp.VarNameWithSwizzle; m_availableFragData.Add(info, new InterpDataHelper(dataType, finalVarName)); return(finalVarName); } } return(string.Empty); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory)) { return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); } OnPropertyNameChanged(); CheckReference(); bool isVertex = (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation); bool instanced = false; if (m_referenceType == TexReferenceType.Instance && m_referenceSampler != null) { instanced = true; } if (instanced) { if (!m_referenceSampler.TexPort.IsConnected) { base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar); } } else if (!m_texPort.IsConnected) { base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar); } string level = string.Empty; if (m_lodPort.Visible) { level = m_lodPort.GeneratePortInstructions(ref dataCollector); } if (isVertex && !m_lodPort.Visible) { level = "0"; } string propertyName = string.Empty; if (instanced) { if (m_referenceSampler.TexPort.IsConnected) { propertyName = m_referenceSampler.TexPort.GeneratePortInstructions(ref dataCollector); } else { propertyName = m_referenceSampler.PropertyName; } } else if (m_texPort.IsConnected) { propertyName = m_texPort.GeneratePortInstructions(ref dataCollector); } else { propertyName = PropertyName; } string uvs = string.Empty; if (m_uvPort.IsConnected) { uvs = m_uvPort.GeneratePortInstructions(ref dataCollector); } else { if (dataCollector.IsTemplate) { uvs = dataCollector.TemplateDataCollectorInstance.GetTextureCoord(m_uvSet, (instanced ? m_referenceSampler.PropertyName : PropertyName), UniqueId, m_currentPrecisionType); } else { if (isVertex) { uvs = TexCoordVertexDataNode.GenerateVertexUVs(ref dataCollector, UniqueId, m_uvSet, propertyName); } else { uvs = TexCoordVertexDataNode.GenerateFragUVs(ref dataCollector, UniqueId, m_uvSet, propertyName); } } } string index = m_indexPort.GeneratePortInstructions(ref dataCollector); string m_normalMapUnpackMode = ""; if (m_autoUnpackNormals) { bool isScaledNormal = false; if (m_normalPort.IsConnected) { isScaledNormal = true; } else { if (m_normalPort.FloatInternalData != 1) { isScaledNormal = true; } } string scaleValue = isScaledNormal?m_normalPort.GeneratePortInstructions(ref dataCollector):"1.0"; m_normalMapUnpackMode = TemplateHelperFunctions.CreateUnpackNormalStr(dataCollector, isScaledNormal, scaleValue); if (isScaledNormal && (!dataCollector.IsTemplate || !dataCollector.IsSRP)) { dataCollector.AddToIncludes(UniqueId, Constants.UnityStandardUtilsLibFuncs); } } string result = string.Empty; if (dataCollector.IsTemplate && dataCollector.IsSRP) { //CAREFUL mipbias here means derivative (this needs index changes) //TODO: unity now supports bias as well if (m_mipMode == MipType.MipBias) { dataCollector.UsingArrayDerivatives = true; result = propertyName + ".SampleGrad(sampler" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions(ref dataCollector) + ", " + m_ddyPort.GeneratePortInstructions(ref dataCollector) + ");"; } else if (m_lodPort.Visible || isVertex) { result = "SAMPLE_TEXTURE2D_ARRAY_LOD(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + ", " + level + " )"; } else { result = "SAMPLE_TEXTURE2D_ARRAY(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + " )"; } } else { //CAREFUL mipbias here means derivative (this needs index changes) if (m_mipMode == MipType.MipBias) { dataCollector.UsingArrayDerivatives = true; result = "ASE_SAMPLE_TEX2DARRAY_GRAD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions(ref dataCollector) + ", " + m_ddyPort.GeneratePortInstructions(ref dataCollector) + " )"; } else if (m_lodPort.Visible || isVertex) { result = "UNITY_SAMPLE_TEX2DARRAY_LOD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + level + " )"; } else { result = "UNITY_SAMPLE_TEX2DARRAY" + (m_lodPort.Visible || isVertex ? "_LOD" : "") + "(" + propertyName + ", float3(" + uvs + ", " + index + ") " + (m_lodPort.Visible || isVertex ? ", " + level : "") + " )"; } } if (m_autoUnpackNormals) { result = string.Format(m_normalMapUnpackMode, result); } RegisterLocalVariable(0, result, ref dataCollector, "texArray" + OutputId); return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); }
void FetchSubShaderProperties() { Match match = Regex.Match( m_templateBody, @"Pass\s*{" ): if( match.Groups.Count == 0 ) { return: } int beginSubShader = m_templateBody.IndexOf( "SubShader" ): int endSubShader = match.Groups[ 0 ].Index: if( beginSubShader > 0 && endSubShader > 0 && endSubShader > beginSubShader ) { // ADD A PLACE TO INSERT GRAB PASSES int passIndex = m_templateBody.IndexOf( TemplatesManager.TemplatePassTag ): if( passIndex < 0 ) { int currIdx = endSubShader - 1: string identation = string.Empty: for( : currIdx > 0: currIdx-- ) { if( m_templateBody[ currIdx ] != '\n' ) { identation = m_templateBody[ currIdx ] + identation: } else { identation = m_templateBody[ currIdx ] + identation: break: } } if( currIdx > 0 ) { m_templateBody = m_templateBody.Insert( currIdx, identation + TemplatesManager.TemplatePassTag ): } } // GET ALL THE MODULES string subBody = m_templateBody.Substring( beginSubShader, endSubShader - beginSubShader ): //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: TemplateHelperFunctions.CreateCullMode( cullParams, ref m_cullModeData ): if( m_cullModeData.DataCheck == TemplateDataCheck.Valid ) AddId( 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: TemplateHelperFunctions.CreateColorMask( colorMaskParams, ref m_colorMaskData ): if( m_colorMaskData.DataCheck == TemplateDataCheck.Valid ) AddId( colorMaskParams, false ): } } //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: TemplateHelperFunctions.CreateBlendMode( blendParams, ref m_blendData ): if( m_blendData.ValidBlendMode ) { AddId( 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 ): BlendData.BlendOpId = blendOpParams: TemplateHelperFunctions.CreateBlendOp( blendOpParams, ref m_blendData ): if( m_blendData.ValidBlendOp ) { AddId( blendOpParams, false ): } } m_blendData.DataCheck = ( m_blendData.ValidBlendMode || m_blendData.ValidBlendOp ) ? TemplateDataCheck.Valid : TemplateDataCheck.Invalid: } //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: TemplateHelperFunctions.CreateStencilOps( stencilParams, ref m_stencilData ): if( m_stencilData.DataCheck == TemplateDataCheck.Valid ) { AddId( 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 ): TemplateHelperFunctions.CreateZWriteMode( m_depthData.ZWriteModeId, ref m_depthData ): if( m_depthData.DataCheck == TemplateDataCheck.Valid ) { AddId( 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 ): TemplateHelperFunctions.CreateZTestMode( m_depthData.ZTestModeId, ref m_depthData ): if( m_depthData.DataCheck == TemplateDataCheck.Valid ) { AddId( 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 ): TemplateHelperFunctions.CreateZOffsetMode( m_depthData.OffsetId, ref m_depthData ): if( m_depthData.DataCheck == TemplateDataCheck.Valid ) { AddId( m_depthData.OffsetId, true ): } } } m_depthData.SetDataCheck(): } //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 ): TemplateHelperFunctions.CreateTags( ref m_tagData, true ): m_tagData.DataCheck = TemplateDataCheck.Valid: AddId( m_tagData.TagsId, false ): } else { m_tagData.DataCheck = TemplateDataCheck.Invalid: } } else { m_tagData.DataCheck = TemplateDataCheck.Invalid: } } } }
void UpdateFromId() { if( m_shaderProperties != null ) { if( m_shaderProperties.Count == 0 ) { for( int i = 0: i < 4: i++ ) m_containerGraph.DeleteConnection( false, UniqueId, i, false, true ): m_headerColor = UIUtils.GetColorFromCategory( "Default" ): m_content.text = "None": m_additionalContent.text = string.Empty: m_previewMaterialPassId = 1: PreviewMaterial.SetFloat( FloatPropertyId, 0 ): m_showPreview = false: m_drawPreviewExpander = false: m_outputPorts[ 0 ].ChangeProperties( "None", WirePortDataType.FLOAT, false ): ConfigurePorts(): return: } m_drawPreviewExpander = true: bool areCompatible = TemplateHelperFunctions.CheckIfCompatibles( m_outputPorts[ 0 ].DataType, m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType ): switch( m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType ) { case WirePortDataType.SAMPLER1D: case WirePortDataType.SAMPLER2D: case WirePortDataType.SAMPLER3D: case WirePortDataType.SAMPLERCUBE: m_outputPorts[ 0 ].ChangeProperties( "Tex", m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false ): m_headerColor = UIUtils.GetColorFromCategory( "Textures" ): break: case WirePortDataType.INT: case WirePortDataType.FLOAT: m_outputPorts[ 0 ].ChangeProperties( Constants.EmptyPortValue, m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false ): m_headerColor = UIUtils.GetColorFromCategory( "Constants And Properties" ): break: case WirePortDataType.FLOAT4: m_outputPorts[ 0 ].ChangeProperties( "XYZW", m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false ): m_headerColor = UIUtils.GetColorFromCategory( "Constants And Properties" ): break: case WirePortDataType.COLOR: m_outputPorts[ 0 ].ChangeProperties( "RGBA", m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false ): m_headerColor = UIUtils.GetColorFromCategory( "Constants And Properties" ): break: default: case WirePortDataType.OBJECT: case WirePortDataType.FLOAT3x3: case WirePortDataType.FLOAT4x4: m_outputPorts[ 0 ].ChangeProperties( "Out", m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false ): m_headerColor = UIUtils.GetColorFromCategory( "Constants And Properties" ): break: } if( !areCompatible ) { for( int i = 0: i < 4: i++ ) m_containerGraph.DeleteConnection( false, UniqueId, i, false, true ): } ConfigurePorts(): m_propertyName = m_shaderProperties[ m_currentPropertyIdx ].PropertyName: m_content.text = m_shaderProperties[ m_currentPropertyIdx ].PropertyInspectorName: m_propertyNameId = Shader.PropertyToID( m_propertyName ): m_typeName = TypeLabelStr + m_shaderProperties[ m_currentPropertyIdx ].PropertyType.ToString(): if( m_shaderProperties[ m_currentPropertyIdx ].PropertyType != PropertyType.Global ) { m_propertyNameLabel = PropertyNameStr + m_shaderProperties[ m_currentPropertyIdx ].PropertyName: } m_sizeIsDirty = true: Material currMat = m_containerGraph.CurrentMaterial: if( currMat != null ) { if( m_shaderProperties[ m_currentPropertyIdx ].PropertyType == PropertyType.Global ) { m_previewMaterialPassId = 0: if( !m_showErrorMessage && m_showPreview ) { ShowTab( NodeMessageType.Info, WarningStr ): } } else { if( m_showErrorMessage && m_errorMessageTypeIsError != NodeMessageType.Error ) { HideTab(): } switch( m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType ) { case WirePortDataType.INT: m_previewMaterialPassId = 0: break: case WirePortDataType.FLOAT: m_previewMaterialPassId = 1: break: case WirePortDataType.FLOAT4: case WirePortDataType.COLOR: m_previewMaterialPassId = 2: break: case WirePortDataType.SAMPLER2D: m_previewMaterialPassId = 3: break: case WirePortDataType.SAMPLER3D: m_previewMaterialPassId = 4: break: case WirePortDataType.SAMPLERCUBE: m_previewMaterialPassId = 5: break: default: PreviewMaterial.SetPass( 0 ): break: } } } CheckWarningState(): } }
void FetchVertexAndInterpData( TemplateModulesData subShaderModule, int offsetIdx, string body ) { // Vertex Data try { int vertexDataTagBegin = body.IndexOf( TemplatesManager.TemplateVertexDataTag ): if( vertexDataTagBegin > -1 ) { m_vertexDataContainer = new VertexDataContainer(): m_vertexDataContainer.VertexDataStartIdx = offsetIdx + vertexDataTagBegin: int vertexDataTagEnd = body.IndexOf( TemplatesManager.TemplateEndOfLine, vertexDataTagBegin ): m_vertexDataContainer.VertexDataId = body.Substring( vertexDataTagBegin, vertexDataTagEnd + TemplatesManager.TemplateEndOfLine.Length - vertexDataTagBegin ): int dataBeginIdx = body.LastIndexOf( '{', vertexDataTagBegin, vertexDataTagBegin ): string vertexData = body.Substring( dataBeginIdx + 1, vertexDataTagBegin - dataBeginIdx ): int parametersBegin = vertexDataTagBegin + TemplatesManager.TemplateVertexDataTag.Length: string parameters = body.Substring( parametersBegin, vertexDataTagEnd - parametersBegin ): m_vertexDataContainer.VertexData = TemplateHelperFunctions.CreateVertexDataList( vertexData, parameters ): m_templateProperties.AddId( body, m_vertexDataContainer.VertexDataId ): } } catch( Exception e ) { Debug.LogException( e ): } // Available interpolators try { int interpDataBegin = body.IndexOf( TemplatesManager.TemplateInterpolatorBeginTag ): if( interpDataBegin > -1 ) { int interpDataEnd = body.IndexOf( TemplatesManager.TemplateEndOfLine, interpDataBegin ): string interpDataId = body.Substring( interpDataBegin, interpDataEnd + TemplatesManager.TemplateEndOfLine.Length - interpDataBegin ): int dataBeginIdx = body.LastIndexOf( '{', interpDataBegin, interpDataBegin ): string interpData = body.Substring( dataBeginIdx + 1, interpDataBegin - dataBeginIdx ): int interpolatorAmount = TemplateHelperFunctions.AvailableInterpolators[ "2.5" ]: if( m_modules.ShaderModel.IsValid ) { interpolatorAmount = m_modules.ShaderModel.InterpolatorAmount: } else if( subShaderModule.ShaderModel.IsValid ) { interpolatorAmount = subShaderModule.ShaderModel.InterpolatorAmount: } m_interpolatorDataContainer = TemplateHelperFunctions.CreateInterpDataList( interpData, interpDataId, interpolatorAmount ): m_interpolatorDataContainer.InterpDataId = interpDataId: m_interpolatorDataContainer.InterpDataStartIdx = offsetIdx + interpDataBegin: m_templateProperties.AddId( body, interpDataId ): } } catch( Exception e ) { Debug.LogException( e ): } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { if (UIUtils.CurrentWindow == null) { return; } TemplatesManager templatesManager = UIUtils.CurrentWindow.TemplatesManagerInstance; if (templatesManager == null) { return; } if (!templatesManager.Initialized) { templatesManager.Init(); } bool refreshMenuItems = false; for (int i = 0; i < importedAssets.Length; i++) { if (TemplateHelperFunctions.CheckIfTemplate(importedAssets[i])) { string guid = AssetDatabase.AssetPathToGUID(importedAssets[i]); TemplateDataParent templateData = templatesManager.GetTemplate(guid); if (templateData != null) { refreshMenuItems = templateData.Reload() || refreshMenuItems; } else { refreshMenuItems = true; string name = TemplatesManager.OfficialTemplates.ContainsKey(guid) ? TemplatesManager.OfficialTemplates[guid] : string.Empty; TemplateMultiPass mp = TemplateMultiPass.CreateInstance <TemplateMultiPass>(); mp.Init(name, guid, true); templatesManager.AddTemplate(mp); } } } if (deletedAssets.Length > 0) { if (deletedAssets[0].IndexOf(Constants.InvalidPostProcessDatapath) < 0) { for (int i = 0; i < deletedAssets.Length; i++) { string guid = AssetDatabase.AssetPathToGUID(deletedAssets[i]); TemplateDataParent templateData = templatesManager.GetTemplate(guid); if (templateData != null) { // Close any window using that template int windowCount = IOUtils.AllOpenedWindows.Count; for (int windowIdx = 0; windowIdx < windowCount; windowIdx++) { TemplateMasterNode masterNode = IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.CurrentMasterNode as TemplateMasterNode; if (masterNode != null && masterNode.CurrentTemplate.GUID.Equals(templateData.GUID)) { IOUtils.AllOpenedWindows[windowIdx].Close(); } } templatesManager.RemoveTemplate(templateData); refreshMenuItems = true; } } } } //for ( int i = 0; i < movedAssets.Length; i++ ) //{ // if ( TemplateHelperFunctions.CheckIfTemplate( movedAssets[ i ] ) ) // { // refreshMenuItems = true; // break; // } //} //for ( int i = 0; i < movedFromAssetPaths.Length; i++ ) //{ // if ( TemplateHelperFunctions.CheckIfTemplate( movedFromAssetPaths[ i ] ) ) // { // refreshMenuItems = true; // break; // } //} if (refreshMenuItems) { //UnityEngine.Debug.Log( "Refresh Menu Items" ); refreshMenuItems = false; templatesManager.CreateTemplateMenuItems(); int windowCount = IOUtils.AllOpenedWindows.Count; for (int windowIdx = 0; windowIdx < windowCount; windowIdx++) { IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.ForceCategoryRefresh(); } } }
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(); } } }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation) { UIUtils.ShowNoVertexModeNodeMessage(this); return("0"); } if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory)) { return(GetOutputColorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); } if (!(dataCollector.IsTemplate && dataCollector.IsSRP)) { dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs); } if (!dataCollector.IsTemplate || dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.HD) { if (dataCollector.IsTemplate && dataCollector.CurrentSRPType == TemplateSRPType.Lightweight) { //dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureSRPVar ); //dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureSRPSampler ); dataCollector.AddToDefines(UniqueId, Constants.CameraDepthTextureLWEnabler); } else { dataCollector.AddToUniforms(UniqueId, Constants.CameraDepthTextureValue); } dataCollector.AddToUniforms(UniqueId, Constants.CameraDepthTextureTexelSize); } string screenPos = string.Empty; if (m_inputPorts[0].IsConnected) { screenPos = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); } else { if (dataCollector.IsTemplate) { if (!dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData(TemplateInfoOnSematics.SCREEN_POSITION_NORMALIZED, WirePortDataType.FLOAT4, PrecisionType.Float, ref screenPos, true, MasterNodePortCategory.Fragment)) { screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); } } else { screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); } } string screenDepthInstruction = TemplateHelperFunctions.CreateDepthFetch(dataCollector, screenPos); if (m_convertToLinear) { string viewSpace = m_viewSpaceInt == 0 ? "LinearEyeDepth" : "Linear01Depth"; string formatStr = string.Empty; if ((dataCollector.IsTemplate && dataCollector.IsSRP)) { formatStr = "(" + screenDepthInstruction + ",_ZBufferParams)"; } else { formatStr = "(" + screenDepthInstruction + ")"; } screenDepthInstruction = viewSpace + formatStr; } else { if (m_viewSpaceInt == 0) { screenDepthInstruction = string.Format("({0}*( _ProjectionParams.z - _ProjectionParams.y ))", screenDepthInstruction); } } dataCollector.AddToLocalVariables(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, m_vertexNameStr[m_viewSpaceInt] + OutputId, screenDepthInstruction); m_outputPorts[0].SetLocalValue(m_vertexNameStr[m_viewSpaceInt] + OutputId, dataCollector.PortCategory); return(GetOutputColorItem(0, outputId, m_vertexNameStr[m_viewSpaceInt] + OutputId)); }
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 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: }
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; }
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); } }
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: } }
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; }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { if (!TemplatesManager.Initialized) { TemplatesManager.Init(); } bool markForRefresh = false; for (int i = 0; i < importedAssets.Length; i++) { if (TemplateHelperFunctions.CheckIfTemplate(importedAssets[i])) { markForRefresh = true; break; } } if (deletedAssets.Length > 0) { if (deletedAssets[0].IndexOf(Constants.InvalidPostProcessDatapath) < 0) { for (int i = 0; i < deletedAssets.Length; i++) { string guid = AssetDatabase.AssetPathToGUID(deletedAssets[i]); TemplateData templateData = TemplatesManager.GetTemplate(guid); if (templateData != null) { // Close any window using that template int windowCount = IOUtils.AllOpenedWindows.Count; for (int windowIdx = 0; windowIdx < windowCount; windowIdx++) { TemplateMasterNode masterNode = IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.CurrentMasterNode as TemplateMasterNode; if (masterNode != null && masterNode.CurrentTemplate.GUID.Equals(templateData.GUID)) { IOUtils.AllOpenedWindows[windowIdx].Close(); } } TemplatesManager.RemoveTemplate(templateData); markForRefresh = true; } } } } for (int i = 0; i < movedAssets.Length; i++) { if (TemplateHelperFunctions.CheckIfTemplate(movedAssets[i])) { markForRefresh = true; break; } } for (int i = 0; i < movedFromAssetPaths.Length; i++) { if (TemplateHelperFunctions.CheckIfTemplate(movedFromAssetPaths[i])) { markForRefresh = true; break; } } if (markForRefresh) { TemplatesManager.CreateTemplateMenuItems(); int windowCount = IOUtils.AllOpenedWindows.Count; for (int windowIdx = 0; windowIdx < windowCount; windowIdx++) { IOUtils.AllOpenedWindows[windowIdx].CurrentGraph.ForceCategoryRefresh(); } } }
public string RegisterUV(int UVChannel) { if (m_currentDataCollector.PortCategory == MasterNodePortCategory.Vertex) { TemplateSemantics semantic = TemplateHelperFunctions.IntToSemantic[UVChannel]; if (m_vertexDataDict.ContainsKey(semantic)) { return(m_vertexDataDict[semantic].VarName); } string varName = TemplateHelperFunctions.BaseInterpolatorName + ((UVChannel > 0) ? UVChannel.ToString() : string.Empty); m_availableVertData.Add(TemplateHelperFunctions.IntToUVChannelInfo[UVChannel], new InterpDataHelper(WirePortDataType.FLOAT4, string.Format(TemplateHelperFunctions.TemplateVarFormat, m_currentTemplateData.VertexFunctionData.InVarName, varName))); m_currentDataCollector.AddToVertexInput( string.Format(TemplateHelperFunctions.TexFullSemantic, varName, semantic)); RegisterOnVertexData(semantic, WirePortDataType.FLOAT2, varName); return(m_availableVertData[TemplateHelperFunctions.IntToUVChannelInfo[UVChannel]].VarName); } else { //search if the correct vertex data is set ... TemplateInfoOnSematics info = TemplateHelperFunctions.IntToInfo[UVChannel]; TemplateSemantics vertexSemantics = TemplateSemantics.NONE; foreach (KeyValuePair <TemplateSemantics, TemplateVertexData> kvp in m_vertexDataDict) { if (kvp.Value.DataInfo == info) { vertexSemantics = kvp.Key; break; } } // if not, add vertex data and create interpolator if (vertexSemantics == TemplateSemantics.NONE) { vertexSemantics = TemplateHelperFunctions.IntToSemantic[UVChannel]; if (!m_vertexDataDict.ContainsKey(vertexSemantics)) { string varName = TemplateHelperFunctions.BaseInterpolatorName + ((UVChannel > 0) ? UVChannel.ToString() : string.Empty); m_availableVertData.Add(TemplateHelperFunctions.IntToUVChannelInfo[UVChannel], new InterpDataHelper(WirePortDataType.FLOAT4, string.Format(TemplateHelperFunctions.TemplateVarFormat, m_currentTemplateData.VertexFunctionData.InVarName, varName))); m_currentDataCollector.AddToVertexInput( string.Format(TemplateHelperFunctions.TexFullSemantic, varName, vertexSemantics)); RegisterOnVertexData(vertexSemantics, WirePortDataType.FLOAT2, varName); } } // either way create interpolator TemplateVertexData availableInterp = RequestNewInterpolator(WirePortDataType.FLOAT2, false); if (availableInterp != null) { string interpVarName = m_currentTemplateData.VertexFunctionData.OutVarName + "." + availableInterp.VarNameWithSwizzle; InterpDataHelper vertInfo = m_availableVertData[TemplateHelperFunctions.IntToUVChannelInfo[UVChannel]]; string interpDecl = string.Format(TemplateHelperFunctions.TemplateVariableDecl, interpVarName, TemplateHelperFunctions.AutoSwizzleData(vertInfo.VarName, vertInfo.VarType, WirePortDataType.FLOAT2)); m_currentDataCollector.AddToVertexInterpolatorsDecl(interpDecl); string finalVarName = m_currentTemplateData.FragFunctionData.InVarName + "." + availableInterp.VarNameWithSwizzle; m_availableFragData.Add(TemplateHelperFunctions.IntToUVChannelInfo[UVChannel], new InterpDataHelper(WirePortDataType.FLOAT2, finalVarName)); return(finalVarName); } } return(string.Empty); }