- Improve dynamic lights for the HUD model

This commit is contained in:
Magnus Norddahl 2017-07-26 09:18:05 +02:00
parent 0c0f0789c2
commit cbda6e9427
6 changed files with 38 additions and 6 deletions

View file

@ -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); void gl_UploadLights(FDynLightData &data);

View file

@ -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 // 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; 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; float cs;
if (light->IsAdditive()) if (light->IsAdditive())
{ {

View file

@ -1099,6 +1099,9 @@ void gl_RenderHUDModel(DPSprite *psp, float ofsX, float ofsY)
// so we have to reset the view matrix. // so we have to reset the view matrix.
gl_RenderState.mViewMatrix.loadIdentity(); 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!). // 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); gl_RenderState.mViewMatrix.scale(smf->xscale, smf->zscale, smf->yscale);

View file

@ -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; Plane p;
p.Set(subsec->sector->ceilingplane); // Is this correct? 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; ADynamicLight *light = node->lightsource;
if (light->visibletoplayer && !(light->flags2&MF2_DORMANT) && (!(light->lightflags&LF_DONTLIGHTSELF) || light->target != self) && !(light->lightflags&LF_DONTLIGHTACTORS)) 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; node = node->nextLight;
} }

View file

@ -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 *self, float x, float y, float z, subsector_t *subsec);
void gl_SetDynSpriteLight(AActor *actor, particle_t *particle); 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 #endif

View file

@ -420,6 +420,10 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep)
{ {
if (gl_lights && GLRenderer->mLightCount && FixedColormap == CM_DEFAULT && gl_light_sprites) if (gl_lights && GLRenderer->mLightCount && FixedColormap == CM_DEFAULT && gl_light_sprites)
{ {
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); gl_SetDynSpriteLight(playermo, NULL);
} }
SetColor(ll, 0, cmc, trans, true); SetColor(ll, 0, cmc, trans, true);