public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (!m_outputPorts[0].IsLocalValue(dataCollector.PortCategory)) { string propertyOrOptions = string.Empty; if (m_texPort.IsConnected) { propertyOrOptions = m_texPort.GeneratePortInstructions(ref dataCollector); } else if (m_referenceNode != null) { m_referenceNode.BaseGenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar); propertyOrOptions = m_referenceNode.PropertyName; } else { propertyOrOptions = GenerateSamplerAttributes(); } string sampler = GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, propertyOrOptions); m_outputPorts[0].SetLocalValue(sampler, dataCollector.PortCategory); } return(m_outputPorts[outputId].LocalValue(dataCollector.PortCategory)); }
public string BaseGenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar); if (outputId > 0) { return(GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, PropertyName)); } else { return(PropertyName); } }
public override void CheckIfAutoRegister(ref MasterNodeDataCollector dataCollector) { // Also testing inside shader function because node can be used indirectly over a custom expression and directly over a Function Output node // That isn't being used externaly making it to not be registered ( since m_connStatus it set to Connected by being connected to an output node if (CurrentParameterType != PropertyType.Constant && m_autoRegister && (m_connStatus != NodeConnectionStatus.Connected || InsideShaderFunction)) { RegisterProperty(ref dataCollector); if (m_autoRegister && m_containerGraph.ParentWindow.OutsideGraph.SamplingMacros) { GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, PropertyName, m_variableMode); } } }
public virtual string GenerateSamplerPropertyName(int outputId, ref MasterNodeDataCollector dataCollector) { string generatedSamplerState = string.Empty; if (outputId > 0 || m_forceSamplingMacrosGen) { generatedSamplerState = GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, PropertyName, m_variableMode); } if (outputId > 0) { return(generatedSamplerState); } else { return(PropertyName); } }
public string BaseGenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar); string generatedSamplerState = string.Empty; if (outputId > 0 || m_forceSamplingMacrosGen) { generatedSamplerState = GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, PropertyName); } if (outputId > 0) { return(generatedSamplerState); } else { return(PropertyName); } }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (!m_texPort.IsConnected) { UIUtils.ShowMessage(UniqueId, "Parallax Occlusion Mapping node only works if a Texture Object is connected to its Tex (R) port"); return("0"); } base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar); ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph; string arrayIndex = m_arrayIndexPort.Visible?m_arrayIndexPort.GeneratePortInstructions(ref dataCollector):"0"; string textcoords = m_uvPort.GeneratePortInstructions(ref dataCollector); if (m_texPort.DataType == WirePortDataType.SAMPLER3D) { string texName = "pomTexCoord" + OutputId; dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, texName, string.Format("float3({0},{1})", textcoords, arrayIndex)); textcoords = texName; } string texture = m_texPort.GeneratePortInstructions(ref dataCollector); GeneratePOMfunction(ref dataCollector); string scale = m_defaultScale.ToString(); if (m_scalePort.IsConnected) { scale = m_scalePort.GeneratePortInstructions(ref dataCollector); } string viewDirTan = ""; if (!m_viewdirTanPort.IsConnected) { if (!dataCollector.DirtyNormal) { dataCollector.ForceNormal = true; } if (dataCollector.IsTemplate) { viewDirTan = dataCollector.TemplateDataCollectorInstance.GetTangentViewDir(CurrentPrecisionType); } else { viewDirTan = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId, ViewSpace.Tangent); //dataCollector.AddToInput( UniqueId, SurfaceInputs.VIEW_DIR, m_currentPrecisionType ); //viewDirTan = Constants.InputVarStr + "." + UIUtils.GetInputValueFromType( SurfaceInputs.VIEW_DIR ); } } else { viewDirTan = m_viewdirTanPort.GeneratePortInstructions(ref dataCollector); } //generate world normal string normalWorld = string.Empty; if (dataCollector.IsTemplate) { normalWorld = dataCollector.TemplateDataCollectorInstance.GetWorldNormal(CurrentPrecisionType); } else { dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType); dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false); normalWorld = GeneratorUtils.GenerateWorldNormal(ref dataCollector, UniqueId); } string worldViewDir = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId, ViewSpace.World); string dx = "ddx(" + textcoords + ")"; string dy = "ddy(" + textcoords + ")"; string refPlane = m_defaultRefPlane.ToString(); if (m_refPlanePort.IsConnected) { refPlane = m_refPlanePort.GeneratePortInstructions(ref dataCollector); } string curvature = "float2(" + m_CurvatureVector.x + "," + m_CurvatureVector.y + ")"; if (m_useCurvature) { dataCollector.AddToProperties(UniqueId, "[Header(Parallax Occlusion Mapping)]", 300); dataCollector.AddToProperties(UniqueId, "_CurvFix(\"Curvature Bias\", Range( 0 , 1)) = 1", 301); dataCollector.AddToUniforms(UniqueId, "uniform float _CurvFix;"); if (m_curvaturePort.IsConnected) { curvature = m_curvaturePort.GeneratePortInstructions(ref dataCollector); } } string localVarName = "OffsetPOM" + OutputId; string textCoordsST = string.Empty; //string textureSTType = dataCollector.IsSRP ? "float4 " : "uniform float4 "; //dataCollector.AddToUniforms( UniqueId, textureSTType + texture +"_ST;"); if (m_texCoordsHelper == null) { m_texCoordsHelper = CreateInstance <Vector4Node>(); m_texCoordsHelper.ContainerGraph = ContainerGraph; m_texCoordsHelper.SetBaseUniqueId(UniqueId, true); m_texCoordsHelper.RegisterPropertyOnInstancing = false; m_texCoordsHelper.AddGlobalToSRPBatcher = true; } if (outsideGraph.IsInstancedShader) { m_texCoordsHelper.CurrentParameterType = PropertyType.InstancedProperty; } else { m_texCoordsHelper.CurrentParameterType = PropertyType.Global; } m_texCoordsHelper.ResetOutputLocals(); m_texCoordsHelper.SetRawPropertyName(texture + "_ST"); textCoordsST = m_texCoordsHelper.GenerateShaderForOutput(0, ref dataCollector, false); ////// string textureArgs = string.Empty; #if UNITY_2018_1_OR_NEWER if (outsideGraph.SamplingMacros || m_texPort.DataType == WirePortDataType.SAMPLER2DARRAY) #else if ((outsideGraph.SamplingMacros && !outsideGraph.IsStandardSurface) || m_texPort.DataType == WirePortDataType.SAMPLER2DARRAY) #endif { string sampler = string.Empty; if (m_ssPort.IsConnected) { sampler = m_ssPort.GeneratePortInstructions(ref dataCollector); } else { sampler = GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, texture, VariableMode.Create); } if (outsideGraph.IsSRP) { textureArgs = texture + ", " + sampler; } else { #if !UNITY_2018_1_OR_NEWER if (outsideGraph.IsStandardSurface) { textureArgs = "UNITY_PASS_TEX2DARRAY(" + texture + ")"; } else #endif textureArgs = texture + ", " + sampler; } } else { textureArgs = texture; } //string functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, ( (m_pomTexType == POMTexTypes.TextureArray) ? "UNITY_PASS_TEX2DARRAY(" + texture + ")": texture), textcoords, dx, dy, normalWorld, worldViewDir, viewDirTan, m_minSamples, m_maxSamples, scale, refPlane, texture+"_ST.xy", curvature, arrayIndex ); string functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, textureArgs, textcoords, dx, dy, normalWorld, worldViewDir, viewDirTan, m_inlineMinSamples.GetValueOrProperty(false), m_inlineMinSamples.GetValueOrProperty(false), scale, refPlane, textCoordsST + ".xy", curvature, arrayIndex); dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, m_pomUVPort.DataType, localVarName, functionResult); return(GetOutputVectorItem(0, outputId, localVarName)); }
public string GenerateSamplerState(ref MasterNodeDataCollector dataCollector) { return(GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, PropertyName, m_variableMode)); }
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(ref dataCollector); 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 = ""; string noiseTex = string.Empty; 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_texPort.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 { ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph; noiseTex = m_texPort.GeneratePortInstructions(ref dataCollector); //GeneratePattern( ref dataCollector ); dataCollector.AddToUniforms(UniqueId, "float4 " + noiseTex + "_TexelSize;", dataCollector.IsSRP); #if UNITY_2018_1_OR_NEWER if (outsideGraph.SamplingMacros) #else if (outsideGraph.SamplingMacros && !outsideGraph.IsStandardSurface) #endif { string sampler = string.Empty; if (m_ssPort.IsConnected) { sampler = m_ssPort.GeneratePortInstructions(ref dataCollector); } else { sampler = GeneratorUtils.GenerateSamplerState(ref dataCollector, UniqueId, noiseTex); } //if( outsideGraph.IsSRP ) // functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, varName, noiseTex + ", " + sampler, noiseTex + "_TexelSize" ); //else functionResult = dataCollector.AddFunctions(m_functionHeader, m_functionBody, varName, noiseTex + ", " + sampler, 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)); }