Skip to content

extend the per entity ref scaling to vehicles#5006

Open
Zephkek wants to merge 2 commits into
multitheftauto:masterfrom
Zephkek:fix/vehicle-alpharef-scaling
Open

extend the per entity ref scaling to vehicles#5006
Zephkek wants to merge 2 commits into
multitheftauto:masterfrom
Zephkek:fix/vehicle-alpharef-scaling

Conversation

@Zephkek

@Zephkek Zephkek commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

builds on #5005. @Dryxio asked whether setElementAlpha on a boat or train goes fully invisible. it does, and it did on 1.6 and every release before it: cars and bikes set ALPHAREF 1 inside their own Render fns, boats and trains never touch it, so at stock refs the hull drops below the test once alpha goes under ~100. run vehicles through the same scaled ref as objects. cars and bikes are unaffected, their own ref write lands after ours and wins. boats and trains get working setElementAlpha out of it.

Test plan

  1. setElementAlpha on a boat or train at any value, hull renders translucent instead of vanishing
  2. cars and bikes unchanged

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

Zephkek added 2 commits July 4, 2026 20:13
GTA runs the world passes with ALPHAREF 140 (CRenderer::RenderEverythingBarRoads)
and 100 (CVisibilityPlugins::RenderEntity), alpha func GREATER. multitheftauto#4751 patched both
to 0 for multitheftauto#425, multitheftauto#4807 made them 1 and added a D3D level dual pass that overrides
the alpha test for every blended z-writing draw. between the two, every low alpha
gradient pixel vanilla throws away started rendering and the LV neon lines turned
into smeared bands. 1.6 has neither change, so it renders like vanilla.

multitheftauto#4996 restored the RenderEntity ref and left the world pass at 1. its fallback
reads materials[0].color.a at RenderOneNonRoad entry, but MTA multiplies element
alpha into the materials later, inside the CObject::Render hook, and undoes it
after the call. the check reads base values, never sees setElementAlpha, fires on
stock models with low material alpha instead, and never restores what it writes.
none of it matters for blended draws anyway, the dual pass swaps the test for
GREATEREQUAL 128 / LESS 128 and the sub-ref gradient still renders in pass 2.

so:

- the MemPuts are gone, both refs stay stock
- the dual pass only runs when the game has no meaningful alpha test of its own
  (ref at the DefinedState baseline of 2 or below). an active test at 100/140
  already clips transparent pixels before z-write, like vanilla
- objects with element alpha A < 255 get the ref scaled to ref * A / 255 around
  their RenderOneNonRoad call, saved and restored. setElementAlpha works at any
  value on both render paths and cutouts keep their vanilla shape

neon renders like 1.6 again, multitheftauto#425 stays fixed.
…ir own ref

cars and bikes set ALPHAREF 1 and restore it inside their own Render fns, so
element alpha always worked for them. boats and trains never touch the ref, at
stock 100/140 their hull drops below the test once alpha goes low enough, and
that has been the case on every release so far. run them through the same
scaled ref as objects. for cars and bikes it's a no-op, their own ref write
lands after ours and wins during the body render.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant