• Stencil outlines
    5 replies, posted
hi; i'm not at all familiar with stencils and it appears that this code to give outlines to entities does not work, in that it does render another model but the same color and on top of the other, such that there is no outline. no clue what might be the issue and i've experimented for about an hour now. 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")) 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.0+math.Rand(0.01,0.013),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)
If you want purely entity outlines, you might consider using the builtin Halo library halo.Add
i've been avoiding it because of its performance hits
If you set the passes to low it's pretty reasonable. That being said, read through this thread: A detailed Stencil tutorial The quotes can help you get a halo effect with stencils, good for performance but a little messy if you expect to be scaling models actively
The halo lib uses stencils internally. I don't know how big of a performance boost would you get if you were to code your own outline system.
To add to this, don't create a new table every time you run halo.Add, initialize the table once and update its contents when needed
Sorry, you need to Log In to post a reply to this thread.