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 ![]()
Any help would appreciated ![]()