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); }
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)); }
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); }