For Material Blending I already have a solution. I think I described it once in the Crafterria thread.
You know you can mix up to 4 materials per vertex.
What if we can, however, have different set of materials
per triangle?
This is what I am doing in my projects.
4 Materials per triangle.Each triangle need to have its own ID. The ID must be same for all vertices by the triangle.
This ID is used to lookup actual Material Indices from a lookup texture that is using integer format!
I've ended doing this because if Unity's limitations, however, you can basically encode 4 ids in a UV4 4-vector channel, however a Vertex Id and a lookup texture gives you basically A LOT of vertex attributes.
E.g.
Triangle 1:
v1: pos, normal, tangent, color(blend factors RGBA), whatnot, uv2(1,2,5,6)
v2: pos, normal, tangent, color(blend factors RGBA), whatnot, uv2(1,2,5,6)
v3: pos, normal, tangent, color(blend factors RGBA), whatnot, uv2(1,2,5,6)
Then, in the pixel shader, you do your usual texture splatting and triplanar texturing,
but use the IDs that will NOT be interpolated to select what texture to use.
For best looking results like these in Crafterria, you should use Texture Array (sometimes they call them Array Samplers) - You load all your texture into a texture array with mipmaps, an you are ready to go. Just don't mistake a Texture Array with 3D Texture - with Textuyre Arrays you get correct mipmaps, they are basically wad of images but with third dimension to access the specific image.
Of course such algorithm requires some preparations, and you will need to calculate your splatting ids on the CPU. And in case more than 5 materials want to contribute to single vertex.... Ignore the least contributor completely and use just the top 4 ranked contributing materials. Trilinear interpolation code is needed for this.
This screenshot shows the idea. Notice that most of triangles have contributions set to (1,0,0,0) and only the Red channel contribution is used, however, the per-triangle-id table points to different texture id.
In places where blending is needed, Red, Green and even Blue and Alpha channels are used to implement the splatting as and if needed.
Attachment:
idea.jpg [ 202.85 KiB | Viewed 11400 times ]