Skip to content

Commit 06329e4

Browse files
committed
add showtime dynamics to sunbeams
sunbeam multiplier: fade factor is multiplicative, with an additional initial "attack" factor (simple linear fade-in to avoid instant flashes while also allowing the fadeout) darken: fade factor is additive
1 parent 0efee70 commit 06329e4

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

lua/pac3/core/client/parts/sunbeams.lua

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,36 @@ local draw_distance = CreateClientConVar("pac_limit_sunbeams_draw_distance", "10
1111

1212

1313
BUILDER:StartStorableVars()
14-
BUILDER:GetSet("Darken", 0)
15-
BUILDER:GetSet("Multiplier", 0.25, {editor_sensitivity = 0.25})
16-
BUILDER:GetSet("Size", 0.1, {editor_sensitivity = 0.25})
17-
BUILDER:GetSet("DrawDistance", 1000, {editor_onchange = function(self, val) return math.max(val,0) end})
18-
BUILDER:GetSet("Translucent", true)
14+
BUILDER:GetSet("Darken", 0)
15+
BUILDER:GetSet("Multiplier", 0.25, {editor_sensitivity = 0.25})
16+
BUILDER:GetSet("Size", 0.1, {editor_sensitivity = 0.25})
17+
BUILDER:GetSet("DrawDistance", 1000, {editor_onchange = function(self, val) return math.max(val,0) end})
18+
BUILDER:GetSet("Translucent", true)
19+
20+
BUILDER:SetPropertyGroup("Showtime dynamics")
21+
BUILDER:GetSet("EnableDynamics", false, {description = "If you want to make a fading effect, you can do it here instead of adding proxies.\nThe multiplier parts work multiplicatively, involving 3 terms: attack * multiplier * fade\nThe darken part works additively. It can add more darken on top of the existing darken value"})
22+
BUILDER:GetSet("EndMultiplier", 1)
23+
BUILDER:GetSet("StartMultiplier", 1)
24+
BUILDER:GetSet("MultiplierFadePower", 1)
25+
BUILDER:GetSet("MultiplierFadeSpeed", 1)
26+
BUILDER:GetSet("MultiplierAttack", 0, {description = "Additional fade-in time to optionally soften the flash. This is in terms of normalized speed"})
27+
28+
BUILDER:GetSet("EndDarken", 0)
29+
BUILDER:GetSet("StartDarken", 0)
30+
BUILDER:GetSet("DarkenFadeSpeed", 1)
31+
BUILDER:GetSet("DarkenFadePower", 1)
32+
1933
BUILDER:EndStorableVars()
2034

2135
function PART:GetNiceName()
2236
local mult = self:GetMultiplier()
2337
return mult > 0 and "bright sunbeams" or mult < 0 and "dark sunbeams" or self.ClassName
2438
end
2539

40+
function PART:OnShow()
41+
self.starttime = CurTime()
42+
end
43+
2644
function PART:OnDraw()
2745
if not DrawSunbeams then DrawSunbeams = _G.DrawSunbeams end
2846

@@ -35,13 +53,38 @@ function PART:OnDraw()
3553

3654
local dist_mult = - math.Clamp(pac.EyePos:Distance(pos) / distance, 0, 1) + 1
3755

38-
DrawSunbeams(
39-
self.Darken,
40-
dist_mult * self.Multiplier * (math.Clamp(pac.EyeAng:Forward():Dot((pos - pac.EyePos):GetNormalized()) - 0.5, 0, 1) * 2) ^ 5,
41-
self.Size,
42-
spos.x / ScrW(),
43-
spos.y / ScrH()
44-
)
56+
if self.EnableDynamics then
57+
local lifetime = (CurTime() - self.starttime)
58+
59+
local init_mult = 1
60+
if self.MultiplierAttack > 0 then init_mult = math.Clamp(lifetime*self.MultiplierAttack,0,1) end
61+
62+
local fade_factor_m = math.Clamp(lifetime*self.MultiplierFadeSpeed,0,1)
63+
local fade_factor_d = math.Clamp(lifetime*self.DarkenFadeSpeed,0,1)
64+
local final_mult_mult = self.EnableDynamics and
65+
self.StartMultiplier + (self.EndMultiplier - self.StartMultiplier) * math.pow(fade_factor_m,self.MultiplierFadePower)
66+
or self.Multiplier
67+
68+
local final_darken_add = self.EnableDynamics and
69+
self.StartDarken + (self.EndDarken - self.StartDarken) * math.pow(fade_factor_d,self.DarkenFadePower)
70+
or 0
71+
72+
DrawSunbeams(
73+
self.Darken + final_darken_add,
74+
dist_mult * init_mult * self.Multiplier * final_mult_mult * (math.Clamp(pac.EyeAng:Forward():Dot((pos - pac.EyePos):GetNormalized()) - 0.5, 0, 1) * 2) ^ 5,
75+
self.Size,
76+
spos.x / ScrW(),
77+
spos.y / ScrH()
78+
)
79+
else
80+
DrawSunbeams(
81+
self.Darken,
82+
dist_mult * self.Multiplier * (math.Clamp(pac.EyeAng:Forward():Dot((pos - pac.EyePos):GetNormalized()) - 0.5, 0, 1) * 2) ^ 5,
83+
self.Size,
84+
spos.x / ScrW(),
85+
spos.y / ScrH()
86+
)
87+
end
4588
cam.End2D()
4689
end
4790

0 commit comments

Comments
 (0)