x


Shader with "alpha" parameter no longer writes to Z-Buffer

I'm working on a set of custom shaders to override Unity's built-in terrain shaders.

When I add the "alpha" parameter:

#pragma surface surf Lambert alpha

...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.

I have ZWrite On set for my terrain Lightmap-FirstPass shader, and ZTest Less set for my BillboardTree shader.

Any ideas about how I can fix this?

alt text

more ▼

asked May 23 '12 at 01:25 AM

smokris gravatar image

smokris
366 5 6 14

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered May 23 '12 at 03:13 AM

Owen Reynolds gravatar image

Owen Reynolds
12.2k 1 7 46

Interesting. Thanks, Owen. I would have assumed that, even if the terrain is being drawn by a special segmented geometry renderer, it would still obey shader parameters as usual — but it looks like some internal magic is going on here.

May 23 '12 at 03:24 AM smokris

I imagine the chunks could be created and then sent for general rendering. But, for example, each chunk of the same LOD has the same Triangle array. So, the terrain renderer can save time by only sending that once.

May 23 '12 at 01:22 PM Owen Reynolds
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Jul 14 '12 at 12:16 PM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1740
x1521
x340
x13

asked: May 23 '12 at 01:25 AM

Seen: 820 times

Last Updated: Jul 14 '12 at 12:17 PM