Correct for 2.5D sprite clipping with shader depth offset?

I’ve got 2D sprites in a 3D game that are set to always face the camera. The problem is, as the camera is angled, the top of the sprite can pass through walls. To correct for this, I’ve set the sprite’s shader Offset property to something like -1000 for the units variable which helps, but a portion of the head of the sprite still passes through walls. Anything further than that (ie -2000), and I reach a point of diminishing returns as the bottom half of the sprite starts to render above foreground objects while the head does not go through walls.

So to clarify, the offset is

Offset 0, -1000

I’ve tried messing around with the first variable (offset factor), but it doesn’t seem to yield any results as best as I can tell, so I don’t think I quite understand what it does.

You can see the bottom half of the sprite rendering above foreground elements in this image with the units set to -2000

And here it is with the head being cropped with the units set to -1000.

Is there a way to like angle the offset of the depth order? Is this something I’d have to get into writing into a vertex shader? Currently I’m just using the unity Sprite Diffuse shader with the offset line added (which is a simple lambertian subsurf shader, so that… complicates things), and the camera facing is done through a C# script, not through the shader.

Ok i know I’m very late on this. But i had the same type of problem making a 2.5D game. I’m leaving this reply mainly in case someone has this problem and needs help.


The camera renders the sprites by what sprite objects pivot is closest to the camera. This creates the clipping.
You can fix it by going in to “edit → project settings → Graphics” then close to the top there is “Camera Settings”. Set “Transparency Sort Mode” to “Custom Axis” and adjust the axis to what you need.