Skip to content

Commit

Permalink
basic implementation of dynamic mesh lights
Browse files Browse the repository at this point in the history
added fields DLight and DLightFallOff to mesh lights to enable dynamic lighting overrides useful for advanced light meshes, probably not the best way to do it but it works and it shouldn't break anything :SteamHappy:
  • Loading branch information
SentryGunMan committed Oct 17, 2024
1 parent c86a236 commit eee4d28
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .annotations/interfaces/ann_element_mesh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
---@field ManipulateAlpha? boolean If the mesh's alpha channel should be manipulated.
---@field EnableDraw? boolean Whether or the mesh should be rendered in the normal pass.
---@field EnableBloom? boolean Whether or not the mesh should be drawn during the bloom pass.
---@field DLight? boolean If the mesh should be illuminated by a Dynamic Light.
---@field DLightFallOff? number The number used to calculate the falloff of the Dynamic Light.

---@class PhotonElementMeshEntry : PhotonElementMeshProperties
---@field [1] string Element template name.
Expand Down
32 changes: 30 additions & 2 deletions lua/photon-v2/cl_render_light_mesh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,21 @@ function Photon2.RenderLightMesh.DrawBloom()
-- light.BloomMaterial--[[@as IMaterial]]:SetVector( "$color", Vector(1, 0, 0) )
light.BloomMaterial:SetFloat( "$alpha", 1 )
light.BloomMaterial--[[@as IMaterial]]:SetVector( "$color", light.BloomColor:GetVector() )
if ( light.Mesh ) then light.Mesh:Draw() end
if ( light.Mesh ) then
if light.DLight then
render.SetLocalModelLights(
{
{
type = MATERIAL_LIGHT_POINT,
color = light.BloomColor:GetVector()*light.Intensity,
pos = light.Matrix:GetTranslation(),
quadraticFalloff = light.DLightFallOff or 0.06
}
}
)
end
light.Mesh:Draw()
end
cam.PopModelMatrix()
end
end
Expand Down Expand Up @@ -65,7 +79,21 @@ function Photon2.RenderLightMesh.Render( depth, sky )
light.DrawMaterial--[[@as IMaterial]]:SetFloat( "$alpha", 1 )
end

if ( light.Mesh ) then light.Mesh:Draw() end
if ( light.Mesh ) then
if light.DLight then
render.SetLocalModelLights(
{
{
type = MATERIAL_LIGHT_POINT,
color = light.DrawColor:GetVector()*light.Intensity,
pos = light.Matrix:GetTranslation(),
quadraticFalloff = light.DLightFallOff or 0.06
}
}
)
end
light.Mesh:Draw()
end

-- light.DrawMaterial--[[@as IMaterial]]:SetInt( "$alpha", light.Intensity )
-- local cMatrix = Matrix({{512, 512, 512, 512}, {512, 512, 512, 512}, {512,512,512,512}, {512,512,512,512}})
Expand Down
3 changes: 3 additions & 0 deletions lua/photon-v2/meta/light_mesh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Light.IntensityTransitions = false
Light.Scale = Vector( 1, 1, 1 )
Light.BoneParent = -1

Light.DLight = false
Light.DLightFallOff = 0.06

local white = { r = 235, g = 235, b = 255 }
local softWhite = { r = 255, g = 235, b = 205 }
local red = { r = 255, g = 0, b = 0 }
Expand Down

0 comments on commit eee4d28

Please sign in to comment.