light flares ported from tacrp

This commit is contained in:
Darsu 2025-01-25 22:23:50 +07:00
parent 42c63ac5dc
commit 72ff0f177e
5 changed files with 58 additions and 72 deletions

View File

@ -1,7 +1,3 @@
ARC9.Flares = {}
local flaremat = Material("effects/arc9_lensflare", "mips smooth")
hook.Add("PostDrawHUD", "ARC9_SSE_PP", function()
if !IsValid(LocalPlayer()) then return end
local wpn = LocalPlayer():GetActiveWeapon()
@ -10,22 +6,6 @@ hook.Add("PostDrawHUD", "ARC9_SSE_PP", function()
if !wpn.ARC9 then return end
wpn:HoldBreathPP()
for i, flare in ipairs(ARC9.Flares) do
cam.Start3D(_, _ , flare.invm and wpn.ViewModelFOV + 16 or _) -- no idea why 16
local toscreen = flare.pos:ToScreen()
cam.End3D()
if toscreen.visible then
surface.SetMaterial(flaremat)
surface.SetDrawColor(flare.color)
local s = ScreenScale(flare.size)
surface.DrawTexturedRect(toscreen.x - (s / 2), toscreen.y - (s / 2), s, s)
end
end
ARC9.Flares = {}
wpn.FlaresAlreadyDrawn = {}
if wpn:GetSight().FlatScope and wpn:GetSight().FlatScopeCC and wpn:GetSightAmount() > 0.75 then
DrawColorModify(wpn:GetSight().FlatScopeCC)

View File

@ -1,45 +0,0 @@
local badcolor = Color(255, 255, 255)
SWEP.FlaresAlreadyDrawn = {}
function SWEP:DrawLightFlare(pos, ang, col, size, flareid, vm, nodotter)
col = col or badcolor
size = size or 1
local lp = LocalPlayer()
local campos = vm and EyePos() or lp:GetViewEntity():GetPos()
if !vm then -- walls!!!!!
local tr = util.TraceLine({
start = campos,
endpos = pos,
mask = MASK_OPAQUE,
filter = lp,
})
if tr.Fraction != 1 then return end
end
local dotter = 1
if !nodotter then
local diff = campos - pos
if -ang:Right():Dot(diff) < 0 then return end
dotter = math.max(0, -ang:Right():Dot(diff) / diff:Length())
if dotter < 0.4 then return end
dotter = math.ease.InExpo(dotter)
end
local distancer = math.ease.InExpo(math.max(1 - campos:DistToSqr(pos) * 0.0000005, 0))
size = size * dotter * 3 * distancer
if self.FlaresAlreadyDrawn[flareid] then return end
self.FlaresAlreadyDrawn[flareid] = true
table.insert(ARC9.Flares, {
pos = pos,
size = math.Clamp(size, 0, 1000),
color = col,
invm = vm
})
end

View File

@ -163,7 +163,7 @@ function SWEP:DrawLasers(wm, behav)
if (atttbl.LaserColorPlayer or atttbl.LaserPlayerColor) then color = colorplayer or color end
self:DrawLightFlare(a.Pos, lasang, color, wm and 5 or 10, (slottbl.Address or 0) + 69, !wm)
self:DrawLightFlare(a.Pos, wm and self:GetShootDir() or lasang, color, 0.075, (slottbl.Address or 0) + 69, !wm)
if !wm or owner == LocalPlayer() or wm and owner:IsNPC() then
if behav then

View File

@ -84,6 +84,7 @@ function SWEP:KillFlashlights()
end
local fuckingbullshit = Vector(0, 0, 0.001)
local gunoffset = Vector(0, 0, -16)
function SWEP:DrawFlashlightsWM()
local owner = self:GetOwner()
@ -98,6 +99,7 @@ function SWEP:DrawFlashlightsWM()
end
if isotherplayer and lp:EyePos():DistToSqr(owner:EyePos()) > 2048^2 then self:KillFlashlights() return end
local wmnotdrawn = self.LastWMDrawn != UnPredictedCurTime() and isotherplayer
for i, k in ipairs(self.Flashlights) do
local model = (k.slottbl or {}).WModel
@ -107,8 +109,8 @@ function SWEP:DrawFlashlightsWM()
local pos, ang
if isotherplayer or !IsValid(model) then
pos = owner:EyePos()
if wmnotdrawn or !IsValid(model) then
pos = owner:EyePos() + gunoffset
ang = owner:EyeAngles()
else
pos = model:GetPos()
@ -121,7 +123,7 @@ function SWEP:DrawFlashlightsWM()
end
end
self:DrawLightFlare(pos + fuckingbullshit, ang, k.col, k.br * 20, i, nil, k.nodotter)
self:DrawLightFlare(pos + fuckingbullshit, ang, k.col, k.br / 6, nil, k.nodotter)
local tr = util.TraceLine({
start = pos,
endpos = pos + ang:Forward() * 16,
@ -182,7 +184,7 @@ function SWEP:DrawFlashlightsVM()
end
end
self:DrawLightFlare(pos, ang, k.col, k.br * 25, i, true, k.nodotter)
-- self:DrawLightFlare(pos, ang, k.col, k.br * 25, i, true, k.nodotter, ang:Forward())
if k.qca then ang:RotateAroundAxis(ang:Up(), 90) end
@ -208,4 +210,47 @@ function SWEP:DrawFlashlightsVM()
k.light:SetAngles(ang)
k.light:Update()
end
end
local flaremat = Material("effects/arc9_lensflare", "mips smooth")
local badcolor = Color(255, 255, 255)
function SWEP:DrawLightFlare(pos, ang, col, size, vm, nodotter) -- mostly tacrp
col = col or badcolor
size = size or 1
local dot = -ang:Forward():Dot(EyeAngles():Forward())
local dot2 = ang:Forward():Dot((EyePos() - pos):GetNormalized())
dot = (dot + dot2) / 2
if nodotter then dot, dot2 = 1, 1 end
if dot < 0 then return end
local diff = EyePos() - pos
dot = dot ^ 4
local tr = util.QuickTrace(pos, diff, {self:GetOwner(), LocalPlayer()})
local s = math.Clamp(1 - diff:Length() / 700, 0, 1) ^ 1 * dot * 500 * math.Rand(0.95, 1.05) * size
if tr.Fraction == 1 then
s = ScreenScale(s)
local toscreen = pos:ToScreen()
cam.Start2D()
surface.SetMaterial(flaremat)
surface.SetDrawColor(col, 128)
surface.DrawTexturedRect(toscreen.x - s / 2, toscreen.y - s / 2, s, s)
cam.End2D()
if !vm then
local rad = 128 * size * dot2
col.a = 50 + size * 205
pos = pos + ang:Forward() * 2
pos = pos + diff:GetNormalized() * (2 + 14 * size)
render.SetMaterial(flaremat)
render.DrawSprite(pos, rad, rad, col)
end
end
end

View File

@ -1,3 +1,5 @@
-- local goodmin, goodmax, extramax = Vector(-16, -16, -16), Vector(16, 16, 16), Vector(16, 16, 2048)
function SWEP:DrawWorldModel()
local owner = self:GetOwner()
@ -15,6 +17,12 @@ function SWEP:DrawWorldModel()
self:DoTPIK()
-- self:DrawFlashlightsWM()
self.LastWMDrawn = UnPredictedCurTime()
-- if self:GetValue("Laser") and self:GetTactical() then -- too hard to know if any laser is active
-- self:SetRenderBounds(goodmin, extramax)
-- else
-- self:SetRenderBounds(goodmin, goodmax)
-- end
end
end
@ -24,8 +32,6 @@ hook.Add("PostDrawTranslucentRenderables", "ARC9_TranslucentDraw", function() --
if IsValid(wep) and wep.ARC9 then
wep:DrawLasers(true)
wep:DrawFlashlightsWM()
-- wep:DrawFlashlightGlares()
-- wep:DoScopeGlint()
end
end
end)