Skip to content

Instantly share code, notes, and snippets.

@AMD-NICK
Created April 26, 2017 16:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AMD-NICK/82621390b4ec8473b3c328ad9ac81b7a to your computer and use it in GitHub Desktop.
Визуализатор "эхо". Имеет проблему с неудалением эхо после добавления, в связи с чем при большом кол-ве эхо начинает все лагать. Взято отсюда: https://facepunch.com/showthread.php?t=1440586&p=51617841&viewfull=1#post51617841
local echoes = {}
local echo_thickness = 10
local color_mask = Color(0,0,0,0)
local function drawStencilSphere( pos, ref, compare_func, radius, color, detail )
render.SetStencilReferenceValue( ref )
render.SetStencilCompareFunction( compare_func )
render.DrawSphere(pos, radius, detail, detail, color)
end
hook.Add("PostDrawTranslucentRenderables", "Echo", function( )
local localplayer_pos = LocalPlayer():EyePos()
local detail = 25
local realtime = RealTime()
render.SetStencilEnable(true)
render.SetStencilPassOperation( STENCILOPERATION_KEEP )
render.SetStencilFailOperation( STENCILOPERATION_KEEP )
for _, echo in ipairs(echoes) do
local dist = echo.pos:Distance(localplayer_pos)
local opacity = ((echo.radius - (dist / 2)) / echo.radius) * 0.25
local p = (realtime - echo.start) / echo.lifetime
if p < 1.0 and opacity > 0 then
local outer_r = Lerp(p, 0, echo.radius)
local inner_r = math.max(outer_r-echo_thickness,0)
local color = echo.color
color.a = 255 * opacity * math.pow(1-p, 2)
render.ClearStencil()
render.SetColorMaterial()
render.SetStencilZFailOperation( STENCILOPERATION_REPLACE )
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_ALWAYS, -outer_r, color_mask, detail ) -- big, inside-out
render.SetStencilZFailOperation( STENCILOPERATION_INCR )
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_ALWAYS, outer_r, color_mask, detail ) -- big
render.SetStencilZFailOperation( STENCILOPERATION_INCR )
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_ALWAYS, -inner_r, color_mask, detail ) -- small, inside-out
render.SetStencilZFailOperation( STENCILOPERATION_DECR )
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_ALWAYS, inner_r, color_mask, detail ) -- small
render.SetColorMaterialIgnoreZ()
drawStencilSphere(echo.pos, 2, STENCILCOMPARISONFUNCTION_EQUAL, -outer_r, color, detail ) -- big, inside-out
end
end
render.SetStencilEnable(false)
end)
local function addEcho(time,pos,radius,color)
local i = table.insert(echoes,{
pos = pos,
start = RealTime(),
lifetime = time,
radius = radius,
color = color,
})
timer.Simple(time,function()
table.remove(echoes,i)
end)
end
timer.Create("string identifiesdfar",.2,50,function()
addEcho(20, LocalPlayer():GetPos(), 20000, Color(255,0,0))
end)
timer.Simple(20,function()
echoes = {}
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment