fix: smooth procedural weapon-wheel ring edges (issue #31)
linux / build (push) Successful in 13m50s
linux / build (push) Successful in 13m50s
This commit is contained in:
+78
-10
@@ -103,6 +103,7 @@ enum
|
||||
#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_ANGULAR_FEATHER 0.10f // angular edge fade, fraction of one sector's angle
|
||||
|
||||
#define WHEEL_ART_WW_PATH "weapon_wheel/ww%d.png"
|
||||
#define WHEEL_ART_ICON_PATH "weapon_wheel/icon%d.png"
|
||||
@@ -943,6 +944,28 @@ Wheel_DrawRingQuadFade(float a0, float a1, float rSolid, float rFade, const CRGB
|
||||
RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::GetVertices(), 4);
|
||||
}
|
||||
|
||||
// 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.
|
||||
static void
|
||||
Wheel_DrawRingQuadGrad(float a0, float a1, float r0, float r1,
|
||||
const CRGBA &c00, const CRGBA &c01, const CRGBA &c10, const CRGBA &c11)
|
||||
{
|
||||
float cx = SCREEN_WIDTH * 0.5f;
|
||||
float cy = SCREEN_HEIGHT * 0.5f;
|
||||
|
||||
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)
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
static void
|
||||
Wheel_DrawRing(void)
|
||||
{
|
||||
@@ -953,11 +976,13 @@ Wheel_DrawRing(void)
|
||||
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();
|
||||
int32 highlight = ms_nHovered >= 0 ? ms_nHovered : ms_nCurrentSegment;
|
||||
bool draw[WHEEL_MAX_RADIO];
|
||||
CRGBA color[WHEEL_MAX_RADIO];
|
||||
|
||||
// Pass 1: decide which sectors are drawn and their colour.
|
||||
for (int32 i = 0; i < ms_nSegments; i++) {
|
||||
bool available = true;
|
||||
if (!ms_bRadio)
|
||||
@@ -977,20 +1002,34 @@ Wheel_DrawRing(void)
|
||||
color[i] = CRGBA(235, 200, 120, 225);
|
||||
else
|
||||
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.
|
||||
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 a0 = center + step * 0.5f;
|
||||
float a1 = center - step * 0.5f;
|
||||
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 = a0 + (a1 - a0) * (k / (float)WHEEL_ARC_STEPS);
|
||||
float ab = a0 + (a1 - a0) * ((k + 1) / (float)WHEEL_ARC_STEPS);
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
// Alpha-feather the inner/outer circumference instead of leaving the
|
||||
// un-antialiased polygon edges: the rest of the 2D pass has no MSAA.
|
||||
// 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);
|
||||
@@ -999,22 +1038,51 @@ Wheel_DrawRing(void)
|
||||
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 a0 = center + step * 0.5f;
|
||||
float a1 = center - step * 0.5f;
|
||||
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 = a0 + (a1 - a0) * (k / (float)WHEEL_ARC_STEPS);
|
||||
float ab = a0 + (a1 - a0) * ((k + 1) / (float)WHEEL_ARC_STEPS);
|
||||
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.
|
||||
for (int32 i = 0; i < ms_nSegments; i++) {
|
||||
int32 next = (i + 1) % ms_nSegments;
|
||||
if (!draw[i] || !draw[next])
|
||||
continue;
|
||||
|
||||
float b = HALFPI - (i + 0.5f) * step; // clockwise edge of sector i
|
||||
float aL = b + aFeather;
|
||||
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);
|
||||
}
|
||||
|
||||
RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE);
|
||||
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user