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) { return(GetOutputColorItem(0, outputId, m_outputPorts[0].LocalValue)); } dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs); dataCollector.AddToUniforms(UniqueId, "uniform sampler2D _CameraDepthTexture;"); string screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, true); string screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, true); string screenDepth = "LinearEyeDepth(UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture,UNITY_PROJ_COORD(" + screenPos + "))))"; string distance = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); dataCollector.AddLocalVariable(UniqueId, "float screenDepth" + OutputId + " = " + screenDepth + ";"); dataCollector.AddLocalVariable(UniqueId, "float distanceDepth" + OutputId + " = abs( ( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z ) ) / ( " + distance + " ) );"); m_outputPorts[0].SetLocalValue("distanceDepth" + OutputId); return(GetOutputColorItem(0, outputId, "distanceDepth" + OutputId)); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { if (m_outputPorts[0].IsLocalValue) { return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue)); } base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar); string screenPos = string.Empty; if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug) { screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, false); } else { screenPos = GeneratorUtils.GenerateVertexScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, false); } string localVarName = screenPos + UniqueId; string value = UIUtils.PrecisionWirePortToCgType(m_currentPrecisionType, m_outputPorts[0].DataType) + " " + localVarName + " = " + screenPos + ";"; dataCollector.AddLocalVariable(UniqueId, value); if (m_outputTypeInt == 0) { dataCollector.AddLocalVariable(UniqueId, string.Format(ProjectionInstruction, localVarName)); } m_outputPorts[0].SetLocalValue(localVarName); return(GetOutputVectorItem(0, outputId, localVarName)); }
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.IsLightweight)) { dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs); } dataCollector.AddToUniforms(UniqueId, "uniform sampler2D _CameraDepthTexture;"); string screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); string screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); string screenDepth = "UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture,UNITY_PROJ_COORD(" + screenPos + ")))"; if (dataCollector.IsTemplate && dataCollector.IsLightweight) { screenDepth = "tex2Dproj( _CameraDepthTexture," + screenPos + ").r"; } if (m_convertToLinear) { if (dataCollector.IsTemplate && dataCollector.IsLightweight) { 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 = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); dataCollector.AddLocalVariable(UniqueId, "float screenDepth" + OutputId + " = " + screenDepth + ";"); if (dataCollector.IsTemplate && dataCollector.IsLightweight) { dataCollector.AddLocalVariable(UniqueId, "float distanceDepth" + OutputId + " = abs( ( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z,_ZBufferParams ) ) / ( " + distance + " ) );"); } else { dataCollector.AddLocalVariable(UniqueId, "float distanceDepth" + OutputId + " = abs( ( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z ) ) / ( " + distance + " ) );"); } m_outputPorts[0].SetLocalValue("distanceDepth" + OutputId, dataCollector.PortCategory); return(GetOutputColorItem(0, outputId, "distanceDepth" + OutputId)); }
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"); } dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs); dataCollector.AddToUniforms(UniqueId, "uniform sampler2D _CameraDepthTexture;"); string screenPos = string.Empty; if (m_inputPorts[0].IsConnected) { screenPos = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT4, false); } else { screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, true); } //string screenPos = m_inputPorts[ 0 ].GenerateShaderForOutput( ref dataCollector, WirePortDataType.FLOAT4, false ); string viewSpace = m_viewSpaceInt == 0 ? "Eye" : "01"; string screenDepthInstruction = "Linear" + viewSpace + "Depth(UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture,UNITY_PROJ_COORD(" + screenPos + "))))"; dataCollector.AddToLocalVariables(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, m_vertexNameStr[m_viewSpaceInt] + UniqueId, screenDepthInstruction); return(m_vertexNameStr[m_viewSpaceInt] + UniqueId); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { if (m_outputPorts[0].IsLocalValue) { return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue)); } if (dataCollector.IsFragmentCategory && !dataCollector.UsingCustomScreenPos) { base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar); } string screenPos = string.Empty; if (dataCollector.IsTemplate) { screenPos = dataCollector.TemplateDataCollectorInstance.GetScreenPos(); } else { screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, false); } if (m_outputTypeInt == 0) { screenPos = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, false); } m_outputPorts[0].SetLocalValue(screenPos); return(GetOutputVectorItem(0, outputId, screenPos)); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { if (m_outputPorts[0].IsLocalValue) { return(GetOutputColorItem(0, outputId, m_outputPorts[0].LocalValue)); } //string localVarName = ScreenPosStr + m_uniqueId; string localVarName = string.Empty; bool isFragment = dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug; if (isFragment) { string screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, true); localVarName = screenPos + OutputId; //dataCollector.AddToInput( m_uniqueId, "float4 " + ScreenPosStr, true ); string value = UIUtils.PrecisionWirePortToCgType(m_currentPrecisionType, m_outputPorts[0].DataType) + " " + localVarName + " = " + screenPos + ";"; dataCollector.AddLocalVariable(UniqueId, value); } else { string screenPos = GeneratorUtils.GenerateVertexScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, false); localVarName = screenPos + OutputId; string localVarDecl = UIUtils.PrecisionWirePortToCgType(m_currentPrecisionType, m_outputPorts[0].DataType) + " " + localVarName; string value = string.Format(ScreenPosOnVert00Str, localVarDecl, Constants.VertexShaderInputStr); dataCollector.AddLocalVariable(UniqueId, value); //dataCollector.AddLocalVariable( m_uniqueId, string.Format( ScreenPosOnVert01Str, localVarName ) ); } dataCollector.AddLocalVariable(UniqueId, HackInstruction[0], true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[1], OutputId), true); dataCollector.AddLocalVariable(UniqueId, HackInstruction[2], true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[3], OutputId), true); dataCollector.AddLocalVariable(UniqueId, HackInstruction[4], true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[5], localVarName, OutputId), true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[6], localVarName, OutputId), true); dataCollector.AddLocalVariable(UniqueId, HackInstruction[7], true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[8], localVarName, OutputId), true); dataCollector.AddLocalVariable(UniqueId, HackInstruction[9], true); if (m_outputTypeInt == 0) { dataCollector.AddLocalVariable(UniqueId, string.Format(ProjectionInstruction, localVarName)); } m_outputPorts[0].SetLocalValue(localVarName); //RegisterLocalVariable(outputId, localVarName ,ref dataCollector) return(GetOutputColorItem(0, outputId, localVarName)); }
public string GetUVCoords(ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar, bool isProjecting) { if (m_inputPorts[0].IsConnected) { string result = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, (isProjecting ? WirePortDataType.FLOAT4 : WirePortDataType.FLOAT2), ignoreLocalVar, true); if (isProjecting) { return("UNITY_PROJ_COORD( " + result + " )"); } else { return(result); } } else { string localVarName = string.Empty; if (dataCollector.IsTemplate) { localVarName = dataCollector.TemplateDataCollectorInstance.GetScreenPos(); } else { //dataCollector.AddToInput( UniqueId, "float4 " + ScreenPosStr, true ); string screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); localVarName = screenPos + OutputId; string value = UIUtils.PrecisionWirePortToCgType(m_currentPrecisionType, m_outputPorts[0].DataType) + " " + localVarName + " = " + screenPos + ";"; dataCollector.AddLocalVariable(UniqueId, value, true); } dataCollector.AddLocalVariable(UniqueId, HackInstruction[0], true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[1], OutputId), true); dataCollector.AddLocalVariable(UniqueId, HackInstruction[2], true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[3], OutputId), true); dataCollector.AddLocalVariable(UniqueId, HackInstruction[4], true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[5], localVarName, OutputId), true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[6], localVarName, OutputId), true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[7], localVarName), true); dataCollector.AddLocalVariable(UniqueId, string.Format(HackInstruction[8], localVarName), true); return("UNITY_PROJ_COORD( " + localVarName + " )"); } }
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))); } dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs); dataCollector.AddToUniforms(UniqueId, "uniform sampler2D_float _CameraDepthTexture;"); dataCollector.AddCodeComments(true, new string[] { "Start - Stylized Water custom depth" }); string screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, true); string screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, true); string screenDepth = "UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture,UNITY_PROJ_COORD(" + screenPos + ")))"; screenDepth = string.Format("LinearEyeDepth({0})", screenDepth); string distance = "lerp( 1.0 , ( 1.0 / _ProjectionParams.z ) , unity_OrthoParams.w)"; dataCollector.AddLocalVariable(UniqueId, "float screenDepth" + OutputId + " = " + screenDepth + ";"); string depthVal = " ( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z ) ) / ( " + distance + " );"; dataCollector.AddLocalVariable(UniqueId, "float distanceDepth" + OutputId + " = " + depthVal); dataCollector.AddLocalVariable(UniqueId, "#if SHADER_API_MOBILE && UNITY_VERSION >= 20183 //Build only, abs() function causes offset in depth on mobile in 2018.3", true); dataCollector.AddLocalVariable(UniqueId, "#else", true); dataCollector.AddLocalVariable(UniqueId, "distanceDepth" + OutputId + " = " + "abs(distanceDepth" + OutputId + ");", true); dataCollector.AddLocalVariable(UniqueId, "#endif", true); m_outputPorts[0].SetLocalValue("distanceDepth" + OutputId, MasterNodePortCategory.Fragment); dataCollector.AddCodeComments(true, new string[] { "End - Stylized Water custom depth" }); return(GetOutputColorItem(0, outputId, "distanceDepth" + OutputId)); }
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))); } m_currentPrecisionType = PrecisionType.Float; string screenPos = string.Empty; if (m_outputTypeInt == 0) { if (dataCollector.IsTemplate) { screenPos = dataCollector.TemplateDataCollectorInstance.GetScreenPosNormalized(CurrentPrecisionType); } else { screenPos = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, CurrentPrecisionType); } } else { if (dataCollector.IsTemplate) { screenPos = dataCollector.TemplateDataCollectorInstance.GetScreenPos(CurrentPrecisionType); } else { screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, CurrentPrecisionType); } } m_outputPorts[0].SetLocalValue(screenPos, dataCollector.PortCategory); return(GetOutputVectorItem(0, outputId, screenPos)); }
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.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 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) { return(GetOutputColorItem(0, outputId, m_outputPorts[0].LocalValue)); } if (!(dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight)) { dataCollector.AddToIncludes(UniqueId, Constants.UnityCgLibFuncs); } dataCollector.AddToUniforms(UniqueId, "uniform sampler2D _CameraDepthTexture;"); string screenPos = string.Empty; if (m_inputPorts[0].IsConnected) { screenPos = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT4, false); } else { screenPos = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos); } string screenDepthInstruction = "UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture,UNITY_PROJ_COORD(" + screenPos + ")))"; if ((dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight)) { screenDepthInstruction = "tex2Dproj(_CameraDepthTexture," + screenPos + ").r"; } if (m_convertToLinear) { string viewSpace = m_viewSpaceInt == 0 ? "LinearEyeDepth" : "Linear01Depth"; string formatStr = string.Empty; if ((dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight)) { 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); return(GetOutputColorItem(0, outputId, m_vertexNameStr[m_viewSpaceInt] + OutputId)); }