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:
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:
The result looks like this:
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):
As you can see, the grid is no more visible at the parts with the water texture:
That only happens if the texture is not one of the first 4 textures.
I added some screenshots and sample code to demonstrate the behavior.
– Hovu96_1It 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.
– fffMalzbierThanks fffmalzbier, modifying the add pass shader solved the problem.
– Hovu96_1