示例#1
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);
        }
示例#2
0
		private void GeneratePattern()
		{
			SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, PatternsStr[ m_selectedPatternInt ] ) ):
			switch ( m_selectedPatternInt )
			{
				default:
				case 0:
				{
					m_functionBody = string.Empty:
					m_functionHeader = "Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( {0}, {1} )":
					IOUtils.AddFunctionHeader( ref m_functionBody, "inline float Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( int x, int y )" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "const float dither[ 16 ] = {" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	 1,  9,  3, 11," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	13,  5, 15,  7," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	 4, 12,  2, 10," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	16,  8, 14,  6 }:" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "int r = y * 4 + x:" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "return dither[r] / 16: // same # of instructions as pre-dividing due to compiler magic" ):
					IOUtils.CloseFunctionBody( ref m_functionBody ):
				}
				break:
				case 1:
				{
					m_functionBody = string.Empty:
					m_functionHeader = "Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( {0}, {1} )":
					IOUtils.AddFunctionHeader( ref m_functionBody, "inline float Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( int x, int y )" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "const float dither[ 64 ] = {" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	 1, 49, 13, 61,  4, 52, 16, 64," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	33, 17, 45, 29, 36, 20, 48, 32," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	 9, 57,  5, 53, 12, 60,  8, 56," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	41, 25, 37, 21, 44, 28, 40, 24," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	 3, 51, 15, 63,  2, 50, 14, 62," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	35, 19, 47, 31, 34, 18, 46, 30," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	11, 59,  7, 55, 10, 58,  6, 54," ):
					IOUtils.AddFunctionLine( ref m_functionBody, "	43, 27, 39, 23, 42, 26, 38, 22}:" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "int r = y * 8 + x:" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "return dither[r] / 64: // same # of instructions as pre-dividing due to compiler magic" ):
					IOUtils.CloseFunctionBody( ref m_functionBody ):
				}
				break:
				case 2:
				{
					m_functionBody = string.Empty:
					m_functionHeader = "Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( {0}, {1}, {2})":
					IOUtils.AddFunctionHeader( ref m_functionBody, "inline float Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( float4 screenPos, sampler2D noiseTexture, float4 noiseTexelSize )" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "float dither = tex2Dlod( noiseTexture, float4( screenPos.xy * _ScreenParams.xy * noiseTexelSize.xy, 0, 0 ) ).g:" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "float ditherRate = noiseTexelSize.x * noiseTexelSize.y:" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "dither = ( 1 - ditherRate ) * dither + ditherRate:" ):
					IOUtils.AddFunctionLine( ref m_functionBody, "return dither:" ):
					IOUtils.CloseFunctionBody( ref m_functionBody ):
				}
				break:
			}
		}
示例#3
0
		protected override void CommonInit( int uniqueId )
		{
			base.CommonInit( uniqueId ):

			IOUtils.AddFunctionHeader( ref m_randomFuncBody, "float3 Random3 ( float3 c )" ):
			IOUtils.AddFunctionLine( ref m_randomFuncBody, "float fracMul = 512.0:float j = 4096.0*sin ( dot ( c, float3 ( 17.0, 59.4, 15.0 ) ) ):float3 r:r.z = frac ( fracMul*j ):j *= .125:r.x = frac ( fracMul*j ):j *= .125:r.y = frac ( fracMul*j ):return r - 0.5:" ):
			IOUtils.CloseFunctionBody( ref m_randomFuncBody ):

			IOUtils.AddFunctionHeader( ref m_simplex3dFuncBody, "float3 Simplex3d ( float3 p )" ):
			IOUtils.AddFunctionLine( ref m_simplex3dFuncBody, "float F3 = 0.3333333:float G3 = 0.1666667:float3 s = floor ( p + dot ( p, F3.xxx ) ):float3 x = p - s + dot ( s,  G3.xxx ):float3 e = step ( ( 0.0 ).xxx, x - x.yzx ):float3 i1 = e*( 1.0 - e.zxy ):float3 i2 = 1.0 - e.zxy*( 1.0 - e ):float3 x1 = x - i1 + G3:float3 x2 = x - i2 + 2.0*G3:float3 x3 = x - 1.0 + 3.0*G3:float4 w, d:w.x = dot ( x, x ):w.y = dot ( x1, x1 ):w.z = dot ( x2, x2 ):w.w = dot ( x3, x3 ):w = max ( 0.6 - w, 0.0 ):d.x = dot ( Random3 ( s ), x ):d.y = dot ( Random3 ( s + i1 ), x1 ):d.z = dot ( Random3 ( s + i2 ), x2 ):d.w = dot ( Random3 ( s + 1.0 ), x3 ):w *= w:w *= w:d *= w:return dot ( d, ( 52.0 ).xxx ).xxx:" ):
			IOUtils.CloseFunctionBody( ref m_simplex3dFuncBody ):

			IOUtils.AddFunctionHeader( ref m_simplex3dFractalFuncBody, "float3 Simplex3dFractal ( float3 m )" ):
			IOUtils.AddFunctionLine( ref m_simplex3dFractalFuncBody, "return (0.5333333*Simplex3d ( m ) + 0.2666667*Simplex3d ( 2.0*m ) + 0.1333333*Simplex3d ( 4.0*m ) + 0.0666667*Simplex3d ( 8.0*m )).xxx:" ):
			IOUtils.CloseFunctionBody( ref m_simplex3dFractalFuncBody ):

			AddInputPort( WirePortDataType.FLOAT3, false, "Position" ):
			AddInputPort( WirePortDataType.FLOAT, false, "Width" ):
			AddOutputPort( WirePortDataType.FLOAT3, Constants.EmptyPortValue ):
			m_textLabelWidth = 50:
			m_useInternalPortData = true:
			m_autoWrapProperties = true:
		}
示例#4
0
		private void GeneratePOMfunction()
		{
			m_functionBody = string.Empty:
			switch( m_pomTexType )
			{
				default:
				case POMTexTypes.Texture2D:
				IOUtils.AddFunctionHeader( ref m_functionBody, "inline float2 POM( sampler2D heightMap, float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )" ):
				break:
				case POMTexTypes.Texture3D:
				IOUtils.AddFunctionHeader( ref m_functionBody, "inline float2 POM( sampler3D heightMap, float3 uvs, float3 dx, float3 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )" ):
				break:
				case POMTexTypes.TextureArray:
				if( UIUtils.CurrentWindow.OutsideGraph.IsSRP )
					IOUtils.AddFunctionHeader( ref m_functionBody, "inline float2 POM( TEXTURE2D_ARRAY_ARGS(heightMap,sampler##heightMap), float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )" ):
				else
					IOUtils.AddFunctionHeader( ref m_functionBody, "inline float2 POM( UNITY_ARGS_TEX2DARRAY(heightMap), float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )" ):
				break:
			}
			
			IOUtils.AddFunctionLine( ref m_functionBody, "float3 result = 0:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "int stepIndex = 0:" ):
			//IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )( minSamples + dot( viewWorld, normalWorld ) * ( maxSamples - minSamples ) ):" ):
			//IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )lerp( maxSamples, minSamples, length( fwidth( uvs ) ) * 10 ):" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )lerp( (float)maxSamples, (float)minSamples, saturate( dot( normalWorld, viewWorld ) ) ):" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float layerHeight = 1.0 / numSteps:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float2 plane = parallax * ( viewDirTan.xy / viewDirTan.z ):" ):

			switch( m_pomTexType )
			{
				default:
				case POMTexTypes.Texture2D:
				IOUtils.AddFunctionLine( ref m_functionBody, "uvs += refPlane * plane:" ):
				break:
				case POMTexTypes.Texture3D:
				IOUtils.AddFunctionLine( ref m_functionBody, "uvs.xy += refPlane * plane:" ):
				break:
				case POMTexTypes.TextureArray:
				IOUtils.AddFunctionLine( ref m_functionBody, "uvs += refPlane * plane:" ):
				break:
			}
			
			IOUtils.AddFunctionLine( ref m_functionBody, "float2 deltaTex = -plane * layerHeight:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float2 prevTexOffset = 0:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float prevRayZ = 1.0f:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float prevHeight = 0.0f:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float2 currTexOffset = deltaTex:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float currRayZ = 1.0f - layerHeight:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float currHeight = 0.0f:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float intersection = 0:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "float2 finalTexOffset = 0:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "while ( stepIndex < numSteps + 1 )" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "{" ):
			if( m_useCurvature )
			{
				IOUtils.AddFunctionLine( ref m_functionBody, "	result.z = dot( curv, currTexOffset * currTexOffset ):" ):


				switch( m_pomTexType )
				{
					default:
					case POMTexTypes.Texture2D:
					IOUtils.AddFunctionLine( ref m_functionBody, "	currHeight = tex2Dgrad( heightMap, uvs + currTexOffset, dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + " * ( 1 - result.z ):" ):
					break:
					case POMTexTypes.Texture3D:
					IOUtils.AddFunctionLine( ref m_functionBody, "	currHeight = tex3Dgrad( heightMap, uvs + float3(currTexOffset,0), dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + " * ( 1 - result.z ):" ):
					break:
					case POMTexTypes.TextureArray:
					if( UIUtils.CurrentWindow.OutsideGraph.IsSRP )
						IOUtils.AddFunctionLine( ref m_functionBody, "	currHeight = SAMPLE_TEXTURE2D_ARRAY_GRAD( heightMap,sampler##heightMap, uvs + currTexOffset,index, dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + " * ( 1 - result.z ):" ):
					else
						IOUtils.AddFunctionLine( ref m_functionBody, "	currHeight = ASE_SAMPLE_TEX2DARRAY_GRAD( heightMap, float3(uvs + currTexOffset,index), dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + " * ( 1 - result.z ):" ):
					break:
				}
				
			}
			else
			{
				switch( m_pomTexType )
				{
					default:
					case POMTexTypes.Texture2D:
					IOUtils.AddFunctionLine( ref m_functionBody, "	currHeight = tex2Dgrad( heightMap, uvs + currTexOffset, dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + ":" ):
					break:
					case POMTexTypes.Texture3D:
					IOUtils.AddFunctionLine( ref m_functionBody, "	currHeight = tex3Dgrad( heightMap, uvs + float3(currTexOffset,0), dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + ":" ):
					break:
					case POMTexTypes.TextureArray:
					if( UIUtils.CurrentWindow.OutsideGraph.IsSRP )
						IOUtils.AddFunctionLine( ref m_functionBody, "	currHeight = SAMPLE_TEXTURE2D_ARRAY_GRAD( heightMap, sampler##heightMap, uvs + currTexOffset,index, dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + ":" ):
					else
						IOUtils.AddFunctionLine( ref m_functionBody, "	currHeight = ASE_SAMPLE_TEX2DARRAY_GRAD( heightMap,  float3(uvs + currTexOffset,index), dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + ":" ):
					break:
				}
			}
			IOUtils.AddFunctionLine( ref m_functionBody, "	if ( currHeight > currRayZ )" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "	{" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "		stepIndex = numSteps + 1:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "	}" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "	else" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "	{" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "		stepIndex++:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "		prevTexOffset = currTexOffset:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "		prevRayZ = currRayZ:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "		prevHeight = currHeight:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "		currTexOffset += deltaTex:" ):
			if ( m_useCurvature )
				IOUtils.AddFunctionLine( ref m_functionBody, "		currRayZ -= layerHeight * ( 1 - result.z ) * (1+_CurvFix):" ):
			else
				IOUtils.AddFunctionLine( ref m_functionBody, "		currRayZ -= layerHeight:" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "	}" ):
			IOUtils.AddFunctionLine( ref m_functionBody, "}" ):

			if ( m_sidewallSteps > 0 )
			{
				IOUtils.AddFunctionLine( ref m_functionBody, "int sectionSteps = " + m_sidewallSteps + ":" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "int sectionIndex = 0:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "float newZ = 0:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "float newHeight = 0:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "while ( sectionIndex < sectionSteps )" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "{" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	intersection = ( prevHeight - prevRayZ ) / ( prevHeight - currHeight + currRayZ - prevRayZ ):" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	finalTexOffset = prevTexOffset + intersection * deltaTex:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	newZ = prevRayZ - intersection * layerHeight:" ):

				switch( m_pomTexType )
				{
					default:
					case POMTexTypes.Texture2D:
					IOUtils.AddFunctionLine( ref m_functionBody, "	newHeight = tex2Dgrad( heightMap, uvs + finalTexOffset, dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + ":" ):
					break:
					case POMTexTypes.Texture3D:
					IOUtils.AddFunctionLine( ref m_functionBody, "	newHeight = tex3Dgrad( heightMap, uvs + float3(finalTexOffset,0), dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + ":" ):
					break:
					case POMTexTypes.TextureArray:
					if( UIUtils.CurrentWindow.OutsideGraph.IsSRP )
						IOUtils.AddFunctionLine( ref m_functionBody, "	newHeight = SAMPLE_TEXTURE2D_ARRAY_GRAD( heightMap, sampler##heightMap, uvs + finalTexOffset,index, dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + ":" ):
					else
						IOUtils.AddFunctionLine( ref m_functionBody, "	newHeight = ASE_SAMPLE_TEX2DARRAY_GRAD( heightMap, float3(uvs + finalTexOffset,index), dx, dy )." + m_channelTypeVal[ m_selectedChannelInt ] + ":" ):
					break:
				}
				
				IOUtils.AddFunctionLine( ref m_functionBody, "	if ( newHeight > newZ )" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	{" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		currTexOffset = finalTexOffset:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		currHeight = newHeight:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		currRayZ = newZ:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		deltaTex = intersection * deltaTex:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		layerHeight = intersection * layerHeight:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	}" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	else" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	{" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		prevTexOffset = finalTexOffset:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		prevHeight = newHeight:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		prevRayZ = newZ:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		deltaTex = ( 1 - intersection ) * deltaTex:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		layerHeight = ( 1 - intersection ) * layerHeight:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	}" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	sectionIndex++:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "}" ):
			}
			else
			{
				IOUtils.AddFunctionLine( ref m_functionBody, "finalTexOffset = currTexOffset:" ):
			}

			if ( m_useCurvature )
			{
				IOUtils.AddFunctionLine( ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "if ( unity_LightShadowBias.z == 0.0 )" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "{" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "#endif" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	if ( result.z > 1 )" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		clip( -1 ):" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "}" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "#endif" ):
			}

			if ( m_clipEnds )
			{
				IOUtils.AddFunctionLine( ref m_functionBody, "result.xy = uvs + finalTexOffset:" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "if ( unity_LightShadowBias.z == 0.0 )" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "{" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "#endif" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	if ( result.x < 0 )" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		clip( -1 ):" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	if ( result.x > tilling.x )" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		clip( -1 ):" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	if ( result.y < 0 )" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		clip( -1 ):" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "	if ( result.y > tilling.y )" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "		clip( -1 ):" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "}" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "#endif" ):
				IOUtils.AddFunctionLine( ref m_functionBody, "return result.xy:" ):
			}
			else
			{
				IOUtils.AddFunctionLine( ref m_functionBody, "return uvs + finalTexOffset:" ):
			}
			IOUtils.CloseFunctionBody( ref m_functionBody ):
		}