Combine two Materials (not textures) as a normal bumped shader

I’ve run into a predicament where I need to plug in materials and combine them as a normal map shader. I’ve written two custom shaders that give me a diffuse and a normal that I can modify for customization of a character but I’d like to combine these into one. However in the list of shader lab input there is no input for this as I can tell. The closest would be “2D” but that doesn’t take materials.

Does anyone have ideas on how to do this?

As far as I know you cant combine materials. Why not just consolidate your two custom shaders into a single one that does what you want?

Sure - that’s a great idea. I’m not there in my learning yet. So far I’m not sure how to make separate sets of passes combine with each other. For instance I have a few passes for diffuse in shaderDiff, one pass in ShaderNml. How do I take those two results and combine them? I imagine it would be similar to the code I see in the default normal map shader in the ‘CGPROGRAM’ section that I’m not familiar with, but don’t know how to connect that.

That would be huge for me if you could shed some light on how that works.

Thanks for the reply

I cant help much without looking at them. So in the pass that you calculate your lighting info for diffuse insert your ShaderNml’s code that calculates normals and applies them along with anything else that makes that script special. You shouldn’t need to add an additional pass.

Sure - here is the shader for the diffuse:

Shader "Composite Shader" {

Properties {
    _SkinColor ("Skin Color", Color) = (1,1,1,1)
    _HairColor ("Hair Color", Color) = (1,1,1,1)
    _EyeColor ("Eye Color", Color) = (1,1,1,1)
    _AccessoryColor ("Accessory Color", Color) = (1,1,1,1)
    _NoseMouth ("Nose Mouth", 2D) = "white" {}
    _Eyes ("Eyes", 2D) = "white" {}
    _EyeMask ("Eye Mask", 2D) = "white" {}
    _Pupils ("Pupils", 2D) = "white" {}
    _Eyebrows ("Eyebrows", 2D) = "white" {}
    _Accessory ("Accessory", 2D) = "white" {}
    _Hair ("Hair", 2D) = "white" {}
}
SubShader {
    Pass {
        Color [_SkinColor]
        SetTexture[_NoseMouth] { combine texture lerp (texture) previous }
        SetTexture[_Eyes] { combine texture lerp (texture) previous }
    }
    Pass {
        Blend SrcAlpha OneMinusSrcAlpha
        SetTexture[_EyeMask] { combine texture }
        SetTexture[_EyeMask]
        SetTexture[_Pupils] {
            constantColor[_EyeColor]
            combine texture * constant, texture * previous
        }
    }
    Pass {
        Blend SrcAlpha OneMinusSrcAlpha
        SetTexture[_Eyebrows] {
            constantColor [_HairColor]
            combine texture * constant
        }
    }
    Pass {
        Blend SrcAlpha OneMinusSrcAlpha
        SetTexture[_Accessory] {
            constantColor [_AccessoryColor]
            combine texture * constant
        }
    }
    Pass {
        Blend SrcAlpha OneMinusSrcAlpha
        SetTexture[_Hair] {
            constantColor [_HairColor]
            combine texture * constant
        }
    }
}

}

And the code for the normal
(Note that I’m getting an error if I try to do more than 4 layers in a pass, so I have a second pass here for the last layer . Also note that each of these normal maps are normals with alpha and are not tagged as normal maps in unity)

Shader "Composite Normal Shader" {

Properties {
    _NmlColor ("Base Normal Color", Color) = (0.5,0.5,1,1)
    _EyesNml ("Eyes", 2D) = "white" {}
    _EyebrowsNml ("Eyebrows", 2D) = "white" {}
    _AccessoryNml ("Accessory", 2D) = "white" {}
    _HairNml ("Hair", 2D) = "white" {}
}
SubShader {
    Pass {
        Color [_NmlColor]
        SetTexture[_EyesNml] { combine texture lerp (texture) previous }
        SetTexture[_EyebrowsNml] { combine texture lerp (texture) previous }
        SetTexture[_AccessoryNml] { combine texture lerp (texture) previous }
    }
    Pass {
        Blend SrcAlpha OneMinusSrcAlpha
        SetTexture[_HairNml] { combine texture }
    }
}

}

And here is the error I get when I have that extra layer in one pass:
offset >= 0 && offset+size <= (m_BufferKeys[idx]>>16) && size > 0

Unfortunately I’m not familiar with texture combiners and can clearly see why you thought to combine two mats or add another pass. I suggest creating a new thread with both these shaders posted.