--[[local rt = GetRenderTargetEx( "__rt__AlphaTest", 512, 512, RT_SIZE_FULL_FRAME_BUFFER, MATERIAL_RT_DEPTH_NONE, 0, 0, IMAGE_FORMAT_BGRA8888 ) local mat = CreateMaterial( "AlphaTest", "UnlitGeneric", { ["$basetexture"] = rt, ["$alpha"] = 1, ["$translucent"] = 1 } )]] local o = file.Read( "lua/roundhudv2.lua", true ) hook.Add( "Think", "autorun", function() if file.Read( "lua/roundhudv2.lua", true ) ~= o then MsgN( "Change detected, re-including" ) include "roundhudv2.lua" end end ) local matBlack = CreateMaterial( "BlackOutline", "UnlitGeneric", { [ "$basetexture" ] = "vgui/black" } ) ROUNDHUD = {} local function approachangle(a1, a2, inc) local r = Angle( 0, 0, 0 ) r.p = math.ApproachAngle( a1.p, a2.p, inc ) r.y = math.ApproachAngle( a1.y, a2.y, inc ) r.r = math.ApproachAngle( a1.r, a2.r, inc ) return r end function ROUNDHUD:Initialize() self:Shutdown() self.Mesh = self:GenerateMesh( 180 ) self.ScreenRenderTarget = GetRenderTargetEx( "__rt_Visor", 512, 512, RT_SIZE_FULL_FRAME_BUFFER, MATERIAL_RT_DEPTH_NONE, 0, 0, IMAGE_FORMAT_BGRA8888 ) self.matScreen = CreateMaterial( "RoundHUDScreen", "UnlitGeneric", { ["$basetexture"] = self.ScreenRenderTarget, ["$alpha"] = 1, ["$translucent"] = 1 } ) local lastupdate = CurTime() local visonangle = Angle( 0, 0, 0 ) local lasteyeangle = Angle( 0, 0, 0 ) hook.Add( "PostDrawViewModel", "Visor", function() local w, h = ScrW(), ScrH() local oRT = render.GetRenderTarget() render.SetRenderTarget( self.ScreenRenderTarget ) render.Clear( 0, 0, 0, 0 ) cam.Start2D() self:PaintScreen( w, h ) cam.End2D() render.SetRenderTarget( oRT ) self.matScreen:SetMaterialTexture( "$basetexture", self.ScreenRenderTarget ) --visonangle = approachangle( visonangle, EyeAngles(), ( CurTime() - lastupdate ) * 180 )--visonangle + ( EyeAngles()-lasteyeangle ) --lasteyeangle = EyeAngles() local fov = LocalPlayer():GetFOV() local o, a = Vector( 0, 0, 0 ), Angle( 0, 0, 0 ) cam.Start3D( o, a, fov ) self:Render( o, a * 1, fov ) cam.End3D() lastupdate = CurTime() end ) local dontdraw = { "CHudHealth", "CHudSuitPower", "CHudBattery", "CHudCrosshair", "CHudAmmo", "CHudSecondaryAmmo", } hook.Add( "HUDShouldDraw", "Visor", function( e ) if table.HasValue( dontdraw, e ) then return false end end ) end function ROUNDHUD:Shutdown() --hook.Remove( "PostDrawOpaqueRenderables", "Visor" ) end local deg_to_rad = math.pi / 180 function ROUNDHUD:GenerateMesh( size ) local triangles = {} local last_i = 0 local last_x = math.cos( 0 * deg_to_rad ) * 0.5 local last_y = math.sin( 0 * deg_to_rad ) * 0.5 for i=1, size do local x = math.cos( i * deg_to_rad ) * 0.5 local y = math.sin( i * deg_to_rad ) * 0.5 local tc = Vector( x, y, 0.5 ) local bc = Vector( x, y, -0.5 ) local tp = Vector( last_x, last_y, 0.5 ) local bp = Vector( last_x, last_y, -0.5 ) -- Outside table.insert( triangles, { pos = tp, normal=tp:GetNormal(), u=1-last_i/size, v=0 } ) table.insert( triangles, { pos = bp, normal=bp:GetNormal(), u=1-last_i/size, v=1 } ) table.insert( triangles, { pos = tc, normal=tc:GetNormal(), u=1-i/size, v=0 } ) table.insert( triangles, { pos = bc, normal=bc:GetNormal(), u=1-i/size, v=1 } ) table.insert( triangles, { pos = tc, normal=tc:GetNormal(), u=1-i/size, v=0 } ) table.insert( triangles, { pos = bp, normal=bp:GetNormal(), u=1-last_i/size, v=1 } ) last_i = i last_x = x last_y = y end local mesh = NewMesh() mesh:BuildFromTriangles( triangles ) return mesh end function ROUNDHUD:DrawBar( x, y, w, h, p, vert ) p = math.min( p, 1 ) surface.DrawRect( x, y, w * ( vert and 1 or p ), h * ( vert and p or 1 ) ) surface.DrawOutlinedRect( x, y, w, h ) end local matBlack = CreateMaterial( "BlackOutline", "UnlitGeneric", { [ "$basetexture" ] = "vgui/black" } ) local matBlur = Material( "pp/blurscreen" ) surface.CreateFont( "Courier New", 16, 600, true, false, "VISOR_FONT" ) --[[function ROUNDHUD:PaintIntro( w, h ) end]] function ROUNDHUD:PaintScreen( w, h ) if not self.StartTime then self.StartTime = CurTime() end --[[if CurTime() - self.StartTime <= 5 then self:PaintIntro( w, h ) return end]] --[[surface.SetDrawColor( 150, 0, 255, 255 ) surface.DrawRect( 0, 0, w, 20 ) surface.DrawRect( 0, h-20, w, 20 ) surface.DrawRect( 0, 0, 20, h ) surface.DrawRect( w-20, 0, 20, h )]] surface.SetDrawColor( 0, 0, 0, 150 ) surface.DrawRect( 0, 0, w, 20 ) surface.DrawRect( 0, h-20, w, 20 ) surface.SetDrawColor( 255, 150, 0, 200 ) surface.SetDrawColor( 0, 0, 0, 150 ) surface.DrawRect( 20, 30, 300, 100 ) surface.SetDrawColor( 150, 255, 200, 200 ) local last_x, last_y local max = LocalPlayer():Armor()/100*99--math.floor((1+math.sin(CurTime()))*0.5*99) for i=1, max do local x = 20 + i/100 * 300 local value = 0 value = math.sin(i+CurTime() * 0.25)*40 local y = 80 - math.Clamp( value, -50, 50 ) surface.SetDrawColor( 150, 255, 200, 200-i/max*200 ) surface.DrawRect( x-1, y-1, 2, 2 ) --surface.DrawLine( last_x or x, last_y or y, x, y ) last_x, last_y = x, y end self:DrawWeaponModule( w, h) surface.SetDrawColor( 0, 0, 0, 250 ) surface.DrawRect( w/2-2, h/2-2, 4, 4 ) surface.SetDrawColor( 0, 150, 255, 255 ) surface.DrawRect( w/2-1, h/2-1, 2, 2 ) end local silhouette = Material( "bullet-silhouette.png" ) local bullets = {} local lastcall = CurTime() function ROUNDHUD:DrawWeaponModule( w, h ) local deltat = ( CurTime() - lastcall ) lastcall = CurTime() --draw.DrawText( tostring(tid), "Default", 50, 50, Color( 255, 255, 255, 255 ) ) surface.SetMaterial( silhouette ) surface.SetDrawColor( 0, 150, 255, 255 ) local count = 0 for _, v in pairs( bullets ) do if not v.s then count = count + 1 end end if count < LocalPlayer():GetActiveWeapon():Clip1() then for i=count+1, LocalPlayer():GetActiveWeapon():Clip1() do table.insert( bullets, { s=false, v=Vector( math.random(-200, 0), math.random(-500, -100), 0 ), a=0, av=math.random(0,180) } ) end elseif count > LocalPlayer():GetActiveWeapon():Clip1() then local i, last = 0 for _, v in pairs( bullets ) do if not v.s then i = i + 1 last = v end end if last then last.s = true i = i - 1 local xi = i%10 local yi = math.floor( i/10 ) last.p = Vector( w-50 - 9 * xi, h-50 - 21 *yi, 0 ) end end render.SetScissorRect( 0, 20, w, h-20, true ) local i = 0 for k, d in pairs( bullets ) do if not d.s then local xi = i%10 local yi = math.floor( i/10 ) surface.SetDrawColor( 0, 0, 0, 200 ) surface.DrawTexturedRectRotated( w-50 - 9 * xi, h-50 - 21 * yi, 10, 22, 0 ) surface.SetDrawColor( 150, 255, 200, 200 ) surface.DrawTexturedRectRotated( w-50 - 9 * xi, h-50 - 21 * yi, 8, 20, 0 ) i = i + 1 elseif d.p then surface.SetDrawColor( 0, 0, 0, 200 ) surface.DrawTexturedRectRotated( d.p.x, d.p.y, 10, 22, d.a ) surface.SetDrawColor( 150, 255, 200, 200 ) surface.DrawTexturedRectRotated( d.p.x, d.p.y, 8, 20, d.a ) d.v = d.v + Vector( 0, 500, 0 ) * deltat d.p = d.p + d.v * deltat --d.av = math.Approach( d.av, 0, deltat*0.2 ) d.a = d.a + d.av * deltat if d.p.y > h then table.remove( bullets, k ) end end end render.SetScissorRect( 0, 0, 0, 0, false ) end local l = 10 local StartTime = CurTime() function ROUNDHUD:Render( origin, angles, fov ) local ang = angles ang:RotateAroundAxis( ang:Up(), -90 ) local w, h = ScrW(), ScrH() local hFov = fov --local vFov = math.deg( 2 * math.atan( ( h * math.tan( math.rad( hFov ) / 2 ) ) / w ) ) local ratio = w / h local w = l * math.tan( math.rad( hFov / 2 ) ) * 2 local h = w / ratio-- * math.min( 1, (CurTime()-StartTime)/0.1 )--l * math.tan( math.rad( vFov / 2 ) ) * 4 local p = 1 - hFov / 180 local d = w / 2 * p local pos = origin + ang:Right() * -1 * l local matrix = Matrix() matrix:Translate( pos ) matrix:Rotate( ang ) matrix:Scale( Vector( w, d, h ) ) --cam.StartOrthoView( origin, angles ) cam.IgnoreZ( true ) render.SuppressEngineLighting( true ) cam.PushModelMatrix( matrix ) render.SetMaterial( self.matScreen ) self.Mesh:Draw() cam.PopModelMatrix() render.SuppressEngineLighting( false ) cam.IgnoreZ( false ) --cam.EndOrthoView() end function ROUNDHUD:RenderScene( origin, angles ) local view = {} view.x = 0 view.y = 0 view.w = ScrW() view.h = ScrH() view.origin = origin view.angles = angles view.drawhud = true view.drawviewmodel = true local oRT = render.GetRenderTarget() render.SetRenderTarget( self.ScreenRenderTarget ) render.Clear( 0, 0, 0, 255, true ) render.ClearDepth() render.ClearStencil() render.RenderView( view ) cam.Start2D() self:PaintScreen( ScrW(), ScrH() ) cam.End2D() render.SetRenderTarget( oRT ) self.matScreen:SetMaterialTexture( "$basetexture", self.ScreenRenderTarget ) render.SetMaterial( self.matScreen ) render.DrawScreenQuad() return true end ROUNDHUD:Initialize()