(no title)
jkcxn
|
1 year 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
turtledragonfly|1 year ago
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.
jkcxn|1 year ago
My project was using 2D SDFs for UI which meant you could use a bunch of primitive shapes and union/difference between them, and also add outlines, shadows, glows etc. This means that if you tile up the screen and use a union between two rectangles, only the tile with the overlap needs to calculate the union. It's a little more complicated in 3D with frustum culling.
I was doing it in webgl which doesn't have storage buffers and so I had to use uniforms to pass the data which is a huge limitation. Apparently webgpu could be better so I will try to figure that out one day. But it is early prototype so no links or anything yet.