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)); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (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.AddToDirectives(Constants.CameraDepthTextureLWEnabler, -1, AdditionalLineType.Define); } else { dataCollector.AddToUniforms(UniqueId, Constants.CameraDepthTextureValue); } dataCollector.AddToUniforms(UniqueId, Constants.CameraDepthTextureTexelSize); } string screenPosNorm = string.Empty; InputPort vertexPosPort = GetInputPortByUniqueId(1); if (vertexPosPort.IsConnected) { string vertexPosVar = "vertexPos" + OutputId; GenerateInputInVertex(ref dataCollector, 1, vertexPosVar, false); screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalizedForValue(vertexPosVar, OutputId, ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos); } else { if (dataCollector.IsTemplate) { string ppsScreenPos = string.Empty; if (!dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData(TemplateInfoOnSematics.SCREEN_POSITION_NORMALIZED, WirePortDataType.FLOAT4, PrecisionType.Float, ref ppsScreenPos, true, MasterNodePortCategory.Fragment)) { screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos); } else { screenPosNorm = ppsScreenPos; } } else { screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos); } } string screenDepth = TemplateHelperFunctions.CreateDepthFetch(dataCollector, screenPosNorm); 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 = "( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z,_ZBufferParams ) ) / ( " + distance + " )"; } else { finalVarValue = "( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z ) ) / ( " + distance + " )"; } if (m_mirror) { finalVarValue = string.Format("abs( {0} )", finalVarValue); } if (m_saturate) { finalVarValue = string.Format("saturate( {0} )", finalVarValue); } dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, finalVarName, finalVarValue); m_outputPorts[0].SetLocalValue(finalVarName, dataCollector.PortCategory); return(GetOutputColorItem(0, outputId, finalVarName)); }