From 3b14e45249605d4f86cdee90a0bb29ca0d81d6ed Mon Sep 17 00:00:00 2001 From: opencode Date: Wed, 2 Dec 2026 11:01:57 +0000 Subject: [PATCH] fix: revert wheel-centre backdrop, replace per-vertex feather with flat-alpha AA (issue #31) --- src/extras/weaponwheel.cpp | 233 +++++++++++++++++-------------------- 1 file changed, 106 insertions(+), 127 deletions(-) diff --git a/src/extras/weaponwheel.cpp b/src/extras/weaponwheel.cpp index 795859ff..c04ed5c4 100644 --- a/src/extras/weaponwheel.cpp +++ b/src/extras/weaponwheel.cpp @@ -72,6 +72,8 @@ enum // See src/weapons/WeaponType.h for the eWeaponType ordering. WHEEL_SEGMENTS = 12, WHEEL_ARC_STEPS = 8, // quads per segment; smoother arcs, only for the procedural ring + WHEEL_FEATHER_STEPS = 4, // flat alpha steps for the radial/backdrop feather + WHEEL_RING_ANGULAR_STEPS = 4, // flat colour steps across one spoke gap WHEEL_BACKDROP_SEGMENTS = 48, WHEEL_MAX_RADIO = 12 }; @@ -103,10 +105,10 @@ enum #define WHEEL_CURSOR_DEADZONE 0.06f #define WHEEL_CURSOR_ARM 0.012f // marker arm length, fraction of screen height #define WHEEL_CURSOR_THICK 0.0018f // marker thickness, fraction of screen height -#define WHEEL_RING_FEATHER 0.003f // alpha-feather band on the procedural ring edges +#define WHEEL_RING_FEATHER 0.006f // stepped alpha-feather band on the ring edges #define WHEEL_RING_ANGULAR_FEATHER 0.10f // angular edge fade, fraction of one sector's angle -#define WHEEL_BACKDROP_MARGIN 0.012f // dark disc extends this far past WHEEL_OUTER_RADIUS -#define WHEEL_BACKDROP_FEATHER 0.010f // soft outer edge of the dark disc +#define WHEEL_BACKDROP_MARGIN 0.012f // dark annulus spans this far inside the inner radius and past the outer radius +#define WHEEL_BACKDROP_FEATHER 0.016f // soft edges of the dark annulus #define WHEEL_ART_WW_PATH "weapon_wheel/ww%d.png" #define WHEEL_ART_ICON_PATH "weapon_wheel/icon%d.png" @@ -913,6 +915,11 @@ Wheel_Process(void) Wheel_ConsumeMouse(); } +// Draw2DPolygon forwards to SetVertices, which fills the vertex buffer in the +// fan order (x3, x4, x2, x1). It therefore expects the four points in Z-order: +// (x1,x2) is one edge, (x3,x4) the opposite edge in the same direction. +// Passing them in angular order instead makes the fan cover only ~80% of the +// quad, leaving notches along every arc step - the source of the ragged ring. static void Wheel_DrawRingQuad(float a0, float a1, float r0, float r1, const CRGBA &color) { @@ -920,53 +927,61 @@ Wheel_DrawRingQuad(float a0, float a1, float r0, float r1, const CRGBA &color) float cy = SCREEN_HEIGHT * 0.5f; CSprite2d::Draw2DPolygon( - cx + r0 * Cos(a0), cy - r0 * Sin(a0), - cx + r1 * Cos(a0), cy - r1 * Sin(a0), - cx + r1 * Cos(a1), cy - r1 * Sin(a1), - cx + r0 * Cos(a1), cy - r0 * Sin(a1), + cx + r0 * Cos(a0), cy - r0 * Sin(a0), // x1: inner, a0 + cx + r1 * Cos(a0), cy - r1 * Sin(a0), // x2: outer, a0 + cx + r0 * Cos(a1), cy - r0 * Sin(a1), // x3: inner, a1 + cx + r1 * Cos(a1), cy - r1 * Sin(a1), // x4: outer, a1 color); } -static void -Wheel_DrawRingQuadFade(float a0, float a1, float rSolid, float rFade, const CRGBA &color) +// Alpha for one step of a stepped flat-alpha feather. step 0 is fully +// transparent, step (steps-1) is the full colour. +static uint8 +Wheel_StepAlpha(uint8 alpha, int32 step, int32 steps) { - // Assumes the caller has set up 2D rendering state (GOURAUD, alpha blend, - // no texture). rSolid gets the sector colour, rFade is fully transparent. - float cx = SCREEN_WIDTH * 0.5f; - float cy = SCREEN_HEIGHT * 0.5f; - CRGBA clear(color.r, color.g, color.b, 0); - - float xA = cx + rSolid * Cos(a0), yA = cy - rSolid * Sin(a0); - float xB = cx + rFade * Cos(a0), yB = cy - rFade * Sin(a0); - float xC = cx + rFade * Cos(a1), yC = cy - rFade * Sin(a1); - float xD = cx + rSolid * Cos(a1), yD = cy - rSolid * Sin(a1); - - // SetVertices maps (x1,c0)->v3, (x2,c1)->v2, (x3,c2)->v0, (x4,c3)->v1. - CSprite2d::SetVertices(xD, yD, xC, yC, xA, yA, xB, yB, - color, clear, color, clear); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::GetVertices(), 4); + if (steps <= 1) + return step > 0 ? alpha : 0; + return (uint8)((int32)alpha * step / (steps - 1)); } -// A quad with independent colours at all four corners. c00=(a0,r0), -// c01=(a0,r1), c10=(a1,r0), c11=(a1,r1). Used for the angular transition -// between two sectors (colour gradient) combined with the radial alpha fade. +// A flat sector band: solid core plus a stepped radial feather. Every strip +// uses the same plain CSprite2d::Draw2DPolygon as the solid sectors, so the +// fade does not depend on the GOURAUD path at all. Three visible strips step +// the alpha down to zero, which is wide enough to soften the edge. static void -Wheel_DrawRingQuadGrad(float a0, float a1, float r0, float r1, - const CRGBA &c00, const CRGBA &c01, const CRGBA &c10, const CRGBA &c11) +Wheel_DrawSectorBand(float a0, float a1, int32 arcSteps, const CRGBA &color) { - float cx = SCREEN_WIDTH * 0.5f; - float cy = SCREEN_HEIGHT * 0.5f; + float inner = SCREEN_HEIGHT * WHEEL_INNER_RADIUS; + float outer = SCREEN_HEIGHT * WHEEL_OUTER_RADIUS; + float feather = SCREEN_HEIGHT * WHEEL_RING_FEATHER; + int32 steps = WHEEL_FEATHER_STEPS; - float xA = cx + r0 * Cos(a0), yA = cy - r0 * Sin(a0); // (a0,r0) - float xB = cx + r0 * Cos(a1), yB = cy - r0 * Sin(a1); // (a1,r0) - float xC = cx + r1 * Cos(a1), yC = cy - r1 * Sin(a1); // (a1,r1) - float xD = cx + r1 * Cos(a0), yD = cy - r1 * Sin(a0); // (a0,r1) + // Subdivide the arc so the circumference stays a smooth polygon; the tiny + // angular gap strips pass arcSteps=1 (their chord is well under a pixel). + for (int32 k = 0; k < arcSteps; k++) { + float aa = a0 + (a1 - a0) * (k / (float)arcSteps); + float ab = a0 + (a1 - a0) * ((k + 1) / (float)arcSteps); - // Fan A-B-C-D: SetVertices maps (x1,c0)->v3, (x2,c1)->v2, - // (x3,c2)->v0, (x4,c3)->v1. - CSprite2d::SetVertices(xD, yD, xC, yC, xA, yA, xB, yB, - c01, c11, c00, c10); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::GetVertices(), 4); + Wheel_DrawRingQuad(aa, ab, inner + feather, outer - feather, color); + + for (int32 j = 0; j < steps; j++) { + float t0 = (float)j / steps; + float t1 = (float)(j + 1) / steps; + + // Inner circumference: transparent at "inner", full at the core. + uint8 aIn = Wheel_StepAlpha(color.a, j, steps); + if (aIn != 0) + Wheel_DrawRingQuad(aa, ab, inner + feather * t0, inner + feather * t1, + CRGBA(color.r, color.g, color.b, aIn)); + + // Outer circumference: full at the core, transparent at "outer". + uint8 aOut = Wheel_StepAlpha(color.a, steps - 1 - j, steps); + if (aOut != 0) + Wheel_DrawRingQuad(aa, ab, outer - feather + feather * t0, + outer - feather + feather * t1, + CRGBA(color.r, color.g, color.b, aOut)); + } + } } static void @@ -975,9 +990,6 @@ Wheel_DrawRing(void) if (ms_nSegments <= 0 || ms_nSegments > WHEEL_MAX_RADIO) return; - float outer = SCREEN_HEIGHT * WHEEL_OUTER_RADIUS; - float inner = SCREEN_HEIGHT * WHEEL_INNER_RADIUS; - float feather = SCREEN_HEIGHT * WHEEL_RING_FEATHER; float step = TWOPI / ms_nSegments; float aFeather = step * WHEEL_RING_ANGULAR_FEATHER; CPlayerPed *player = FindPlayerPed(); @@ -1007,9 +1019,9 @@ Wheel_DrawRing(void) color[i] = CRGBA(18, 18, 18, 150); } - // Pass 2: solid core. Sides with a drawn neighbour are narrowed by the - // angular feather; sides next to the art-covered sector stay full so the - // wwN edge has solid ground underneath and no gap is exposed. + // Pass 2: solid sectors with their stepped radial feather. Sides with a + // drawn neighbour are narrowed by the angular feather; sides next to the + // art-covered sector stay full so the wwN edge has solid ground underneath. for (int32 i = 0; i < ms_nSegments; i++) { if (!draw[i]) continue; @@ -1024,50 +1036,13 @@ Wheel_DrawRing(void) if (s1 <= s0) continue; - for (int32 k = 0; k < WHEEL_ARC_STEPS; k++) { - float aa = s0 + (s1 - s0) * (k / (float)WHEEL_ARC_STEPS); - float ab = s0 + (s1 - s0) * ((k + 1) / (float)WHEEL_ARC_STEPS); - Wheel_DrawRingQuad(aa, ab, inner + feather, outer - feather, color[i]); - } + Wheel_DrawSectorBand(s0, s1, WHEEL_ARC_STEPS, color[i]); } - // The per-vertex colour path needs GOURAUD, vertex alpha and straight - // alpha blending; the rest of the 2D pass has no MSAA. - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - - // Pass 3: radial feather on the inner/outer circumference. - for (int32 i = 0; i < ms_nSegments; i++) { - if (!draw[i]) - continue; - - int32 prev = (i + ms_nSegments - 1) % ms_nSegments; - int32 next = (i + 1) % ms_nSegments; - float cwInset = draw[next] ? aFeather : 0.0f; - float ccwInset = draw[prev] ? aFeather : 0.0f; - float center = HALFPI - i * step; - float s0 = center - step * 0.5f + cwInset; - float s1 = center + step * 0.5f - ccwInset; - if (s1 <= s0) - continue; - - for (int32 k = 0; k < WHEEL_ARC_STEPS; k++) { - float aa = s0 + (s1 - s0) * (k / (float)WHEEL_ARC_STEPS); - float ab = s0 + (s1 - s0) * ((k + 1) / (float)WHEEL_ARC_STEPS); - Wheel_DrawRingQuadFade(aa, ab, inner + feather, inner, color[i]); - Wheel_DrawRingQuadFade(aa, ab, outer - feather, outer, color[i]); - } - } - - // Pass 4: angular feather between each pair of drawn neighbours. The - // strips fill exactly the angular gaps left by the Pass 2 insets; colour - // and alpha interpolate from one sector to the next, with the same radial - // fade as the rest of the ring. Hard radial "spokes" are gone. + // Pass 3: angular (spoke) feather. The gap left by the Pass 2 insets is + // filled by a few flat colour strips stepping from one sector colour to + // the next; each strip also gets the stepped radial feather. No per-vertex + // alpha is involved. for (int32 i = 0; i < ms_nSegments; i++) { int32 next = (i + 1) % ms_nSegments; if (!draw[i] || !draw[next]) @@ -1078,59 +1053,63 @@ Wheel_DrawRing(void) float aR = b - aFeather; const CRGBA &cL = color[i]; const CRGBA &cR = color[next]; - CRGBA clL(cL.r, cL.g, cL.b, 0); - CRGBA clR(cR.r, cR.g, cR.b, 0); - Wheel_DrawRingQuadGrad(aL, aR, inner, inner + feather, clL, cL, clR, cR); - Wheel_DrawRingQuadGrad(aL, aR, inner + feather, outer - feather, cL, cL, cR, cR); - Wheel_DrawRingQuadGrad(aL, aR, outer - feather, outer, cL, clL, cR, clR); + for (int32 k = 0; k < WHEEL_RING_ANGULAR_STEPS; k++) { + float t0 = (float)k / WHEEL_RING_ANGULAR_STEPS; + float t1 = (float)(k + 1) / WHEEL_RING_ANGULAR_STEPS; + // First and last strip match the neighbouring sectors exactly. + float t = (float)k / (WHEEL_RING_ANGULAR_STEPS - 1); + + float aa = aL + (aR - aL) * t0; + float ab = aL + (aR - aL) * t1; + CRGBA c((uint8)(cL.r + (cR.r - cL.r) * t), + (uint8)(cL.g + (cR.g - cL.g) * t), + (uint8)(cL.b + (cR.b - cL.b) * t), + (uint8)(cL.a + (cR.a - cL.a) * t)); + Wheel_DrawSectorBand(aa, ab, 1, c); + } } - - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); } -// A near-black disc behind the ring. The sectors and their feathers are -// semi-transparent; without it, a fading sector reveals the bright game scene -// and reads as a light fringe. The disc extends past the ring's outer feather -// and covers the centre, so every feather edge fades into dark. +// A dark annulus behind the ring: it hides the bright game scene under the +// semi-transparent sectors and their feathers while leaving the centre hole +// open so the player remains visible. Both edges are stepped flat-alpha +// strips (plain Draw2DPolygon), matching the ring's AA style. static void Wheel_DrawBackdrop(void) { - float cx = SCREEN_WIDTH * 0.5f; - float cy = SCREEN_HEIGHT * 0.5f; + float inner = SCREEN_HEIGHT * WHEEL_INNER_RADIUS; float outer = SCREEN_HEIGHT * WHEEL_OUTER_RADIUS; - float discR = outer + SCREEN_HEIGHT * WHEEL_BACKDROP_MARGIN; - float fadeR = discR + SCREEN_HEIGHT * WHEEL_BACKDROP_FEATHER; + float margin = SCREEN_HEIGHT * WHEEL_BACKDROP_MARGIN; + float fade = SCREEN_HEIGHT * WHEEL_BACKDROP_FEATHER; + float annInner = inner - margin; + float annOuter = outer + margin; CRGBA color(8, 8, 8, 235); - - // Solid disc as a triangle fan: centre plus each pair of rim points. - for (int32 i = 0; i < WHEEL_BACKDROP_SEGMENTS; i++) { - float a0 = TWOPI * i / WHEEL_BACKDROP_SEGMENTS; - float a1 = TWOPI * (i + 1) / WHEEL_BACKDROP_SEGMENTS; - float p0x = cx + discR * Cos(a0), p0y = cy - discR * Sin(a0); - float p1x = cx + discR * Cos(a1), p1y = cy - discR * Sin(a1); - // Fan A-B-C-D with A=centre, B=p0, C=p1, D=centre (degenerate). - CSprite2d::Draw2DPolygon(cx, cy, p1x, p1y, cx, cy, p0x, p0y, color); - } - - // Soft rim so the dark hub does not end in a hard circle. - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + int32 steps = WHEEL_FEATHER_STEPS; for (int32 i = 0; i < WHEEL_BACKDROP_SEGMENTS; i++) { float a0 = TWOPI * i / WHEEL_BACKDROP_SEGMENTS; float a1 = TWOPI * (i + 1) / WHEEL_BACKDROP_SEGMENTS; - Wheel_DrawRingQuadFade(a0, a1, discR, fadeR, color); - } - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + Wheel_DrawRingQuad(a0, a1, annInner, annOuter, color); + + for (int32 k = 0; k < steps; k++) { + float t0 = (float)k / steps; + float t1 = (float)(k + 1) / steps; + + uint8 aIn = Wheel_StepAlpha(color.a, k, steps); + if (aIn != 0) + Wheel_DrawRingQuad(a0, a1, annInner - fade + fade * t0, + annInner - fade + fade * t1, + CRGBA(color.r, color.g, color.b, aIn)); + + uint8 aOut = Wheel_StepAlpha(color.a, steps - 1 - k, steps); + if (aOut != 0) + Wheel_DrawRingQuad(a0, a1, annOuter + fade * t0, + annOuter + fade * t1, + CRGBA(color.r, color.g, color.b, aOut)); + } + } } static void