From a19f843a3ecae75c2963918675c66c7dcae89d73 Mon Sep 17 00:00:00 2001 From: MIDIMan Date: Sun, 19 May 2024 22:21:09 -0400 Subject: [PATCH] Implement Lactozilla's suggestions and add 3D model support --- src/hardware/hw_md2.c | 7 +++++++ src/p_saveg.c | 2 +- src/r_things.c | 17 +++++++---------- src/r_things.h | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 0bb8de851..d16700909 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1285,6 +1285,11 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) // Apparently people don't like jump frames like that, so back it goes //if (tics > durs) //durs = tics; + + // Make linkdraw objects use their tracer's alpha value + fixed_t newalpha = spr->mobj->alpha; + if ((spr->mobj->flags2 & MF2_LINKDRAW) && spr->mobj->tracer) + newalpha = spr->mobj->tracer->alpha; INT32 blendmode; if (spr->mobj->frame & FF_BLENDMASK) @@ -1299,6 +1304,8 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) Surf.PolyColor.s.alpha = (spr->mobj->flags2 & MF2_SHADOW) ? 0x40 : 0xff; Surf.PolyFlags = HWR_GetBlendModeFlag(blendmode); } + + Surf.PolyColor.s.alpha = FixedMul(newalpha, Surf.PolyColor.s.alpha); // don't forget to enable the depth test because we can't do this // like before: model polygons are not sorted diff --git a/src/p_saveg.c b/src/p_saveg.c index 1aed73784..219410bb6 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1990,7 +1990,7 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) diff2 |= MD2_DONTDRAWFORVIEWMOBJ; if (mobj->dispoffset != mobj->info->dispoffset) diff2 |= MD2_DISPOFFSET; - if (mobj->alpha < FRACUNIT) + if (mobj->alpha != FRACUNIT) diff2 |= MD2_ALPHA; if (diff2 != 0) diff --git a/src/r_things.c b/src/r_things.c index 41e1c144e..afa861832 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -992,12 +992,10 @@ UINT8 *R_GetTranslationForThing(mobj_t *mobj, skincolornum_t color, UINT16 trans return NULL; } -transnum_t R_GetTransmapFromAlpha(fixed_t alpha, transnum_t transmap) +// Based off of R_GetLinedefTransTable +transnum_t R_GetThingTransTable(fixed_t alpha, transnum_t transmap) { - INT32 value = 10 - transmap; - value = 10 - (FixedCeil(alpha * value)>>FRACBITS); - - return value; + return (20*(FRACUNIT - ((alpha * (10 - transmap))/10) - 1) + FRACUNIT) >> (FRACBITS+1); } // @@ -1505,7 +1503,7 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, floordiff = abs((isflipped ? interp.height : 0) + interp.z - groundz); trans = floordiff / (100*FRACUNIT) + 3; - trans = R_GetTransmapFromAlpha(thing->alpha, trans); + trans = R_GetThingTransTable(thing->alpha, trans); if (trans >= 9) return; scalemul = FixedMul(FRACUNIT - floordiff/640, scale); @@ -2194,9 +2192,9 @@ static void R_ProjectSprite(mobj_t *thing) trans = 0; if ((oldthing->flags2 & MF2_LINKDRAW) && oldthing->tracer) - trans = R_GetTransmapFromAlpha(oldthing->tracer->alpha, trans); + trans = R_GetThingTransTable(oldthing->tracer->alpha, trans); else - trans = R_GetTransmapFromAlpha(oldthing->alpha, trans); + trans = R_GetThingTransTable(oldthing->alpha, trans); // Check if this sprite needs to be rendered like a shadow shadowdraw = (!!(thing->renderflags & RF_SHADOWDRAW) && !(papersprite || splat)); @@ -3658,8 +3656,7 @@ boolean R_ThingVisible (mobj_t *thing) (thing->sprite == SPR_NULL) || // Don't draw null-sprites (thing->flags2 & MF2_DONTDRAW) || // Don't draw MF2_LINKDRAW objects (thing->drawonlyforplayer && thing->drawonlyforplayer != viewplayer) || // Don't draw other players' personal objects - ((rendermode == render_soft && R_GetTransmapFromAlpha(thing->alpha, (thing->frame & FF_TRANSMASK)>>FF_TRANSSHIFT) >= 10) || - (rendermode == render_opengl && thing->alpha == 0)) || + (!R_BlendLevelVisible(thing->blendmode, R_GetThingTransTable(thing->alpha, 0))) || (!P_MobjWasRemoved(r_viewmobj) && ( (r_viewmobj == thing) || // Don't draw first-person players or awayviewmobj objects (r_viewmobj->player && r_viewmobj->player->followmobj == thing) || // Don't draw first-person players' followmobj diff --git a/src/r_things.h b/src/r_things.h index 530898917..55ab71ec3 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -93,7 +93,7 @@ boolean R_ThingIsFullDark (mobj_t *thing); boolean R_ThingIsFlashing (mobj_t *thing); UINT8 *R_GetTranslationForThing(mobj_t *mobj, skincolornum_t color, UINT16 translation); -transnum_t R_GetTransmapFromAlpha(fixed_t alpha, transnum_t transmap); +transnum_t R_GetThingTransTable(fixed_t alpha, transnum_t transmap); void R_ThingOffsetOverlay (mobj_t *thing, fixed_t *outx, fixed_t *outy);