decentraland / decentraland/godot-explorer

Hide Avatars Beyond Visibility Distance

Open
#1,190 1 comment 0 reactions 1 assignee Claimed by @rodrigo685 View on GitHub
need definition performance
Dominant language
Rust
Stars
18
Forks
19
Avg merge
4d 2h
Merged PRs (30d)
43

Description

## Parent Issue
Part of #1085 (Rendering Optimizations)

## Summary
Implement distance-based visibility for avatars to avoid rendering players that are too far away to be meaningfully visible. This is a simple visibility toggle, not a LOD (Level of Detail) system.

## Background
Rendering distant avatars consumes significant GPU resources (skinned meshes, multiple materials, accessories) while providing little visual value. A straightforward solution is to hide avatars beyond a configurable distance threshold.

## Implementation Details

### Target File
- `godot/src/decentraland_components/avatar.gd`

### Approach
1. Calculate distance from local player to each avatar every frame (or throttled)
2. Toggle avatar visibility based on distance threshold
3. Use hysteresis to prevent rapid toggling at boundary

### Suggested Implementation
```gdscript
const AVATAR_MAX_DISTANCE := 50.0
const AVATAR_HYSTERESIS := 5.0 # Prevents flickering at boundary

var _is_hidden_by_distance := false

func _process(_delta: float):
var local_player_pos = get_local_player_position()
var distance = global_position.distance_to(local_player_pos)

if _is_hidden_by_distance:
# Show again when closer (with hysteresis)
if distance < AVATAR_MAX_DISTANCE - AVATAR_HYSTERESIS:
_is_hidden_by_distance = false
visible = true
else:
# Hide when too far
if distance > AVATAR_MAX_DISTANCE:
_is_hidden_by_distance = true
visible = false
```

### Considerations
- The local player's own avatar should never be hidden
- Consider using Godot's visibility range instead for GPU-level culling
- Distance check can be throttled (every 0.5s) if performance is a concern

## Expected Impact
- Reduced draw calls in crowded scenes
- Lower GPU load from skinned mesh rendering
- Lower memory bandwidth from avatar textures

## Acceptance Criteria
- [ ] Avatars beyond 50m from local player are hidden
- [ ] Hysteresis prevents flickering at distance boundary
- [ ] Local player avatar is never hidden
- [ ] Distance threshold is configurable (optional)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.