AO maps

Has anyone written a shader that would allow an AO map to be placed on top of a diffuse map. You can do this in Blender using multiple UV maps. I have been baking the textures to one 2048x2048 map, but this reduces quality in some cases. Thanks for any help.

I suppose someone has… it’s not that hard. I’m quite interested in how separating the texture into AO and diffuse maps can possibly hurt the quality, though.

Say, I use a tiled (512x512) wood texture to colour a desk, and this texture is repeated over the surface. Then I make an AO map, if they are seperate the wood texture does not have to be reduced to the AO map.
Another way of looking at it: A tiled texture can be repeated over an object many time, i.e. 8 copies of the same image can cover the desk. But an AO map is not tiled, and it can not be repeated, so if you combine the two, the 8 wood images must be reduced to fit on to the 2048x2048 AO map.

Hopefully you can understand that, as I am quite awful at explaining things

Using an extra texture to sample the AO from seems a little wasteful. You could pack it into the alpha channel of either the diffuse or the normal map (requiring you to use a custom UnpackNormal() method).
But here you go with an example:

Shader "Custom/AO"
{
	Properties
	{
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_AO ("AO", 2D) = "white" {}
	}
	
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf Lambert

		sampler2D _MainTex;
		sampler2D _AO;

		struct Input
		{
			float2 uv_MainTex;
			float2 uv2_AO;
		};

		void surf (Input IN, inout SurfaceOutput o)
		{
			half4 c = tex2D (_MainTex, IN.uv_MainTex);
			c.rgb *= tex2D (_AO, IN.uv2_AO).r;
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

It uses the secondary UV set of the mesh. That’s the one required for lightmapping, too. So UVs in that set have to be unique anyway.