Draw Glow / Outline / Material Around Player

I want to draw a glow around players, but am having a lot of problems.
Basically, everything i have tried doesn’t work and/or crashes the player.

This should give you an idea of what i’m after:

[lua]
– cl_init.lua

function CustomPlyDraw( ply )
local scale = ply:GetModelScale()
local upsize = 0.2

local material = Material( "models/effects/comball_tape" )

ply:SetModelScale( scale + upsize, 0 )
ply:SetMaterial( material )
ply:DrawModel() -- CRASH!!!

ply:SetModelScale( scale, 0 )

end

hook.Add( “PostPlayerDraw”, “CustomPlyDraw”, CustomPlyDraw )
[/lua]

Oh, and i’ve already tried the effects.halo lib. it’s not quite what i’m looking for.

Any help would be appreciated! thanks~

Someone posted a stencil tutorial which could do something similar.

Here’s how I handle drawing a halo / glow around players on PreDrawHalo hook:

where _p is Player
[lua]local _color = _p:GetAccessLevelColor( );

local _sin = math.sinwave( 5, 1.5, true );

effects.halo.Add( { _p }, _color, 1 + _sin, 1 + _sin, 1 )

if ( _p:GetVehicle( ) ) then
	effects.halo.Add( { _p:GetVehicle( ) }, _color, 1 + _sin, 1 + _sin, 1 )
end[/lua]

And it looks like this – You’ll see it work on vehicles and the player, and strobe smoothly. The Emergency Lighting demo was for someone that asked how to prevent red and blue from mixing to formulate purple in Dynamic Lighting - spoke to him on Steam on how to fix that problem - but this short video still shows you how the above code looks when running:

-snip-

And, as the math.sinwave is a helper function; I’m sorry, here’s what it means:

[lua]local _sin = math.sinwave( 5, 1.5, true );[/lua]

is the same as

[lua]local _sin = math.abs( math.sin( RealTime( ) * 5 ) * 1.5 );[/lua]

[lua]//
// Handles repetitive sin wave code into 1 line - Josh ‘Acecool’ Moser
//
function math.sinwave( _speed, _size, _abs )
local _sin = math.sin( RealTime( ) * ( _speed or 1 ) ) * ( _size or 1 );

if ( _abs ) then _sin = math.abs( _sin ); end

return _sin;

end[/lua]

Interesting yes…
but it ultimately uses the halo lib, which isn’t quite what i’m after.

Guess i’ll shelve the idea till another time.

Someone posted this somewhere on the forum:

[lua]-- Clear the stencils
– Enable the new stencil
– Set the masks for halo compatibility
– Set your reference value[1]
– Set various operations[2]
– Set the comparison function[3]
– Draw something to the screen to work with reference values in order to determine the filtered end drawing.[1]
– Optionally make the stencil more complex by doing more drawing and changing the comparison function/operations.
– Draw your desired object to the screen. It will only be drawn where the comparison function/operators allow.
– Disable the new stencil
hook.Add(“PostDrawOpaqueRenderables”,“PlayerBorders”,function()
– stencil work is done in postdrawopaquerenderables, where surface doesn’t work correctly
– workaround via 3D2D
local pos = LocalPlayer():EyePos()+LocalPlayer():EyeAngles():Forward()*10
local ang = LocalPlayer():EyeAngles()
ang = Angle(ang.p+90,ang.y,0)
for k, v in pairs(ents.FindByClass(“prop_physics_multiplayer”)) do
render.ClearStencil()
render.SetStencilEnable(true)
render.SetStencilWriteMask(255)
render.SetStencilTestMask(255)
render.SetStencilReferenceValue(15)
render.SetStencilFailOperation(STENCILOPERATION_KEEP)
render.SetStencilZFailOperation(STENCILOPERATION_KEEP)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_ALWAYS)
render.SetBlend(0) --don’t visually draw, just stencil
v:SetModelScale(1.025,0) --slightly fuzzy, looks better this way
v:DrawModel()
v:SetModelScale(1,0)
render.SetBlend(1)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_EQUAL)
cam.Start3D2D(pos,ang,1)
surface.SetDrawColor(math.Rand(200,255),math.Rand(200,255),math.Rand(200,255),255)
surface.DrawRect(-ScrW(),-ScrH(),ScrW()*2,ScrH()*2)
cam.End3D2D()
v:DrawModel()
render.SetStencilEnable(false)
end
end)
– hook.Remove(“PostDrawOpaqueRenderables”,“PlayerBorders”)[/lua]

Let me see if I can find the link to it.

Edit: http://forum.facepunch.com/showthread.php?t=1257350 == http://forum.facepunch.com/showthread.php?t=1257350&p=40080246&viewfull=1#post40080246

and

http://forum.facepunch.com/showthread.php?t=1337232&p=43271812&viewfull=1#post43271812 – This post is in this thread: http://forum.facepunch.com/showthread.php?t=1337232 which covers stencils quite nicely. Stencils should give you a little more flexibility in terms of not limiting yourself to a “halo glow” but use solid colors, textures and more.

Be sure to thank Bletotum

He’ll be in my credits page. Thanks! :smiley: