mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 05:43:46 +03:00
Upload
This commit is contained in:
445
gamemodes/ixhl2rp/plugins/gratua_visuals/modules/cl_adof.lua
Normal file
445
gamemodes/ixhl2rp/plugins/gratua_visuals/modules/cl_adof.lua
Normal file
@@ -0,0 +1,445 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
--[[
|
||||
Copyright (C) 2016 DBot
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
]]
|
||||
|
||||
--ADOF - Advanced Depth of Field
|
||||
|
||||
local DRAW_ON_SCREEN = CreateClientConVar('adof_screen', '1', true, false, 'Draw ADOF on Screen')
|
||||
local ADOF_PASSES = CreateClientConVar('adof_passes', '16', true, false, 'ADOF Passes')
|
||||
local ALWAYS_DOF = CreateClientConVar('adof_always', '1', true, false, 'Always draw DoF')
|
||||
local DRAW_MODE = CreateClientConVar('adof_mode', '0', true, false, 'Draw Mode - 0 as Renderable, 1 as effect')
|
||||
local ENABLE_BOKEN = CreateClientConVar('adof_boken', '0', true, false, 'Enable Boken DOF. Breaks things!')
|
||||
|
||||
ADOF = ADOF or {}
|
||||
ADOF.Ents = ADOF.Ents or {}
|
||||
|
||||
ADOF.SPACING = 50
|
||||
ADOF.OFFSET = 1000
|
||||
ADOF.REAL_NUM_DOF_NODES = 16
|
||||
ADOF.NUM_DOF_NODES = 16
|
||||
ADOF.Render = true
|
||||
ADOF.Max = 6000
|
||||
ADOF.Critical = ADOF.Max * 0.5
|
||||
|
||||
local function IsCurrVehicle(ent)
|
||||
local ply = LocalPlayer()
|
||||
|
||||
return IsValid(ent) and
|
||||
ent:IsVehicle() and
|
||||
ply:InVehicle() and
|
||||
IsValid(ply:GetVehicle()) and
|
||||
(ply:GetVehicle() == ent or
|
||||
ply:GetVehicle():GetParent() == ent)
|
||||
end
|
||||
|
||||
local blur_mat = Material('pp/bokehblur')
|
||||
local fmat = CreateMaterial('ADOF_Material', 'Refract', {
|
||||
['$model'] = '1',
|
||||
["$normalmap"] = "effects/flat_normal",
|
||||
["$refractamount"] = "0",
|
||||
["$vertexalpha"] = "1",
|
||||
["$vertexcolor"] = "1",
|
||||
["$translucent"] = "1",
|
||||
["$forcerefract"] = '1',
|
||||
["$bluramount"] = "1",
|
||||
["$nofog"] = "1",
|
||||
})
|
||||
|
||||
local TotalRenderTime = 0
|
||||
local NextCleanup = 0
|
||||
local Hits = 0
|
||||
local LastHit = 0
|
||||
|
||||
local SPACE, SPACING = 0, 0
|
||||
local ShouldDrawOnScreen = false
|
||||
|
||||
local Rendering = false
|
||||
|
||||
local function DrawOnScreen()
|
||||
if not ADOF.Render then return end
|
||||
if not DRAW_ON_SCREEN:GetBool() then return end
|
||||
if not ShouldDrawOnScreen then return end
|
||||
if not system.HasFocus() then return end
|
||||
surface.SetDrawColor(255, 255, 255, 255)
|
||||
surface.SetMaterial(fmat)
|
||||
|
||||
local W, H = ScrW(), ScrH()
|
||||
|
||||
local toupdate = LocalPlayer():WaterLevel() < 1
|
||||
for i=0, ADOF.NUM_DOF_NODES do
|
||||
if toupdate then
|
||||
render.UpdateScreenEffectTexture()
|
||||
else
|
||||
render.UpdateRefractTexture()
|
||||
end
|
||||
surface.DrawTexturedRect(0, H / 2 + SPACE + i * SPACING, W, H)
|
||||
surface.DrawTexturedRect(0, 0, W, H / 2 - SPACE - i * SPACING)
|
||||
end
|
||||
end
|
||||
|
||||
local function HUDPaintBackground()
|
||||
DrawOnScreen()
|
||||
Rendering = true
|
||||
end
|
||||
|
||||
local function PostDrawHUD()
|
||||
if Rendering then Rendering = false return end
|
||||
DrawOnScreen()
|
||||
end
|
||||
|
||||
-- Note: UpdateScreenEffectTexture fucks up the water, RefractTexture is lower quality
|
||||
local function Render()
|
||||
if not ADOF.Render then return end
|
||||
if bDrawingDepth or bDrawingSkybox then return end
|
||||
if not system.HasFocus() then return end
|
||||
|
||||
if not ALWAYS_DOF:GetBool() and ADOF.OFFSET == ADOF.Max then return end
|
||||
local ply = LocalPlayer()
|
||||
|
||||
local pos = ply:EyePos()
|
||||
local langles = EyeAngles()
|
||||
local fwd = langles:Forward()
|
||||
|
||||
if ply:GetViewEntity() ~= ply then
|
||||
pos = ply:GetViewEntity():GetPos()
|
||||
fwd = ply:GetViewEntity():GetForward()
|
||||
end
|
||||
|
||||
local toupdate = ply:WaterLevel() < 1
|
||||
|
||||
local CurrentAlpha = 0.1
|
||||
|
||||
render.SetMaterial(fmat)
|
||||
|
||||
for i=0, ADOF.NUM_DOF_NODES do
|
||||
if toupdate then
|
||||
render.UpdateScreenEffectTexture()
|
||||
else
|
||||
render.UpdateRefractTexture()
|
||||
end
|
||||
|
||||
local npos = pos + fwd * ADOF.SPACING * i + fwd * ADOF.OFFSET
|
||||
local SpriteSize = (ADOF.SPACING * i + ADOF.OFFSET) * 8
|
||||
|
||||
if pos:Distance(npos) > ADOF.Max * 2 then break end
|
||||
|
||||
CurrentAlpha = CurrentAlpha + 0.1
|
||||
|
||||
render.DrawSprite(npos, SpriteSize, SpriteSize, Color( 255, 255, 255, CurrentAlpha * 255 ) )
|
||||
end
|
||||
end
|
||||
|
||||
local SHOULD_DRAW_BOKEN = false
|
||||
local BOKEN_FOCUS = 0.1
|
||||
local BOKEN_FOCUS_D = 0.1
|
||||
local BOKEN_FORCE = 1
|
||||
local BOKEN_STEP = 0.03
|
||||
|
||||
local function RenderScreenspaceEffects()
|
||||
if not ADOF.Render then return end
|
||||
if not SHOULD_DRAW_BOKEN then return end
|
||||
if not ENABLE_BOKEN:GetBool() then return end
|
||||
if not system.HasFocus() then return end
|
||||
|
||||
local ply = LocalPlayer()
|
||||
if ply:WaterLevel() > 0 then return end
|
||||
|
||||
render.UpdateScreenEffectTexture()
|
||||
|
||||
blur_mat:SetTexture("$BASETEXTURE", render.GetScreenEffectTexture())
|
||||
blur_mat:SetTexture("$DEPTHTEXTURE", render.GetResolvedFullFrameDepth())
|
||||
|
||||
blur_mat:SetFloat("$size", BOKEN_FOCUS * 3)
|
||||
blur_mat:SetFloat("$focus", BOKEN_FOCUS)
|
||||
blur_mat:SetFloat("$focusradius", 2 - BOKEN_FORCE * 2)
|
||||
|
||||
render.SetMaterial(blur_mat)
|
||||
render.DrawScreenQuad()
|
||||
end
|
||||
|
||||
local function NeedsDepthPass()
|
||||
if not ADOF.Render then return end
|
||||
if not SHOULD_DRAW_BOKEN then return end
|
||||
if not ENABLE_BOKEN:GetBool() then return end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
hook.Add('PostDrawTranslucentRenderables', 'ADOF.Draw', function(a, b)
|
||||
if a or b then return end
|
||||
if not DRAW_MODE:GetBool() then Render() end
|
||||
end, 2) --Lower priority
|
||||
|
||||
hook.Add('PreDrawEffects', 'ADOF.Draw', function()
|
||||
if DRAW_MODE:GetBool() then Render() end
|
||||
end, 2) --Lower priority
|
||||
|
||||
hook.Add('RenderScreenspaceEffects', 'ADOF.Draw', RenderScreenspaceEffects)
|
||||
hook.Add('HUDPaintBackground', 'ADOF.Draw', HUDPaintBackground)
|
||||
hook.Add('PostDrawHUD', 'ADOF.Draw', PostDrawHUD)
|
||||
hook.Add('NeedsDepthPass', 'ADOF.Draw', NeedsDepthPass)
|
||||
|
||||
local last = 0
|
||||
local lastdist = 0
|
||||
local LastHitWasEntity = false
|
||||
local EntityHitCooldown = 0
|
||||
local FocusCooldown = 0
|
||||
local Focused = false
|
||||
local mult = 5
|
||||
local BokenCooldown = 0
|
||||
|
||||
local function Change(old, new)
|
||||
local delta = new - old
|
||||
if delta >= 0 then
|
||||
return math.Clamp(old + delta^(1/2), old, new)
|
||||
else
|
||||
return math.Clamp(old - (-delta)^(1/2), new, old)
|
||||
end
|
||||
end
|
||||
|
||||
local function ShouldEnabledScreen()
|
||||
if pace and pace.IsActive and pace.IsActive() then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
local function pointInsideBox(point, mins, maxs)
|
||||
return
|
||||
mins.x < point.x and point.x < maxs.x and
|
||||
mins.y < point.y and point.y < maxs.y and
|
||||
mins.z < point.z and point.z < maxs.z
|
||||
end
|
||||
|
||||
local function Think()
|
||||
if not ix.option.Get("enableADOF", false) then
|
||||
ADOF.Render = false
|
||||
return
|
||||
else
|
||||
ADOF.Render = true
|
||||
end
|
||||
|
||||
if not system.HasFocus() then return end
|
||||
|
||||
local ply = LocalPlayer()
|
||||
local obs = ply:GetObserverTarget()
|
||||
local observer = false
|
||||
|
||||
if IsValid(obs) and obs:IsPlayer() then
|
||||
ply = obs
|
||||
observer = true
|
||||
end
|
||||
|
||||
local trace = {}
|
||||
|
||||
local eye, langles, ignoreEnts
|
||||
|
||||
if observer then
|
||||
eye = ply:EyePos()
|
||||
langles = ply:EyeAngles()
|
||||
else
|
||||
if not ply:ShouldDrawLocalPlayer() then
|
||||
eye = ply:EyePos()
|
||||
langles = ply:EyeAngles()
|
||||
|
||||
if ply:InVehicle() then
|
||||
langles = ply:GetVehicle():GetAngles() + langles
|
||||
end
|
||||
else
|
||||
eye = EyePos()
|
||||
langles = EyeAngles()
|
||||
ignoreEnts = true
|
||||
end
|
||||
end
|
||||
|
||||
local FILTER = {}
|
||||
|
||||
trace.start = eye
|
||||
trace.endpos = langles:Forward() * 300 + eye
|
||||
trace.filter = function(ent)
|
||||
if ent == ply then return false end
|
||||
if ent:GetClass() == 'func_breakable_surf' then return false end
|
||||
if FILTER[ent] then return false end
|
||||
|
||||
if ignoreEnts and (pointInsideBox(eye, ent:WorldSpaceAABB()) or eye:DistToSqr(ent:GetPos()) < 400) then return false end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
if ply:InVehicle() then
|
||||
if IsValid(ply:GetVehicle()) then
|
||||
FILTER[ply:GetVehicle()] = true
|
||||
|
||||
if IsValid(ply:GetVehicle():GetParent()) then
|
||||
FILTER[ply:GetVehicle():GetParent()] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, ent in pairs(ents.FindInSphere(eye, 32)) do --Finding ents what are parented to player (player seats on player, etc.)
|
||||
if ent:GetParent() == ply then
|
||||
FILTER[ent] = true
|
||||
end
|
||||
|
||||
if ent:IsPlayer() and ent ~= ply and ent:InVehicle() and IsValid(ent:GetVehicle()) and ent:GetVehicle():GetParent() == ply then
|
||||
FILTER[ent] = true
|
||||
end
|
||||
end
|
||||
|
||||
local tr = util.TraceLine(trace)
|
||||
|
||||
local dist = tr.HitPos:Distance(ply:GetPos())
|
||||
|
||||
if IsValid(tr.Entity) then
|
||||
if tr.Entity:IsPlayer() and langles.p > 20 and tr.Entity:GetPos().z - LocalPlayer():GetPos().z < -30 then --We are looking at player when standing on him
|
||||
dist = dist*4
|
||||
elseif langles.p > 25 then --Small thing
|
||||
dist = dist*2
|
||||
end
|
||||
|
||||
if tr.Entity:IsPlayer() then dist = math.max(dist, 50) end
|
||||
end
|
||||
|
||||
if ((IsValid(tr.Entity) and dist < 300) or dist < 200) and FocusCooldown < CurTime() then
|
||||
if not Focused then
|
||||
FocusCooldown = CurTime() + 0.3
|
||||
Focused = true
|
||||
end
|
||||
local offset = 40
|
||||
|
||||
last = CurTime() + 0.4
|
||||
|
||||
if not IsValid(tr.Entity) then
|
||||
offset = 20
|
||||
|
||||
if ShouldDrawOnScreen then
|
||||
SPACING = SPACING * 1.05
|
||||
SPACE = SPACE * 1.05
|
||||
|
||||
if SPACE > 2000 then
|
||||
ShouldDrawOnScreen = false
|
||||
end
|
||||
end
|
||||
else
|
||||
LastHitWasEntity = true
|
||||
EntityHitCooldown = CurTime() + 1
|
||||
|
||||
local dist = dist / 2
|
||||
if tr.Entity:IsPlayer() and dist < 60 and ShouldEnabledScreen() then
|
||||
if tr.Entity:InVehicle() then dist = dist * .75 end
|
||||
SPACE = Change(SPACE, math.max(dist * 6, 100))
|
||||
SPACING = Change(SPACING, dist / 3)
|
||||
ShouldDrawOnScreen = true
|
||||
else
|
||||
if ShouldDrawOnScreen then
|
||||
SPACING = SPACING * 1.05
|
||||
SPACE = SPACE * 1.05
|
||||
|
||||
if SPACE > 2000 then
|
||||
ShouldDrawOnScreen = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not (ADOF.OFFSET - ADOF.OFFSET * FrameTime()*mult < dist + dist - offset and ADOF.OFFSET + ADOF.OFFSET * FrameTime() * mult > dist + dist - offset) then
|
||||
if ADOF.OFFSET - ADOF.OFFSET * FrameTime() * mult < dist + dist - offset then
|
||||
ADOF.OFFSET = math.max(ADOF.OFFSET + ADOF.OFFSET * FrameTime() * mult, dist + dist - offset)
|
||||
else
|
||||
ADOF.OFFSET = math.max(ADOF.OFFSET - ADOF.OFFSET * FrameTime() * mult, dist + dist - offset)
|
||||
end
|
||||
end
|
||||
|
||||
if ENABLE_BOKEN:GetBool() then
|
||||
if dist < 150 and (not IsValid(tr.Entity) or not (tr.Entity:IsPlayer() or tr.Entity:GetClass() == 'prop_door_rotating')) then --We are looking at the thing, not player
|
||||
SHOULD_DRAW_BOKEN = true
|
||||
BOKEN_FOCUS = math.Clamp(0.6 - dist / 150, 0,1)
|
||||
BokenCooldown = CurTime() + 2
|
||||
BOKEN_FORCE = math.Clamp(BOKEN_FORCE + BOKEN_STEP * (FrameTime() * 66), 0,1)
|
||||
elseif dist < 150 and IsValid(tr.Entity) then
|
||||
SHOULD_DRAW_BOKEN = true
|
||||
BOKEN_FOCUS = math.Clamp(0.5 - dist / 90, 0,1)
|
||||
BokenCooldown = CurTime() + 2
|
||||
BOKEN_FORCE = math.Clamp(BOKEN_FORCE + BOKEN_STEP * (FrameTime() * 66), 0,1)
|
||||
else --We are too far or not looking at anything
|
||||
if BokenCooldown < CurTime() then
|
||||
SHOULD_DRAW_BOKEN = false
|
||||
BOKEN_FOCUS = 0.1
|
||||
else
|
||||
BOKEN_FORCE = math.Clamp(BOKEN_FORCE - BOKEN_STEP * (FrameTime() * 66), 0,1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not IsValid(tr.Entity) and LastHitWasEntity and EntityHitCooldown < CurTime() then
|
||||
lastdist = dist
|
||||
LastHitWasEntity = false
|
||||
elseif not IsValid(tr.Entity) and not LastHitWasEntity then
|
||||
lastdist = dist
|
||||
elseif IsValid(tr.Entity) then
|
||||
lastdist = dist
|
||||
end
|
||||
|
||||
ADOF.SPACING = Change(ADOF.SPACING, ((lastdist - 40)^2)/6)
|
||||
elseif last < CurTime() then
|
||||
ADOF.OFFSET = math.min(ADOF.OFFSET + 80 * (FrameTime() * 66), ADOF.Max)
|
||||
ADOF.SPACING = math.min(ADOF.SPACING + 80 * (FrameTime() * 66), 400)
|
||||
LastHitWasEntity = false
|
||||
|
||||
if ENABLE_BOKEN:GetBool() then
|
||||
if ADOF.OFFSET > 200 and BokenCooldown < CurTime() then
|
||||
SHOULD_DRAW_BOKEN = false
|
||||
BOKEN_FOCUS = 0.1
|
||||
BOKEN_FORCE = math.Clamp(BOKEN_FORCE - BOKEN_STEP * (FrameTime() * 66), 0,1)
|
||||
elseif BokenCooldown > CurTime() and ADOF.OFFSET > 200 then
|
||||
BOKEN_FORCE = math.Clamp(BOKEN_FORCE - BOKEN_STEP * (FrameTime() * 66), 0,1)
|
||||
end
|
||||
end
|
||||
|
||||
if ShouldDrawOnScreen then
|
||||
SPACING = SPACING * 1.2
|
||||
SPACE = SPACE * 1.2
|
||||
|
||||
if SPACE > 2000 then
|
||||
ShouldDrawOnScreen = false
|
||||
end
|
||||
end
|
||||
|
||||
if Focused then
|
||||
FocusCooldown = 0
|
||||
Focused = false
|
||||
end
|
||||
end
|
||||
|
||||
if ADOF.OFFSET > ADOF.Critical then
|
||||
local delta = (ADOF.OFFSET - ADOF.Critical) / (ADOF.Max - ADOF.Critical)
|
||||
local MAX = ADOF_PASSES:GetInt()
|
||||
local count = math.ceil(delta * MAX / 1.2)
|
||||
ADOF.NUM_DOF_NODES = MAX - count
|
||||
else
|
||||
ADOF.NUM_DOF_NODES = ADOF_PASSES:GetInt()
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add("Think", "ADOF", Think)
|
||||
@@ -0,0 +1,72 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local addonName = "Simple Chromatic Aberration Filter"
|
||||
|
||||
-- https://wiki.facepunch.com/gmod/Global.CreateClientConVar
|
||||
local pp_scaf_intensity = CreateClientConVar( "pp_scaf_intensity", "3", true, false, "How intense the chromatic aberration will be.", 0, 100 )
|
||||
|
||||
-- https://i.imgur.com/8B3KakB.png
|
||||
local pp_scaf_redx = CreateClientConVar( "pp_scaf_redx", "8", true, false, "Mixing of chromatic aberrations in the red channel along the X-axis.", 0, 128 )
|
||||
local pp_scaf_redy = CreateClientConVar( "pp_scaf_redy", "4", true, false, "Mixing of chromatic aberrations in the red channel along the Y-axis.", 0, 128 )
|
||||
|
||||
local pp_scaf_greenx = CreateClientConVar( "pp_scaf_greenx", "4", true, false, "Mixing of chromatic aberrations in the green channel along the X-axis.", 0, 128 )
|
||||
local pp_scaf_greeny = CreateClientConVar( "pp_scaf_greeny", "2", true, false, "Mixing of chromatic aberrations in the green channel along the Y-axis.", 0, 128 )
|
||||
|
||||
local pp_scaf_bluex = CreateClientConVar( "pp_scaf_bluex", "0", true, false, "Mixing of chromatic aberrations in the blue channel along the X-axis.", 0, 128 )
|
||||
local pp_scaf_bluey = CreateClientConVar( "pp_scaf_bluey", "0", true, false, "Mixing of chromatic aberrations in the blue channel along the Y-axis.", 0, 128 )
|
||||
|
||||
local redX, greenX, blueX = 0, 0, 0
|
||||
local redY, greenY, blueY = 0, 0, 0
|
||||
local floor = math.floor
|
||||
local intensity = 0
|
||||
|
||||
hook.Add( "Think", addonName, function()
|
||||
intensity = pp_scaf_intensity:GetFloat()
|
||||
redX, greenX, blueX = floor( pp_scaf_redx:GetInt() * intensity ), floor( pp_scaf_greenx:GetInt() * intensity ), floor( pp_scaf_bluex:GetInt() * intensity )
|
||||
redY, greenY, blueY = floor( pp_scaf_redy:GetInt() * intensity ), floor( pp_scaf_greeny:GetInt() * intensity ), floor( pp_scaf_bluey:GetInt() * intensity )
|
||||
end )
|
||||
|
||||
-- https://wiki.facepunch.com/gmod/GM:OnScreenSizeChanged
|
||||
local width, height = ScrW(), ScrH()
|
||||
hook.Add( "OnScreenSizeChanged", addonName, function()
|
||||
width, height = ScrW(), ScrH()
|
||||
end )
|
||||
|
||||
-- https://gitspartv.github.io/LuaJIT-Benchmarks/#test1
|
||||
local SetMaterial, DrawScreenQuad, DrawScreenQuadEx, UpdateScreenEffectTexture = render.SetMaterial, render.DrawScreenQuad, render.DrawScreenQuadEx, render.UpdateScreenEffectTexture
|
||||
local screenEffectTexture, black = render.GetScreenEffectTexture( 0 ), Material( "vgui/black" )
|
||||
|
||||
local red = Material( "color/red" )
|
||||
red:SetTexture( "$basetexture", screenEffectTexture )
|
||||
|
||||
local green = Material( "color/green" )
|
||||
green:SetTexture( "$basetexture", screenEffectTexture )
|
||||
|
||||
local blue = Material( "color/blue" )
|
||||
blue:SetTexture( "$basetexture", screenEffectTexture )
|
||||
|
||||
hook.Add( "RenderScreenspaceEffects", addonName, function()
|
||||
if not ix.option.Get("enableChromaticAberration", false) then return end
|
||||
|
||||
UpdateScreenEffectTexture()
|
||||
|
||||
SetMaterial( black )
|
||||
DrawScreenQuad()
|
||||
|
||||
SetMaterial( red )
|
||||
DrawScreenQuadEx( -redX / 2, -redY / 2, width + redX, height + redY )
|
||||
|
||||
SetMaterial( green )
|
||||
DrawScreenQuadEx( -greenX / 2, -greenY / 2, width + greenX, height + greenY )
|
||||
|
||||
SetMaterial( blue )
|
||||
DrawScreenQuadEx( -blueX / 2, -blueY / 2, width + blueX, height + blueY )
|
||||
end )
|
||||
@@ -0,0 +1,81 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local dl_blurrange = CreateClientConVar("pp_dlens_blurrange", "10", true, false)
|
||||
local dl_blurpasses = CreateClientConVar("pp_dlens_blurpasses", "30", true, false)
|
||||
local dl_multiply = CreateClientConVar("pp_dlens_multiply", "1", true, false)
|
||||
local dl_darken = CreateClientConVar("pp_dlens_darken", "0.30", true, false)
|
||||
local dl_texture = CreateClientConVar("pp_dlens_texture", "dlenstexture/dlensdefault", true, false)
|
||||
local dl_sunenable = CreateClientConVar("pp_dlens_sun", "1", true, false)
|
||||
local dl_sunmultiply = CreateClientConVar("pp_dlens_sunmultiply", "2", true, false)
|
||||
local dl_suninterpolation = CreateClientConVar("pp_dlens_suninterpolation", "6", true, false)
|
||||
|
||||
local mat_Downsample = Material("pp/downsample")
|
||||
local mat_Bloom = Material("dlenstexture/dlensmat")
|
||||
local OldRT = render.GetRenderTarget()
|
||||
local tex_Bloom0 = render.GetBloomTex0()
|
||||
local w, h = ScrW(), ScrH()
|
||||
local targetMultiply = 1
|
||||
local multiply = 1
|
||||
|
||||
hook.Add("RenderScreenspaceEffects", "DrawDirtLens", function()
|
||||
if not ix.option.Get("enableDirtyLens", false) then return end
|
||||
|
||||
if not render.SupportsPixelShaders_2_0() then return end
|
||||
|
||||
local blur = dl_blurrange:GetFloat()
|
||||
local passes = dl_blurpasses:GetFloat()
|
||||
local darken = dl_darken:GetFloat()
|
||||
local lens_texture = dl_texture:GetString()
|
||||
local SunMultiply = dl_sunmultiply:GetFloat()
|
||||
local SunInterpolation = dl_suninterpolation:GetInt()
|
||||
|
||||
if dl_sunenable:GetBool() then
|
||||
local sun = util.GetSunInfo()
|
||||
if sun then
|
||||
if ( sun.obstruction ~= 0 ) then
|
||||
targetMultiply = dl_multiply:GetFloat() + SunMultiply
|
||||
else
|
||||
targetMultiply = dl_multiply:GetFloat()
|
||||
end
|
||||
else
|
||||
targetMultiply = dl_multiply:GetFloat()
|
||||
end
|
||||
multiply = Lerp(FrameTime() * SunInterpolation, multiply, targetMultiply)
|
||||
else
|
||||
multiply = dl_multiply:GetFloat()
|
||||
end
|
||||
|
||||
mat_Downsample:SetFloat("$multiply", multiply)
|
||||
mat_Downsample:SetFloat("$darken", darken)
|
||||
mat_Downsample:SetTexture("$fbtexture", render.GetScreenEffectTexture())
|
||||
|
||||
render.SetViewPort(0, 0, w, h)
|
||||
render.SetRenderTarget(tex_Bloom0)
|
||||
render.SetBlend(1)
|
||||
render.SetMaterial(mat_Downsample)
|
||||
render.DrawScreenQuad()
|
||||
render.BlurRenderTarget(tex_Bloom0, blur, blur, passes)
|
||||
render.ClearDepth()
|
||||
render.SetRenderTarget(OldRT)
|
||||
|
||||
mat_Bloom:SetFloat("$levelr", 1)
|
||||
mat_Bloom:SetFloat("$levelg", 1)
|
||||
mat_Bloom:SetFloat("$levelb", 1)
|
||||
mat_Bloom:SetFloat("$colormul", 16)
|
||||
|
||||
mat_Bloom:SetTexture("$basetexture", lens_texture)
|
||||
mat_Bloom:SetTexture("$dudvmap", lens_texture)
|
||||
mat_Bloom:SetTexture("$normalmap", lens_texture)
|
||||
mat_Bloom:SetTexture("$refracttinttexture", tex_Bloom0)
|
||||
|
||||
render.SetMaterial(mat_Bloom)
|
||||
render.DrawScreenQuad()
|
||||
end)
|
||||
@@ -0,0 +1,31 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local fg_alpha = CreateClientConVar("pp_filmgrain_alpha", "4", true, false)
|
||||
local fg_addalpha = CreateClientConVar("pp_filmgrain_addalpha", "3", true, false)
|
||||
|
||||
local NoiseTexture = Material("filmgrain/noise")
|
||||
local NoiseTexture2 = Material("filmgrain/noiseadd")
|
||||
--[[local NoiseTexture = Material(fg_texture:GetString())
|
||||
cvars.AddChangeCallback("pp_filmgrain_texture", function (_, __, ___)
|
||||
NoiseTexture:SetTexture("$basetexture", fg_texture:GetString())
|
||||
end)]]
|
||||
|
||||
hook.Add("RenderScreenspaceEffects", "FilmGrain", function()
|
||||
if not ix.option.Get("enableFilmGrain", false) then return end
|
||||
|
||||
surface.SetMaterial(NoiseTexture)
|
||||
surface.SetDrawColor(255, 255, 255, fg_alpha:GetInt())
|
||||
surface.DrawTexturedRect(0, 0, ScrW(), ScrH())
|
||||
|
||||
surface.SetMaterial(NoiseTexture2)
|
||||
surface.SetDrawColor(255, 255, 255, fg_addalpha:GetInt()*10)
|
||||
surface.DrawTexturedRect(0, 0, ScrW(), ScrH())
|
||||
end)
|
||||
@@ -0,0 +1,124 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
-- Lens Flare Post-Processing Effect
|
||||
-- Version 2.0
|
||||
-- By Mahalis (revised by Rush_Freak)<mahalis@gmail.com>
|
||||
--
|
||||
-- Feel free to learn from and reuse this code; if you release something that uses it,
|
||||
-- please credit me as the original author.
|
||||
|
||||
-- Mew appreciates this. Thank you - shortnamesalex
|
||||
|
||||
local pp_lensflare_intensity = 1
|
||||
|
||||
local iris = surface.GetTextureID("effects/lensflare/iris")
|
||||
local iris2 = surface.GetTextureID("effects/lensflare/iris2")
|
||||
local iris3 = surface.GetTextureID("effects/lensflare/iris3")
|
||||
local flare = surface.GetTextureID("effects/lensflare/flare")
|
||||
local flare2 = surface.GetTextureID("effects/lensflare/flare2")
|
||||
local color_ring = surface.GetTextureID("effects/lensflare/color_ring")
|
||||
|
||||
local function mulW(x,f)
|
||||
return (x - ScrW()/2) * f + ScrW()/2
|
||||
end
|
||||
|
||||
local function mulH(y,f)
|
||||
return (y - ScrH()/2) * f + ScrH()/2
|
||||
end
|
||||
|
||||
local function CenteredSprite(x,y,sz)
|
||||
surface.DrawTexturedRect(x - sz/2,y - sz/2,sz,sz)
|
||||
end
|
||||
|
||||
local function DrawFlare()
|
||||
if !ix.option.Get("enableLensFlare", false) then return end
|
||||
|
||||
local sun = util.GetSunInfo()
|
||||
|
||||
if !sun or sun.obstruction == 0 then return end
|
||||
|
||||
local sunpos = (EyePos() + sun.direction * 4096):ToScreen()
|
||||
|
||||
local dot = (sun.direction:Dot(EyeVector()) - 0.8) * 5
|
||||
|
||||
local rSz = ScrW() * 0.15
|
||||
|
||||
local aMul = math.Clamp((sun.direction:Dot(EyeVector()) - 0.4) * (1 - math.pow(1 - sun.obstruction,2)),0,1) * pp_lensflare_intensity
|
||||
|
||||
if aMul == 0 then return end
|
||||
|
||||
surface.SetTexture(flare)
|
||||
surface.SetDrawColor(255,255,255,255 * aMul)
|
||||
CenteredSprite(sunpos.x,sunpos.y,rSz*9)
|
||||
|
||||
///
|
||||
|
||||
surface.SetTexture(flare2)
|
||||
surface.SetDrawColor(255,255,255,255 * aMul)
|
||||
CenteredSprite(sunpos.x,sunpos.y,rSz*9)
|
||||
|
||||
///
|
||||
|
||||
surface.SetTexture(color_ring)
|
||||
surface.SetDrawColor(255,255,255,255 * aMul)
|
||||
CenteredSprite(sunpos.x,sunpos.y,rSz*14)
|
||||
|
||||
///
|
||||
|
||||
surface.SetTexture(iris)
|
||||
surface.SetDrawColor(255,255,255,555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,1.8),mulH(sunpos.y,1.0),rSz*0.55)
|
||||
|
||||
surface.SetDrawColor(255,255,255,555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,-0.2),mulH(sunpos.y,1.2),rSz*0.55)
|
||||
|
||||
surface.SetDrawColor(255,255,255,555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,1.2),mulH(sunpos.y,1.0),rSz*1.55)
|
||||
|
||||
///
|
||||
|
||||
surface.SetTexture(iris2)
|
||||
surface.SetDrawColor(255,255,255,1555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,2.4),mulH(sunpos.y,1.2),rSz*0.95)
|
||||
|
||||
surface.SetDrawColor(255,255,255,1555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,-1.2),mulH(sunpos.y,0.8),rSz*0.55)
|
||||
|
||||
surface.SetDrawColor(255,255,255,1555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,1.0),mulH(sunpos.y,1.0),rSz*1.55)
|
||||
|
||||
surface.SetDrawColor(255,255,255,1555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,-2.3),mulH(sunpos.y,1.0),rSz*1.5)
|
||||
|
||||
surface.SetDrawColor(255,255,255,1555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,-3.2),mulH(sunpos.y,1.0),rSz*1.5)
|
||||
|
||||
surface.SetDrawColor(255,255,255,1555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,2.3),mulH(sunpos.y,1.0),rSz*1.5)
|
||||
|
||||
surface.SetDrawColor(255,255,255,1555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,2.3),mulH(sunpos.y,1.3),rSz*0.55)
|
||||
|
||||
surface.SetDrawColor(255,255,255,1555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,1.0),mulH(sunpos.y,1.0),rSz*0.65)
|
||||
|
||||
surface.SetDrawColor(255,255,255,1555 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,3.4),mulH(sunpos.y,1.0),rSz*0.25)
|
||||
|
||||
///
|
||||
|
||||
surface.SetTexture(iris3)
|
||||
surface.SetDrawColor(255,255,255,255 * math.pow(aMul,3))
|
||||
CenteredSprite(mulW(sunpos.x,-1.5),mulH(sunpos.y,-1.5),rSz*1.9)
|
||||
|
||||
end
|
||||
|
||||
hook.Add("RenderScreenspaceEffects","LensFlare",DrawFlare)
|
||||
Reference in New Issue
Block a user