Entity Draw Hook


Currently I want to draw a laser up to the Sky, but when the entity gets out of sight, the laser isn’t drawed


So i need to create a hook on PostDrawOpaqueRenderables?

BTW: It should be always visible


How are you drawing the laser?

Currently in the ENT:Draw hook:

function ENT:Draw()
self:DrawModel() --Draw model
local startpos = self:GetPos()
local spos = self:GetPos()
local ang = self:GetAngles()
local epos = self:GetPos() + (ang:Forward()*16384 )
local tr = util.TraceLine({start=spos,endpos=epos ,filter= self,mask=MASK_SOLID})

local endpos = tr.HitPos
render.SetMaterial( laser )
render.DrawBeam( startpos, endpos, 5, 1, 1, Color( 255, 255, 255, 255 ) ) 


You should probably use a hook, yeah.

Okay, now: Which one? It should be always visible, no excuses :smiley:

PostDrawTranslucentRenderables = Only Displayed if you have free sight on it
PreDrawTranslucentRenderables = Same
PostDrawOpaqueRenderables = Same
PreDrawOpaqueRenderables = Same

It shoud be drawed always

No, that’s caused by renderbounds. No need for hooks.

It feels like it’s the wrong approach to the problem to just have a huge renderbound.

[editline]7th December 2013[/editline]

I mean, it works fine in this situation without making it huge because the laser is axis-aligned relative to the entity (and just scaling it according to the trace length), but if it wasn’t it just seems wrong. I don’t know, I guess I just really like universal solutions :v:

Okay, got it working now, but still, i dont see the laser through walls etc.


Oh, i forgot to mention, that these lasers also can be placed on walls:

So this:
local min,max = self:GetRenderBounds()
self:SetRenderBounds(min,max + endpos)
won’t work

A hook would be better in this situation would’nt it?

Just make it draw everywhere, it isn’t going to impact performance unless you put hundreds of those.

[editline]7th December 2013[/editline]

If the hook works, use it.

Okay, but do you have any suggestions on how to achieve drawing it through walls?

Use a hook that is called after everything else is rendered.

Holy, i don’t get it…

ATM i use PostDrawTranslucentRenderables, which should be the correct hook, but then this happens:


It’s getting called, but it’s not drawn…

Try calling **[Lua/Libraries/render/ClearDepth

http://gmodwiki.net/favicon.ico](http://gmodwiki.net/Lua/Libraries/render/ClearDepth)** after or before drawing it.

Thanks again, now its working, but:



Try enabling that before drawing it and then disabling it immediately after.

[editline]7th December 2013[/editline]

So like this:
render.OverrideDepthEnable( true, true )
render.OverrideDepthEnable( false, false )

So my current code:

render.SetMaterial( laser )
render.OverrideDepthEnable( true, true )
render.DrawBeam( startpos, endpos, 5, 1, 1, Color( 255, 255, 255, 255 ) )
render.OverrideDepthEnable( false, false )

ClearDepth before drawing = Laser visible, but also creepy lamps
ClearDepth after drawing = only creepy Lamps, no laser visible
no ClearDepth = no creepy lamps, no laser visible

Ow god,


Using PostDrawTranslucentRenderables


a pretty simple question:
How to draw a Beam through Walls etc, without seeing lights/lamps through walls

Solved using surface.DrawLine in the HUDPaint Hook