[Beta] Viewmodel Outline Glitch

Alright so I tried making a specific outline on parts of a weapon’s viewmodel (In this case the .357 rounds) and it works, sorta. The outline projection is further away from the weapon itself, and I’ve check, it renders as if it’s in FOV 75:

I’m using a modified version of the Gmod 13 halo library code:

[lua]local matColor = Material( “model_color” )
local mat_Copy = Material( “pp/copy” )
local mat_Add = Material( “pp/add” )
local mat_Sub = Material( “pp/sub” )
local rt_Stencil = render.GetBloomTex0()
local rt_Store = render.GetScreenEffectTexture( 0 )

local WeaponTable = {}
local List = {}
local Bones = { “Base”, “Arm”, “Hand”, “Python”, “Cylinder”, “Cylinder_release”, “Bip01_L_UpperArm”, “Bip01_L_Forearm”, “Bip01_L_Hand”, “Bip01_L_Finger4”, “Bip01_L_Finger41”, “Bip01_L_Finger42”, “Bip01_L_Finger3”, “Bip01_L_Finger31”, “Bip01_L_Finger32”, “Bip01_L_Finger2”, “Bip01_L_Finger21”, “Bip01_L_Finger22”, “Bip01_L_Finger1”, “Bip01_L_Finger11”, “Bip01_L_Finger12”, “Bip01_L_Finger0”, “Bip01_L_Finger01”, “Bip01_L_Finger02” }
local Bones2 = { “Bullet1”, “Bullet2”, “Bullet3”, “Bullet4”, “Bullet5”, “Bullet6” }
local AllBones = {}

for i = 0, LocalPlayer():GetViewModel():GetBoneCount() - 1 do
local name = LocalPlayer():GetViewModel():GetBoneName(i)
if (LocalPlayer():GetViewModel():LookupBone(name)) then // filter out invalid bones
table.insert(AllBones, name)
end
end

function Add( ents, color, blurx, blury, passes, add, ignorez )

if ( add == nil ) then add = true end
if ( ignorez == nil ) then ignorez = false end

local t = 
{
	Ents = ents,
	Color = color,
	BlurX = 2,
	BlurY = 2,
	DrawPasses = 1,
	Additive = true,
	IgnoreZ = true
}

table.insert( List, t )

end

function Render( entry )

local OldRT = render.GetRenderTarget()

-- Copy what's currently on the screen to another texture
render.CopyRenderTargetToTexture( rt_Store )

-- Clear the colour and the stencils, not the depth
if ( entry.Additive ) then			
	render.Clear( 0, 0, 0, 255, false, true )
else
	render.Clear( 255, 255, 255, 255, false, true )
end
	

-- FILL STENCIL
-- Write to the stencil..		
cam.Start3D( EyePos(), EyeAngles() )

	cam.IgnoreZ( entry.IgnoreZ )
	render.OverrideDepthEnable( true, false )									-- Don't write depth
	
	render.SetStencilEnable( true );
	render.SetStencilFailOperation( STENCILOPERATION_KEEP );
	render.SetStencilZFailOperation( STENCILOPERATION_KEEP );
	render.SetStencilPassOperation( STENCILOPERATION_REPLACE );
	render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_ALWAYS );
	render.SetStencilWriteMask( 1 );
	render.SetStencilReferenceValue( 1 );
	
	render.SetBlend( 0 ); -- don't render any colour
	
	for k, v in pairs( entry.Ents ) do
	
		if ( !IsValid( v ) ) then continue end
		
		local vm = LocalPlayer():GetViewModel()
		render.PushFlashlightMode( true )
			for q, w in pairs(Bones) do
				local bone = vm:LookupBone(w)
				if (!bone) then continue end
				local m = vm:GetBoneMatrix(bone)
				if (!m) then continue end
				m:Scale(Vector(0, 0, 0))
				m:Rotate(Angle(0, 0, 0))
				m:SetTranslation(Vector(0, 20, 0))
				vm:SetBoneMatrix(bone, m)
			end
			vm:DrawModel()
		render.PopFlashlightMode()
	
	end
		
cam.End3D()	

-- FILL COLOUR
-- Write to the colour buffer
cam.Start3D( EyePos(), EyeAngles() )

	render.MaterialOverride( matColor )			
	cam.IgnoreZ( entry.IgnoreZ )
	
	render.SetStencilEnable( true );
	render.SetStencilWriteMask( 0 );
	render.SetStencilReferenceValue( 0 );
	render.SetStencilTestMask( 1 );
	render.SetStencilFailOperation( STENCILOPERATION_KEEP );
	render.SetStencilPassOperation( STENCILOPERATION_KEEP );
	render.SetStencilZFailOperation( STENCILOPERATION_KEEP );
	render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_NOTEQUAL );
	
	for k, v in pairs( entry.Ents ) do
		
		if ( !IsValid( v ) ) then continue end
		
		render.SetColorModulation( entry.Color.r/255, entry.Color.g/255, entry.Color.b/255 )
		render.SetBlend( entry.Color.a/255 );
		
		local vm = LocalPlayer():GetViewModel()
		for q, w in pairs(Bones) do
			local bone = vm:LookupBone(w)
			if (!bone) then continue end
			local m = vm:GetBoneMatrix(bone)
			if (!m) then continue end
			m:Scale(Vector(0, 0, 0))
			m:Rotate(Angle(0, 0, 0))
			m:SetTranslation(Vector(0, 20, 0))
			vm:SetBoneMatrix(bone, m)
		end
		vm:DrawModel()
		
	end
		
	render.MaterialOverride( nil )
	render.SetStencilEnable( false );

cam.End3D()

-- BLUR IT
	render.CopyRenderTargetToTexture( rt_Stencil )
	render.OverrideDepthEnable( false, false )
	render.SetStencilEnable( false );
	render.BlurRenderTarget( rt_Stencil, entry.BlurX, entry.BlurY, 1 )

-- Put our scene back
	render.SetRenderTarget( OldRT )
	render.SetColorModulation( 1, 1, 1 )
	render.SetStencilEnable( false );
	render.OverrideDepthEnable( true, false )
	render.SetBlend( 1 );
	mat_Copy:SetMaterialTexture( "$basetexture", rt_Store )
	render.SetMaterial( mat_Copy )
	render.DrawScreenQuad()
	

-- DRAW IT TO THE SCEEN

	render.SetStencilEnable( true );
	render.SetStencilWriteMask( 0 );
	render.SetStencilReferenceValue( 0 );
	render.SetStencilTestMask( 1 );
	render.SetStencilFailOperation( STENCILOPERATION_KEEP );
	render.SetStencilPassOperation( STENCILOPERATION_KEEP );
	render.SetStencilZFailOperation( STENCILOPERATION_KEEP );
	render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL );
	    
	if ( entry.Additive ) then	
		mat_Add:SetMaterialTexture( "$basetexture", rt_Stencil )
		render.SetMaterial( mat_Add )
	else
		mat_Sub:SetMaterialTexture( "$basetexture", rt_Stencil )
		render.SetMaterial( mat_Sub )
	end
	
	for i=0, entry.DrawPasses do
		render.DrawScreenQuad()
	end

-- PUT EVERYTHING BACK HOW WE FOUND IT

	render.SetStencilWriteMask( 0 );
	render.SetStencilReferenceValue( 0 );
	render.SetStencilTestMask( 0 );
	render.SetStencilEnable( false )
	render.OverrideDepthEnable( false )
	render.SetBlend( 1 )
	
	cam.IgnoreZ( false )

end

hook.Add( “PostDrawEffects”, “TestHaloRender”, function()

if ( #List == 0 ) then return end

for k, v in pairs( List ) do
	Render( v )
end
	
List = {}

end )

function TestHaloThink()
for k, v in pairs(player.GetAll()) do
if v:GetViewModel():GetModel() == “models/weapons/v_357.mdl” then
WeaponTable[1] = v:GetViewModel()
Add( WeaponTable, Color(255,255,255,255), 2, 2, 1, true, true )
end
end
end
hook.Add(“Think”, “TestHaloThink”, TestHaloThink)[/lua]

So what am I doing wrong?

I guess you need to set the FOV manually every time you call cam.Start3D. The third parameter is the FOV. For SWEPs you can check the ViewModelFOV member, and for HL2 weapons, simply grab the value of the viewmodel_fov convar.

LocalPlayer():GetActiveWeapon().ViewModelFOV + 15

This is what I had to use as FOV… weird but it works fine now. Thanks chief!