DiffuseLight function

What exactly does DiffuseLight function do?

I tried to replace this line

return DiffuseLight( i.lightDir, i.normal, texcol, LIGHT_ATTENUATION(i));

with this one

return texcol*LIGHT_ATTENUATION(i)*dot(i.lightDir,i.normal);

but results are nothing like I expected.

This is the DiffuseLight() function, from UnityCG.cginc. You can find this file in your Unity.app bundle under CGIncludes, or some equivalent in the Windows Unity install folder.

inline half4 DiffuseLight( half3 lightDir, half3 normal, half4 color, half atten )
{
	#ifndef USING_DIRECTIONAL_LIGHT
	lightDir = normalize(lightDir);
	#endif
	
	half diffuse = dot( normal, lightDir );
	
	half4 c;
	c.rgb = color.rgb * _ModelLightColor0.rgb * (diffuse * atten * 2);
	c.a = 0; // diffuse passes by default don't contribute to overbright
	return c;
}

Your replacement is similar, but incomplete. It’s missing the light colour and the doubling. If you were using a directional light, the lack of normalization might have caused trouble.

You must normalize your vectors before doing a dot product if you wish to retrieve the arc cosine value required for lambertian (and other) diffuse calculations.

In most cases, the normal is already very close to unit length by the time you get to the fragment shader. The light direction is already normalized in the case of directional lights, and gets normalized in DiffuseLight() when it is not a directional light.