#How to make billboarded AnimatedSprite3D appear through floor, but not through walls

1 messages · Page 1 of 1 (latest)

neat field
#

In a pure 2D top-down game, this walk cycle is totally fine because the sprite is always drawn “on top” of the world. You see the whole frame, including the foot swinging “down” in screen space.

In my setup, the character is a billboarded AnimatedSprite3D in a 3D scene with an orthographic, 45-degree angle camera. The billboard stays upright and faces the camera, so it looks like normal top-down in the camera view, but it still occupies real 3D space: the sprite is a vertical quad sitting on the ground plane.

The issue is that this walk animation uses “south/down on the screen” motion (the foot swings lower in the frame). In 3D, that “down in the sprite” corresponds to geometry that extends below the ground plane. So when the foot goes “below” the character’s baseline, that part of the sprite ends up behind the floor in the depth buffer and gets clipped/occluded by the floor mesh (shown by the green/red boundary in the GIF).

neat field
#

I came up with a shadier-oriented concept, but I also don't know how feasible this is.

Render the sprite “fully” (so the floor doesn’t clip it), but then for each sprite pixel, decide whether to discard it based on what’s between camera and sprite along the ray cast by the camera to decide what pixel to render. Conceptually, if the ray only hits polygons whose normals are visible to the camera, keep the pixel. If it hits at least one polygon whose normal faces AWAY from the camera, then discard it. This would effectively make any solid walls occlude the sprite.

neat field
#

I was just informed of the Stencil feature in 4.6. I just updated the PR version of the engine I'm on to 4.6, so this option is accessible now.