diffuse+Specular+Normal+Detail Diffuse+ Detail Normal Shader for 4.x help.

Hi there!

I looked up on google and didn’t get a chance to get my hands on such a thing. I Know that it’s already available and way better with the standard shader in unity 5, however I need this to be compatible with unity 4x as I’m trying to support both legacy and PBR on my environmental packs.

I manage to find something that is almost what I need: diffuse+Specular+Normal+Detail Diffuse Shader however as I’m far from being a shader coder I really can’t figure out how to add this damn Detail Bump map slot…
Here is the code I have :

Shader "Custom/Diffuse Detail Bumped Specular" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
    _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    _Detail ("Detail (RGB)", 2D) = "gray" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
}
SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 400
 
CGPROGRAM
//#pragma target 3.0
#pragma surface surf BlinnPhong
#pragma exclude_renderers flash
sampler2D _MainTex;
sampler2D _Detail;
sampler2D _BumpMap;
fixed4 _Color;
half _Shininess;
struct Input {
    float2 uv_MainTex;
    float2 uv_Detail;
    float2 uv_BumpMap;
};
void surf (Input IN, inout SurfaceOutput o) {
    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    fixed4 norm= tex2D(_BumpMap, IN.uv_BumpMap);
    fixed4 detail=tex2D(_Detail,IN.uv_Detail);
 
    fixed4 c = tex * _Color;
    c.rgb *= detail.rgb*2;
    o.Albedo = c.rgb;
    o.Gloss = tex.a;
    o.Alpha = tex.a * _Color.a;
    o.Specular = _Shininess;
    o.Normal = UnpackNormal(norm);
}
ENDCG
}
Fallback "Diffuse Detail"
}

If someone could be so kind as to get me that slot I would be eternally grateful and praise you as a god… :slight_smile:

Thanks in advance for your help.

Cheers:)

Ok, so, after a good night of sleep I managed to get it almost right. I just need to add a mask to all this so the details are only shown through a texture’s alpha mask ( 0 to 255). 0 = not visible, 255 = fully visible.

here is what I have so far, I created the properties and stuff, the slots are showing in the inspector, But I can’t get the mask working. And here I know it’s out of reach to me unfortunately.

Feel free to use this shader without the mask properties and stuff for your personal / commercial use.

Shader "Custom/Diffuse Detail Bumped Specular" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
    _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
    _DetailMask("Detail Mask(A)",2D) ="gray"{}
    _Detail ("Detail (RGB)", 2D) = "gray" {}
    _DetailBumpMap ("Normalmap", 2D) = "bump" {}
}
SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 400
  
CGPROGRAM
//#pragma target 3.0
#pragma surface surf BlinnPhong
#pragma exclude_renderers flash
sampler2D _MainTex;
sampler2D _Detail;
sampler2D _DetailMask;
sampler2D _BumpMap;
sampler2D _DetailBumpMap;
fixed4 _Color;
half _Shininess;
struct Input {
    float2 uv_MainTex;
    float2 uv_Detail;
    float2 uv_DetailMask;
    float2 uv_BumpMap;
    float2 uv_DetailBumpMap;
};
void surf (Input IN, inout SurfaceOutput o) {
    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    fixed4 norm = tex2D(_BumpMap, IN.uv_BumpMap);
    fixed4 mask = tex2D(_DetailMask, IN.uv_DetailMask);
    fixed4 detail=tex2D(_Detail,IN.uv_Detail);
    fixed4 detailnorm= tex2D(_DetailBumpMap, IN.uv_DetailBumpMap);
  
    fixed4 c = tex * _Color;
    c.rgb *= detail.rgb*2;
    o.Albedo = c.rgb;
    o.Gloss = tex.a;
    o.Alpha = tex.a * _Color.a;
    o.Specular = _Shininess;
    o.Normal = UnpackNormal(norm);
    o.Normal = UnpackNormal(detailnorm);
}
ENDCG
}
Fallback "Diffuse Detail"
}

Again any help with getting this mask to work would be eternally appreciated.

Thanks in advance. :slight_smile:

My bad… Looks like it’s the second normal map slot that is taking over the first one in my last post… Arghhh… trying to figure something out. Still need help… Please :slight_smile:

Ok, got the detail normal map to show up now… But I still need this mask to work… :frowning:
Here is my shader’s code:

Shader "Custom/Diffuse Detail Bumped Specular" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
    _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
    _DetailMask("Detail Mask(A)",2D) ="gray"{}
    _Detail ("Detail (RGB)", 2D) = "gray" {}
    _DetailBumpMap ("Normalmap", 2D) = "bump" {}
}
SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 400
  
CGPROGRAM
//#pragma target 3.0
#pragma surface surf BlinnPhong
#pragma exclude_renderers flash
sampler2D _MainTex;
sampler2D _Detail;
sampler2D _DetailMask;
sampler2D _BumpMap;
sampler2D _DetailBumpMap;
fixed4 _Color;
half _Shininess;
struct Input {
    float2 uv_MainTex;
    float2 uv_Detail;
    float2 uv_DetailMask;
    float2 uv_BumpMap;
    float2 uv_DetailBumpMap;
};
void surf (Input IN, inout SurfaceOutput o) {
    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    fixed4 norm = tex2D(_BumpMap, IN.uv_BumpMap);
    fixed4 mask = tex2D(_DetailMask, IN.uv_DetailMask);
    fixed4 detail=tex2D(_Detail,IN.uv_Detail);
    fixed4 detailnorm= tex2D(_DetailBumpMap, IN.uv_DetailBumpMap);
  
    fixed4 c = tex * _Color;
    fixed4 n = norm;
    c.rgb *= detail.rgb*2;
    n.rgb *= detailnorm.rgb*2;
    o.Albedo = c.rgb;
    o.Gloss = tex.a;
    o.Alpha = tex.a * _Color.a;
    o.Specular = _Shininess;
    o.Normal = UnpackNormal(n);
   
}
ENDCG
}
Fallback "Diffuse Detail"
}

Help anyone?? Would love to get this to work… thanks in advance.