Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix psprite gpu lighting #132

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/rendering/hwrenderer/scene/hw_weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
{
state.SetAddColor(0);
}
state.SetDynLight(huds->dynrgb[0], huds->dynrgb[1], huds->dynrgb[2]);
state.EnableBrightmap(!(huds->RenderStyle.Flags & STYLEF_ColorIsFixed));

int gl_spritelight = get_gl_spritelight();

if (huds->mframe)
{
state.SetShadeVertex(get_gl_spritelight() == 1);
state.SetDynLight(0.0, 0.0, 0.0);
state.SetShadeVertex(gl_spritelight == 1);
state.AlphaFunc(Alpha_GEqual, 0);

FHWModelRenderer renderer(this, state, huds->lightindex);
Expand All @@ -97,12 +99,30 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
}
else
{
if(gl_spritelight != 0)
{
state.SetShadeVertex(true);
state.SetLightNoNormals(true);
state.SetUseSpriteCenter(true);
state.SetActorCenter(huds->owner->X(), huds->owner->Center(), huds->owner->Y());
state.SetLightIndex(huds->lightindex);
state.SetDynLight(0.0, 0.0, 0.0);
}
else
{
state.SetDynLight(huds->dynrgb[0], huds->dynrgb[1], huds->dynrgb[2]);
}

float thresh = (huds->texture->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold;
state.AlphaFunc(Alpha_GEqual, thresh);
FTranslationID trans = huds->weapon->GetTranslation();
if ((huds->weapon->Flags & PSPF_PLAYERTRANSLATED)) trans = huds->owner->Translation;
state.SetMaterial(huds->texture, UF_Sprite, CTF_Expand, CLAMP_XY_NOMIP, trans, huds->OverrideShader);
state.Draw(DT_TriangleStrip, huds->mx, 4);
state.SetShadeVertex(false);
state.SetLightNoNormals(false);
state.SetUseSpriteCenter(false);
state.SetLightIndex(-1);
}

state.SetTextureMode(TM_NORMAL);
Expand Down Expand Up @@ -741,7 +761,15 @@ void HWDrawInfo::PreparePlayerSprites2D(sector_t * viewsector, area_t in_area, F
// set the lighting parameters
if (hudsprite.RenderStyle.BlendOp != STYLEOP_Shadow && Level->HasDynamicLights && !isFullbrightScene() && gl_light_sprites)
{
GetDynSpriteLight(playermo, nullptr, nullptr, hudsprite.dynrgb);
if(get_gl_spritelight() == 0)
{
GetDynSpriteLight(playermo, nullptr, nullptr, hudsprite.dynrgb);
}
else
{
GetDynSpriteLightList(playermo, nullptr, nullptr, lightdata, true);
hudsprite.lightindex = state.UploadLights(lightdata);
}
}

if (!hudsprite.GetWeaponRect(this, state, psp, spos.X, spos.Y, player, vp.TicFrac)) continue;
Expand Down
Loading