Skip to content

Commit

Permalink
improvements to custom base light
Browse files Browse the repository at this point in the history
  • Loading branch information
MattJeanes committed May 13, 2024
1 parent 9261c34 commit d544e93
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
11 changes: 11 additions & 0 deletions lua/entities/gmod_tardis/modules/cl_projectedlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ function ENT:PickProjectedLightColor()

pickedcolor = pickedcolor or pl.color or int_color_data.color

if pl.baselightmix > 0 and IsValid(self.interior) then
local int_base_light_color = self.interior:GetBaseLightColor()

local mix = pl.baselightmix
pickedcolor = Color(
pickedcolor.r * (1 - mix) + int_base_light_color.r * mix,
pickedcolor.g * (1 - mix) + int_base_light_color.g * mix,
pickedcolor.b * (1 - mix) + int_base_light_color.b * mix
)
end

return pickedcolor
end

Expand Down
4 changes: 2 additions & 2 deletions lua/entities/gmod_tardis_interior/modules/cl_render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local function predraw_o(self, part)

render.SuppressEngineLighting(true)

local col = self:GetData("interior_base_light_color", TARDIS.color_white_vector)
local colvec = self:GetBaseLightColorVector()

local parts_table = power and lo.parts or lo.parts_nopower

Expand All @@ -21,7 +21,7 @@ local function predraw_o(self, part)
render.ResetModelLighting(part_br, part_br, part_br)
end
else
render.ResetModelLighting(col[1], col[2], col[3])
render.ResetModelLighting(colvec[1], colvec[2], colvec[3])
end

--render.SetLightingMode(1)
Expand Down
43 changes: 28 additions & 15 deletions lua/entities/gmod_tardis_interior/modules/sh_interior_lights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,28 @@ end

-- Base light

function ENT:GetCustomBaseLightEnabled()
return self:GetData("interior_custom_base_light_enabled", false)
end

function ENT:GetCustomBaseLightColor()
return self:GetData("interior_custom_base_light_color")
end

function ENT:GetGetBaseLightColorVector()
return self:GetData("interior_base_light_color_vec")
end

function ENT:GetCustomBaseLightBrightness()
return self:GetData("interior_custom_base_light_brightness")
end


if SERVER then
function ENT:SetCustomBaseLightEnabled(enabled, color, brightness)
function ENT:SetCustomBaseLightEnabled(enabled)
self:SetData("interior_custom_base_light_enabled", enabled or false, true)
end

function ENT:GetCustomBaseLightEnabled()
return self:GetData("interior_custom_base_light_enabled", false)
end

function ENT:ToggleCustomBaseLightEnabled()
self:SetCustomBaseLightEnabled(not self:GetCustomBaseLightEnabled())
end
Expand All @@ -645,18 +658,18 @@ if SERVER then
self:SetData("interior_custom_base_light_color", color, true)
end

function ENT:GetCustomBaseLightColor()
return self:GetData("interior_custom_base_light_color")
end

function ENT:SetCustomBaseLightBrightness(brightness)
self:SetData("interior_custom_base_light_brightness", brightness, true)
end
else
function ENT:GetBaseLightColorVector()
return self:GetData("interior_base_light_color_vec", TARDIS.color_white_vector)
end

function ENT:GetCustomBaseLightBrightness()
return self:GetData("interior_custom_base_light_brightness")
function ENT:GetBaseLightColor()
return self:GetBaseLightColorVector():ToColor()
end
else
ENT:AddHook("Think", "baselight", function(self)
local lo = self.metadata.Interior.LightOverride
if not lo then return end
Expand All @@ -669,7 +682,7 @@ else
local customcol = self:GetData("interior_custom_base_light_color")
local custombr = self:GetData("interior_custom_base_light_brightness", normalbr)

local currentcolvec = self:GetData("interior_base_light_color")
local currentcolvec = self:GetData("interior_base_light_color_vec")
local targetcolvec
if self:GetData("interior_custom_base_light_enabled") and customcol then
targetcolvec = customcol:ToVector() * (custombr or normalbr)
Expand All @@ -680,7 +693,7 @@ else
if currentcolvec == targetcolvec then
return
elseif not currentcolvec then
self:SetData("interior_base_light_color", targetcolvec)
self:SetData("interior_base_light_color_vec", targetcolvec)
return
end

Expand All @@ -698,7 +711,7 @@ else

local colvec = LerpVector(fraction, prevcolvec, targetcolvec)

self:SetData("interior_base_light_color", colvec)
self:SetData("interior_base_light_color_vec", colvec)
self:SetData("interior_base_light_transition_fraction", fraction)
end)
end
2 changes: 1 addition & 1 deletion lua/matproxy/matproxy_tardis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ matproxy.Add({
bind = function( self, mat, ent )
if not IsValid(ent) or not ent.TardisPart then return end

local col = ent:GetData("interior_base_light_color", TARDIS.color_white_vector)
local col = ent:GetData("interior_base_light_color_vec", TARDIS.color_white_vector)
mat:SetVector(self.ResultTo, col)
end
})
3 changes: 2 additions & 1 deletion lua/tardis/interiors/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ T.Exterior = {
--horizfov = 90, --vertical and horizontal field of view of the light. Will default to portal height and width.
farz = 750, --FarZ property of the light. Determines how far the light projects.]]
offset = Vector(-21,0,51.1), --Offset from box origin
texture = "effects/flashlight/square" --Texture the projected light will use. You can get these from the Lamp tool.
texture = "effects/flashlight/square", --Texture the projected light will use. You can get these from the Lamp tool.
baselightmix = 0, --How much the base light affects the projected light. 0 = none, 1 = full.
},
Sounds = {
Teleport = {
Expand Down

0 comments on commit d544e93

Please sign in to comment.