Created
April 13, 2019 11:40
-
-
Save CapsAdmin/1638aa77024d1000cd907335d4574692 to your computer and use it in GitHub Desktop.
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 fireBlocks = {} | |
local tilesize = 8 | |
local numberWidthBlocks = math.floor(ScrW() / tilesize) | |
local numberHeightBlocks = 48 -- means all the 36 colors with a little more space to remaining flames | |
local offsetY = ScrH() - (numberHeightBlocks * tilesize) | |
local colorLookup = { | |
Color(7,7,7), | |
Color(31,7,7), | |
Color(47,15,7), | |
Color(71,15,7), | |
Color(87,23,7), | |
Color(103,31,7), | |
Color(119,31,7), | |
Color(143,39,7), | |
Color(159,47,7), | |
Color(175,63,7), | |
Color(191,71,7), | |
Color(199,71,7), | |
Color(223,79,7), | |
Color(223,87,7), | |
Color(223,87,7), | |
Color(215,95,7), | |
Color(215,95,7), | |
Color(215,103,15), | |
Color(207,111,15), | |
Color(207,119,15), | |
Color(207,127,15), | |
Color(207,135,23), | |
Color(199,135,23), | |
Color(199,143,23), | |
Color(199,151,31), | |
Color(191,159,31), | |
Color(191,159,31), | |
Color(191,167,39), | |
Color(191,167,39), | |
Color(191,175,47), | |
Color(183,175,47), | |
Color(183,183,47), | |
Color(183,183,55), | |
Color(207,207,111), | |
Color(223,223,159), | |
Color(239,239,199), | |
Color(255,255,25), | |
} | |
for i,v in ipairs(colorLookup) do | |
v.a = (i/#colorLookup) * 255 | |
end | |
for line = 1,numberHeightBlocks do | |
table.insert(fireBlocks, {}) | |
local yValue = (line - 1) * tilesize + offsetY | |
for col = 1,numberWidthBlocks do | |
if line < numberHeightBlocks - 1 then | |
table.insert(fireBlocks[line], {x = (col-1) * tilesize, y = yValue, color = 1}) | |
else | |
table.insert(fireBlocks[line], {x = (col-1) * tilesize, y = yValue, color = 36}) | |
end | |
end | |
end | |
local function draw() | |
for line, cols in ipairs(fireBlocks) do | |
for _, block in ipairs(cols) do | |
surface.SetDrawColor(colorLookup[math.Clamp(math.floor(block.color), 1, #colorLookup)]) | |
surface.DrawRect(block.x, block.y, tilesize, tilesize) | |
end | |
end | |
end | |
local alphaMap = {} | |
local tex = GetRenderTarget("doomfire"..math.random(), numberWidthBlocks, numberHeightBlocks) | |
print(numberWidthBlocks, numberHeightBlocks) | |
surface.CreateFont( "FireFont", { | |
font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name | |
extended = false, | |
size = 50, | |
weight = 500, | |
blursize = 0, | |
scanlines = 0, | |
antialias = true, | |
underline = false, | |
italic = false, | |
strikeout = false, | |
symbol = false, | |
rotary = false, | |
shadow = false, | |
additive = false, | |
outline = false, | |
} ) | |
surface.DisableClipping(true) | |
render.PushRenderTarget(tex) | |
render.Clear(0,0,0,0) | |
cam.Start2D() | |
surface.SetFont("FireFont") | |
local w, h = surface.GetTextSize("FIRE") | |
surface.SetTextPos(numberWidthBlocks/2 - w/2, 5) | |
surface.SetTextColor(255,255,255,255) | |
surface.DrawText("FIRE") | |
cam.End2D() | |
render.CapturePixels() | |
for x = 0, numberWidthBlocks do | |
alphaMap[x] = alphaMap[x] or {} | |
for y = 0, numberHeightBlocks do | |
alphaMap[x][y] = alphaMap[x][y] or {} | |
local r,g,b = render.ReadPixel(x,y) | |
r = r / 255 | |
g = g / 255 | |
b = b / 255 | |
local dist = math.sqrt(r*r + g*g + b*b) / 1.78 | |
alphaMap[x][y] = dist ^0.1 | |
end | |
end | |
render.PopRenderTarget() | |
surface.DisableClipping(false) | |
local nextUpdate = 0 | |
local function update() | |
if nextUpdate > RealTime() then | |
return | |
end | |
nextUpdate = RealTime() + 1/16 | |
for line = 1,numberHeightBlocks - 1 do | |
for col = 2,numberWidthBlocks - 1 do | |
local windDirection = math.random() | |
local alpha = alphaMap[col] and alphaMap[col][line] or 0 | |
local decay = 5 | |
decay = decay - alpha*6 - math.random() | |
local collumn_To_Apply = col | |
if windDirection < 0.2 then | |
collumn_To_Apply = (col - 1) | |
elseif windDirection > 0.8 then | |
collumn_To_Apply = (col + 1) | |
end | |
if fireBlocks[line+1][col].color - decay > 1 then | |
fireBlocks[line][collumn_To_Apply].color = fireBlocks[line+1][col].color - decay | |
else | |
fireBlocks[line][collumn_To_Apply].color = 1 | |
end | |
end | |
end | |
end | |
local mat = CreateMaterial("firemat" .. math.random(),"UnlitGeneric",{ | |
["$basetexture"] = "models/shadertest/shader5", | |
["$vertexcolor"] = 1, | |
["$vertexalpha"] = 1, | |
}) | |
mat:SetTexture("$basetexture",tex) | |
hook.Add("HUDPaint", "doom", function() | |
surface.SetDrawColor(255,255,255,255) | |
surface.SetMaterial(mat) | |
surface.DrawTexturedRect(0,0,tex:Width(), tex:Height()) | |
draw() | |
end) | |
hook.Add("Think", "doom", update) | |
timer.Remove("doomfire") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment