From 51baa7d137486bf07c40017e471aa4340c2857e1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 5 May 2016 11:32:21 +0200 Subject: [PATCH] - added code to calculate light texture coordinates on walls. --- src/gl/compatibility/gl_20.cpp | 58 ++++++++++++++++++++++++++++++++-- src/gl/scene/gl_wall.h | 3 +- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index 5c7c983d3..96cd88fd8 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -379,7 +379,7 @@ void FRenderState::DrawColormapOverlay() //========================================================================== bool gl_SetupLight(int group, Plane & p, ADynamicLight * light, Vector & nearPt, Vector & up, Vector & right, - float & scale, int desaturation, bool checkside, bool forceadditive) + float & scale, int desaturation, bool checkside, bool additive) { Vector fn, pos; @@ -416,7 +416,7 @@ bool gl_SetupLight(int group, Plane & p, ADynamicLight * light, Vector & nearPt, #endif float cs = 1.0f - (dist / radius); - if (gl_lights_additive || light->flags4&MF4_ADDITIVE || forceadditive) cs *= 0.2f; // otherwise the light gets too strong. + if (additive) cs *= 0.2f; // otherwise the light gets too strong. float r = light->GetRed() / 255.0f * cs * gl_lights_intensity; float g = light->GetGreen() / 255.0f * cs * gl_lights_intensity; float b = light->GetBlue() / 255.0f * cs * gl_lights_intensity; @@ -613,7 +613,7 @@ void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass) } p.Set(plane.plane); - if (!gl_SetupLight(sub->sector->PortalGroup, p, light, nearPt, up, right, scale, CM_DEFAULT, false, foggy)) + if (!gl_SetupLight(sub->sector->PortalGroup, p, light, nearPt, up, right, scale, CM_DEFAULT, false, pass == GLPASS_LIGHTTEX_ADDITIVE)) { node = node->nextLight; continue; @@ -681,6 +681,58 @@ void GLFlat::DrawLightsCompat(int pass) } +//========================================================================== +// +// Sets up the texture coordinates for one light to be rendered +// +//========================================================================== +bool GLWall::PrepareLight(texcoord * tcs, ADynamicLight * light, int pass) +{ + float vtx[] = { glseg.x1,zbottom[0],glseg.y1, glseg.x1,ztop[0],glseg.y1, glseg.x2,ztop[1],glseg.y2, glseg.x2,zbottom[1],glseg.y2 }; + Plane p; + Vector nearPt, up, right; + float scale; + + p.Init(vtx, 4); + + if (!p.ValidNormal()) + { + return false; + } + + if (!gl_SetupLight(seg->frontsector->PortalGroup, p, light, nearPt, up, right, scale, CM_DEFAULT, true, pass == GLPASS_LIGHTTEX_ADDITIVE)) + { + return false; + } + + if (tcs != NULL) + { + Vector t1; + int outcnt[4] = { 0,0,0,0 }; + + for (int i = 0; i<4; i++) + { + t1.Set(&vtx[i * 3]); + Vector nearToVert = t1 - nearPt; + tcs[i].u = (nearToVert.Dot(right) * scale) + 0.5f; + tcs[i].v = (nearToVert.Dot(up) * scale) + 0.5f; + + // quick check whether the light touches this polygon + if (tcs[i].u<0) outcnt[0]++; + if (tcs[i].u>1) outcnt[1]++; + if (tcs[i].v<0) outcnt[2]++; + if (tcs[i].v>1) outcnt[3]++; + + } + // The light doesn't touch this polygon + if (outcnt[0] == 4 || outcnt[1] == 4 || outcnt[2] == 4 || outcnt[3] == 4) return false; + } + + draw_dlight++; + return true; +} + + //========================================================================== // // diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index 3bdcbd6ce..cfd8ae361 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -183,7 +183,7 @@ private: void SplitWall(sector_t * frontsector, bool translucent); void SetupLights(); - bool PrepareLight(texcoord * tcs, ADynamicLight * light); + bool PrepareLight(texcoord * tcs, ADynamicLight * light, int pass); void RenderWall(int textured, unsigned int *store = NULL); void RenderTextured(int rflags); @@ -288,7 +288,6 @@ public: GLSectorPlane plane; int lightlevel; bool stack; - bool foggy; bool ceiling; BYTE renderflags; int vboindex;