The correct way to re-draw the players view model?

I’m trying to use stencils to create a hole in the ground, how ever becuase it uses cam.IgnoreZ(true) it draws over the viewmodel, all my attemps to re-draw it have resulted in it being horrible. For example, see the clip below, and the code that draws it.

		        cam.IgnoreZ( true )
		        cam.IgnoreZ( false )

You could draw the hole before the viewmodel.

I am, its currently being draw in PreDrawOpaqueRenderables, yet it still seems to draw over the view model.

Try using a RenderOverride on the viewmodel entity to draw it with cam.IgnoreZ enabled.

How do you mean? Would overriding it not be the same as what im doing now by making it already ignorez?

ENT:RenderOverride. Your function for the viewmodel would look like:

LocalPlayer():GetViewModel().RenderOverride = function(self)

Just make sure to do it for all the player’s viewmodels since there can be more than one.

[editline]24th October 2017[/editline]

There might be a completely better way to do this.

Same issue, how ever I noticed the physguns beam is drawing fine on it, just not the model.

[editline]24th October 2017[/editline]

Okay, I managed to fix it using

render.ClearDepth how ever, I just want to confirm that clearing the depths before drawing the viewmodel wont break anything else?

Physgun beams are drawn differently. You could do the method you were doing earlier, but use

cam.Start with the “fov” key being the weapon’s SWEP.ViewModelFOV and

SWEP:TranslateFOV settings.

[editline]24th October 2017[/editline]

I don’t believe so, I would think viewmodels would already do this internally.

Turn out it does :confused:

[editline]24th October 2017[/editline]

Litteraly started trying everything releated to depth, as I assumed it was something witht hat. Apprently calling this after drawing the stencil fixes it, maybe cam.IgnoreZ does something to it? render.DepthRange( 0, 1.0 ).

Thanks for you help guys.