From 295f3f1eeb204544d9f8aa3a8cefafff82e681c7 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Thu, 26 Oct 2023 18:05:37 +0300 Subject: [PATCH 1/5] Dynamic light fade in / out --- .../modules/cl_render.lua | 152 +++++++++++++++--- 1 file changed, 130 insertions(+), 22 deletions(-) diff --git a/lua/entities/gmod_tardis_interior/modules/cl_render.lua b/lua/entities/gmod_tardis_interior/modules/cl_render.lua index b5d9c5539..6bdb52e4c 100644 --- a/lua/entities/gmod_tardis_interior/modules/cl_render.lua +++ b/lua/entities/gmod_tardis_interior/modules/cl_render.lua @@ -7,26 +7,6 @@ local function predraw_o(self, part) local power = self:GetPower() - render.SuppressEngineLighting(true) - - local br = power and lo.basebrightness or lo.nopowerbrightness - local col = power and lo.basebrightnessRGB or lo.nopowerbrightnessRGB - - local parts_table = power and lo.parts or lo.parts_nopower - - if part and parts_table and parts_table[part.ID] then - local part_br = parts_table[part.ID] - if istable(part_br) then - render.ResetModelLighting(part_br[1], part_br[2], part_br[3]) - else - render.ResetModelLighting(part_br, part_br, part_br) - end - elseif col then - render.ResetModelLighting(col[1], col[2], col[3]) - else - render.ResetModelLighting(br, br, br) - end - --render.SetLightingMode(1) local light = self.light_data.main @@ -52,17 +32,145 @@ local function predraw_o(self, part) end -- power and no warning return lt.render_table + end + + local function ltempty(lt1) + return table.IsEmpty(lt1) or (not lt1.color) or (not lt1.pos) + end + + local function ltcmp(lt1, lt2, only_pos) + if lt1 == lt2 then return true end + if ltempty(lt1) and ltempty(lt2) then return true end + if ltempty(lt1) or ltempty(lt2) then return false end + + local color_ok = (lt1.color == lt2.color) + local pos_ok = (lt1.pos == lt2.pos) + + return (only_pos or color_ok) and pos_ok + end + + local function GetLightRenderTable(lt) + local sel = SelectLightRenderTable(lt) + + if ltempty(sel) then + sel.color = sel.color or Vector(0,0,0) + sel.pos = sel.pos or (lt.current and lt.current.pos) or Vector(0,0,0) + sel.empty = true + sel.type = sel.type or MATERIAL_LIGHT_POINT + sel.quadraticFalloff = sel.quadraticFalloff or lt.quadraticFalloff or 20 + end + + if not lt.selected or not lt.current then + lt.current = sel + lt.prevsel = lt.selected + lt.selected = sel + lt.select_time = CurTime() + return sel + end + + if not ltcmp(lt.selected, sel) then + lt.prevsel = lt.selected + lt.selected = sel + lt.select_time = CurTime() + end + + if ltcmp(sel, lt.current) then + return sel + end + + local dt = (CurTime() - lt.select_time) / 2 + + if ltcmp(sel, lt.current, true) then + -- same positions but different colors + + local col_approach = math.Clamp(dt,0,1) + local ap2 = 1 - col_approach + local newc = lt.prevsel.color * ap2 + sel.color * col_approach + + lt.current = { + type = sel.type, + quadraticFalloff = sel.quadraticFalloff, + pos = sel.pos, + color = newc, + } + + if newc == Vector(0,0,0) then + return {} + end + + return lt.current + end + + if dt < 0.5 then + local col_approach = math.Clamp(2 * dt,0,1) + local ap2 = 1 - col_approach + + --local nc = lt.prevsel.color:ToColor() + --local newcol2 = Color(nc.r * ap2, nc.g * ap2, nc.b * ap2) + --local newc = newcol2:ToVector() --lt.prevsel.color * ap2 + + local newc = lt.prevsel.color * ap2 + + lt.current = { + type = sel.type, + quadraticFalloff = sel.quadraticFalloff, + color = newc, + pos = lt.prevsel.pos + } + return lt.current + end + + if sel.empty then + lt.current = sel + return {} + end + + -- dt > 0.5 + + local col_approach = math.Clamp((dt - 0.5) * 2,0,1) + local ap2 = 1 - col_approach + + local newc = sel.color * col_approach + + lt.current = { + type = sel.type, + quadraticFalloff = sel.quadraticFalloff, + color = newc, + pos = sel.pos + } + return lt.current + + end + + render.SuppressEngineLighting(true) + + local br = power and lo.basebrightness or lo.nopowerbrightness + local col = power and lo.basebrightnessRGB or lo.nopowerbrightnessRGB + + local parts_table = power and lo.parts or lo.parts_nopower + + if part and parts_table and parts_table[part.ID] then + local part_br = parts_table[part.ID] + if istable(part_br) then + render.ResetModelLighting(part_br[1], part_br[2], part_br[3]) + else + render.ResetModelLighting(part_br, part_br, part_br) + end + elseif col then + render.ResetModelLighting(col[1], col[2], col[3]) + else + render.ResetModelLighting(br, br, br) end - table.insert(tab, SelectLightRenderTable(light)) + table.insert(tab, GetLightRenderTable(light)) if lights then for _,l in pairs(lights) do if not TARDIS:GetSetting("extra-lights") then table.insert(tab, {}) else - table.insert(tab, SelectLightRenderTable(l) or {}) + table.insert(tab, GetLightRenderTable(l) or {}) end end end From c7f75126d585d21b0d065ed006a44fa6eceae4ce Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Thu, 26 Oct 2023 18:05:38 +0300 Subject: [PATCH 2/5] Setting and lighting override transition --- i18n/languages/cy.json | 2 + i18n/languages/de.json | 2 + i18n/languages/en.json | 2 + i18n/languages/es-ES.json | 2 + i18n/languages/fi.json | 2 + i18n/languages/fr.json | 2 + i18n/languages/pt-BR.json | 2 + i18n/languages/pt-PT.json | 2 + i18n/languages/ru.json | 2 + i18n/languages/tr.json | 2 + i18n/languages/zh-CN.json | 2 + i18n/languages/zh-TW.json | 2 + .../modules/cl_render.lua | 63 ++++++++++++++----- lua/tardis/languages/en.lua | 2 + lua/tardis/settings/cl_performance.lua | 12 ++++ 15 files changed, 87 insertions(+), 14 deletions(-) diff --git a/i18n/languages/cy.json b/i18n/languages/cy.json index 73ed6bc74..e18e175a5 100644 --- a/i18n/languages/cy.json +++ b/i18n/languages/cy.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "P'un a fydd pyrth yn rendro ai peidio, trowch hwn i ffwrdd os ydynt yn effeithio'n sylweddol ar y ffrâm", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Golau Allanol Drws Rhagamcanol", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "A ddylai golau ddisgleirio drwy'r drysau pan fyddant ar agor?", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "Sain a Cherddoriaeth", "Settings.Sections.SoundsAndMusic.Music": "Cerddoriaeth", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Galluogwyd", diff --git a/i18n/languages/de.json b/i18n/languages/de.json index 42bdd8f3e..5bb839823 100644 --- a/i18n/languages/de.json +++ b/i18n/languages/de.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "Ob Portale gerendert werden oder nicht, deaktivieren Sie dies, wenn sie die Framerate erheblich beeinträchtigen", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Projizierte Tür-Außenleuchte", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "Sollte Licht durch die Türen scheinen, wenn sie geöffnet sind?", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "Klänge und Musik", "Settings.Sections.SoundsAndMusic.Music": "Musik", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Aktiviert", diff --git a/i18n/languages/en.json b/i18n/languages/en.json index 37e4137bd..28215e824 100644 --- a/i18n/languages/en.json +++ b/i18n/languages/en.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "Whether portals will render or not, turn this off if they impact framerate significantly", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Projected Door Exterior Light", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "Should light shine out through the doors when they're open?", + "Settings.Sections.Performance.SmoothLightTransitions": "Smooth lighting transitions", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "Should interior lights have fading in and out animations?", "Settings.Sections.SoundsAndMusic": "Sounds & Music", "Settings.Sections.SoundsAndMusic.Music": "Music", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Enabled", diff --git a/i18n/languages/es-ES.json b/i18n/languages/es-ES.json index 2e06fccd0..5e075c07a 100644 --- a/i18n/languages/es-ES.json +++ b/i18n/languages/es-ES.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "Controla si se renderizan los portales. Apaga esto si tienen alto impacto en tus cuadros por segundo", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Luz Proyectada de Puerta Exterior", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "Controla si debería brillar luz a través de las puertas exteriores al abrirlas", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "Sonidos y Música", "Settings.Sections.SoundsAndMusic.Music": "Música", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Activado", diff --git a/i18n/languages/fi.json b/i18n/languages/fi.json index 53aad7239..e7038fa53 100644 --- a/i18n/languages/fi.json +++ b/i18n/languages/fi.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "Äänet & musiikki", "Settings.Sections.SoundsAndMusic.Music": "Musiikki", "Settings.Sections.SoundsAndMusic.Music.Enabled": "", diff --git a/i18n/languages/fr.json b/i18n/languages/fr.json index 7a6474535..8fc34c6fc 100644 --- a/i18n/languages/fr.json +++ b/i18n/languages/fr.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "Si les portails seront rendus ou non, désactivez cette option s'ils ont un impact significatif sur la fréquence d'images", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Lumière de porte extérieure projetée", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "La lumière doit-elle briller à travers les portes quand elles sont ouvertes ?", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "Sons et Musique", "Settings.Sections.SoundsAndMusic.Music": "Musique", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Activé", diff --git a/i18n/languages/pt-BR.json b/i18n/languages/pt-BR.json index 3c214bf41..fe178d5f8 100644 --- a/i18n/languages/pt-BR.json +++ b/i18n/languages/pt-BR.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "Controla se os portais serão renderizados, desligue isso se eles afetarem a taxa de quadros significativamente", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Luz Externa Projetada pela Porta", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "Luz deve ser projetada para fora quando as portas estiverem abertas?", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "Sons e Música", "Settings.Sections.SoundsAndMusic.Music": "Música", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Ativado", diff --git a/i18n/languages/pt-PT.json b/i18n/languages/pt-PT.json index 2dafb08d9..40239f833 100644 --- a/i18n/languages/pt-PT.json +++ b/i18n/languages/pt-PT.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "Controla se os portais serão renderizados, desligue isso se eles afetarem a taxa de quadros significativamente", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Luz Externa Projetada pela Porta", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "Luz deve ser projetada para fora quando as portas estiverem abertas?", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "Sons e Música", "Settings.Sections.SoundsAndMusic.Music": "Música", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Ativado", diff --git a/i18n/languages/ru.json b/i18n/languages/ru.json index 5a968b043..7272e8018 100644 --- a/i18n/languages/ru.json +++ b/i18n/languages/ru.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "Визуализация порталов. Отключение может заметно увеличить производительность", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Свет из дверей экстерьера", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "Должен ли свет проникать через двери, когда они открыты?", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "Звуки и Музыка", "Settings.Sections.SoundsAndMusic.Music": "Музыка", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Включена", diff --git a/i18n/languages/tr.json b/i18n/languages/tr.json index d0b716ab8..7df3e980f 100644 --- a/i18n/languages/tr.json +++ b/i18n/languages/tr.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "Portalların oluşturulup oluşturulmayacağı, kare hızını önemli ölçüde etkiliyorsa bunu kapatın", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Öngörülen Kapı Dış Aydınlatma", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "Açıkken kapılardan ışık parlamalı mı?", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "Sesler ve Müzik", "Settings.Sections.SoundsAndMusic.Music": "Müzik", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Etkinleştirilmiş", diff --git a/i18n/languages/zh-CN.json b/i18n/languages/zh-CN.json index ca741013d..d54b4ab95 100644 --- a/i18n/languages/zh-CN.json +++ b/i18n/languages/zh-CN.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "不管传送门是否会显示,如果对帧率有显著影响,关闭此项", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "门外光源投影", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "当门打开时,光线是否从门里照射出来", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "音效与音乐", "Settings.Sections.SoundsAndMusic.Music": "音乐", "Settings.Sections.SoundsAndMusic.Music.Enabled": "启用", diff --git a/i18n/languages/zh-TW.json b/i18n/languages/zh-TW.json index e9fce08af..c17f41e5b 100644 --- a/i18n/languages/zh-TW.json +++ b/i18n/languages/zh-TW.json @@ -569,6 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "不管傳送門是否會顯示,如果對幀率有顯著影響,關閉此項", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "門外光源投影", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "當門打開時,光線是否從門裏照射出來", + "Settings.Sections.Performance.SmoothLightTransitions": "", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "", "Settings.Sections.SoundsAndMusic": "音效與音樂", "Settings.Sections.SoundsAndMusic.Music": "音樂", "Settings.Sections.SoundsAndMusic.Music.Enabled": "啟用", diff --git a/lua/entities/gmod_tardis_interior/modules/cl_render.lua b/lua/entities/gmod_tardis_interior/modules/cl_render.lua index 6bdb52e4c..bf13fc4f2 100644 --- a/lua/entities/gmod_tardis_interior/modules/cl_render.lua +++ b/lua/entities/gmod_tardis_interior/modules/cl_render.lua @@ -2,6 +2,9 @@ local function predraw_o(self, part) if not TARDIS:GetSetting("lightoverride-enabled") then return end + + local smooth = TARDIS:GetSetting("smooth-light-transitions") + local lo = self.metadata.Interior.LightOverride if not lo then return end @@ -51,6 +54,7 @@ local function predraw_o(self, part) local function GetLightRenderTable(lt) local sel = SelectLightRenderTable(lt) + if not smooth then return sel end if ltempty(sel) then sel.color = sel.color or Vector(0,0,0) @@ -69,7 +73,7 @@ local function predraw_o(self, part) end if not ltcmp(lt.selected, sel) then - lt.prevsel = lt.selected + lt.prevsel = lt.current lt.selected = sel lt.select_time = CurTime() end @@ -83,10 +87,10 @@ local function predraw_o(self, part) if ltcmp(sel, lt.current, true) then -- same positions but different colors - local col_approach = math.Clamp(dt,0,1) - local ap2 = 1 - col_approach + local k1 = math.Clamp(dt,0,1) + local k2 = 1 - k1 - local newc = lt.prevsel.color * ap2 + sel.color * col_approach + local newc = lt.prevsel.color * k2 + sel.color * k1 lt.current = { type = sel.type, @@ -103,14 +107,10 @@ local function predraw_o(self, part) end if dt < 0.5 then - local col_approach = math.Clamp(2 * dt,0,1) - local ap2 = 1 - col_approach - - --local nc = lt.prevsel.color:ToColor() - --local newcol2 = Color(nc.r * ap2, nc.g * ap2, nc.b * ap2) - --local newc = newcol2:ToVector() --lt.prevsel.color * ap2 + local k1 = math.Clamp(2 * dt,0,1) + local k2 = 1 - k1 - local newc = lt.prevsel.color * ap2 + local newc = lt.prevsel.color * k2 lt.current = { type = sel.type, @@ -128,10 +128,10 @@ local function predraw_o(self, part) -- dt > 0.5 - local col_approach = math.Clamp((dt - 0.5) * 2,0,1) - local ap2 = 1 - col_approach + local k1 = math.Clamp((dt - 0.5) * 2,0,1) + local k2 = 1 - k1 - local newc = sel.color * col_approach + local newc = sel.color * k1 lt.current = { type = sel.type, @@ -143,6 +143,37 @@ local function predraw_o(self, part) end + local function GetLOBrightness(br) + if not smooth then return br end + + self.lo_model_brightness_data = self.lo_model_brightness_data or {} + local d = self.lo_model_brightness_data + + if not d.aim or not d.now then + d.aim = d.aim or br + d.now = d.now or d.aim + d.change_time = CurTime() + end + + if d.aim ~= br then + d.old = d.now + d.aim = br + d.change_time = CurTime() + end + + if d.now == br then + return br + end + + local dt = (CurTime() - d.change_time) / 2 + local k1 = math.Clamp(dt,0,1) + local k2 = 1 - k1 + + d.now = d.old * k2 + d.aim * k1 + + return d.now + end + render.SuppressEngineLighting(true) local br = power and lo.basebrightness or lo.nopowerbrightness @@ -153,13 +184,17 @@ local function predraw_o(self, part) if part and parts_table and parts_table[part.ID] then local part_br = parts_table[part.ID] if istable(part_br) then + -- todo: GetLOBrightness(br) for colors render.ResetModelLighting(part_br[1], part_br[2], part_br[3]) else + part_br = GetLOBrightness(part_br) render.ResetModelLighting(part_br, part_br, part_br) end elseif col then + -- todo: GetLOBrightness(br) for colors render.ResetModelLighting(col[1], col[2], col[3]) else + br = GetLOBrightness(br) render.ResetModelLighting(br, br, br) end diff --git a/lua/tardis/languages/en.lua b/lua/tardis/languages/en.lua index 656c41e6a..f4ed90412 100644 --- a/lua/tardis/languages/en.lua +++ b/lua/tardis/languages/en.lua @@ -572,6 +572,8 @@ T.Phrases = { ["Settings.Sections.Performance.Portals.Description"] = "Whether portals will render or not, turn this off if they impact framerate significantly", ["Settings.Sections.Performance.ProjectedDoorExteriorLight"] = "Projected Door Exterior Light", ["Settings.Sections.Performance.ProjectedDoorExteriorLight.Description"] = "Should light shine out through the doors when they're open?", + ["Settings.Sections.Performance.SmoothLightTransitions"] = "Smooth lighting transitions", + ["Settings.Sections.Performance.SmoothLightTransitions.Description"] = "Should interior lights have fading in and out animations?", ["Settings.Sections.SoundsAndMusic"] = "Sounds & Music", ["Settings.Sections.SoundsAndMusic.Music"] = "Music", ["Settings.Sections.SoundsAndMusic.Music.Enabled"] = "Enabled", diff --git a/lua/tardis/settings/cl_performance.lua b/lua/tardis/settings/cl_performance.lua index 2c31891aa..faeb1626b 100644 --- a/lua/tardis/settings/cl_performance.lua +++ b/lua/tardis/settings/cl_performance.lua @@ -86,6 +86,18 @@ TARDIS:AddSetting({ name="ProjectedDoorExteriorLight", }) +TARDIS:AddSetting({ + id="smooth-light-transitions", + type="bool", + value=true, + + class="local", + + option=true, + section=SETTING_SECTION, + name="SmoothLightTransitions", +}) + TARDIS:AddSetting({ id="breakdown-effects", type="bool", From 8048b36bcebdbaa5db703a679f93c0479a51513c Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Thu, 26 Oct 2023 18:05:39 +0300 Subject: [PATCH 3/5] Fixed second light fade-in + refactoring --- .../modules/cl_render.lua | 66 ++++++++----------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/lua/entities/gmod_tardis_interior/modules/cl_render.lua b/lua/entities/gmod_tardis_interior/modules/cl_render.lua index bf13fc4f2..0ec448977 100644 --- a/lua/entities/gmod_tardis_interior/modules/cl_render.lua +++ b/lua/entities/gmod_tardis_interior/modules/cl_render.lua @@ -41,15 +41,11 @@ local function predraw_o(self, part) return table.IsEmpty(lt1) or (not lt1.color) or (not lt1.pos) end - local function ltcmp(lt1, lt2, only_pos) + local function ltcmp(lt1, lt2) if lt1 == lt2 then return true end if ltempty(lt1) and ltempty(lt2) then return true end if ltempty(lt1) or ltempty(lt2) then return false end - - local color_ok = (lt1.color == lt2.color) - local pos_ok = (lt1.pos == lt2.pos) - - return (only_pos or color_ok) and pos_ok + return (lt1.color == lt2.color) and (lt1.pos == lt2.pos) end local function GetLightRenderTable(lt) @@ -66,16 +62,18 @@ local function predraw_o(self, part) if not lt.selected or not lt.current then lt.current = sel - lt.prevsel = lt.selected + lt.prev = lt.selected lt.selected = sel lt.select_time = CurTime() + lt.should_move = false return sel end if not ltcmp(lt.selected, sel) then - lt.prevsel = lt.current + lt.prev = lt.current lt.selected = sel lt.select_time = CurTime() + lt.should_move = (lt.prev.pos ~= lt.selected.pos) end if ltcmp(sel, lt.current) then @@ -84,13 +82,11 @@ local function predraw_o(self, part) local dt = (CurTime() - lt.select_time) / 2 - if ltcmp(sel, lt.current, true) then - -- same positions but different colors + if not lt.should_move then + -- same positions but different colors, light transition - local k1 = math.Clamp(dt,0,1) - local k2 = 1 - k1 - - local newc = lt.prevsel.color * k2 + sel.color * k1 + local approach = math.Clamp(dt,0,1) + local newc = lt.prev.color * (1 - approach) + sel.color * approach lt.current = { type = sel.type, @@ -99,39 +95,30 @@ local function predraw_o(self, part) color = newc, } - if newc == Vector(0,0,0) then - return {} - end - + if newc == Vector(0,0,0) then return {} end return lt.current end - if dt < 0.5 then - local k1 = math.Clamp(2 * dt,0,1) - local k2 = 1 - k1 - - local newc = lt.prevsel.color * k2 + -- fading out + if dt < 0.5 or sel.empty then + local approach = math.Clamp(2 * dt,0,1) + if sel.empty then approach = math.Clamp(dt,0,1) end + local newc = lt.prev.color * (1 - approach) lt.current = { type = sel.type, quadraticFalloff = sel.quadraticFalloff, color = newc, - pos = lt.prevsel.pos + pos = lt.prev.pos } - return lt.current - end - if sel.empty then - lt.current = sel - return {} + if newc == Vector(0,0,0) then return {} end + return lt.current end - -- dt > 0.5 - - local k1 = math.Clamp((dt - 0.5) * 2,0,1) - local k2 = 1 - k1 - - local newc = sel.color * k1 + -- dt >= 0.5, fading in + local approach = math.Clamp((dt - 0.5) * 2,0,1) + local newc = sel.color * approach lt.current = { type = sel.type, @@ -139,8 +126,9 @@ local function predraw_o(self, part) color = newc, pos = sel.pos } - return lt.current + if newc == Vector(0,0,0) then return {} end + return lt.current end local function GetLOBrightness(br) @@ -166,10 +154,10 @@ local function predraw_o(self, part) end local dt = (CurTime() - d.change_time) / 2 - local k1 = math.Clamp(dt,0,1) - local k2 = 1 - k1 + local approach = math.Clamp(dt,0,1) + local k2 = 1 - approach - d.now = d.old * k2 + d.aim * k1 + d.now = d.old * k2 + d.aim * approach return d.now end From 1db3dba882d05b88ee6e66951604bdfbdebbc0c0 Mon Sep 17 00:00:00 2001 From: Matt Jeanes Date: Thu, 16 Nov 2023 23:04:14 +0000 Subject: [PATCH 4/5] language tweak --- i18n/languages/en.json | 4 ++-- lua/tardis/languages/en.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/i18n/languages/en.json b/i18n/languages/en.json index 28215e824..63f7523b9 100644 --- a/i18n/languages/en.json +++ b/i18n/languages/en.json @@ -569,8 +569,8 @@ "Settings.Sections.Performance.Portals.Description": "Whether portals will render or not, turn this off if they impact framerate significantly", "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Projected Door Exterior Light", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "Should light shine out through the doors when they're open?", - "Settings.Sections.Performance.SmoothLightTransitions": "Smooth lighting transitions", - "Settings.Sections.Performance.SmoothLightTransitions.Description": "Should interior lights have fading in and out animations?", + "Settings.Sections.Performance.SmoothLightTransitions": "Smooth Lighting Transitions", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "Should interior lights fade in/out?", "Settings.Sections.SoundsAndMusic": "Sounds & Music", "Settings.Sections.SoundsAndMusic.Music": "Music", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Enabled", diff --git a/lua/tardis/languages/en.lua b/lua/tardis/languages/en.lua index f4ed90412..9207458f7 100644 --- a/lua/tardis/languages/en.lua +++ b/lua/tardis/languages/en.lua @@ -572,8 +572,8 @@ T.Phrases = { ["Settings.Sections.Performance.Portals.Description"] = "Whether portals will render or not, turn this off if they impact framerate significantly", ["Settings.Sections.Performance.ProjectedDoorExteriorLight"] = "Projected Door Exterior Light", ["Settings.Sections.Performance.ProjectedDoorExteriorLight.Description"] = "Should light shine out through the doors when they're open?", - ["Settings.Sections.Performance.SmoothLightTransitions"] = "Smooth lighting transitions", - ["Settings.Sections.Performance.SmoothLightTransitions.Description"] = "Should interior lights have fading in and out animations?", + ["Settings.Sections.Performance.SmoothLightTransitions"] = "Smooth Lighting Transitions", + ["Settings.Sections.Performance.SmoothLightTransitions.Description"] = "Should interior lights fade in/out?", ["Settings.Sections.SoundsAndMusic"] = "Sounds & Music", ["Settings.Sections.SoundsAndMusic.Music"] = "Music", ["Settings.Sections.SoundsAndMusic.Music.Enabled"] = "Enabled", From 4e5311cf65cd660672c0c4d6691dca4491d8fa1e Mon Sep 17 00:00:00 2001 From: Matt Jeanes Date: Thu, 16 Nov 2023 23:10:04 +0000 Subject: [PATCH 5/5] language tweak --- i18n/languages/en.json | 2 +- lua/tardis/languages/en.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/i18n/languages/en.json b/i18n/languages/en.json index 63f7523b9..71114814c 100644 --- a/i18n/languages/en.json +++ b/i18n/languages/en.json @@ -570,7 +570,7 @@ "Settings.Sections.Performance.ProjectedDoorExteriorLight": "Projected Door Exterior Light", "Settings.Sections.Performance.ProjectedDoorExteriorLight.Description": "Should light shine out through the doors when they're open?", "Settings.Sections.Performance.SmoothLightTransitions": "Smooth Lighting Transitions", - "Settings.Sections.Performance.SmoothLightTransitions.Description": "Should interior lights fade in/out?", + "Settings.Sections.Performance.SmoothLightTransitions.Description": "Should interior lights fade in/out? (requires Lighting Override)", "Settings.Sections.SoundsAndMusic": "Sounds & Music", "Settings.Sections.SoundsAndMusic.Music": "Music", "Settings.Sections.SoundsAndMusic.Music.Enabled": "Enabled", diff --git a/lua/tardis/languages/en.lua b/lua/tardis/languages/en.lua index 9207458f7..aae58377e 100644 --- a/lua/tardis/languages/en.lua +++ b/lua/tardis/languages/en.lua @@ -573,7 +573,7 @@ T.Phrases = { ["Settings.Sections.Performance.ProjectedDoorExteriorLight"] = "Projected Door Exterior Light", ["Settings.Sections.Performance.ProjectedDoorExteriorLight.Description"] = "Should light shine out through the doors when they're open?", ["Settings.Sections.Performance.SmoothLightTransitions"] = "Smooth Lighting Transitions", - ["Settings.Sections.Performance.SmoothLightTransitions.Description"] = "Should interior lights fade in/out?", + ["Settings.Sections.Performance.SmoothLightTransitions.Description"] = "Should interior lights fade in/out? (requires Lighting Override)", ["Settings.Sections.SoundsAndMusic"] = "Sounds & Music", ["Settings.Sections.SoundsAndMusic.Music"] = "Music", ["Settings.Sections.SoundsAndMusic.Music.Enabled"] = "Enabled",