Last active
June 5, 2020 04:46
-
-
Save meepen/32cc08ca37d796d0ed82 to your computer and use it in GitHub Desktop.
Outliner
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
function render.CreateOutlineData(length, passes, color) | |
local step = length * 2 / 2 ^ (math.Round(passes) - 1) | |
local matrices = {} | |
for coord = -length, length, step do | |
matrices[#matrices + 1] = Matrix() | |
matrices[#matrices]:Translate(Vector(0, 0, coord)) | |
matrices[#matrices + 1] = Matrix() | |
matrices[#matrices]:Translate(Vector(0, coord, 0)) | |
matrices[#matrices + 1] = Matrix() | |
matrices[#matrices]:Translate(Vector(coord, 0, 0)) | |
end | |
return { | |
matrices = matrices, | |
color = color or Color(255,255,255,255) | |
} | |
end | |
function render.RenderOutline(prop, outlinedata) | |
local matrices = outlinedata.matrices | |
local color = outlinedata.color | |
render.SetStencilEnable(true) | |
render.ClearStencil() | |
render.SetStencilTestMask(3) | |
render.SetStencilWriteMask(3) | |
render.SetStencilCompareFunction(STENCIL_ALWAYS) | |
render.SetStencilFailOperation(STENCIL_KEEP) | |
render.SetStencilPassOperation(STENCIL_INCR) | |
render.SetStencilZFailOperation(STENCIL_KEEP) | |
prop:DrawModel() | |
render.SetStencilReferenceValue(0) | |
render.SetStencilCompareFunction(STENCIL_EQUAL) | |
render.SetStencilPassOperation(STENCIL_INVERT) | |
render.SetLightingMode(2) | |
render.PushFilterMin(TEXFILTER.NONE) | |
render.PushFilterMag(TEXFILTER.NONE) | |
render.SuppressEngineLighting(true) | |
for i = 1, #matrices do | |
prop:EnableMatrix("RenderMultiply", matrices[i]) | |
prop:DrawModel() | |
end | |
prop:DisableMatrix("RenderMultiply") | |
render.SuppressEngineLighting(false) | |
render.PopFilterMag() | |
render.PopFilterMin() | |
render.SetLightingMode(0) | |
render.SetStencilReferenceValue(3) | |
render.SetStencilCompareFunction(STENCIL_EQUAL) | |
render.SetStencilPassOperation(STENCIL_KEEP) | |
cam.Start2D() | |
surface.SetDrawColor(color) | |
surface.DrawRect(0, 0, ScrW(), ScrH()) | |
cam.End2D() | |
render.SetStencilEnable(false) | |
end | |
local data = render.CreateOutlineData(0.2, 1, Color(255,0,0,255)) | |
hook.Add("PreDrawOpaqueRenderables", "Blur", function() | |
local prop = LocalPlayer():GetEyeTrace().Entity | |
if (not IsValid(prop)) then | |
return | |
end | |
cam.Start3D() | |
--[[ | |
local t = SysTime | |
local d = t()]] | |
render.RenderOutline(prop, data) | |
--[[ | |
print(t()-d) | |
d = t() | |
halo.Render{ | |
Ents = {prop}, | |
Color = Color(255,0,0,255), | |
BlurX = 2, | |
BlurY = 2, | |
DrawPasses = 1, | |
Additive = false, | |
IgnoreZ = false | |
} | |
print("halo",t()-d) | |
]] | |
cam.End3D() | |
end) |
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
local rt = render.GetScreenEffectTexture(0) | |
local rt2= render.GetScreenEffectTexture(1) | |
local renderer = Material "pp/sub" | |
function render.Outline(prop, color, amount) | |
local dist = prop:GetPos():Distance(me:GetPos()) | |
local old = render.GetRenderTarget() | |
render.SetRenderTarget(rt) | |
render.Clear(255,255,255,255, true, true) | |
render.SetStencilEnable(true) | |
render.SetStencilReferenceValue(0) | |
render.SetStencilCompareFunction(STENCIL_ALWAYS) | |
render.SetStencilPassOperation(STENCIL_INCR) | |
render.SetStencilFailOperation(STENCIL_KEEP) | |
render.SetStencilZFailOperation(STENCIL_KEEP) | |
render.SetStencilWriteMask(1) | |
render.SetStencilTestMask(1) | |
cam.Start3D() | |
prop:DrawModel() | |
cam.End3D() | |
render.SetStencilCompareFunction(STENCIL_NOTEQUAL) | |
render.SetStencilPassOperation(STENCIL_KEEP) | |
cam.Start2D() | |
surface.SetDrawColor(color) | |
surface.DrawRect(0,0,ScrW(),ScrH()) | |
cam.End2D() | |
render.SetStencilEnable(false) | |
render.SetRenderTarget(rt2) | |
render.Clear(255, 255, 255, 255, true, true) | |
renderer:SetTexture("$basetexture", rt) | |
render.SetMaterial(renderer) | |
render.SetStencilEnable(true) | |
render.SetStencilReferenceValue(0) | |
render.SetStencilCompareFunction(STENCIL_ALWAYS) | |
render.SetStencilPassOperation(STENCIL_INCR) | |
render.SetStencilFailOperation(STENCIL_KEEP) | |
render.SetStencilZFailOperation(STENCIL_KEEP) | |
render.SetStencilWriteMask(1) | |
render.SetStencilTestMask(1) | |
cam.Start3D() | |
prop:DrawModel() | |
cam.End3D() | |
render.SetStencilCompareFunction(STENCIL_EQUAL) | |
render.SetStencilPassOperation(STENCIL_KEEP) | |
render.SetMaterial(renderer) | |
local off = math.ceil(amount * 50 / dist) | |
for x = -off, off do | |
for y = -off, off do | |
render.DrawScreenQuadEx(x,y,ScrW(),ScrH()) | |
end | |
end | |
render.SetStencilEnable(false) | |
render.SetRenderTarget(old) | |
renderer:SetTexture("$basetexture", rt2) | |
render.SetMaterial(renderer) | |
render.DrawScreenQuad() | |
end | |
hook.Add("PostDrawOpaqueRenderables", "test", function() | |
local prop = LocalPlayer():GetEyeTrace().Entity | |
if (not IsValid(prop)) then | |
return | |
end | |
local t = SysTime | |
local s = t() | |
render.Outline(prop, Color(255,0,255,255), 3) | |
print(t()-s) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment