shaderlab offset parameter explanation?

I was wondering if someone could explain to me how the Offset parameter in Shaderlab works. I read the documentation but my brain refuses to make sense out of it. What I want to do: I have several (transparent) sprites that should be drawn in correct order. The problem is that if two of the sprite are in the same x,y position but on different z positions I assume that the one closer to the camera (which looks in z-direction) will be drawn over the other one. However this seems to be only true if they are at ~1 unit apart. If the distance in z-direction is smaller (e.g 0.5) the behaviour seems to be random (meaning that the order seems to be affected by some other parameter as the distance to camera alone). I think that has something to do with depth and z-buffer (maybe the precision of the latter?) and thought i could solve that with Shaderlab's Offset parameter, but I have no clue how it is supposed to work. Any idea or documentation to read?

1 Answer

1

http://www.youtube.com/watch?v=f7zDKlsyu6s

http://www.youtube.com/watch?v=MlLvQxZv3h4

But in your case, it sounds like your problems could be solved simply by pushing the near clip plane farther away, and the far clip plane closer. The closer those two are to each other, the better. The depth buffer isn't linear, either. You'll get better results if the objects are closer to the near clip plane, all else being equal.

Ah cool will try that. I remembered somewhere in the back of my head that the depth buffer precision isn't linear, but thought as my objects are close to the camera this wouldn't be a problem. Getting more precision by reducing the depth of the frustum is the clever bit I completely overlooked... ;)

–

Hm, I already tried to reduce the depth of the frustum. Didn't remember it. But that didn't help. Even with the frustum being only 20 units long and the sprites 5units in front of the camera I have to separate them by 1 unit to get the correct order. Could the orthographic camera cause that problem?

–

No. It sounds like your problem is based on rendering order. http://www.youtube.com/watch?v=N9IbcGpOcIg I recommend moving them to different queues.

–