…and I decided to share it with you guys, 'cause you’re awesome.
So how do you use this thing? After importing the package, create a new material and select the Nature->Terrain->Terrain PBR shader, and assign the material to your terrain. It has two texture slots for a basemap that will be used on far terrain (a texture for the whole terrain) and two values; Basemap Distance is the distance before the basemap will be used and should be set to the same as in your terrain, Fade Length is the fade distance between splatmaps and the basemap.
As for the textures, the alpha channel of the diffuse map should be your metalness value, and the alpha channel of your normalmap should be your smoothness (not rough). This goes for both the basemap in the material, and for any splatmaps you define in the terrain inspector.
Because it uses the alpha channel of the normal map, the normal map textures should NOT be set as normalmaps in the import settings, but as a regular texture. This might cause some compression artifacts in the normals, but hopefully should still be acceptable. If you have the memory budget for it, you could set them to be uncompressed to eliminate this.
If anyone knows how to instead take advantage of the unused channels in a DXT5nm in Unity, or has a better idea how to do this, please let me know.
Enjoy!
EDIT: Turns out I forgot to lerp the albedo to black for metallic textures, so here’s a new version that does that.
EDIT2: Whops, one more small mistake corrected.
EDIT3: Reflections for metallic textures wasn’t working, so I’ve uploaded a new version with the solution from this thread.
I’ve got an idea for you, a bit of a proposal.
99.9% of your terrain textures are going to be non-metal. So what if, instead of metalness, the diffuse slot stored a heightmap? Then you could do heightmap-based blending like so: Game Platforms recent news | Game Developer
Oh that’s really neat, I’ll be sure to look into that, thanks. I’ve been thinking about parallax mapping as well, which would also require a heightmap. I’ve also thought about stealing another channel from the normalmap to use as an ao-map.
But I think for both heightmap blending and parallax mapping, it’d have to be restricted to only 4 splat textures, I can’t see how it could be done with an Add-Pass.
There seems to be a problem with specular reflections on terrain that I can’t figure out, as seen in the screenshot below. To the left is the standard shader, to the right is a specular surface shader I’ve written for testing applied to a quad, and in the middle the same shader applied to a small terrain.
Even if they share the same setup, the terrain never gets the orange tint visible on the quads.
Did you manage to fix the problem yet? We recently updated to Unity 5 for our WW1 shooter(http://www.verdungame.com/) and we use a lot of terrain for the trenches so your shader sounds great to accompany with the rest of the PBR assets. We will post some screenshots after a test. Let me know if you have an updated version ready!
Sorry, I haven’t had time to look at this lately, but my bug is still open. The problem only seems to be with metallic surfaces though, so as long as your terrain textures aren’t metallic (which most terrain textures aren’t) I believe it should work as intended.
No screenshots yet but I made some slight adjustments. Since our terrains(and most terrains) never have metallic values in them I modified the shader to have the smoothness map in the albedo alpha and nothing in the normal. With that extra normal alpha I made a second variation of the shader with a height map in the normal map for a parallax shader. Im thinking about also making that blending version but do not have much time. If anyone else feels like doing it I would love to see it!
Does this work correctly with more than 4 splatmaps? I’m not sure, but I think the height might need to be scaled by the splatsum, so that the maximum height will not increase as more add-passes are used.
The problem with this is that you can’t know in the first pass, what the heighs of the add-passes are, and similarly in the add-pass, you don’t know the height from the first pass.
If you only need 4 splatmaps, you only need the first pass anyway so this is not a problem. Another solution would be to add the heightmaps in separate textures set in the material, this way you could use 8 or 12 heightmaps in 2-3 textures. I’ve also been pondering packing 4 splatmaps in a single splat texture.
I’ll probably look into this myself when I get the time, for me it’s important to be able to use more than 4 splatmaps as this makes it much easier to break up repeating patterns by using several similar textures at different scales.