summaryrefslogtreecommitdiff
path: root/gamemode/cl_postprocess.lua
blob: cf4a696eba655f93aca834c5feddeca34898a541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
Sharpen = 0
MotionBlur = 0
DisorientTime = 0

ColorModify = {}
ColorModify[ "$pp_colour_addr" ] 		= 0
ColorModify[ "$pp_colour_addg" ] 		= 0
ColorModify[ "$pp_colour_addb" ] 		= 0
ColorModify[ "$pp_colour_brightness" ] 	= 0
ColorModify[ "$pp_colour_contrast" ] 	= 1
ColorModify[ "$pp_colour_colour" ] 		= 1
ColorModify[ "$pp_colour_mulr" ] 		= 0
ColorModify[ "$pp_colour_mulg" ] 		= 0
ColorModify[ "$pp_colour_mulb" ] 		= 0

MixedColorMod = {}

function GM:DOFThink()

end

function GM:RenderScreenspaceEffects()

	local approach = FrameTime() * 0.05

	if ( Sharpen > 0 ) then

		DrawSharpen( Sharpen, 0.5 )

		Sharpen = math.Approach( Sharpen, 0, FrameTime() * 0.5 )

	end

	if ( MotionBlur > 0 ) then

		DrawMotionBlur( 1 - MotionBlur, 1.0, 0.0 )

		MotionBlur = math.Approach( MotionBlur, 0, approach )

	end

	if LocalPlayer():FlashlightIsOn() then

		ColorModify[ "$pp_colour_brightness" ] = math.Approach( ColorModify[ "$pp_colour_brightness" ], 0.01, FrameTime() * 0.25 )
		ColorModify[ "$pp_colour_contrast" ] = math.Approach( ColorModify[ "$pp_colour_contrast" ], 1.02, FrameTime() * 0.25 )

	end

	local rads = LocalPlayer():GetNWInt( "Radiation", 0 )

	if rads > 0 and LocalPlayer():Alive() then

		local scale = rads / 5

		MotionBlur = math.Approach( MotionBlur, scale * 0.5, FrameTime() )
		Sharpen = math.Approach( Sharpen, scale * 5, FrameTime() * 3 )

		ColorModify[ "$pp_colour_colour" ] = math.Approach( ColorModify[ "$pp_colour_colour" ], 1.0 - scale * 0.8, FrameTime() * 0.1 )

	end

	if GetGlobalBool( "Radiation", false ) and not GAMEMODE.PlayerIsIndoors then

		ColorModify[ "$pp_colour_mulg" ] = 0.15
		ColorModify[ "$pp_colour_mulr" ] = 0.10
		ColorModify[ "$pp_colour_addg" ] = 0.05
		ColorModify[ "$pp_colour_addr" ] = 0.03

	end

	if LocalPlayer():Team() == TEAM_ZOMBIES then

		if LocalPlayer():Alive() then

			ColorModify[ "$pp_colour_brightness" ] 	= -0.15
			ColorModify[ "$pp_colour_addr" ]		= 0.25
			ColorModify[ "$pp_colour_mulr" ] 		= 0.15
			ColorModify[ "$pp_colour_addg" ]		= 0.15

		else

			ColorModify[ "$pp_colour_addr" ]		= 0.25
			ColorModify[ "$pp_colour_mulr" ] 		= 0.30
			ColorModify[ "$pp_colour_addg" ]		= 0.05
			ColorModify[ "$pp_colour_brightness" ] 	= -0.20

			MotionBlur = 0.40

		end

	else

		if not LocalPlayer():Alive() then

			ColorModify[ "$pp_colour_addr" ]		= 0.25
			ColorModify[ "$pp_colour_mulr" ] 		= 0.30
			ColorModify[ "$pp_colour_brightness" ] 	= -0.20

			MotionBlur = 0.40

		elseif LocalPlayer():GetNWBool( "Infected", false ) then

			ColorModify[ "$pp_colour_brightness" ] = -0.02
			ColorModify[ "$pp_colour_mulg" ] = 0.55
			ColorModify[ "$pp_colour_addg" ] = 0.02 // too much? too little?

			//MotionBlur = 0.30

		end

	end

	for k,v in pairs( ColorModify ) do

		if k == "$pp_colour_colour" or k == "$pp_colour_contrast" then

			ColorModify[k] = math.Approach( ColorModify[k], 1, approach )

		elseif k == "$pp_colour_brightness" and GetGlobalBool( "GameOver", false ) then

			ColorModify[k] = -1.50

		else

			ColorModify[k] = math.Approach( ColorModify[k], 0, approach )

		end

		MixedColorMod[k] = math.Approach( MixedColorMod[k] or 0, ColorModify[k], FrameTime() * 0.10 )

	end

	DrawColorModify( MixedColorMod )
	DrawPlayerRenderEffects()
	DrawLaser()

end

function GM:GetMotionBlurValues( y, x, fwd, spin )

	if LocalPlayer():Team() == TEAM_ZOMBIES then return y, x, fwd, spin end

	if LocalPlayer():Alive() and LocalPlayer():Health() <= 50 then

		local scale = math.Clamp( LocalPlayer():Health() / 50, 0, 1 )
		// local beat = math.Clamp( HeartBeat - CurTime(), 0, 2 ) * ( 1 - scale )

		fwd = 1 - scale // + beat

	elseif LocalPlayer():GetNWBool( "InIron", false ) then

		fwd = 0.05

	end

	if DisorientTime and DisorientTime > CurTime() then

		if not LocalPlayer():Alive() then
			DisorientTime = nil
		end

		local scale = ( ( DisorientTime or 0 ) - CurTime() ) / 10
		local newx, newy = RotateAroundCoord( 0, 0, 1, scale * 0.05 )

		return newy, newx, fwd, spin

	end

	if ScreamTime and ScreamTime > CurTime() then

		if not LocalPlayer():Alive() then
			ScreamTime = nil
		end

		local scale = ( ( ScreamTime or 0 ) - CurTime() ) / 10
		local newy = math.sin( CurTime() * 1.5 ) * scale * 0.08

		return newy, x, fwd, spin

	end

	return y, x, fwd, spin

end

function RotateAroundCoord( x, y, speed, dist )

	local newx = x + math.sin( CurTime() * speed ) * dist
	local newy = y + math.cos( CurTime() * speed ) * dist

	return newx, newy

end

local MaterialVision = Material( "nuke/redead/allyvision" )
//local MaterialItem = Material( "toxsin/allyvision" )

function DrawPlayerRenderEffects()

	if LocalPlayer():Team() != TEAM_ZOMBIES and LocalPlayer():Team() != TEAM_ARMY then return end

	if GetGlobalBool( "GameOver", false ) then return end

	cam.Start3D( EyePos(), EyeAngles() )

	--[[if IsValid( TargetedEntity ) and table.HasValue( ValidTargetEnts, TargetedEntity:GetClass() ) then // halos replaced this

		if TargetedEntity:GetPos():Distance( LocalPlayer():GetPos() ) < 500 then

			local scale = 1 - ( TargetedEntity:GetPos():Distance( LocalPlayer():GetPos() ) / 500 )

			render.SuppressEngineLighting( true )
			render.SetBlend( scale * 0.4 )
			render.SetColorModulation( 0, 0.5, 0 )

			render.MaterialOverride( MaterialItem )

			cam.IgnoreZ( false )

			TargetedEntity:DrawModel()

			render.SuppressEngineLighting( false )
			render.SetColorModulation( 1, 1, 1 )
			render.SetBlend( 1 )

			render.MaterialOverride( 0 )

		end

	end]]

	for k,v in pairs( GAMEMODE:GetHighlightedUnits() ) do

		if ( v:IsPlayer() and v:Alive() and v != LocalPlayer() ) or v:IsNPC() then

			local scale = ( math.Clamp( v:GetPos():Distance( LocalPlayer():GetPos() ), 500, 3000 ) - 500 ) / 2500

			//render.SuppressEngineLighting( true )
			render.SetBlend( scale )

			render.MaterialOverride( MaterialVision )

			if LocalPlayer():Team() == TEAM_ARMY then

				render.SetColorModulation( 0, 0.2, 1.0 )

			else

				render.SetColorModulation( 1.0, 0.2, 0 )

			end

			cam.IgnoreZ( false )

			v:SetupBones()
			v:DrawModel()

			//render.SuppressEngineLighting( false )
			render.SetColorModulation( 1, 1, 1 )
			render.SetBlend( 1 )

			render.MaterialOverride( 0 )

		end

	end

	cam.End3D()

end

DotMat = Material( "sprites/light_glow02_add_noz" )
LasMat = Material( "sprites/bluelaser1" )

function DrawLaser()

	if LocalPlayer():Team() != TEAM_ARMY then return end

	//local vm = LocalPlayer():GetViewModel( 0 )

	//if not IsValid( vm ) then return end

	local wep = LocalPlayer():GetActiveWeapon()

	if not IsValid( wep ) or not wep:GetNWBool( "Laser", false ) then return end

	//local idx = vm:LookupAttachment( "1" )

	//if idx == 0 then idx = vm:LookupAttachment( "muzzle" ) end

	--[[local trace = util.GetPlayerTrace( LocalPlayer() )
	local tr = util.TraceLine( trace )
	local tbl = vm:GetAttachment( idx )

	local pos = tr.HitPos]]

	local look = LocalPlayer():EyeAngles()
	local dir = look:Forward()
	//local tbl = vm:GetAttachment( idx )
	//local ang = tbl.Ang
	//local offset = wep.LaserOffset

	//ang:RotateAroundAxis( look:Up(), ( offset.p or 0 ) )
	//ang:RotateAroundAxis( look:Forward(), ( offset.r or 0 ) )
	//ang:RotateAroundAxis( look:Right(), ( offset.y or 0 ) )

	//local forward = ang:Forward()
	//lasforward = tbl.Ang:Forward()

	//forward = forward * wep.LaserScale

	//dir = dir +	forward

	local trace = {}

	trace.start = LocalPlayer():GetShootPos()
	trace.endpos = trace.start + dir * 9000
	trace.filter = { LocalPlayer(), weap, lp }
	trace.mask = MASK_SOLID

	local tr = util.TraceLine( trace )
	local dist = math.Clamp( tr.HitPos:Distance( EyePos() ), 0, 500 )
	local size = math.Rand( 2, 4 ) + ( dist / 500 ) * 6
	local col = Color( 255, 0, 0, 255 )

	--[[if v == lp and IsValid( GAMEMODE.TargetEnt ) and GAMEMODE.TargetEnt:IsPlayer() and GAMEMODE.TargetEnt:Team() == TEAM_HUMAN then

		size = size + math.Rand( 0.5, 2.0 )

	elseif v != lp then

		size = math.Rand( 0, 1 ) + ( dist / 500 ) * 6

	end]]

	if ( wep.LastRunFrame or  0 ) > CurTime() then return end

	cam.Start3D( EyePos(), EyeAngles() )

		local norm = ( EyePos() - tr.HitPos ):GetNormal()

		render.SetMaterial( DotMat )
		render.DrawQuadEasy( tr.HitPos + norm * size, norm, size, size, col, 0 )

	cam.End3D()

	--[[if vm:GetSequence() != ACT_VM_IDLE then

		wep.AngDiff = ( tbl.Ang - ( wep.LastGoodAng or Angle(0,0,0) ) )//:Forward()

		trace = {}
		trace.start = EyePos() or Vector(0,0,0)
		trace.endpos = trace.start + ( ( EyeAngles() + wep.AngDiff ):Forward() * 99999 )
		trace.filter = { wep, LocalPlayer() }

		local tr2 = util.TraceLine( trace )

		pos = tr2.HitPos

	else

		wep.LastGoodAng = tbl.Ang

	end]]

	--[[cam.Start3D( EyePos(), EyeAngles() )

		local dir = ( tbl.Ang + Angle(0,90,0) ):Forward()
		dir.z = EyeAngles():Forward().z

		local start = tbl.Pos + ( dir * -5 ) + wep.LaserOffset

		render.SetMaterial( LasMat )

		for i=0,254 do

			render.DrawBeam( start, start + dir * 0.2, 2, 0, 12, Color( 255, 0, 0, 255 - i ) )

			start = start + dir * 0.2

		end

		local dist = tr.HitPos:Distance( EyePos() )
		local size = math.Rand( 7, 8 )
		local dotsize = dist / ( size ^ 2 )

		render.SetMaterial( DotMat )
		render.DrawQuadEasy( pos, ( EyePos() - tr.HitPos ):GetNormal(), dotsize, dotsize, Color( 255, 0, 0, 255 ), 0 )

	cam.End3D()	]]

end

function GM:GetHighlightedUnits()

	local tbl = team.GetPlayers( TEAM_ARMY )
	tbl = table.Add( tbl, ents.FindByClass( "npc_scientist" ) )

	return tbl

end

function GM:PreDrawHalos()

	if GetGlobalBool( "GameOver", false ) then return end

	if LocalPlayer():Team() != TEAM_ZOMBIES and LocalPlayer():Team() != TEAM_ARMY then return end

	--[[for k,v in pairs( GAMEMODE:GetHighlightedUnits() ) do

		if ( ( v:IsPlayer() and v:Alive() and v != LocalPlayer() ) or ( v:IsNPC() and not v.Ragdolled ) ) then

			local dist = math.Clamp( v:GetPos():Distance( LocalPlayer():GetPos() ), 250, 500 ) - 250
			local scale = dist / 250

			if scale > 0 then

				if LocalPlayer():Team() == TEAM_ARMY then

					//halo.Add( {v}, Color( 0, 200, 200, 200 * scale ), 2, 2, 1, 1, true ) // removed till garry optimizes this

				else

					//halo.Add( {v}, Color( 200, 0, 0, 200 * scale ), 2, 2, 1, 1, false )

				end

			end

		end

	end]]

	if LocalPlayer():Team() == TEAM_ARMY then

		if IsValid( TargetedEntity ) and not TargetedEntity:IsPlayer() and ( TargetedEntity:GetClass() != "npc_scientist" or TargetedEntity:GetNWBool( "Dead", false ) == false ) then

			local dist = math.Clamp( TargetedEntity:GetPos():Distance( LocalPlayer():GetPos() ), 0, 500 )
			local scale = 1 - ( dist / 500 )

			halo.Add( {TargetedEntity}, Color( 0, 100, 200, 255 * scale ), 2 * scale, 2 * scale, 1, 1, false )

		end

		if IsValid( GAMEMODE.ClientAntidote ) then

			local dist = math.Clamp( GAMEMODE.ClientAntidote:GetPos():Distance( LocalPlayer():GetPos() ), 250, 500 ) - 250
			local scale = dist / 250

			halo.Add( {GAMEMODE.ClientAntidote}, Color( 0, 200, 0, 200 * scale ), 2, 2, 1, 1, true )

		end

	end

end

WalkTimer = 0
VelSmooth = 0
DeathAngle = Angle(0,0,0)
DeathOrigin = Vector(0,0,0)

function GM:CalcView( ply, origin, angle, fov )

	local vel = ply:GetVelocity()
	local ang = ply:EyeAngles()

	VelSmooth = VelSmooth * 0.5 + vel:Length() * 0.1
	WalkTimer = WalkTimer + VelSmooth * FrameTime() * 0.1

	angle.roll = angle.roll + ang:Right():DotProduct( vel ) * 0.002

	if ply:Alive() then

		--[[if ViewWobble > 0 then

			angle.roll = angle.roll + math.sin( CurTime() + TimeSeed( 1, -2, 2 ) ) * ( ViewWobble * 15 )
			angle.pitch = angle.pitch + math.sin( CurTime() + TimeSeed( 2, -2, 2 ) ) * ( ViewWobble * 15 )
			angle.yaw = angle.yaw + math.sin( CurTime() + TimeSeed( 3, -2, 2 ) ) * ( ViewWobble * 15 )

		end]]

		DeathAngle = angle
		DeathOrigin = origin

	elseif not ply:Alive() and CV_RagdollVision:GetBool() then

		local rag = ply:GetRagdollEntity()

		if IsValid( rag ) then

			local eyes = rag:LookupAttachment( "eyes" )
			local tbl = rag:GetAttachment( eyes )

			if tbl then

				angle = tbl.Ang
				origin = tbl.Pos + ( tbl.Ang:Up() * 16 ) + ( tbl.Ang:Forward() * -8 )

			end

		end

	end

	if ply:GetGroundEntity() != NULL then

		angle.roll = angle.roll + math.sin( WalkTimer ) * VelSmooth * 0.001
		angle.pitch = angle.pitch + math.cos( WalkTimer * 1.25 ) * VelSmooth * 0.005

	end

	return self.BaseClass:CalcView( ply, origin, angle, fov )

end