From 6a804cd4c7cfc1a5bc8f3ae12853effe01ae90c0 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 14 Oct 2021 06:11:54 +0200 Subject: [PATCH] Fix lightmaps got applied to model meshes --- .../hwrenderer/data/hw_modelvertexbuffer.cpp | 1 + src/common/rendering/i_modelvertexbuffer.h | 3 +++ src/rendering/hwrenderer/scene/hw_sprites.cpp | 13 +++++++------ src/rendering/hwrenderer/scene/hw_weapon.cpp | 1 - 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp b/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp index e4d5ba030..7460eebaf 100644 --- a/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp +++ b/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp @@ -46,6 +46,7 @@ FModelVertexBuffer::FModelVertexBuffer(bool needindex, bool singleframe) { 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FModelVertex, x) }, { 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FModelVertex, u) }, { 0, VATTR_NORMAL, VFmt_Packed_A2R10G10B10, (int)myoffsetof(FModelVertex, packedNormal) }, + { 0, VATTR_LIGHTMAP, VFmt_Float3, (int)myoffsetof(FModelVertex, lu) }, { 1, VATTR_VERTEX2, VFmt_Float3, (int)myoffsetof(FModelVertex, x) }, { 1, VATTR_NORMAL2, VFmt_Packed_A2R10G10B10, (int)myoffsetof(FModelVertex, packedNormal) } }; diff --git a/src/common/rendering/i_modelvertexbuffer.h b/src/common/rendering/i_modelvertexbuffer.h index febec3c71..170291511 100644 --- a/src/common/rendering/i_modelvertexbuffer.h +++ b/src/common/rendering/i_modelvertexbuffer.h @@ -7,6 +7,8 @@ struct FModelVertex float x, y, z; // world position float u, v; // texture coordinates unsigned packedNormal; // normal vector as GL_INT_2_10_10_10_REV. + float lu, lv; // lightmap texture coordinates + float lindex; // lightmap texture index void Set(float xx, float yy, float zz, float uu, float vv) { @@ -15,6 +17,7 @@ struct FModelVertex z = zz; u = uu; v = vv; + lindex = -1.0f; } void SetNormal(float nx, float ny, float nz) diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index f7e41cbc8..ddc50e760 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -172,12 +172,6 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) di->GetDynSpriteLight(gl_light_sprites ? actor : nullptr, gl_light_particles ? particle : nullptr, out); state.SetDynLight(out[0], out[1], out[2]); } - else if (di->Level->LightProbes.Size() > 0) - { - LightProbe* probe = FindLightProbe(di->Level, actor->X(), actor->Y(), actor->Center()); - if (probe) - state.SetDynLight(probe->Red, probe->Green, probe->Blue); - } } sector_t *cursec = actor ? actor->Sector : particle ? particle->subsector->sector : nullptr; if (cursec != nullptr) @@ -298,6 +292,13 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) } else { + if (actor && di->Level->LightProbes.Size() > 0) + { + LightProbe* probe = FindLightProbe(di->Level, actor->X(), actor->Y(), actor->Center()); + if (probe) + state.SetDynLight(probe->Red, probe->Green, probe->Blue); + } + FHWModelRenderer renderer(di, state, dynlightindex); RenderModel(&renderer, x, y, z, modelframe, actor, di->Viewpoint.TicFrac); state.SetVertexBuffer(screen->mVertexData); diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index e95512f0f..1ba5dafe6 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -641,7 +641,6 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) { hw_GetDynModelLight(playermo, lightdata); hudsprite.lightindex = screen->mLights->UploadLights(lightdata); - LightProbe* probe = FindLightProbe(playermo->Level, playermo->X(), playermo->Y(), playermo->Center()); if (probe) {