Skip to content

Ortho tint: alpha-masked silhouette rendering with batching - #86248

Merged
GuardianDll merged 1 commit into
CleverRaven:masterfrom
dobbry-vechur:fix/tint-overlay-ortho
Apr 5, 2026
Merged

GuardianDll merged 1 commit into
CleverRaven:masterfrom
dobbry-vechur:fix/tint-overlay-ortho

Conversation

@dobbry-vechur

@dobbry-vechur dobbry-vechur commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Interface "Pixel-accurate colored light tint overlay for ortho mode"

Purpose of change

The colored light tint overlay (beacons, colored fields, dawn/dusk) draws a flat rect over each tinted tile. In ortho mode with tall sprites (32x64 characters, multi-layer gear), this shows color seams at the tile boundary and rectangular halos around transparent padding.

Describe the solution

Hybrid tint path for ortho. Simple tiles whose sprites fit inside the tile footprint still get a cheap colored rect. Complex tiles with oversized sprites use a per-pixel silhouette mask instead: recorded sprites are replayed as white silhouettes (RGB=255, original alpha) into a scratch render target, then composited back with the tint color.

  • Silhouette textures (6th color filter variant) and per-sprite opaque bounding boxes computed once at tileset load
  • Tint eligibility precomputed in a per-tile prepass so the overlay iterates only eligible tiles
  • Contiguous same-color complex tiles batched into one mask/composite with a union area growth cap
  • small_literal_vector<4> for per-tile sprite records avoids heap allocation in the common case

Iso mode keeps the existing flat rect tint unchanged.

Describe alternatives you've considered

Proper fix would be to move to SDL3 shaders, but that's a larger effort. This works within SDL2's render target API.

Testing

Unit tests for the new data structures. Perf profiled near beacons, no measurable regression.

Before:
image

After:
image

Additional context

Only addresses ortho mode. Iso has its own set of issues (diamond footprint mismatch) that need separate treatment.

@github-actions github-actions Bot added Code: Tests Measurement, self-control, statistics, balancing. [C++] Changes (can be) made in C++. Previously named `Code` Info / User Interface Game - player communication, menus, etc. astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Apr 4, 2026
@dobbry-vechur
dobbry-vechur force-pushed the fix/tint-overlay-ortho branch 2 times, most recently from 7c66c3b to dd65493 Compare April 5, 2026 00:22
@github-actions github-actions Bot removed the astyled astyled PR, label is assigned by github actions label Apr 5, 2026
@dobbry-vechur
dobbry-vechur force-pushed the fix/tint-overlay-ortho branch from dd65493 to 1ae2b78 Compare April 5, 2026 00:26
@github-actions github-actions Bot added the astyled astyled PR, label is assigned by github actions label Apr 5, 2026
@dobbry-vechur
dobbry-vechur force-pushed the fix/tint-overlay-ortho branch from 1ae2b78 to 4808c1b Compare April 5, 2026 00:52
Comment thread tests/tint_overlay_test.cpp Resolved
The colored light tint overlay used a fixed tile_width x tile_height
rect for all tiles. In ortho mode, tall sprites (32x64 characters with
gear) showed a color seam at the tile boundary, and transparent sprite
padding got tinted as a rectangular halo.

Replace the ortho rect tint with a hybrid path:
- Simple tiles (sprites fit inside tile footprint) keep the cheap rect.
- Complex tiles (oversized sprites) use per-pixel silhouette masking:
  record sprites during the layer loop, replay them as white silhouettes
  into a scratch render target, composite back with the tint color.

Infrastructure:
- Silhouette texture variant (6th color filter, RGB=255 + original alpha)
  computed once at tileset load alongside existing five filters.
- Per-sprite opaque_rect (tightest non-transparent bounding box) computed
  at load for accurate bounds tracking, excluding transparent padding.
- Precomputed tint eligibility and color in a per-tile prepass so the
  overlay pass skips re-scanning.
- Contiguous same-color complex tiles batched into a single mask/composite
  operation with a union area growth cap (2x) to limit waste.
- small_literal_vector<4> for tint_sprites avoids heap allocation.
- shared_ptr<SDL_Texture> overloads in sdl_wrappers for silhouette atlas.

Iso mode keeps the existing flat rect tint unchanged.
@dobbry-vechur
dobbry-vechur force-pushed the fix/tint-overlay-ortho branch from 4808c1b to 88335cb Compare April 5, 2026 01:18
@dobbry-vechur

Copy link
Copy Markdown
Contributor Author

/retry

@github-actions

github-actions Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

@dobbry-vechur

Copy link
Copy Markdown
Contributor Author

/retry

@github-actions

github-actions Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

@GuardianDll

Copy link
Copy Markdown
Member

to my knowledge, moving to sld3 is quite desired

@GuardianDll
GuardianDll merged commit 41b36b7 into CleverRaven:master Apr 5, 2026
37 of 52 checks passed
@dobbry-vechur
dobbry-vechur deleted the fix/tint-overlay-ortho branch May 25, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

astyled astyled PR, label is assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. Info / User Interface Game - player communication, menus, etc. json-styled JSON lint passed, label assigned by github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants