2 Normal map shader + lightmapping

Hi all,
i write a shader that take in consideration 2 different normal map, one for general bumping and the other for the detail.
If i try to lightmap an object with my shader only the information from the first normal map is baked.
From what i know lightmap take in consideration only normal map called _Bumpmap.
But what if i need to use more normal map?

Thanks

inline fixed3 combineNormalMaps (fixed3 base, fixed3 detail) {
	base += fixed3(0, 0, 1);
	detail *= fixed3(-1, -1, 1);
	return base * dot(base, detail) / base.z - detail;
}

This function will take in two normal maps and return a value with both of them combined.

e.g.

fixed3 baseNormal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
fixed3 detailNormal = UnpackNormal(tex2D(_BumpMapDetail, IN.uv_BumpMapDetail));
fixed3 combinedNormal = combineNormalMaps(baseNormal, detailNormal);
1 Like

Hi,
thanks for your answer.
But your solution work with lightmap?
Because in my shader i’m already combining the 2 normal map in this way :

float3 normalMap = UnpackNormal(tex2D(_NormalTex, IN.uv_NormalTex));
float3 detailNormal = UnpackNormal(tex2D(_NormalTexDetail, IN.uv_NormalTexDetail));
fixed3 finalNormals = float3(normalMap.x + detailNormal.x,
										 normalMap.y + detailNormal.y,
										 normalMap.z + detailNormal.z);

but if i use the lightmap functionality only the first normal is taken into account, otherwise the shader work well.

It’ll likely not, no. I think it’ll use whatever texture is in the _BumpMap slot.

And the way you’re doing it isn’t the correct way to combine two normal maps together.

Here’s an Editor script that will combined two normal maps and spit the result out to a new texture;

Really thanks for the help,i’ll try this solution.

:rage: