diff --git a/src/gl/dynlights/gl_dynlight.h b/src/gl/dynlights/gl_dynlight.h index a85814b6b..1ecdca4ce 100644 --- a/src/gl/dynlights/gl_dynlight.h +++ b/src/gl/dynlights/gl_dynlight.h @@ -59,7 +59,7 @@ struct FDynLightData bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, FDynLightData &data); -void gl_AddLightToList(int group, ADynamicLight * light, FDynLightData &ldata, bool hudmodel); +void gl_AddLightToList(int group, ADynamicLight * light, FDynLightData &ldata); void gl_UploadLights(FDynLightData &data); diff --git a/src/gl/dynlights/gl_dynlight1.cpp b/src/gl/dynlights/gl_dynlight1.cpp index 92a503c8d..e42f89ac4 100644 --- a/src/gl/dynlights/gl_dynlight1.cpp +++ b/src/gl/dynlights/gl_dynlight1.cpp @@ -77,7 +77,7 @@ bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, FD return false; } - gl_AddLightToList(group, light, ldata, false); + gl_AddLightToList(group, light, ldata); return true; } @@ -86,38 +86,13 @@ bool gl_GetLight(int group, Plane & p, ADynamicLight * light, bool checkside, FD // Add one dynamic light to the light data list // //========================================================================== -void gl_AddLightToList(int group, ADynamicLight * light, FDynLightData &ldata, bool hudmodel) +void gl_AddLightToList(int group, ADynamicLight * light, FDynLightData &ldata) { int i = 0; DVector3 pos = light->PosRelative(group); float radius = light->GetRadius(); - 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 45b955b56..fcad2a95b 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -1095,33 +1095,33 @@ void gl_RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) glFrontFace(GL_CCW); } - // [BB] The model has to be drawn independently from the position of the player, - // so we have to reset the view matrix. - gl_RenderState.mViewMatrix.loadIdentity(); - - // Need to reset the normal matrix too - gl_RenderState.mNormalViewMatrix.loadIdentity(); + // The model position and orientation has to be drawn independently from the position of the player, + // but we need to position it correctly in the world for light to work properly. + VSMatrix objectToWorldMatrix; + gl_RenderState.mViewMatrix.inverseMatrix(objectToWorldMatrix); // 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); + objectToWorldMatrix.scale(smf->xscale, smf->zscale, smf->yscale); // Aplying model offsets (model offsets do not depend on model scalings). - gl_RenderState.mViewMatrix.translate(smf->xoffset / smf->xscale, smf->zoffset / smf->zscale, smf->yoffset / smf->yscale); + objectToWorldMatrix.translate(smf->xoffset / smf->xscale, smf->zoffset / smf->zscale, smf->yoffset / smf->yscale); // [BB] Weapon bob, very similar to the normal Doom weapon bob. - gl_RenderState.mViewMatrix.rotate(ofsX/4, 0, 1, 0); - gl_RenderState.mViewMatrix.rotate((ofsY-WEAPONTOP)/-4., 1, 0, 0); + objectToWorldMatrix.rotate(ofsX/4, 0, 1, 0); + objectToWorldMatrix.rotate((ofsY-WEAPONTOP)/-4., 1, 0, 0); // [BB] For some reason the jDoom models need to be rotated. - gl_RenderState.mViewMatrix.rotate(90.f, 0, 1, 0); + objectToWorldMatrix.rotate(90.f, 0, 1, 0); // Applying angleoffset, pitchoffset, rolloffset. - gl_RenderState.mViewMatrix.rotate(-smf->angleoffset, 0, 1, 0); - gl_RenderState.mViewMatrix.rotate(smf->pitchoffset, 0, 0, 1); - gl_RenderState.mViewMatrix.rotate(-smf->rolloffset, 1, 0, 0); - gl_RenderState.ApplyMatrices(); + objectToWorldMatrix.rotate(-smf->angleoffset, 0, 1, 0); + objectToWorldMatrix.rotate(smf->pitchoffset, 0, 0, 1); + objectToWorldMatrix.rotate(-smf->rolloffset, 1, 0, 0); + gl_RenderState.mModelMatrix = objectToWorldMatrix; + gl_RenderState.EnableModelMatrix(true); gl_RenderFrameModels( smf, psp->GetState(), psp->GetTics(), playermo->player->ReadyWeapon->GetClass(), nullptr, 0 ); + gl_RenderState.EnableModelMatrix(false); glDepthFunc(GL_LESS); if (!( playermo->RenderStyle == LegacyRenderStyles[STYLE_Normal] )) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 5ca2cd65d..154720022 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -335,7 +335,7 @@ void GLSprite::Draw(int pass) if (gl_lights && GLRenderer->mLightCount && mDrawer->FixedColormap == CM_DEFAULT && !fullbright) { if (modelframe && !particle) - gl_SetDynModelLight(gl_light_sprites ? actor : NULL, false); + gl_SetDynModelLight(gl_light_sprites ? actor : NULL); else gl_SetDynSpriteLight(gl_light_sprites ? actor : NULL, gl_light_particles ? particle : NULL); } diff --git a/src/gl/scene/gl_spritelight.cpp b/src/gl/scene/gl_spritelight.cpp index e348956bf..2d2e65b76 100644 --- a/src/gl/scene/gl_spritelight.cpp +++ b/src/gl/scene/gl_spritelight.cpp @@ -177,7 +177,7 @@ void BSPWalkCircle(float x, float y, float radiusSquared, const Callback &callba BSPNodeWalkCircle(level.HeadNode(), x, y, radiusSquared, callback); } -void gl_SetDynModelLight(AActor *self, bool hudmodel) +void gl_SetDynModelLight(AActor *self) { // Legacy and deferred render paths gets the old flat model light if (gl.lightmethod != LM_DIRECT) @@ -218,7 +218,7 @@ void gl_SetDynModelLight(AActor *self, bool hudmodel) { if (std::find(addedLights.begin(), addedLights.end(), light) == addedLights.end()) // Check if we already added this light from a different subsector { - gl_AddLightToList(group, light, modellightdata, hudmodel); + gl_AddLightToList(group, light, modellightdata); addedLights.push_back(light); } } diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index 47cf5654c..aa0bbaed4 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, bool hudmodel); +void gl_SetDynModelLight(AActor *self); #endif diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 551f34cbd..3d4224520 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -422,7 +422,7 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) { FSpriteModelFrame *smf = playermo->player->ReadyWeapon ? gl_FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetState()->sprite, psp->GetState()->GetFrame(), false) : nullptr; if (smf) - gl_SetDynModelLight(playermo, true); + gl_SetDynModelLight(playermo); else gl_SetDynSpriteLight(playermo, NULL); }