|
|
|
|
|
by jkcxn
656 days ago
|
|
I've done this for a project where the SDF functions are basically instructions, and you can build up instrictions on the CPU to send to the shader. and then the fragment shader runs them like a mini bytecode interpreter. You can tile up the screen to avoid having too many instructions per fragment. Kinda wild idea and performance may vary depend on what you're 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.