예제 #1
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			

			string posValue = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
			string widthValue = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):
			dataCollector.AddFunctions( RandomfunctionHeader, m_randomFuncBody, "0" ):
			string result = string.Empty:
			switch ( m_type )
			{
				case NoiseType.Simplex3D:
				{
					string finalValue = dataCollector.AddFunctions( Simplex3dfunctionHeader, m_simplex3dFuncBody, posValue + "*" + widthValue ):
					result = finalValue + "* 0.5 + 0.5":
				}break:

				case NoiseType.Simplex3DFractal:
				{
					dataCollector.AddFunctions( Simplex3dfunctionHeader, m_simplex3dFuncBody, posValue + "*" + widthValue ):
					string finalValue = dataCollector.AddFunctions( Simplex3dFractalfunctionHeader, m_simplex3dFractalFuncBody, posValue + "*" + widthValue + "+" + widthValue ):
					result = finalValue + "* 0.5 + 0.5":
				}break:
			}

			return CreateOutputLocalVariable( 0, result, ref dataCollector ):
		}
예제 #2
0
        // GRAB SCREEN POSITION
        static public string GenerateGrabScreenPosition(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision, bool addInput = true, string customScreenPos = null)
        {
            string screenPos = string.Empty;

            if (string.IsNullOrEmpty(customScreenPos))
            {
                screenPos = GenerateScreenPosition(ref dataCollector, uniqueId, precision, addInput);
            }
            else
            {
                screenPos = customScreenPos;
            }

            string computeBody = string.Empty;

            IOUtils.AddFunctionHeader(ref computeBody, GrabFunctionHeader);
            foreach (string line in GrabFunctionBody)
            {
                IOUtils.AddFunctionLine(ref computeBody, line);
            }
            IOUtils.CloseFunctionBody(ref computeBody);
            string functionResult = dataCollector.AddFunctions(GrabFunctionCall, computeBody, screenPos);

            dataCollector.AddLocalVariable(uniqueId, precision, WirePortDataType.FLOAT4, GrabScreenPositionStr, functionResult);
            return(GrabScreenPositionStr);
        }
예제 #3
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 ):

			string contrastValue = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):
			string colorTarget = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ):
			string result = dataCollector.AddFunctions( FunctionHeader, m_functionBody, false, contrastValue, colorTarget ):

			return CreateOutputLocalVariable( 0, result, ref dataCollector ):
		}
예제 #4
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, m_currentPrecisionType, WirePortDataType.FLOAT4, varName, customScreenPosVal ):
			}
			else
			{
				if( dataCollector.TesselationActive && isFragment )
				{
					varName = GeneratorUtils.GenerateClipPositionOnFrag( ref dataCollector, UniqueId, m_currentPrecisionType ):
				}
				else
				{
					if( dataCollector.IsTemplate )
					{
						varName = dataCollector.TemplateDataCollectorInstance.GetScreenPosNormalized():
					}
					else
					{
						varName = GeneratorUtils.GenerateScreenPositionNormalized( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ):
					}
				}
			}
			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" + OutputId + ".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" + 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
					{
						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, dataCollector.PortCategory ):

			return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ):
		}
예제 #5
0
		public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
		{
			if( !m_texPort.IsConnected )
			{
				UIUtils.ShowMessage( "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 ):
			WirePortDataType texType = ( m_pomTexType == POMTexTypes.Texture3D )?WirePortDataType.SAMPLER3D: WirePortDataType.SAMPLER2D:

			GeneratePOMfunction():
			string arrayIndex = m_arrayIndexPort.Visible?m_arrayIndexPort.GeneratePortInstructions( ref dataCollector ):"0":
			string textcoords = m_uvPort.GeneratePortInstructions( ref dataCollector ):
			if( m_pomTexType == POMTexTypes.Texture3D )
			{
				string texName = "pomTexCoord" + OutputId:
				dataCollector.AddToLocalVariables( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, texName, string.Format( "float3({0},{1})", textcoords, arrayIndex ) ):
				textcoords = texName:
			}

			string texture = m_texPort.GenerateShaderForOutput( ref dataCollector, texType,false,true ):
			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( m_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( m_currentPrecisionType ):
			}
			else
			{
				dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType ):
				dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ):
				normalWorld = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId ):
			}

			//string normalWorld = "WorldNormalVector( " + Constants.InputVarStr + ", float3( 0, 0, 1 ) )":

			//generate viewDir in world space

			//string worldPos = string.Empty:
			//if( dataCollector.IsTemplate )
			//{
			//	worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos():
			//}
			//else
			//{
			//	dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS ):
			//	worldPos = Constants.InputVarStr + ".worldPos":
			//}

			//if( !dataCollector.IsTemplate )
			//	dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS ):

			string worldViewDir = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId, ViewSpace.World ):
			//dataCollector.AddToLocalVariables( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, WorldDirVarStr, TemplateHelperFunctions.WorldSpaceViewDir( dataCollector, worldPos, true ) ):
			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" + UniqueId:
			string textureSTType = dataCollector.IsSRP ? "float4 " : "uniform float4 ":
			dataCollector.AddToUniforms(UniqueId, textureSTType + texture +"_ST:"):

			

			if( m_pomTexType == POMTexTypes.TextureArray )
				dataCollector.UsingArrayDerivatives = true:
			string textureArgs = string.Empty:
			if( m_pomTexType == POMTexTypes.TextureArray )
			{
				if( UIUtils.CurrentWindow.OutsideGraph.IsSRP )
				{
					textureArgs = "TEXTURE2D_ARRAY_PARAM(" + texture +" , "+"sampler##"+texture + ")":
				}
				else
				{
					textureArgs = "UNITY_PASS_TEX2DARRAY(" + texture + ")":
				}
			}
			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, texture + "_ST.xy", curvature, arrayIndex ):

			dataCollector.AddToLocalVariables( UniqueId, m_currentPrecisionType, m_pomUVPort.DataType, localVarName, functionResult ):

			return GetOutputVectorItem( 0, outputId, localVarName ):
		}