I'm working on a set of custom shaders to override Unity's built-in terrain shaders.
When I add the "alpha" parameter:
...suddenly distant terrain trees start drawing on top of nearby terrain hills — it looks as though the terrain shader is no longer writing to the Z-Buffer.
Any ideas about how I can fix this?
asked May 23 '12 at 01:25 AM
I believe it's a problem specific to Terrain, and can't really be solved.
Transparent objects need to be drawn back to front(?) after everything else. But, Terrain is drawn by a special routine -- the ground is cut up on the fly into squares, each subdivided based on LOD, then drawn probably outward from the player (for efficiency.) It's probably also run 1st, also for efficiency (these are just guesses.)
I tried a transparent shader with only Terrain, maxed out the "use low-res overmap" setting, and got the same occasional completely transparent hill. Transparent terrain didn't even draw correctly with itself, never mind trees.
answered May 23 '12 at 03:13 AM
as you use own shader you just need terrain be rendered before trees and writes it's depth to z-buffer, then on tree-drawings stage z-buffer will hide far trees. just try to decrease queue (in shader parameters) value for terrain shader, to be lower then for tree shader