+4
Under review
Support for Terrain dependency shaders
Currently, if you use a shader with Shader Forge, terrain patches will turn black when it switches to the low resolution basemap (maximum range 2k). This is most likely due to undefined dependency shaders inside the shader.
As seen here (blog post), adding these lines to the shader:
Dependency "AddPassShader" = "Custom/ToonTerrainAddPass"
Dependency "BaseMapShader" = "Toon/Lighted Outline"
Defines those shaders (AddPassShader may or may not be required). Adding some kind of support for these, would make Shader Forge fully compatible with the current terrain system. Pretty much everything works except for this.
As seen here (blog post), adding these lines to the shader:
Dependency "AddPassShader" = "Custom/ToonTerrainAddPass"
Dependency "BaseMapShader" = "Toon/Lighted Outline"
Defines those shaders (AddPassShader may or may not be required). Adding some kind of support for these, would make Shader Forge fully compatible with the current terrain system. Pretty much everything works except for this.
Customer support service by UserEcho
Just use channel blend node and put the splat map on as the mask texture.
This post isn't about that however. If you read my first post, you'll see that I've mentioned Unity Terrain uses another shader for the low res basemap that it displays after a certain range. That range is called basemap distance, and only goes up to 2000 units max. Once you reach that range, if you don't have a dependency shader setup, terrain goes black.
This idea is about giving the ShaderForge the necessary tools, so that we can define our own dependency shaders somehow.
After getting frustrated with ready made terrain shader options, once again I tried to figure out how to do it with shader forge. This time, I think I succeeded.
TL;DR
You need to use the naming convention seen in the default shaders, you need to add a Dependency line at the end of the shader for correctly shading BaseMap, and you need to setup a SplatCount tag.
Long version:
You need to setup 2 shaders. FirstPass, and BaseMap. FirstPass is the normal shader you'll see and use. BaseMap is specifically for the low res version of the terrain. Basically, terrain fades to BaseMap after a certain distance for performance reasons. This distance is setup from terrain script inspector.
Textures and normal maps need to be named through Splat0...Splat3 and Normal0...Normal3, your masking texture must be named Control, you also need another texture slot called MainTex, and a color property called, Color.
Finally, you'll need to add SplatCount tag and the dependency line to the Firstpass shader, with a text editor.
Here's screenshots of my basic setup.
FirstPass diffuse chain
http://i.imgur.com/NIvzsUw.png
FirstPass normal chain
http://i.imgur.com/WUBzNCU.png
BaseMap shader basic setup
http://i.imgur.com/yDzicT3.png
Shader tags
http://i.imgur.com/P7VHe7f.png
Dependency setup
http://imgur.com/iR6zllv
The gotcha here is, the dependency shader name is the one you set from Shader Forge. First few times I've tried, I always thought it was a folder path. You can also access the Unity properties like Splat1, Control and so on from BaseMap shader.
I haven't tried more complex shaders with these, but this setup is basically all you need for using terrains with 4 textures. If you need more than 4, you need to create an AddPass shader, which is basically the same as the FirstPass shaders, but you don't need to edit it by hand, you just need to define it as a dependency shader, exactly the same way as BaseMap shader is defined.
Basically, Shader Forge just needs to add:
1) A way to define a BaseMap shader. This is literally just a string of the shader name.
2) A way to add SplatCount tag.
After that, there won't be any need to edit the shaders by hand to just add 2 lines.
Edit: Just realized I haven't added a working pic of it all. Here's a pic:
http://i.imgur.com/7ly8C4z.png
After doing all of the above, you just need to plug in an empty material of your shader, and that is it. As you can see, BaseMap shader is working, no black terrain tiles, even though BaseMap distance is at 0.
Here's my chain: http://i.imgur.com/pBPdeMA.jpg
And here's the terrain: http://i.imgur.com/KCJIjqJ.png
No normals. :(
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
With:
float3 normalDirection = normalize( normalLocal )); // Perturbed normals
And the normal maps should work.
i.e., replace
tex2D(_Normal0,TRANSFORM_TEX(node_#.rg, _Normal0))).rgb
with
tex2D(_Normal0,TRANSFORM_TEX(node_#.rg, _Splat0))).rgb
Could you put up a tutorial on the Wiki, so others can find out how to do it?