Combining vertex and surface shader

Hi!
Excuse me for wasting your time, but I have another problem. This time I try to combine vertex and surface shader. The vertex shader is the default shader for sprite:

SubShader
	{
		Tags
		{ 
			"Queue"="Transparent" 
			"IgnoreProjector"="True" 
			"RenderType"="Transparent" 
			"PreviewType"="Plane"
			"CanUseSpriteAtlas"="True"
		}

		Cull Off
		Lighting Off
		ZWrite Off
		Fog { Mode Off }
		Blend SrcAlpha OneMinusSrcAlpha

		Pass
		{
		CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile DUMMY PIXELSNAP_ON
			#include "UnityCG.cginc"
			
			struct appdata_t
			{
				float4 vertex   : POSITION;
				float4 color    : COLOR;
				float2 texcoord : TEXCOORD0;
			};

			struct v2f
			{
				float4 vertex   : SV_POSITION;
				fixed4 color    : COLOR;
				half2 texcoord  : TEXCOORD0;
			};
			
			fixed4 _Color;

			v2f vert(appdata_t IN)
			{
				v2f OUT;
				OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
				OUT.texcoord = IN.texcoord;
				OUT.color = IN.color * _Color;
				#ifdef PIXELSNAP_ON
				OUT.vertex = UnityPixelSnap (OUT.vertex);
				#endif

				return OUT;
			}

			sampler2D _MainTex;

			fixed4 frag(v2f IN) : COLOR
			{
				return tex2D(_MainTex, IN.texcoord) * IN.color;
			}
		ENDCG
		}
	}

The surface shader works for quad, it looks like this:

Shader "Custom/FoldInvis" {
	Properties {
       _MainTex ("Base (RGB) Trans(A)", 2D) = "white" {}
       _Color ("Color", Color) = (1,1,1,1)
       _a ("a", float) = 100
       _b ("b", float) = 100
       
       
    }
   	
   	SubShader {
       Tags{"Queue"="Transparent"}
       LOD 200
 
       CGPROGRAM
       #pragma surface surf Lambert
 
       sampler2D _MainTex;
       float4 _Color;
       float _a;
       float _b;
		
	
       struct Input {
         float2 uv_MainTex;
       };
       
 
       void surf (Input IN, inout SurfaceOutput o) {
         half4 result = tex2D (_MainTex, IN.uv_MainTex);
         clip(IN.uv_MainTex.y < _a * IN.uv_MainTex.x + _b ? 1 : -1 );
         
         o.Albedo = result.rgb * _Color.rgb;
         o.Alpha = result.a;
       }
       ENDCG
	}
	FallBack "Diffuse"
}

Unfortunately, when I try to combine it, it always returns an error. I tried to use this example http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderExamples.html (under Custom data computed per-vertex).

Could you, please, help me a bit? I’m kind of lost again. Thanks for any help.
Excuse my english…
Thanks and have a nice day!

Well, if anyone wanted the solution, I found it out. Actually it was pretty easy:

Shader "Custom/FoldInvisSprite" 
{
	Properties
	{
		[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
		_Color ("Tint", Color) = (1,1,1,1)
		[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
		_a ("a", float) = 100
        _b ("b", float) = 100
	}

	SubShader
	{
		Tags
		{ 
			"Queue"="Transparent" 
			"IgnoreProjector"="True" 
			"RenderType"="Transparent" 
			"PreviewType"="Plane"
			"CanUseSpriteAtlas"="True"
		}

		Cull Off
		Lighting Off
		ZWrite Off
		Fog { Mode Off }
		Blend SrcAlpha OneMinusSrcAlpha

		Pass
		{
		CGPROGRAM
			// Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members _a,_b)
			#pragma exclude_renderers d3d11 xbox360
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile DUMMY PIXELSNAP_ON
			#include "UnityCG.cginc"
			
			struct appdata_t
			{
				float4 vertex   : POSITION;
				float4 color    : COLOR;
				float2 texcoord : TEXCOORD0;
			};

			struct v2f
			{
				float4 vertex   : SV_POSITION;
				fixed4 color    : COLOR;
				half2 texcoord  : TEXCOORD0;
			};
			
			fixed4 _Color;

			v2f vert(appdata_t IN)
			{
				v2f OUT;
				OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
				OUT.texcoord = IN.texcoord;
				OUT.color = IN.color * _Color;
				#ifdef PIXELSNAP_ON
				OUT.vertex = UnityPixelSnap (OUT.vertex);
				#endif

				return OUT;
			}

			sampler2D _MainTex;
			float _a;
		    float _b;

			fixed4 frag(v2f IN) : COLOR
			{
			if(IN.texcoord.y < _a * IN.texcoord.x + _b)
				return tex2D(_MainTex, IN.texcoord) * IN.color;
			else
				return 0;
			}
			
		ENDCG
		}
	}
}

Have a nice day, everyone!

1 Like