From eee4d289aa10ee7f96e59c13bd4e18f0fcfb9e11 Mon Sep 17 00:00:00 2001 From: SGM Date: Thu, 17 Oct 2024 00:18:17 -0400 Subject: [PATCH] basic implementation of dynamic mesh lights 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: --- .annotations/interfaces/ann_element_mesh.lua | 2 ++ lua/photon-v2/cl_render_light_mesh.lua | 32 ++++++++++++++++++-- lua/photon-v2/meta/light_mesh.lua | 3 ++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/.annotations/interfaces/ann_element_mesh.lua b/.annotations/interfaces/ann_element_mesh.lua index de4118ee..a7d2e24e 100644 --- a/.annotations/interfaces/ann_element_mesh.lua +++ b/.annotations/interfaces/ann_element_mesh.lua @@ -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. diff --git a/lua/photon-v2/cl_render_light_mesh.lua b/lua/photon-v2/cl_render_light_mesh.lua index ff0eed3d..9c90efcd 100644 --- a/lua/photon-v2/cl_render_light_mesh.lua +++ b/lua/photon-v2/cl_render_light_mesh.lua @@ -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 @@ -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}}) diff --git a/lua/photon-v2/meta/light_mesh.lua b/lua/photon-v2/meta/light_mesh.lua index 07ab6d00..43ea60e0 100644 --- a/lua/photon-v2/meta/light_mesh.lua +++ b/lua/photon-v2/meta/light_mesh.lua @@ -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 }