From cbda6e942790b207e8f58003cbe911125c9d75fb Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 26 Jul 2017 09:18:05 +0200 Subject: [PATCH] - Improve dynamic lights for the HUD model --- src/gl/dynlights/gl_dynlight.h | 2 +- src/gl/dynlights/gl_dynlight1.cpp | 27 ++++++++++++++++++++++++++- src/gl/models/gl_models.cpp | 3 +++ src/gl/scene/gl_spritelight.cpp | 4 ++-- src/gl/scene/gl_wall.h | 2 +- src/gl/scene/gl_weapon.cpp | 6 +++++- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/gl/dynlights/gl_dynlight.h b/src/gl/dynlights/gl_dynlight.h index 2796f093e..3eb19ee39 100644 --- a/src/gl/dynlights/gl_dynlight.h +++ b/src/gl/dynlights/gl_dynlight.h @@ -58,7 +58,7 @@ struct FDynLightData -bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, FDynLightData &data, bool planecheck = true); +bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, FDynLightData &data, bool planecheck = true, bool hudmodel = false); void gl_UploadLights(FDynLightData &data); diff --git a/src/gl/dynlights/gl_dynlight1.cpp b/src/gl/dynlights/gl_dynlight1.cpp index db1eebc43..13443c26a 100644 --- a/src/gl/dynlights/gl_dynlight1.cpp +++ b/src/gl/dynlights/gl_dynlight1.cpp @@ -63,7 +63,7 @@ CVAR(Int, gl_attenuate, -1, 0); // This is mainly a debug option. // Sets up the parameters to render one dynamic light onto one plane // //========================================================================== -bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, FDynLightData &ldata, bool planecheck) +bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, FDynLightData &ldata, bool planecheck, bool hudmodel) { int i = 0; @@ -82,6 +82,31 @@ bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, FD } } + if (hudmodel) + { + // HUD model is already translated and rotated. We must rotate the lights into that view space. + + DVector3 rotation; + DVector3 localpos = pos - r_viewpoint.Pos; + + rotation.X = localpos.X * r_viewpoint.Angles.Yaw.Sin() - localpos.Y * r_viewpoint.Angles.Yaw.Cos(); + rotation.Y = localpos.X * r_viewpoint.Angles.Yaw.Cos() + localpos.Y * r_viewpoint.Angles.Yaw.Sin(); + rotation.Z = localpos.Z; + localpos = rotation; + + rotation.X = localpos.X; + rotation.Y = localpos.Y * r_viewpoint.Angles.Pitch.Sin() - localpos.Z * r_viewpoint.Angles.Pitch.Cos(); + rotation.Z = localpos.Y * r_viewpoint.Angles.Pitch.Cos() + localpos.Z * r_viewpoint.Angles.Pitch.Sin(); + localpos = rotation; + + rotation.Y = localpos.Y; + rotation.Z = localpos.Z * r_viewpoint.Angles.Roll.Sin() - localpos.X * r_viewpoint.Angles.Roll.Cos(); + rotation.X = localpos.Z * r_viewpoint.Angles.Roll.Cos() + localpos.X * r_viewpoint.Angles.Roll.Sin(); + localpos = rotation; + + pos = localpos; + } + float cs; if (light->IsAdditive()) { diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index a118e20f2..45b955b56 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -1099,6 +1099,9 @@ void gl_RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) // so we have to reset the view matrix. gl_RenderState.mViewMatrix.loadIdentity(); + // Need to reset the normal matrix too + gl_RenderState.mNormalViewMatrix.loadIdentity(); + // Scaling model (y scale for a sprite means height, i.e. z in the world!). gl_RenderState.mViewMatrix.scale(smf->xscale, smf->zscale, smf->yscale); diff --git a/src/gl/scene/gl_spritelight.cpp b/src/gl/scene/gl_spritelight.cpp index 58b31f67d..7a30015f8 100644 --- a/src/gl/scene/gl_spritelight.cpp +++ b/src/gl/scene/gl_spritelight.cpp @@ -132,7 +132,7 @@ void gl_SetDynSpriteLight(AActor *thing, particle_t *particle) } } -void gl_SetDynModelLight(AActor *self, float x, float y, float z, subsector_t * subsec) +void gl_SetDynModelLight(AActor *self, float x, float y, float z, subsector_t * subsec, bool hudmodel) { Plane p; p.Set(subsec->sector->ceilingplane); // Is this correct? @@ -146,7 +146,7 @@ void gl_SetDynModelLight(AActor *self, float x, float y, float z, subsector_t * ADynamicLight *light = node->lightsource; if (light->visibletoplayer && !(light->flags2&MF2_DORMANT) && (!(light->lightflags&LF_DONTLIGHTSELF) || light->target != self) && !(light->lightflags&LF_DONTLIGHTACTORS)) { - gl_GetLight(subsec->sector->PortalGroup, p, node->lightsource, false, modellightdata, false); + gl_GetLight(subsec->sector->PortalGroup, p, node->lightsource, false, modellightdata, false, hudmodel); } node = node->nextLight; } diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index 2f3fb6638..9298a4703 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -422,6 +422,6 @@ inline float Dist2(float x1,float y1,float x2,float y2) void gl_SetDynSpriteLight(AActor *self, float x, float y, float z, subsector_t *subsec); void gl_SetDynSpriteLight(AActor *actor, particle_t *particle); -void gl_SetDynModelLight(AActor *self, float x, float y, float z, subsector_t * subsec); +void gl_SetDynModelLight(AActor *self, float x, float y, float z, subsector_t * subsec, bool hudmodel = false); #endif diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index ff2321da5..36990944e 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -420,7 +420,11 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) { if (gl_lights && GLRenderer->mLightCount && FixedColormap == CM_DEFAULT && gl_light_sprites) { - gl_SetDynSpriteLight(playermo, NULL); + FSpriteModelFrame *smf = gl_FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetState()->sprite, psp->GetState()->GetFrame(), false); + if (smf) + gl_SetDynModelLight(playermo, playermo->X(), playermo->Y(), playermo->Center(), playermo->subsector, true); + else + gl_SetDynSpriteLight(playermo, NULL); } SetColor(ll, 0, cmc, trans, true); }