- prepared the weapon sprite drawer for full separation.

This commit is contained in:
Christoph Oelckers 2018-05-03 23:49:16 +02:00
parent e309fd1f3d
commit e0833d5005
4 changed files with 140 additions and 114 deletions

View file

@ -9,6 +9,8 @@
#include "r_utility.h" #include "r_utility.h"
#include "c_cvars.h" #include "c_cvars.h"
struct HUDSprite;
class GLSceneDrawer class GLSceneDrawer
{ {
fixed_t viewx, viewy; // since the nodes are still fixed point, keeping the view position also fixed point for node traversal is faster. fixed_t viewx, viewy; // since the nodes are still fixed point, keeping the view position also fixed point for node traversal is faster.
@ -68,7 +70,7 @@ public:
void RenderView(player_t *player); void RenderView(player_t *player);
void WriteSavePic(player_t *player, FileWriter *file, int width, int height); void WriteSavePic(player_t *player, FileWriter *file, int width, int height);
void DrawPSprite(player_t * player, DPSprite *psp, float sx, float sy, int OverrideShader, bool alphatexture); void DrawPSprite(HUDSprite *huds);
void DrawPlayerSprites(sector_t * viewsector, bool hudModelStep); void DrawPlayerSprites(sector_t * viewsector, bool hudModelStep);
void DrawTargeterSprites(); void DrawTargeterSprites();
void DrawPlayerHUDModel(sector_t * viewsector); void DrawPlayerHUDModel(sector_t * viewsector);

View file

@ -50,30 +50,43 @@
EXTERN_CVAR (Bool, r_drawplayersprites) EXTERN_CVAR (Bool, r_drawplayersprites)
EXTERN_CVAR (Bool, r_deathcamera) EXTERN_CVAR (Bool, r_deathcamera)
//========================================================================== //==========================================================================
// //
// R_DrawPSprite // R_DrawPSprite
// //
//========================================================================== //==========================================================================
void GLSceneDrawer::DrawPSprite (player_t * player,DPSprite *psp, float sx, float sy, int OverrideShader, bool alphatexture) void GLSceneDrawer::DrawPSprite (HUDSprite *huds)
{ {
WeaponRect rc; if (huds->RenderStyle.BlendOp == STYLEOP_Shadow)
if (!GetWeaponRect(psp, sx, sy, player, rc)) return;
gl_RenderState.SetMaterial(rc.tex, CLAMP_XY_NOMIP, 0, OverrideShader, alphatexture);
if (rc.tex->tex->GetTranslucency() || OverrideShader != -1)
{ {
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.SetColor(0.2f, 0.2f, 0.2f, 0.33f, huds->cm.Desaturation);
} }
else
{
SetColor(huds->lightlevel, 0, huds->cm, huds->alpha, true);
}
gl_SetRenderStyle(huds->RenderStyle, false, false);
gl_RenderState.SetObjectColor(huds->ObjectColor);
gl_RenderState.SetDynLight(huds->dynrgb[0], huds->dynrgb[1], huds->dynrgb[2]);
gl_RenderState.SetMaterial(huds->tex, CLAMP_XY_NOMIP, 0, huds->OverrideShader, !!(huds->RenderStyle.Flags & STYLEF_RedIsAlpha));
float thresh = (huds->tex->tex->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold;
gl_RenderState.AlphaFunc(GL_GEQUAL, thresh);
gl_RenderState.EnableBrightmap(!(huds->RenderStyle.Flags & STYLEF_ColorIsFixed));
gl_RenderState.Apply(); gl_RenderState.Apply();
FQuadDrawer qd; FQuadDrawer qd;
qd.Set(0, rc.x1, rc.y1, 0, rc.u1, rc.v1); qd.Set(0, huds->x1, huds->y1, 0, huds->u1, huds->v1);
qd.Set(1, rc.x1, rc.y2, 0, rc.u1, rc.v2); qd.Set(1, huds->x1, huds->y2, 0, huds->u1, huds->v2);
qd.Set(2, rc.x2, rc.y1, 0, rc.u2, rc.v1); qd.Set(2, huds->x2, huds->y1, 0, huds->u2, huds->v1);
qd.Set(3, rc.x2, rc.y2, 0, rc.u2, rc.v2); qd.Set(3, huds->x2, huds->y2, 0, huds->u2, huds->v2);
qd.Render(GL_TRIANGLE_STRIP); qd.Render(GL_TRIANGLE_STRIP);
gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold);
gl_RenderState.SetObjectColor(0xffffffff);
gl_RenderState.SetDynLight(0, 0, 0);
gl_RenderState.EnableBrightmap(false);
} }
//========================================================================== //==========================================================================
@ -143,8 +156,6 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep)
WeaponPosition weap = GetWeaponPosition(camera->player); WeaponPosition weap = GetWeaponPosition(camera->player);
WeaponLighting light = GetWeaponLighting(viewsector, r_viewpoint.Pos, FixedColormap, in_area, camera->Pos()); WeaponLighting light = GetWeaponLighting(viewsector, r_viewpoint.Pos, FixedColormap, in_area, camera->Pos());
gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold);
// hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change // hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change
// light mode here to draw the weapon sprite. // light mode here to draw the weapon sprite.
int oldlightmode = level.lightmode; int oldlightmode = level.lightmode;
@ -153,61 +164,40 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep)
for(DPSprite *psp = player->psprites; psp != nullptr && psp->GetID() < PSP_TARGETCENTER; psp = psp->GetNext()) for(DPSprite *psp = player->psprites; psp != nullptr && psp->GetID() < PSP_TARGETCENTER; psp = psp->GetNext())
{ {
if (!psp->GetState()) continue; if (!psp->GetState()) continue;
WeaponRenderStyle rs = GetWeaponRenderStyle(psp, camera); FSpriteModelFrame *smf = playermo->player->ReadyWeapon ? gl_FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetState()->sprite, psp->GetState()->GetFrame(), false) : nullptr;
if (rs.RenderStyle.BlendOp == STYLEOP_None) continue; // This is an 'either-or' proposition. This maybe needs some work to allow overlays with weapon models but as originally implemented this just won't work.
if (smf && !hudModelStep) continue;
if (!smf && hudModelStep) continue;
gl_SetRenderStyle(rs.RenderStyle, false, false); HUDSprite hudsprite;
hudsprite.owner = playermo;
hudsprite.mframe = smf;
PalEntry ThingColor = (camera->RenderStyle.Flags & STYLEF_ColorIsFixed) ? camera->fillcolor : 0xffffff; if (!hudsprite.GetWeaponRenderStyle(psp, camera, viewsector, light)) continue;
ThingColor.a = 255;
// now draw the different layers of the weapon.
// For stencil render styles brightmaps need to be disabled.
gl_RenderState.EnableBrightmap(!(rs.RenderStyle.Flags & STYLEF_ColorIsFixed));
const bool bright = isBright(psp);
const PalEntry finalcol = bright? ThingColor : ThingColor.Modulate(viewsector->SpecialColors[sector_t::sprites]);
gl_RenderState.SetObjectColor(finalcol);
auto ll = light;
if (bright) ll.SetBright();
// set the lighting parameters
if (rs.RenderStyle.BlendOp == STYLEOP_Shadow)
{
gl_RenderState.SetColor(0.2f, 0.2f, 0.2f, 0.33f, ll.cm.Desaturation);
}
else
{
if (level.HasDynamicLights && FixedColormap == CM_DEFAULT && gl_light_sprites)
{
FSpriteModelFrame *smf = playermo->player->ReadyWeapon ? gl_FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetState()->sprite, psp->GetState()->GetFrame(), false) : nullptr;
if (!smf || gl.legacyMode) // For models with per-pixel lighting this was done in a previous pass.
{
float out[3];
gl_drawinfo->GetDynSpriteLight(playermo, nullptr, out);
gl_RenderState.SetDynLight(out[0], out[1], out[2]);
}
}
SetColor(ll.lightlevel, 0, ll.cm, rs.alpha, true);
}
FVector2 spos = BobWeapon(weap, psp); FVector2 spos = BobWeapon(weap, psp);
hudsprite.dynrgb[0] = hudsprite.dynrgb[1] = hudsprite.dynrgb[2] = 0;
// set the lighting parameters
if (hudsprite.RenderStyle.BlendOp != STYLEOP_Shadow && level.HasDynamicLights && FixedColormap == CM_DEFAULT && gl_light_sprites && !hudModelStep || gl.legacyMode)
// For models with per-pixel lighting this was done in a previous pass.
{
gl_drawinfo->GetDynSpriteLight(playermo, nullptr, hudsprite.dynrgb);
}
// [BB] In the HUD model step we just render the model and break out. // [BB] In the HUD model step we just render the model and break out.
if (hudModelStep) if (hudModelStep)
{ {
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); hudsprite.x1 = spos.X;
hudsprite.y1 = spos.Y;
gl_RenderHUDModel(psp, spos.X, spos.Y, weapondynlightindex[psp]); gl_RenderHUDModel(psp, spos.X, spos.Y, weapondynlightindex[psp]);
} }
else else
{ {
DrawPSprite(player, psp, spos.X, spos.Y, rs.OverrideShader, !!(rs.RenderStyle.Flags & STYLEF_RedIsAlpha)); if (!hudsprite.GetWeaponRect(psp, spos.X, spos.Y, player)) continue;
DrawPSprite(&hudsprite);
} }
} }
gl_RenderState.SetObjectColor(0xffffffff);
gl_RenderState.SetDynLight(0, 0, 0);
gl_RenderState.EnableBrightmap(false);
level.lightmode = oldlightmode; level.lightmode = oldlightmode;
} }
@ -220,22 +210,32 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep)
void GLSceneDrawer::DrawTargeterSprites() void GLSceneDrawer::DrawTargeterSprites()
{ {
AActor * playermo=players[consoleplayer].camera; AActor * playermo = players[consoleplayer].camera;
player_t * player=playermo->player; player_t * player = playermo->player;
if(!player || playermo->renderflags&RF_INVISIBLE || !r_drawplayersprites ||
GLRenderer->mViewActor!=playermo) return;
gl_RenderState.EnableBrightmap(false); if (!player || playermo->renderflags&RF_INVISIBLE || !r_drawplayersprites || GLRenderer->mViewActor != playermo) return;
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl_RenderState.AlphaFunc(GL_GEQUAL,gl_mask_sprite_threshold); HUDSprite hudsprite;
gl_RenderState.BlendEquation(GL_FUNC_ADD);
gl_RenderState.ResetColor(); hudsprite.owner = playermo;
gl_RenderState.SetTextureMode(TM_MODULATE); hudsprite.mframe = nullptr;
hudsprite.cm.Clear();
hudsprite.lightlevel = 255;
hudsprite.ObjectColor = 0xffffffff;
hudsprite.alpha = 1;
hudsprite.RenderStyle = DefaultRenderStyle();
hudsprite.OverrideShader = -1;
hudsprite.dynrgb[0] = hudsprite.dynrgb[1] = hudsprite.dynrgb[2] = 0;
// The Targeter's sprites are always drawn normally. // The Targeter's sprites are always drawn normally.
for (DPSprite *psp = player->FindPSprite(PSP_TARGETCENTER); psp != nullptr; psp = psp->GetNext()) for (DPSprite *psp = player->FindPSprite(PSP_TARGETCENTER); psp != nullptr; psp = psp->GetNext())
{ {
if (psp->GetState() != nullptr) DrawPSprite(player, psp, psp->x, psp->y, 0, false); if (psp->GetState() != nullptr && (psp->GetID() != PSP_TARGETCENTER || CrosshairImage == nullptr))
{
hudsprite.weapon = psp;
hudsprite.GetWeaponRect(psp, psp->x, psp->y, player);
DrawPSprite(&hudsprite);
}
} }
} }

View file

@ -47,7 +47,7 @@ EXTERN_CVAR(Int, gl_fuzztype)
// //
//========================================================================== //==========================================================================
bool isBright(DPSprite *psp) static bool isBright(DPSprite *psp)
{ {
if (psp != nullptr && psp->GetState() != nullptr) if (psp != nullptr && psp->GetState() != nullptr)
{ {
@ -134,7 +134,7 @@ FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp)
// //
//========================================================================== //==========================================================================
WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int FixedColormap, area_t in_area, const DVector3 &playerpos ) WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int FixedColormap, area_t in_area, const DVector3 &playerpos)
{ {
WeaponLighting l; WeaponLighting l;
@ -212,7 +212,13 @@ WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int
return l; return l;
} }
void WeaponLighting::SetBright() //==========================================================================
//
//
//
//==========================================================================
void HUDSprite::SetBright(bool isbelow)
{ {
if (!isbelow) if (!isbelow)
{ {
@ -234,9 +240,8 @@ void WeaponLighting::SetBright()
// //
//========================================================================== //==========================================================================
WeaponRenderStyle GetWeaponRenderStyle(DPSprite *psp, AActor *playermo) bool HUDSprite::GetWeaponRenderStyle(DPSprite *psp, AActor *playermo, sector_t *viewsector, WeaponLighting &lighting)
{ {
WeaponRenderStyle r;
auto rs = psp->GetRenderStyle(playermo->RenderStyle, playermo->Alpha); auto rs = psp->GetRenderStyle(playermo->RenderStyle, playermo->Alpha);
visstyle_t vis; visstyle_t vis;
@ -251,52 +256,63 @@ WeaponRenderStyle GetWeaponRenderStyle(DPSprite *psp, AActor *playermo)
if (vis.RenderStyle != STYLE_Count && !(psp->Flags & PSPF_FORCESTYLE)) if (vis.RenderStyle != STYLE_Count && !(psp->Flags & PSPF_FORCESTYLE))
{ {
r.RenderStyle = vis.RenderStyle; RenderStyle = vis.RenderStyle;
} }
else else
{ {
r.RenderStyle = rs.first; RenderStyle = rs.first;
} }
if (r.RenderStyle.BlendOp == STYLEOP_None) return r; if (RenderStyle.BlendOp == STYLEOP_None) return false;
if (vis.Invert) if (vis.Invert)
{ {
// this only happens for Strife's inverted weapon sprite // this only happens for Strife's inverted weapon sprite
r.RenderStyle.Flags |= STYLEF_InvertSource; RenderStyle.Flags |= STYLEF_InvertSource;
} }
// Set the render parameters // Set the render parameters
r.OverrideShader = -1; OverrideShader = -1;
if (r.RenderStyle.BlendOp == STYLEOP_Fuzz) if (RenderStyle.BlendOp == STYLEOP_Fuzz)
{ {
if (gl_fuzztype != 0) if (gl_fuzztype != 0)
{ {
// Todo: implement shader selection here // Todo: implement shader selection here
r.RenderStyle = LegacyRenderStyles[STYLE_Translucent]; RenderStyle = LegacyRenderStyles[STYLE_Translucent];
r.OverrideShader = SHADER_NoTexture + gl_fuzztype; OverrideShader = SHADER_NoTexture + gl_fuzztype;
r.alpha = 0.99f; // trans may not be 1 here alpha = 0.99f; // trans may not be 1 here
} }
else else
{ {
r.RenderStyle.BlendOp = STYLEOP_Shadow; RenderStyle.BlendOp = STYLEOP_Shadow;
} }
} }
if (RenderStyle.Flags & STYLEF_TransSoulsAlpha)
if (r.RenderStyle.Flags & STYLEF_TransSoulsAlpha)
{ {
r.alpha = transsouls; alpha = transsouls;
} }
else if (r.RenderStyle.Flags & STYLEF_Alpha1) else if (RenderStyle.Flags & STYLEF_Alpha1)
{ {
r.alpha = 1.f; alpha = 1.f;
} }
else if (trans == 0.f) else if (trans == 0.f)
{ {
r.alpha = vis.Alpha; alpha = vis.Alpha;
} }
return r; if (!RenderStyle.IsVisible(alpha)) return false; // if it isn't visible skip the rest.
PalEntry ThingColor = (playermo->RenderStyle.Flags & STYLEF_ColorIsFixed) ? playermo->fillcolor : 0xffffff;
ThingColor.a = 255;
const bool bright = isBright(psp);
ObjectColor = bright ? ThingColor : ThingColor.Modulate(viewsector->SpecialColors[sector_t::sprites]);
lightlevel = lighting.lightlevel;
cm = lighting.cm;
if (bright) SetBright(lighting.isbelow);
return true;
} }
//========================================================================== //==========================================================================
@ -305,10 +321,9 @@ WeaponRenderStyle GetWeaponRenderStyle(DPSprite *psp, AActor *playermo)
// //
//========================================================================== //==========================================================================
bool GetWeaponRect(DPSprite *psp, float sx, float sy, player_t *player, WeaponRect &rc) bool HUDSprite::GetWeaponRect(DPSprite *psp, float sx, float sy, player_t *player)
{ {
float tx; float tx;
float x1, x2;
float scale; float scale;
float scalex; float scalex;
float ftexturemid; float ftexturemid;
@ -333,13 +348,13 @@ bool GetWeaponRect(DPSprite *psp, float sx, float sy, player_t *player, WeaponRe
tx = (psp->Flags & PSPF_MIRROR) ? ((160 - r.width) - (sx + r.left)) : (sx - (160 - r.left)); tx = (psp->Flags & PSPF_MIRROR) ? ((160 - r.width) - (sx + r.left)) : (sx - (160 - r.left));
x1 = tx * scalex + vw / 2; x1 = tx * scalex + vw / 2;
if (x1 > vw) return false; // off the right side if (x1 > vw) return false; // off the right side
rc.x1 = x1 + viewwindowx; x1 += viewwindowx;
tx += r.width; tx += r.width;
x2 = tx * scalex + vw / 2; x2 = tx * scalex + vw / 2;
if (x2 < 0) return false; // off the left side if (x2 < 0) return false; // off the left side
rc.x2 = x2 + viewwindowx; x2 += viewwindowx;
// killough 12/98: fix psprite positioning problem // killough 12/98: fix psprite positioning problem
ftexturemid = 100.f - sy - r.top; ftexturemid = 100.f - sy - r.top;
@ -359,25 +374,25 @@ bool GetWeaponRect(DPSprite *psp, float sx, float sy, player_t *player, WeaponRe
} }
scale = (SCREENHEIGHT*vw) / (SCREENWIDTH * 200.0f); scale = (SCREENHEIGHT*vw) / (SCREENWIDTH * 200.0f);
rc.y1 = viewwindowy + vh / 2 - (ftexturemid * scale); y1 = viewwindowy + vh / 2 - (ftexturemid * scale);
rc.y2 = rc.y1 + (r.height * scale) + 1; y2 = y1 + (r.height * scale) + 1;
if (!(mirror) != !(psp->Flags & (PSPF_FLIP))) if (!(mirror) != !(psp->Flags & (PSPF_FLIP)))
{ {
rc.u2 = tex->GetSpriteUL(); u2 = tex->GetSpriteUL();
rc.v1 = tex->GetSpriteVT(); v1 = tex->GetSpriteVT();
rc.u1 = tex->GetSpriteUR(); u1 = tex->GetSpriteUR();
rc.v2 = tex->GetSpriteVB(); v2 = tex->GetSpriteVB();
} }
else else
{ {
rc.u1 = tex->GetSpriteUL(); u1 = tex->GetSpriteUL();
rc.v1 = tex->GetSpriteVT(); v1 = tex->GetSpriteVT();
rc.u2 = tex->GetSpriteUR(); u2 = tex->GetSpriteUR();
rc.v2 = tex->GetSpriteVB(); v2 = tex->GetSpriteVB();
} }
rc.tex = tex; this->tex = tex;
return true; return true;
} }

View file

@ -6,6 +6,9 @@ class DPSprite;
class player_t; class player_t;
class AActor; class AActor;
enum area_t : int; enum area_t : int;
struct FSpriteModelFrame;
struct WeaponPosition struct WeaponPosition
{ {
@ -19,31 +22,37 @@ struct WeaponLighting
FColormap cm; FColormap cm;
int lightlevel; int lightlevel;
bool isbelow; bool isbelow;
void SetBright();
}; };
struct WeaponRenderStyle struct HUDSprite
{ {
AActor *owner;
DPSprite *weapon;
FMaterial *tex;
FSpriteModelFrame *mframe;
FColormap cm;
int lightlevel;
PalEntry ObjectColor;
FRenderStyle RenderStyle; FRenderStyle RenderStyle;
float alpha; float alpha;
int OverrideShader; int OverrideShader;
};
struct WeaponRect
{
FMaterial *tex;
float x1, y1; float x1, y1;
float x2, y2; float x2, y2;
float u1, v1; float u1, v1;
float u2, v2; float u2, v2;
float dynrgb[3];
void SetBright(bool isbelow);
bool GetWeaponRenderStyle(DPSprite *psp, AActor *playermo, sector_t *viewsector, WeaponLighting &light);
bool GetWeaponRect(DPSprite *psp, float sx, float sy, player_t *player);
}; };
bool isBright(DPSprite *psp);
WeaponPosition GetWeaponPosition(player_t *player); WeaponPosition GetWeaponPosition(player_t *player);
FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp); FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp);
WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int FixedColormap, area_t in_area, const DVector3 &playerpos ); WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int FixedColormap, area_t in_area, const DVector3 &playerpos );
WeaponRenderStyle GetWeaponRenderStyle(DPSprite *psp, AActor *playermo);
bool GetWeaponRect(DPSprite *psp, float sx, float sy, player_t *player, WeaponRect &rc);