Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smooth light transitions #935

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions i18n/languages/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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é",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Включена",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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ş",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "启用",
Expand Down
2 changes: 2 additions & 0 deletions i18n/languages/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "啟用",
Expand Down
175 changes: 153 additions & 22 deletions lua/entities/gmod_tardis_interior/modules/cl_render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lua/tardis/languages/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions lua/tardis/settings/cl_performance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading