From c69941a9e9465c247353f3195b1bb85b0cf9f599 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Thu, 14 Jun 2018 18:26:34 -0400 Subject: [PATCH] - add 'sublighttype' for Subtractive dynamic lights to change the colour formula. --- src/g_shared/a_dynlight.h | 12 ++++++++++ src/hwrenderer/dynlights/hw_dynlightdata.cpp | 13 ++++++---- src/r_data/gldefs.cpp | 25 +++++++++++++++++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/g_shared/a_dynlight.h b/src/g_shared/a_dynlight.h index ae2493ca2a..fe2fa2a1d6 100644 --- a/src/g_shared/a_dynlight.h +++ b/src/g_shared/a_dynlight.h @@ -46,6 +46,13 @@ enum LightFlag LF_SPOT = 64 }; +enum SubLightFormula +{ + SLF_ZDOOMGL = 1, + SLF_PRECISE = 2, + SLF_RAW = 3, +}; + //========================================================================== // // Light definitions @@ -72,6 +79,8 @@ public: void SetSpot(bool spot) { m_spot = spot; } void SetSpotInnerAngle(double angle) { m_spotInnerAngle = angle; } void SetSpotOuterAngle(double angle) { m_spotOuterAngle = angle; } + uint8_t GetSubLightType() { return m_sublighttype; } + void SetSubLightType(uint8_t val) { m_sublighttype = val; } void OrderIntensities() { @@ -98,6 +107,7 @@ protected: bool m_spot = false; double m_spotInnerAngle = 10.0; double m_spotOuterAngle = 25.0; + uint8_t m_sublighttype = 1; }; //========================================================================== @@ -203,6 +213,8 @@ public: bool IsSubtractive() { return !!(lightflags & LF_SUBTRACTIVE); } bool IsAdditive() { return !!(lightflags & LF_ADDITIVE); } bool IsSpot() { return !!(lightflags & LF_SPOT); } + uint8_t GetSubLightType(); + void SetSubLightType(uint8_t Val); FState *targetState; FLightNode * touching_sides; FLightNode * touching_subsectors; diff --git a/src/hwrenderer/dynlights/hw_dynlightdata.cpp b/src/hwrenderer/dynlights/hw_dynlightdata.cpp index c881f9b4ec..56be3d5cb8 100644 --- a/src/hwrenderer/dynlights/hw_dynlightdata.cpp +++ b/src/hwrenderer/dynlights/hw_dynlightdata.cpp @@ -97,11 +97,14 @@ void FDynLightData::AddLightToList(int group, ADynamicLight * light, bool forceA if (light->IsSubtractive()) { DVector3 v(r, g, b); - float length = (float)v.Length(); - - r = length - r; - g = length - g; - b = length - b; + float length = (light->GetSubLightType() == 1) ? ((float)v.Length()) : (r + g + b - clamp(r, g, b)); + + if (light->GetSubLightType() != 3) + { + r = length - r; + g = length - g; + b = length - b; + } i = 1; } diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index 4ebd8283fd..f455a0214d 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -136,6 +136,7 @@ static const char *LightTags[]= "attenuate", "dontlightactors", "spot", + "sublighttype", nullptr }; @@ -158,7 +159,8 @@ enum { LIGHTTAG_DONTLIGHTSELF, LIGHTTAG_ATTENUATE, LIGHTTAG_DONTLIGHTACTORS, - LIGHTTAG_SPOT + LIGHTTAG_SPOT, + LIGHTTAG_SUBLIGHTTYPE, }; //========================================================================== @@ -463,6 +465,10 @@ class GLDefsParser defaults->SetSpotOuterAngle(outerAngle); } break; + case LIGHTTAG_SUBLIGHTTYPE: + intVal = clamp(ParseInt(sc), 1, 3); + defaults->SetSubLightType(intVal); + break; default: sc.ScriptError("Unknown tag: %s\n", sc.String); } @@ -556,6 +562,10 @@ class GLDefsParser defaults->SetSpotOuterAngle(outerAngle); } break; + case LIGHTTAG_SUBLIGHTTYPE: + intVal = clamp(ParseInt(sc), 1, 3); + defaults->SetSubLightType(intVal); + break; default: sc.ScriptError("Unknown tag: %s\n", sc.String); } @@ -652,6 +662,10 @@ class GLDefsParser defaults->SetSpotOuterAngle(outerAngle); } break; + case LIGHTTAG_SUBLIGHTTYPE: + intVal = clamp(ParseInt(sc), 1, 3); + defaults->SetSubLightType(intVal); + break; default: sc.ScriptError("Unknown tag: %s\n", sc.String); } @@ -747,6 +761,10 @@ class GLDefsParser defaults->SetSpotOuterAngle(outerAngle); } break; + case LIGHTTAG_SUBLIGHTTYPE: + intVal = clamp(ParseInt(sc), 1, 3); + defaults->SetSubLightType(intVal); + break; default: sc.ScriptError("Unknown tag: %s\n", sc.String); } @@ -777,6 +795,7 @@ class GLDefsParser int type; float floatVal; float floatTriple[3]; + int intVal; FLightDefaults *defaults; // get name @@ -839,6 +858,10 @@ class GLDefsParser defaults->SetSpotOuterAngle(outerAngle); } break; + case LIGHTTAG_SUBLIGHTTYPE: + intVal = clamp(ParseInt(sc), 1, 3); + defaults->SetSubLightType(intVal); + break; default: sc.ScriptError("Unknown tag: %s\n", sc.String); }