--by pavetr.top/ds RunConsoleCommand("spawnmenu_reload") local cvars_gost = {524288, 8192, 268435456, 128, 1} local gmod_nfog_enable = CreateClientConVar( "gmod_nfog_enable", 1, cvars_gost, "Enable or disable custom fog") local gmod_nfog_useworldz = CreateClientConVar( "gmod_nfog_useworldz", 1, cvars_gost, "Use worldpos Z height for fog position calculation") local gmod_nfog_useselfdist = CreateClientConVar( "gmod_nfog_useselfdist", 0, cvars_gost, "Use own fog distance instead of the gmod farz of the fog") local gmod_nfog_usebubblefog = CreateClientConVar( "gmod_nfog_usebubblefog", 0, cvars_gost, "Use different type of fog") local gmod_nfog_detail = CreateClientConVar( "gmod_nfog_detail", 12, cvars_gost, "Level of detail of fog (how many corners will be drawn)") local gmod_nfog_layers = CreateClientConVar( "gmod_nfog_layers", 16, cvars_gost, "Level of detail of fog (how many layers of fog will be drawn)") local gmod_nfog_ldist = CreateClientConVar( "gmod_nfog_ldist", 48, cvars_gost, "Level of detail of fog (how much spacing between layers)") local gmod_nfog_height = CreateClientConVar( "gmod_nfog_height", 2048, cvars_gost, "Height of the fog planes") local gmod_nfog_addworldz = CreateClientConVar( "gmod_nfog_addworldz", 0, cvars_gost, "Increase or decrease fog height relative to worldpos Z") local gmod_nfog_addplyz = CreateClientConVar( "gmod_nfog_addplyz", 0, cvars_gost, "Increase or decrease fog height relative to player") local gmod_nfog_adddist = CreateClientConVar( "gmod_nfog_adddist", 1200, cvars_gost, "Increase or decrease fog distance relative to gmod farz of the fog") local gmod_nfog_owndist = CreateClientConVar( "gmod_nfog_owndist", 3000, cvars_gost, "Distance of the fog when not using gmod farz") local gmod_nfog_coverradius = CreateClientConVar( "gmod_nfog_coverradius", 32000, cvars_gost, "Distance of the fog top cover") if CLIENT then --touch local fogdisabled = GetConVar("gmod_nfog_enable"):GetBool() --false local worldZ = GetConVar("gmod_nfog_useworldz"):GetBool() --true local standalonefog = GetConVar("gmod_nfog_useselfdist"):GetBool() --false local bubblefog = GetConVar("gmod_nfog_usebubblefog"):GetBool() --false local layers = GetConVar("gmod_nfog_layers"):GetInt() --16 local dist = GetConVar("gmod_nfog_ldist"):GetInt() --48 local corners = GetConVar("gmod_nfog_detail"):GetInt() --12 local height = GetConVar("gmod_nfog_height"):GetInt() --2048 local AddWorldZ = GetConVar("gmod_nfog_addworldz"):GetInt() ---512 local AddPlayerZ = GetConVar("gmod_nfog_addplyz"):GetInt() --0 local AddDist = GetConVar("gmod_nfog_adddist"):GetInt() --1200 local standaloneradius = GetConVar("gmod_nfog_owndist"):GetInt() --3000 local topcoverradius = GetConVar("gmod_nfog_coverradius"):GetInt() --32000 local slowercheck2 = true hook.Add( "Think", "checkfogvars2", function() if slowercheck2 then slowercheck2 = false timer.Simple(1,function() slowercheck2 = true end) fogdisabled = GetConVar("gmod_nfog_enable"):GetBool() --false worldZ = GetConVar("gmod_nfog_useworldz"):GetBool() --true standalonefog = GetConVar("gmod_nfog_useselfdist"):GetBool() --false bubblefog = GetConVar("gmod_nfog_usebubblefog"):GetBool() --false layers = GetConVar("gmod_nfog_layers"):GetInt() --16 dist = GetConVar("gmod_nfog_ldist"):GetInt() --48 corners = GetConVar("gmod_nfog_detail"):GetInt() --12 height = GetConVar("gmod_nfog_height"):GetInt() --2048 AddWorldZ = GetConVar("gmod_nfog_addworldz"):GetInt() ---512 AddPlayerZ = GetConVar("gmod_nfog_addplyz"):GetInt() --0 AddDist = GetConVar("gmod_nfog_adddist"):GetInt() --1200 standaloneradius = GetConVar("gmod_nfog_owndist"):GetInt() --3000 topcoverradius = GetConVar("gmod_nfog_coverradius"):GetInt() --32000 end end) --no touch local mat2 = Material( "models/XQM/PoleX1_diffuse" ) --for test purposes local fogstart, fogend, fogz = render.GetFogDistances() local radius = fogend-AddDist local r, g, b = render.GetFogColor() local radianmult = math.pi / 180 local postable = {} local angle = 0 local points = 0 local postabletop = {} local fogthinkslower = true hook.Add( "Think", "checkfogvars", function() if fogthinkslower then fogthinkslower = false timer.Simple(1,function() fogthinkslower = true end) fogstart, fogend, fogz = render.GetFogDistances() if fogend == 0 then return end if standalonefog then radius = fogend-AddDist else radius = standaloneradius end r, g, b = render.GetFogColor() for k=1, layers do for i=1, corners do local angle = radianmult * (360/corners) * (i-1) postable[k.."x"..i]=(radius+(k*dist))*math.cos(angle) postable[k.."y"..i]=(radius+(k*dist))*math.sin(angle) end points = (table.Count( postable )/2)/layers postabletop = {} for i=1, corners do local angle = radianmult * (360/corners) * (i-1) postabletop["x"..i]=(radius+topcoverradius)*math.cos(angle) postabletop["y"..i]=(radius+topcoverradius)*math.sin(angle) end end end end) hook.Add( "PostDrawTranslucentRenderables", "fogdraw", function(bDrawingDepth, bDrawingSkybox, isDraw3DSkybox) if fogend == 0 or fogdisabled != true then return end if bubblefog then local pos = LocalPlayer():GetPos()+Vector(0,0,1000) --render.SetMaterial( mat2 ) render.SetColorMaterial() for i=1,layers do render.DrawSphere( pos+Vector(0,0,AddPlayerZ), -3000-(dist*i), corners, corners, Color(r,g,b,Lerp(math.ease.InCirc(i/layers), 0, 255) ) ) end else --render.SetMaterial( mat2 ) render.SetColorMaterial() local pos = LocalPlayer():GetPos() if worldZ then pos.z = AddWorldZ else pos.z = pos.z + AddPlayerZ end local function drawfogcircle(layer) for i=1, points do if i != points then render.DrawQuad( pos+Vector( postable[layer.."x"..i], postable[layer.."y"..i], 0 ), pos+Vector( postable[layer.."x"..(i+1)], postable[layer.."y"..(i+1)], 0 ), pos+Vector( postable[layer.."x"..(i+1)], postable[layer.."y"..(i+1)], height ), pos+Vector( postable[layer.."x"..i], postable[layer.."y"..i], height ), Color(r,g,b,Lerp(math.ease.InCirc(layer/layers), 0, 255)) ) else render.DrawQuad( pos+Vector( postable[layer.."x"..i], postable[layer.."y"..i], 0 ), pos+Vector( postable[layer.."x1"], postable[layer.."y1"], 0 ), pos+Vector( postable[layer.."x1"], postable[layer.."y1"], height ), pos+Vector( postable[layer.."x"..i], postable[layer.."y"..i], height ), Color(r,g,b,Lerp(math.ease.InCirc(layer/layers), 0, 255)) ) end end end local function drawfogtop() for i=1, points do if i != points then render.DrawQuad( pos+Vector( postable[layers.."x"..i], postable[layers.."y"..i], height ), pos+Vector( postable[layers.."x"..(i+1)], postable[layers.."y"..(i+1)], height ), pos+Vector( postabletop["x"..(i+1)], postabletop["y"..(i+1)], height ), pos+Vector( postabletop["x"..i], postabletop["y"..i], height ), Color(r,g,b,255) ) else render.DrawQuad( pos+Vector( postable[layers.."x"..i], postable[layers.."y"..i], height ), pos+Vector( postable[layers.."x1"], postable[layers.."y1"], height ), pos+Vector( postabletop["x1"], postabletop["y1"], height ), pos+Vector( postabletop["x"..i], postabletop["y"..i], height ), Color(r,g,b,255) ) end end end for k=1, layers do drawfogcircle(k) end drawfogtop() end end ) end if CLIENT then hook.Add( "AddToolMenuCategories", "NavaFogCategory", function() spawnmenu.AddToolCategory( "Utilities", "Fog", "#Fog" ) end ) hook.Add( "PopulateToolMenu", "NavaFogSettings", function() spawnmenu.AddToolMenuOption( "Utilities", "Fog", "NavaCustomMenuNumbaInf", "#Fog Settings", "", "", function( panel ) panel:Clear() -- Add stuff here local EnableFog = vgui.Create( "DCheckBoxLabel", panel ) EnableFog:Dock(TOP) EnableFog:SetText("Enable or disable custom fog") EnableFog:SetConVar("gmod_nfog_enable") EnableFog:SetValue( GetConVar("gmod_nfog_enable"):GetBool() ) EnableFog:SizeToContents() local Useworldz = vgui.Create( "DCheckBoxLabel", panel ) Useworldz:Dock(TOP) Useworldz:SetText("Use worldpos Z height for fog position calculation") Useworldz:SetConVar("gmod_nfog_useworldz") Useworldz:SetValue( GetConVar("gmod_nfog_useworldz"):GetBool() ) Useworldz:SizeToContents() local Useselfdist = vgui.Create( "DCheckBoxLabel", panel ) Useselfdist:Dock(TOP) Useselfdist:SetText("Use self fog distance instead of the gmod farz of the fog") Useselfdist:SetConVar("gmod_nfog_useselfdist") Useselfdist:SetValue( GetConVar("gmod_nfog_useselfdist"):GetBool() ) Useselfdist:SizeToContents() local UseBubbleFog = vgui.Create( "DCheckBoxLabel", panel ) UseBubbleFog:Dock(TOP) UseBubbleFog:SetText("Use bubble type of fog") UseBubbleFog:SetConVar("gmod_nfog_usebubblefog") UseBubbleFog:SetValue( GetConVar("gmod_nfog_usebubblefog"):GetBool() ) UseBubbleFog:SizeToContents() local gmod_nfog_detailSlider = vgui.Create( "DNumSlider", panel ) gmod_nfog_detailSlider:Dock(TOP) -- Set the position gmod_nfog_detailSlider:SetSize( 250, 20 ) -- Set the size gmod_nfog_detailSlider:SetText( "Fog corners num" ) -- Set the text above the slider gmod_nfog_detailSlider:SetMin( 3 ) -- Set the minimum number you can slide to gmod_nfog_detailSlider:SetMax( 128 ) -- Set the maximum number you can slide to gmod_nfog_detailSlider:SetDecimals( 0 ) -- Decimal places - zero for whole number gmod_nfog_detailSlider:SetValue(GetConVar("gmod_nfog_detail"):GetInt()) gmod_nfog_detailSlider:SetConVar( "gmod_nfog_detail" ) -- If not using convars, you can use this hook + Panel.SetValue() gmod_nfog_detailSlider.OnValueChanged = function( self, value ) -- Called when the slider value changes end local gmod_nfog_layersSliders = vgui.Create( "DNumSlider", panel ) gmod_nfog_layersSliders:Dock(TOP) gmod_nfog_layersSliders:SetSize( 250, 20 ) gmod_nfog_layersSliders:SetText( "Fog layers num" ) gmod_nfog_layersSliders:SetMin( 1 ) gmod_nfog_layersSliders:SetMax( 256 ) gmod_nfog_layersSliders:SetDecimals( 0 ) gmod_nfog_layersSliders:SetValue(GetConVar("gmod_nfog_layers"):GetInt()) gmod_nfog_layersSliders:SetConVar( "gmod_nfog_layers" ) -- If not using convars, you can use this hook + Panel.SetValue() gmod_nfog_layersSliders.OnValueChanged = function( self, value ) -- Called when the slider value changes end local gmod_nfog_ldistSlider = vgui.Create( "DNumSlider", panel ) gmod_nfog_ldistSlider:Dock(TOP) gmod_nfog_ldistSlider:SetSize( 250, 20 ) gmod_nfog_ldistSlider:SetText( "Layer spacing" ) gmod_nfog_ldistSlider:SetMin( 1 ) gmod_nfog_ldistSlider:SetMax( 1024 ) gmod_nfog_ldistSlider:SetDecimals( 0 ) gmod_nfog_ldistSlider:SetValue(GetConVar("gmod_nfog_ldist"):GetInt()) gmod_nfog_ldistSlider:SetConVar( "gmod_nfog_ldist" ) -- If not using convars, you can use this hook + Panel.SetValue() gmod_nfog_ldistSlider.OnValueChanged = function( self, value ) -- Called when the slider value changes end local gmod_nfog_heightSlider = vgui.Create( "DNumSlider", panel ) gmod_nfog_heightSlider:Dock(TOP) gmod_nfog_heightSlider:SetSize( 250, 20 ) gmod_nfog_heightSlider:SetText( "Fog height" ) gmod_nfog_heightSlider:SetMin( 1 ) gmod_nfog_heightSlider:SetMax( 32768 ) gmod_nfog_heightSlider:SetDecimals( 0 ) gmod_nfog_heightSlider:SetValue(GetConVar("gmod_nfog_height"):GetInt()) gmod_nfog_heightSlider:SetConVar( "gmod_nfog_height" ) -- If not using convars, you can use this hook + Panel.SetValue() gmod_nfog_heightSlider.OnValueChanged = function( self, value ) -- Called when the slider value changes end local gmod_nfog_addworldzSlider = vgui.Create( "DNumSlider", panel ) gmod_nfog_addworldzSlider:Dock(TOP) gmod_nfog_addworldzSlider:SetSize( 250, 20 ) gmod_nfog_addworldzSlider:SetText( "Relative fog world height" ) gmod_nfog_addworldzSlider:SetMin( -32768 ) gmod_nfog_addworldzSlider:SetMax( 32768 ) gmod_nfog_addworldzSlider:SetDecimals( 0 ) gmod_nfog_addworldzSlider:SetValue(GetConVar("gmod_nfog_addworldz"):GetInt()) gmod_nfog_addworldzSlider:SetConVar( "gmod_nfog_addworldz" ) -- If not using convars, you can use this hook + Panel.SetValue() gmod_nfog_addworldzSlider.OnValueChanged = function( self, value ) -- Called when the slider value changes end local gmod_nfog_addplyzSlider = vgui.Create( "DNumSlider", panel ) gmod_nfog_addplyzSlider:Dock(TOP) gmod_nfog_addplyzSlider:SetSize( 250, 20 ) gmod_nfog_addplyzSlider:SetText( "Relative fog player height" ) gmod_nfog_addplyzSlider:SetMin( -32768 ) gmod_nfog_addplyzSlider:SetMax( 32768 ) gmod_nfog_addplyzSlider:SetDecimals( 0 ) gmod_nfog_addplyzSlider:SetValue(GetConVar("gmod_nfog_addplyz"):GetInt()) gmod_nfog_addplyzSlider:SetConVar( "gmod_nfog_addplyz" ) -- If not using convars, you can use this hook + Panel.SetValue() gmod_nfog_addplyzSlider.OnValueChanged = function( self, value ) -- Called when the slider value changes end local gmod_nfog_adddistSlider = vgui.Create( "DNumSlider", panel ) gmod_nfog_adddistSlider:Dock(TOP) gmod_nfog_adddistSlider:SetSize( 250, 20 ) gmod_nfog_adddistSlider:SetText( "Relative fog farz dist" ) gmod_nfog_adddistSlider:SetMin( -10000 ) gmod_nfog_adddistSlider:SetMax( 10000 ) gmod_nfog_adddistSlider:SetDecimals( 0 ) gmod_nfog_adddistSlider:SetValue(GetConVar("gmod_nfog_adddist"):GetInt()) gmod_nfog_adddistSlider:SetConVar( "gmod_nfog_adddist" ) -- If not using convars, you can use this hook + Panel.SetValue() gmod_nfog_adddistSlider.OnValueChanged = function( self, value ) -- Called when the slider value changes end local gmod_nfog_owndistSlider = vgui.Create( "DNumSlider", panel ) gmod_nfog_owndistSlider:Dock(TOP) gmod_nfog_owndistSlider:SetSize( 250, 20 ) gmod_nfog_owndistSlider:SetText( "Absolute fog dist" ) gmod_nfog_owndistSlider:SetMin( -30000 ) gmod_nfog_owndistSlider:SetMax( 30000 ) gmod_nfog_owndistSlider:SetDecimals( 0 ) gmod_nfog_owndistSlider:SetValue(GetConVar("gmod_nfog_owndist"):GetInt()) gmod_nfog_owndistSlider:SetConVar( "gmod_nfog_owndist" ) -- If not using convars, you can use this hook + Panel.SetValue() gmod_nfog_owndistSlider.OnValueChanged = function( self, value ) -- Called when the slider value changes 714420 end end ) end ) end