How to modify output color of built-in Terrain Shader with more than 4 Splat Textures?

I changed the Built-in Sureface Shader to modify the output color in certain circumstances. In fact I implemented Fog of War for parts of the terrain that isn’t visible by the player.

That works great as long as the terrain is using 4 splat textures. In case it’s using more than 4 textures, the color modification is only applied to the first 4 textures. The other textures are rendered normally, as though nothing had happened.

I tried to modify the color using the actual surface function (SurfaceOutput.Albedo) and tried modify it using the (finalcolor) function. Both worked for the first 4 textures. But for the other textures it doesn’t work.

Any Ideas?

Let me show you an example. This is a Unity terrain using a custom shader:
alt text

I added to the built-in terrain shader a finalcolor:grid function to render the hexes:

void grid (Input IN, SurfaceOutput o, inout fixed4 col) {
	fixed4 grid=tex2D (_TerrainGrid, _TerrainGridOffset+IN.uv_TerrainGrid*_TerrainGridScale) * _GridVisibility;
	col += grid * col * 2.0f; 
}

When I use the terrain inspector to paint another texture to the terrain. For now, the terrain only contains 3 splat textures:
alt text

The result looks like this:
alt text

As you can see, the grid is still visible at the changed parts.

Then I added some other splat textures and selected the last one (in this case a water texture):
alt text

As you can see, the grid is no more visible at the parts with the water texture:
alt text

That only happens if the texture is not one of the first 4 textures.

As far as i know you can only have 4 textures per splatmap, you may however have more than one splatmap. see this thread

i don’t know however if having more splatmaps affects your shader, but maybe this info helps you to figure it out

fffmalzbier solved the problem, his answer is:

It looks like Unity is using 2 different shader for the terrain. FirstPass.shader and AddPass.shader.

You need to modify both of thous shader if you like to use more then 1 Splat-map / more then 4 textures.

Thanks!