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..71114814c 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 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/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 b5d9c5539..0ec448977 100644 --- a/lua/entities/gmod_tardis_interior/modules/cl_render.lua +++ b/lua/entities/gmod_tardis_interior/modules/cl_render.lua @@ -2,31 +2,14 @@ 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 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 +35,165 @@ 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) + 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 + return (lt1.color == lt2.color) and (lt1.pos == lt2.pos) + end + + 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) + 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.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.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 + return sel + end + + local dt = (CurTime() - lt.select_time) / 2 + + if not lt.should_move then + -- same positions but different colors, light transition + + local approach = math.Clamp(dt,0,1) + local newc = lt.prev.color * (1 - approach) + sel.color * 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 + + -- 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.prev.pos + } + + if newc == Vector(0,0,0) then return {} end + return lt.current + end + + -- 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, + quadraticFalloff = sel.quadraticFalloff, + color = newc, + pos = sel.pos + } + + if newc == Vector(0,0,0) then return {} end + return lt.current + 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 approach = math.Clamp(dt,0,1) + local k2 = 1 - approach + + d.now = d.old * k2 + d.aim * approach + + return d.now + 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 + -- 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 - 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 diff --git a/lua/tardis/languages/en.lua b/lua/tardis/languages/en.lua index 656c41e6a..aae58377e 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 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/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",