I hope that I picked the right thread here and that my question is not redundant.
My question is weather it is possible to build custom Terrain shaders that work with unitys Terrain system using the Shader Graph Tool. I searched around the internet for a while now and couldnt really find positive answers for this.
I would like to implement some height based blending and triplanar mapping for my terrain AND use unitys terrain system.
If it is not possible with Shader Graph, why is it not ? What are the things to concider with terrain shaders ?
i think you can use shader graph to generate terrain-compatiable shaders, espcially by using custom function nodes in shader graph… you need to check up/ Explore functions used in unity’s shaders libraries so you can call them in your shader function and read that data so you can blend/apply your textures in your shader graph shader…
you need to see how unity terrain shaders work, apparently they are using splatmaps, so you need to know which functions are being called obtain splatmaps then replicate that effect in shader graph then add your own stuff as well…
I would too like this. Waaay too complicated creating terrain shaders with ShaderGraph. I just want a triplanar terrain shader, and can’t get it to work
The best option is to buy a high quality terrain asset and let a great developer fiddle with the SRP mess or deal yourself with the hardcoded Unity shaders.
Well, in Unity, many things are not achievable out of the box (terrain, water, foliage, etc.) or are very limited, not performent or not good looking. You need either to buy a lot of good asset from the store or have a very good graphic programmer on your side. That’s my experience so far. Unless you are an allround talent. Nevertheless custom solutions are in most cases needed and this is not easy.
True. I just wish the URP were documented a bit more thoroughly, digging into the repo often feels like shooting into the dark. For anyone interested, the URP Terrain shaders are here
Thank you for the example mate, been meaning to give this a shot and with an example i’ll certainly attempt it aswell.
Edit; Can make this work fine with URP but attempting conversion to HDRP even after four hours of digging through the TerrainLit shaders it turns into a vertex monster.
I downloaded your custom terrain shader Juvennn.
Whenever I apply it to a terrain I get the error “Cant use material with shaders which need tangent geometry on terrain”
Which is the same error I was getting with my own custom shader.
Any ideas how to resolve this ? Otherwise it isn’t really usable.
In my experience, draw instancing is in terrain settings is usually responsible for the vertex monster. My PC is a potato and I get 2 frames a second whether I’m draw instancing or not. But in my PCs defense, I was running a scene with about 2 million tree prefabs. Yes occlusion was active.
Convert the normals to object/worldspace.
Also note that particular error will show up with a shadergraph shader regardless of whether you fetch any tangent data or not.
So make sure you arent using tangent space for anything and output normals in object or worldspace.
As an update, you can in fact actually use tangents on the terrain despite what the warning says which really just presumes that the shader you use for the terrain doesn’t use them, you can suppress that warning somewhere but i cant remember where now.
And it is also possible to make a shader graph for HDRP Terrain use but it is quite a bit more involved than just copying or updating Juvennn’s initial work which was a very good starting point to terrain shaders but there’s quite a bit more to it if you want to recreate the full functionality of a decent terrain shader.
However as a bonus effect if you make your own graph however you can also support lots of features that Unity TerrainLit does Not support, any number of lights your SRP supports, vertex animation, tangent space normals and special effects masks and the like.
Or the infamous TODO: Triplanar / POM comments that remain in the Unity shaders since who knows how long ago
Update: For a project I have been working on we used this triplanar shader, which our artists created. They said its using splat maps, and as such only supports up to 4 different textures. Not sure if this ended up working 100%, but this might be a good starting point for anyone working with URP:
So instead of painting textures with the terrain brush tool you manually create splatmaps and feed them in later? Oh boy still not a great solution. Like you said URP is a mess. Thanks for your input. I’m currently at the same roadblock.
That sounds like a horrible workflow and utterly unnecessary if so o.0, why not just apply the stuff to the terrain itself.
Only real downside atleast in HDRP is that one can’t use instancing with a ShaderGraph shader. One could propably fix that by injecting the requisite matrices with an include but i haven’t seen the need yet.
For URP it was ten times easier to get it working.
Had a peek at that, just be sure to not include mistakes from that (too many unique sampler states on most things for example will result in a failed compilation/crash on hardware that URP projects often target, there’s a limit to the number of them you can use) and it’ll work well enough yup