• he/him

Avatar by @DrDubz.
Banner by one of Colin Jackson, Rick Lodge, Steve Noake, or David Severn from Bubsy in: Fractured Furry Tales for the Atari Jaguar.


echo-parallax
@echo-parallax

I enjoyed @jam2go's video about stylized depth-of-field bokeh where instead of getting blurrier, it looks like it gets more and more JPEG artifacts. But it bothered me that it wasn't emulating JPEG compression directly — it artistically mimics the visual aspects of JPEG compression instead1.

So, here's a Shadertoy that models JPEG compression more closely! It simulates JPEG's frequency-domain quantization, YCoCg transform, and (sort of) 4:2:0 chroma subsampling, in 4 shader passes2. It also has versions of a few of the other stylized depth-of-field effects from @jam2go's video!

The scene here is @blackle's Whack-A-Mole Pistons, modified to add environment lighting. I've included a few links to other JPEG shaders and resources in the shader code comments as well.


  1. Which is likely a good choice in production, of course! By focusing on the artistic rather than technical aspects of JPEG compression, you can likely write a faster shader and have more control over the output. @ompuco's JPGPU is sort of a middle ground — it lets you also control the block size and resolution and has more options for the DCT quantization stage, but still simulates JPEG's core algorithm.

  2. This could probably be reduced to 1 if each thread did 64 texture reads in one pass instead of 8 texture reads in 4 passes. Or one might use shared memory and warp operations in a single pass if the rendering API and platform supports it; then each thread could only perform 1 texture read, and it would probably be faster. I've included some notes in the shader comments!


You must log in to comment.

in reply to @echo-parallax's post:

This is a thing I'd been wanting to mess with at some point in the past but as with most of the things I've been wanting to mess with I, uh, forgot to actually do it

The video was really cool but it also bugged me a little bit that it was superficially emulating JPEG without actually doing the real transforms on it. I'll have to pick apart your shader code to see how you pulled it off! I had it in my mind that doing a proper DCT from a shader wouldn't be efficient enough for practical use.

Very late on this but this is great! I came across this by chance while searching for ways to apply JPEG compression in a real time effect for TouchDesigner. Gonna study this and try it out. Very happy I won’t have to hack in some Python library instead.