예제 #1
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar)
        {
            if (m_outputPorts[0].IsLocalValue)
            {
                return(m_outputPorts[0].LocalValue);
            }

            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
                {
                    if (isFragment)
                    {
                        dataCollector.AddToInput(UniqueId, "float4 " + CustomScreenPosStr, true);
                        string screenPos         = GeneratorUtils.GenerateVertexScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, false);
                        string vertexInstruction = Constants.VertexShaderOutputStr + "." + CustomScreenPosStr + " = " + screenPos + ";";
                        dataCollector.AddToVertexLocalVariables(UniqueId, vertexInstruction);
                        varName = Constants.InputVarStr + "." + CustomScreenPosStr;
                    }
                    else
                    {
                        varName = GeneratorUtils.GenerateVertexScreenPosition(ref dataCollector, UniqueId, m_currentPrecisionType, false);
                    }
                }
            }

            string surfInstruction = "( " + varName + ".xy / " + varName + ".w ) * _ScreenParams.xy";

            dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT2, "clipScreen" + OutputId, surfInstruction);

            string functionResult = "";

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

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


            RegisterLocalVariable(0, functionResult, ref dataCollector, "dither" + OutputId);
            return(m_outputPorts[0].LocalValue);
        }
예제 #2
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));
            }

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