Skip to content

Commit

Permalink
Prevent long streak artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
boatbomber committed Nov 18, 2021
1 parent 83d0088 commit a2f8ed8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function module.new(ResX: number, ResY: number)
}

local invX, invY = 1 / ResX, 1 / ResY
local dist = ResY * 0.03
local diff = 0.015
local lossy = diff + math.clamp(0.5 * (ResY / 250)^2, 0, 0.6)

Expand Down Expand Up @@ -121,7 +122,7 @@ function module.new(ResX: number, ResY: number)
{ p = 0, c = column[1] },
}

local pixelStart, pixelCount = 0, 0
local pixelStart, lastPixel, pixelCount = 0, 0, 0
local lastColor = column[1]

-- Compress into gradients
Expand All @@ -137,14 +138,15 @@ function module.new(ResX: number, ResY: number)
if delta > diff then
local offset = y - pixelStart - 1

if delta > lossy then
if (delta > lossy) or (y-lastPixel > dist) then
table.insert(colorData, { p = offset - 0.02, c = lastColor })
colorCount += 1
end
table.insert(colorData, { p = offset, c = color })
colorCount += 1

lastColor = color
lastPixel = y

if colorCount > 17 then
table.insert(colorData, { p = pixelCount, c = color })
Expand Down

0 comments on commit a2f8ed8

Please sign in to comment.