Last active
May 14, 2016 05:59
-
-
Save samuelmaddock/cf2c12c3e328cbf2868d to your computer and use it in GitHub Desktop.
Glass effect for Garry's Mod; save in lua/autorun.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
-- Sublime Glass - Garry's Mod | |
-- | |
-- Use with the 'Sublime Text Trans' package. | |
-- https://github.com/vhanla/SublimeTextTrans | |
-- | |
if SERVER then | |
AddCSLuaFile() | |
return | |
end | |
local UpdateScreenEffectTexture = render.UpdateScreenEffectTexture | |
local DrawTexturedRect = surface.DrawTexturedRect | |
local SetMaterial = surface.SetMaterial | |
local SetDrawColor = surface.SetDrawColor | |
local EaseInOut = math.EaseInOut | |
local HasFocus = system.HasFocus | |
local RealTime = RealTime | |
local ScrW = ScrW | |
local ScrH = ScrH | |
local min = math.min | |
local GlassCvar = CreateClientConVar( "subl_glass", 1, true, false ) | |
local color_white = color_white | |
local matBlurScreen = Material( "pp/blurscreen" ) | |
local defaultBlur = 5 | |
local function BackgroundBlur( x, y, w, h, blurAmnt ) | |
if not blurAmnt then | |
blurAmnt = defaultBlur | |
end | |
SetMaterial( matBlurScreen ) | |
SetDrawColor( color_white ) | |
for i = 0.33, 1, 0.33 do | |
matBlurScreen:SetFloat( "$blur", blurAmnt * i ) | |
matBlurScreen:Recompute() | |
UpdateScreenEffectTexture() | |
DrawTexturedRect( x, y, w, h ) | |
end | |
end | |
local GlassBlur = 8 | |
local TransitionDuration = 0.314 | |
local LastFocus = 0 | |
local CurBlur = 0 | |
local function GlassEffect() | |
if not GlassCvar:GetBool() then return end | |
if HasFocus() then | |
LastFocus = RealTime() | |
else | |
local progress = min(1, (RealTime() - LastFocus) / TransitionDuration) | |
local fade = EaseInOut(progress, 0.8, 0.1) | |
BackgroundBlur(0, 0, ScrW(), ScrH(), fade * GlassBlur) | |
end | |
end | |
hook.Add( "PostRenderVGUI", "Sublime Text Glass Effect", GlassEffect ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment