How can be done ? (Mix two surface shader)

Hi!
I wanted to create a hatching shader and i found this one on the forum :
http://forum.unity3d.com/threads/137018-Cross-Hatching-Shader-finished
I just modified a little from 6 to 4 image hatches.
Here is it :

Shader "Custom/Hatching" {
	Properties {
		_Hatch0 ("Hatch 0", 2D) = "white" {}
		_Hatch1 ("Hatch 1", 2D) = "white" {}
		_Hatch2 ("Hatch 2", 2D) = "white" {}
		_Hatch3 ("Hatch 3", 2D) = "white" {}						
	}
	SubShader {
		Tags { "RenderType" = "Opaque" }
		CGPROGRAM
		#pragma surface surf SimpleLambert
		#pragma only_renderers d3d9
		#pragma target 3.0
		
		sampler2D _Hatch0;
		sampler2D _Hatch1;
		sampler2D _Hatch2;
		sampler2D _Hatch3;

		half4 LightingSimpleLambert (inout SurfaceOutput s, half3 lightDir, half atten)
		{
			float2 uv = s.Albedo.xy;		
			s.Albedo = 0.0;			
		
			half NdotL = dot (s.Normal, lightDir);
			half diff = NdotL; //* 0.75 + 0.25;
			half4 c;
			
			half lightColor = _LightColor0.r * 0.3 + _LightColor0.g * 0.59 + _LightColor0.b * 0.11;
			half intensity = lightColor * (diff * atten * 2);
			intensity = saturate(intensity);
			
			float part = 1 / 5.0;
			if (intensity <= part)
			{	
				float temp = intensity;
				temp *= 6;
				c.rgb = lerp(tex2D(_Hatch0, uv), tex2D(_Hatch1, uv), temp);			
			}
			if (intensity > part  intensity <= part * 2)
			{
				float temp = intensity - part;
				temp *= 6;				
				c.rgb = lerp(tex2D(_Hatch1, uv), tex2D(_Hatch2, uv), temp);			
			}
			if (intensity > part * 2  intensity <= part * 3)
			{
				float temp = intensity - part * 2;
				temp *= 6;				
				c.rgb = lerp(tex2D(_Hatch2, uv), tex2D(_Hatch3, uv), temp);			
			}
			if (intensity > part * 3)
			{
				float temp = intensity - part * 3;
				temp *= 6;				
				c.rgb = lerp(tex2D(_Hatch3, uv), 1, temp);
			}

			return c;
		}

		struct Input 
		{
			float2 uv_Hatch0;
		};

		void surf (Input IN, inout SurfaceOutput o) 
		{
			o.Albedo.xy = IN.uv_Hatch0;
		}
		ENDCG
	}
    Fallback "Diffuse"
}

And my problem is that i want to use Diffuse, Normal, Specular map’s with this shader.
I created some day a nice Surface shader with (diff,norm,spec) but i can’t figure it out how to mix the two.
Here is the Surface shader one :

Shader "Custom/Bumped Specular" {
	Properties {
		_Color ("Main Color", Color) = (.5,.5,.5,1)
		_SpecColor ("Specular Material Color (RGB)", Color) = (1,1,1,1)
	    _ShinPower ("Shininess", Range(0,1)) = 0.5
	    _GlossPower ("Gloss", Range(0.01,1)) = 0.5
		_MainTex ("Base (RGB)", 2D) = "white" { }
		_BumpMap ("Bumpmap", 2D) = "bump" {}
		_SpecularTex ("Specular Map", 2D) = "gray" {}
	}

	SubShader {
		Tags { "Queue" = "Geometry+10" "RenderType" = "Opaque" }

			CGPROGRAM
			#pragma surface surf Test
			#pragma only_renderers d3d9
			#pragma target 3.0
			
            struct Input
			{
				float2 uv_MainTex;
				float2 uv_BumpMap;
				float3 worldNormal;
				INTERNAL_DATA
			};
			
            sampler2D _MainTex, _SpecularTex, _BumpMap;
			uniform float3 _Color;
		    float _ShinPower;
	        float _GlossPower;

            inline fixed4 LightingTest (SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten)
            {
                fixed3 h = normalize (lightDir + viewDir);

                fixed NdotL = dot(s.Normal, lightDir) * 0.5 + 0.5;

                float nh = max (0, dot (s.Normal, h));
                float spec = pow (nh, s.Gloss * 128) * s.Specular;

                fixed4 c;
                c.rgb = ((s.Albedo * _Color.rgb * _LightColor0.rgb + _LightColor0.rgb * spec * s.Specular * _SpecColor) * (atten * 2));
                return c;
            }
                
            void surf (Input IN, inout SurfaceOutput o)
            {
                o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb * _Color;
                o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
                float3 specGloss = tex2D(_SpecularTex, IN.uv_MainTex).rgb;
          		o.Specular = specGloss.r * _ShinPower;
          		o.Gloss = specGloss.g * _GlossPower;
			}
			ENDCG
	}
	Fallback "Bumped Specular"
}

And if i see it right the hatching and the other one is a Surface shader.
So the question is it possible to mix the two, if yes then how?
Or just could someone make a _MainTex variable for the hatching shader that works :slight_smile:
Any help would appreciated :slight_smile:

Hi, all!
I have succesfully implemented the Normal,Specular map to the hatching shader and plus some outline :slight_smile:
But i ran into a problem, no matter how hard I try i can’t get the Diffuse working.
Perhaps because the hatching uses the Diffuse (o.Albedo) ?
So my question is still there, how could be the (_MainTex) implemented into the below shader, so that it has two (2) o.Albedo ?
Any help would greatly appreciated :slight_smile:

Here is the shader :

Shader "Custom/Silhoutted Hatching" {
	Properties {
		_OutlineColor ("Outline Color", Color) = (0,0,0,1)
		_Outline ("Outline width", Range (0.0, 0.03)) = .005
		_ShinPower ("Shininess", Range(0,1)) = 0.5
	    _GlossPower ("Gloss", Range(0.01,1)) = 0.5
		_BumpMap ("Bumpmap", 2D) = "bump" {}
		_SpecularTex ("Specular Map", 2D) = "gray" {}
		_Hatch0 ("Hatch 0", 2D) = "white" {}
		_Hatch1 ("Hatch 1", 2D) = "white" {}
		_Hatch2 ("Hatch 2", 2D) = "white" {}
		_Hatch3 ("Hatch 3", 2D) = "white" {}						
	}
	
	CGINCLUDE
	#include "UnityCG.cginc"

	struct appdata {
		float4 vertex : POSITION;
		float3 normal : NORMAL;
	};

	struct v2f {
		float4 pos : POSITION;
		float4 color : COLOR;
	};

	uniform float _Outline;
	uniform float4 _OutlineColor;

	v2f vert(appdata v) {
		v2f o;
		o.pos = mul(UNITY_MATRIX_MVP, v.vertex);

		float3 norm   = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);
		float2 offset = TransformViewToProjection(norm.xy);

		o.pos.xy += offset * o.pos.z * _Outline;
		o.color = _OutlineColor;
		return o;
	}
	ENDCG

	SubShader {
		Tags { "Queue" = "Geometry+10" "RenderType" = "Opaque" }
		Pass {
			Name "OUTLINE"
			Tags { "LightMode" = "Always" }
			Cull Off
			ZWrite Off

			Blend SrcAlpha OneMinusSrcAlpha

		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag

		half4 frag(v2f i) : COLOR {
			return i.color;
		}
		ENDCG
		}

		CGPROGRAM
		#pragma surface surf Hatching
		#pragma only_renderers d3d9
		#pragma target 3.0
		
		struct Input 
		{
			float2 uv_Hatch0;
			float2 uv_BumpMap;
			float3 worldNormal;
			INTERNAL_DATA
		};
		
		sampler2D _Hatch0, _Hatch1, _Hatch2, _Hatch3;
		sampler2D _BumpMap;
		sampler2D _SpecularTex;
		float _ShinPower;
	    float _GlossPower;

		inline half4 LightingHatching (inout SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
		{
			half3 h = normalize (lightDir + viewDir);
			
			float2 uv = s.Albedo.xy;		
			s.Albedo = 0.0;			
		
			half NdotL = dot (s.Normal, lightDir);
			half diff = NdotL * 0.75 + 0.45;
			
			float nh = max (0, dot (s.Normal, h));
            float spec = pow (nh, s.Gloss * 64) * s.Specular;
			
			half4 c;
			half lightColor = _LightColor0.r * 0.3 + _LightColor0.g * 0.59 + _LightColor0.b * 0.11 * spec * s.Specular;
			half intensity = lightColor * (diff * atten * 2);
			intensity = saturate(intensity);
			
			float part = 1 / 4.0;
			if (intensity <= part)
			{	
				float temp = intensity;
				temp *= 4;
				c.rgb = lerp(tex2D(_Hatch0, uv), tex2D(_Hatch1, uv), temp);			
			}
			if (intensity > part  intensity <= part * 2)
			{
				float temp = intensity - part;
				temp *= 4;				
				c.rgb = lerp(tex2D(_Hatch1, uv), tex2D(_Hatch2, uv), temp);			
			}
			if (intensity > part * 2  intensity <= part * 3)
			{
				float temp = intensity - part * 2;
				temp *= 4;				
				c.rgb = lerp(tex2D(_Hatch2, uv), tex2D(_Hatch3, uv), temp);			
			}
			if (intensity > part * 3)
			{
				float temp = intensity - part * 3;
				temp *= 4;				
				c.rgb = lerp(tex2D(_Hatch3, uv), 1, temp);
			}
			return c;
		}

		void surf (Input IN, inout SurfaceOutput o) 
		{
			o.Albedo.xy = IN.uv_Hatch0;
			o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
			float3 specGloss = tex2D(_SpecularTex, IN.uv_BumpMap).rgb;
          	o.Specular = specGloss.r * _ShinPower;
          	o.Gloss = specGloss.g * _GlossPower;
		}
		ENDCG
	}
    Fallback "Bumped Specular"
}