How do I get the associated colors of terrain layers used in splat-maps?

Where does Unity store the data of what colors to use for the splat mat? To be clear, I'm not looking for the splat mat texture, I already know how to get that.

More info about why I need this, you don't have to read:
I have a splat mat system for associating color with footstep sounds, as you walk, it gets the color of the pixel found with the hit's UV. It selects the closest color in the associations hash map, and returns the associated sound.
It works good in situations where colors aren't blending like models where I can do all the texturing by hand... However I have to do things differently with terrains. Since painting is handled by the editor, I have to get the splat mat that's generated from the terrain. This causes an issue because when associations are generated I get EVERY unique color that's blended from more than 1 layer, creating a long unnecessary list.

Image describing what I'm facing, and what looking for:

TLDR: If Unity stores the color/layer association map, where can I find it? If Unity has a procedual system where the engine goes down a list of default colors for each new layer, where do I find that list?

I believe, TerranData.GetAlphamaps() is what you need. There are separated RGBA values for every splat map.

1 Like

[quote=“akareactor”, post:2, topic: 867615]
I believe, TerranData.GetAlphamaps() is what you need. There are separated RGBA values for every splat map.
[/quote]
I did already mention in my post I knew that method, but I guess I didn’t actually understand it. But you still are right because unity doesn’t cache a list of associated colors like I thought.
This is good, because like how you say “There are separated RGBA values for every splat map.” means that you could have terrain textures 4 times the integer limit (not factoring how much RAM that would take.)
I had to write my own way to calculate that and use a Dictionary to create associates with the splat layer and RGBA value.

Although I wish there was a baked-in way to get associations, would have saved me a headache. At the very least there should be documentation explaining how terrain splatmats work.

[quote=“HunterAhlquist”, post:3, topic: 867615]
I did already mention in my post I knew that method, but I guess I didn’t actually understand it. But you still are right because unity doesn’t cache a list of associated colors like I thought.
This is good, because like how you say “There are separated RGBA values for every splat map.” means that you could have terrain textures 4 times the integer limit (not factoring how much RAM that would take.)
I had to write my own way to calculate that and use a Dictionary to create associates with the splat layer and RGBA value.

Although I wish there was a baked-in way to get associations, would have saved me a headache. At the very least there should be documentation explaining how terrain splatmats work.
[/quote]

Texture splatting is a common technique

Every texture layer is linked to one of R, G, B or A values in 32-bit texture map. If there a zero 8-bit value, no texture displaying, and vice versa. This mean, Unity using only grayscale 8-bit color for specific texture layer.
Thus, you should go two steps:

  1. maps[,] = t.terrainData.GetAlphamaps
  2. process layer you need with alphamapLayers = maps.GetLength(2); // same as t.terrainData.alphamapLayers

So, you can compare values from layers and select appropriate value to generate specific footstep sound. If I understood your problem correctly, of course :)))