stride3d / stride3d/stride

Sprite disappears with non standard Center

Open
#3,227 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
7.8k
Forks
1.2k
Avg merge
2d 17h
Merged PRs (30d)
49

Description

Release Type: GitHub

Version: master

Platform(s): Reproduced on Windows; not platform-specific

Describe the bug
SpriteComponent's bounding box, used for frustum culling, does not account for a non-default Sprite.Center (pivot offset). When a sprite's pivot is moved away from the texture's geometric center — for example to align the sprite's bottom edge with the entity's position so it appears to stand on the ground — the bounding box used for culling stays centered on the entity's world position instead of following the visual offset of the sprite.
As a result, the sprite is culled (disappears) as soon as the entity's position, not the sprite's actual visible edge, crosses the frustum boundary. This causes the sprite to vanish from view while a significant portion of it (up to roughly half, depending on the pivot offset) is still visually on screen.As a result, the sprite is culled (disappears) as soon as the entity's position, not the sprite's actual visible edge, crosses the frustum boundary. This causes the sprite to vanish from view while a significant portion of it (up to roughly half, depending on the pivot offset) is still visually on screen.

To Reproduce

  1. Import a texture, e.g. 1920x1080 pixels.
  2. Add a SpriteComponent to an entity using this texture, with CenterFromMiddle enabled.
  3. Set Center to (0, 540) — this offsets the pivot down by half the texture height, moving the sprite's pivot to its bottom edge.
  4. Position the entity in the scene so the sprite sits at the desired location (e.g. on the ground, Position.Y set so the bottom of the sprite touches the floor).
  5. In running game, move the camera or the entity so the sprite moves toward the bottom edge of the screen.
  6. Observe that the sprite disappears entirely as soon as the entity's position (i.e. the midpoint of the sprite, before the Center offset) crosses the bottom of the screen — while the upper half of the sprite is still visually within the camera's view.

Expected behavior

The sprite should remain visible and only be culled once it is actually fully outside the camera's frustum.

Screenshots

https://github.com/user-attachments/assets/ac098014-0385-4350-bd03-8c91481ce247

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SpriteComponent and trace how its bounding box is calculated for frustum culling, then follow how Sprite.Center affects the sprite's visual bounds. Reproduce the reported setup with CenterFromMiddle and Center set to (0, 540); done means the sprite remains visible until its actual visible bounds leave the camera frustum.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.