Exemplo n.º 1
0
        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     = GeneratorUtils.GenerateScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos);
            string 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 = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);

            dataCollector.AddLocalVariable(UniqueId, "float screenDepth" + OutputId + " = " + screenDepth + ";");
            if (dataCollector.IsTemplate && dataCollector.IsSRP)
            {
                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));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }