Right now I'm working on a project that involves applying splatmaps to a generated mesh. I'm trying to use the built in Terrain shaders to achieve this but I'm running into one problem that involves the "FirstPass" and "AddPass" shaders.
It's pretty clear how these shaders are supposed to work. FirstPass is applied and handles 4 textures and a control (splat) texture. If the user applies more than 4 textures, AddPass (which is very similar to FirstPass) is "added" as another shader pass at compile time. AddPass is added an arbitrary amount of times depending on how many textures the user applies to the terrain (4 textures per pass.)
How does the terrain engine achieve this multi-pass effect? The amount of passes required can be determined at compile time so I don't think its impossible... I just don't know where to go from here. I think it may have something to do with the Dependency properties at the bottom of FirstPass, but I'm not sure.
Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Standard-AddPass"
Dependency "BaseMapShader" = "Hidden/TerrainEngine/Splatmap/Standard-Base"
If anyone has any insight on this please let me know. For convenience I've uploaded FirstPass, AddPass, and TerrainEngine.cginc shader files from the Unity archive to pastebin.
Thanks!
To those who are curious, I actually discovered the answer myself. Internally it looks like the Terrain Engine uses a hidden MeshRenderer to include multiple shader passes at once. To achieve this multipass effect, the TerrainEngine adds the FirstPass shader to an instantiated Material and assigns it to the material field in MeshRenderer. In the case of > 4 textures being required, the AddPass shader is then also added to a Material and is appended to the materials field.
Note that MeshRenderer will warn you about using multiple shader passes on a single mesh. This warning can be ignored because splatmapping requires multiple shader passes if more than 4 textures are needed.