Hello guys.
First of all, for @Magnus Wolffelt 's questions:
Yes it is possible to write your own shaders for Terrain. It is a bit complicated but not too much. Basically you should base it on an existing Terrain shader.
There is an article here which is very helpfull:
Custom Unity Terrain Material Shaders.
Also check on the wiki, there is an example tweaked shader that allows you to paint transparent textures on your terrain to make portions…well transparent.
http://wiki.unity3d.com/index.php/TerrainTransparency
Would it be possible to write a terrain shader that, instead of blending textures based on the splatmap, blended materials based on the splatmap?
Well this one I don’t know, @n8 must be correct that it is not possible but it would be interesting if it was. If anyone knows better it would be great to post an answer here 
As for what @Dagan asked:
I was Looking for the answer to this myself and couldn’t find much in my searches.
After some testing and trial and error (lots of errors) I finally found something that actually works.
There is a property on Terrain called materialTemplate. It is actually missing form the Reference Documentation on the site, don’t know why.
So if you have a material called “myMaterial” that uses your own shader you can do something like this:
public Material referencedMaterial;
public Terrain referencedTerrain;
and assign “myMaterial” to “Referenced Material” slot of your script (in the inspector).
Then later in your code when you want to change your terrain’s material
just do:
referencedTerrain.materialTemplate = referencedMaterial;
Hope this helps you, it worked for me 
NOTE: This works for Unity 4 Pro/Free. Haven’t tried in older versions.