예제 #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)
            {
                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));
        }
예제 #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.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));
        }
예제 #3
0
        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));
        }
예제 #4
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)));
            }

            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));
        }
예제 #6
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory))
            {
                return(m_outputPorts[0].LocalValue(dataCollector.PortCategory));
            }

            GeneratePattern();

            if (!(dataCollector.IsTemplate && dataCollector.IsSRP))
            {
                dataCollector.AddToIncludes(UniqueId, Constants.UnityShaderVariables);
            }
            string varName    = string.Empty;
            bool   isFragment = dataCollector.IsFragmentCategory;

            if (m_customScreenPos && m_inputPorts[2].IsConnected)
            {
                varName = "ditherCustomScreenPos" + OutputId;
                string customScreenPosVal = m_inputPorts[2].GeneratePortInstructions(ref dataCollector);
                dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT4, varName, customScreenPosVal);
            }
            else
            {
                if (dataCollector.TesselationActive && isFragment)
                {
                    varName = GeneratorUtils.GenerateClipPositionOnFrag(ref dataCollector, UniqueId, CurrentPrecisionType);
                }
                else
                {
                    if (dataCollector.IsTemplate)
                    {
                        varName = dataCollector.TemplateDataCollectorInstance.GetScreenPosNormalized(CurrentPrecisionType);
                    }
                    else
                    {
                        varName = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos);
                    }
                }
            }
            string surfInstruction = varName + ".xy * _ScreenParams.xy";

            m_showErrorMessage = false;
            string functionResult = "";

            switch (m_selectedPatternInt)
            {
            default:
            case 0:
                dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT2, "clipScreen" + OutputId, surfInstruction);
                functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, "fmod(" + "clipScreen" + OutputId + ".x, 4)", "fmod(" + "clipScreen" + OutputId + ".y, 4)");
                break;

            case 1:
                dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT2, "clipScreen" + OutputId, surfInstruction);
                functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, "fmod(" + "clipScreen" + OutputId + ".x, 8)", "fmod(" + "clipScreen" + OutputId + ".y, 8)");
                break;

            case 2:
            {
                if (!m_inputPorts[1].IsConnected)
                {
                    m_showErrorMessage        = true;
                    m_errorMessageTypeIsError = NodeMessageType.Warning;
                    m_errorMessageTooltip     = "Please connect a texture object to the Pattern input port to generate a proper dithered pattern";
                    return("0");
                }
                else
                {
                    bool sampleThroughMacros = UIUtils.CurrentWindow.OutsideGraph.SamplingThroughMacros;

                    string noiseTex = m_inputPorts[1].GeneratePortInstructions(ref dataCollector);
                    dataCollector.AddToUniforms(UniqueId, "float4 " + noiseTex + "_TexelSize;", dataCollector.IsSRP);
                    if (sampleThroughMacros)
                    {
                        dataCollector.AddToUniforms(UniqueId, string.Format(Constants.SamplerDeclarationSRPMacros[TextureType.Texture2D], noiseTex));
                        functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, varName, noiseTex + ", sampler" + noiseTex, noiseTex + "_TexelSize");
                    }
                    else
                    {
                        functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, varName, noiseTex, noiseTex + "_TexelSize");
                    }
                }
            }
            break;
            }

            dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, "dither" + OutputId, functionResult);

            if (m_inputPorts[0].IsConnected)
            {
                string driver = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);
                dataCollector.AddLocalVariable(UniqueId, "dither" + OutputId + " = step( dither" + OutputId + ", " + driver + " );");
            }

            //RegisterLocalVariable( 0, functionResult, ref dataCollector, "dither" + OutputId );
            m_outputPorts[0].SetLocalValue("dither" + OutputId, dataCollector.PortCategory);

            return(m_outputPorts[0].LocalValue(dataCollector.PortCategory));
        }
예제 #7
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));
        }
예제 #8
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.AddToDefines(UniqueId, Constants.CameraDepthTextureLWEnabler);
                }
                else
                {
                    dataCollector.AddToUniforms(UniqueId, Constants.CameraDepthTextureValue);
                }
                dataCollector.AddToUniforms(UniqueId, Constants.CameraDepthTextureTexelSize);
            }


            string screenPosNorm = string.Empty;

            if (m_inputPorts[0].IsConnected)
            {
                screenPosNorm = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);
            }
            else
            {
                if (dataCollector.IsTemplate)
                {
                    if (!dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData(TemplateInfoOnSematics.SCREEN_POSITION_NORMALIZED, WirePortDataType.FLOAT4, PrecisionType.Float, ref screenPosNorm, true, MasterNodePortCategory.Fragment))
                    {
                        screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos);
                    }
                }
                else
                {
                    screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos);
                }
            }

            string screenDepthInstruction = TemplateHelperFunctions.CreateDepthFetch(dataCollector, screenPosNorm);

            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.AddLocalVariable(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));
        }
예제 #9
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));
        }
예제 #10
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (m_outputPorts[0].IsLocalValue)
            {
                return(m_outputPorts[0].LocalValue);
            }

            GeneratePattern();

            dataCollector.AddToIncludes(UniqueId, Constants.UnityShaderVariables);
            string varName    = string.Empty;
            bool   isFragment = dataCollector.IsFragmentCategory;

            if (dataCollector.TesselationActive && isFragment)
            {
                varName = GeneratorUtils.GenerateClipPositionOnFrag(ref dataCollector, UniqueId, m_currentPrecisionType);
            }
            else
            {
                if (dataCollector.IsTemplate)
                {
                    varName = dataCollector.TemplateDataCollectorInstance.GetScreenPos();
                }
                else
                {
                    varName = GeneratorUtils.GenerateScreenPositionNormalized(ref dataCollector, UniqueId, m_currentPrecisionType, true);
                }
            }

            string surfInstruction = varName + ".xy * _ScreenParams.xy";

            m_showErrorMessage = false;
            string functionResult = "";

            switch (m_selectedPatternInt)
            {
            default:
            case 0:
                dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT2, "clipScreen" + OutputId, surfInstruction);
                functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, "fmod(" + "clipScreen" + OutputId + ".x, 4)", "fmod(" + "clipScreen" + UniqueId + ".y, 4)");
                break;

            case 1:
                dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT2, "clipScreen" + OutputId, surfInstruction);
                functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, "fmod(" + "clipScreen" + OutputId + ".x, 8)", "fmod(" + "clipScreen" + UniqueId + ".y, 8)");
                break;

            case 2:
            {
                if (!m_inputPorts[1].IsConnected)
                {
                    m_showErrorMessage        = true;
                    m_errorMessageTypeIsError = NodeMessageType.Warning;
                    m_errorMessageTooltip     = "Please connect a texture object to the Pattern input port to generate a proper dithered pattern";
                    return("0");
                }
                else
                {
                    string noiseTex = m_inputPorts[1].GeneratePortInstructions(ref dataCollector);
                    dataCollector.AddToUniforms(UniqueId, "uniform float4 " + noiseTex + "_TexelSize;");
                    functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, varName, noiseTex, noiseTex + "_TexelSize");
                }
            }
            break;
            }

            dataCollector.AddLocalVariable(UniqueId, "float dither" + OutputId + " = " + functionResult + ";");

            if (m_inputPorts[0].IsConnected)
            {
                string driver = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);
                dataCollector.AddLocalVariable(UniqueId, "dither" + OutputId + " = step( dither" + OutputId + ", " + driver + " );");
            }

            //RegisterLocalVariable( 0, functionResult, ref dataCollector, "dither" + OutputId );
            m_outputPorts[0].SetLocalValue("dither" + OutputId);

            return(m_outputPorts[0].LocalValue);
        }