Comment

Comment by turtledragonfly

That's pretty similar to what I'm doing!

The CPU builds an RPN expression (like "circle, square, union, triangle, subtract"), and the shader evaluates that in a loop.

I wasn't able to find examples of other people doing similar, but it seemed too useful to not be invented yet (:

Do you have any links to your work?

I'm writing some blog posts for my approach, but haven't finished them yet.

> You can tile up the screen to avoid having too many instructions per fragment.

I don't quite understand this part... If a given SDF needs N instructions to be evaluated, then how does tiling reduce N?

> performance may vary depend on what you're doing

Yeah, fill rate was not good enough with a straightforward approach, so I had to cache the evaluated distance values to a (float) texture atlas, then use those to render to screen. Luckily, standard bilinear filtering on distance values produces pretty decent results.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton