Skip to content

Commit

Permalink
feat: enhance dithering (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan committed Apr 29, 2024
1 parent 5082a0f commit 2ad2b0c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/pixel-profile/src/shaders/dithering.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render } from '../renderer'
import { render, TEXTURE_FILTER } from '../renderer'
import { hslToRgb, rgbToHsl } from '../utils'
import { Vec3 } from '../utils/math'

Expand Down Expand Up @@ -358,10 +358,18 @@ function dither(pos: [number, number], color: [number, number, number]): [number
}

export function orderedBayer(source: Buffer, width: number, height: number): Buffer {
return render(source, width, height, (pixelCoords, texture) => {
const color = texture(pixelCoords)
const ditheredColor = dither(pixelCoords, rgbToHsl(color))
return render(
source,
width,
height,
(pixelCoords, texture) => {
const color = texture(pixelCoords)
const ditheredColor = dither(pixelCoords, rgbToHsl(color))

return [...ditheredColor, color[3]]
})
return [...ditheredColor, color[3]]
},
{
textureFilter: TEXTURE_FILTER.NEAREST
}
)
}

0 comments on commit 2ad2b0c

Please sign in to comment.