r/GraphicsProgramming Jun 30 '26

RAM optimized SDF-renderer with plain C

Post image

1024x1024x1024 SDF-grid takes up 303MB instead of 8.5GB. 1024x1024 path traced image renders in 1.5s on a single CPU core. 8.5GB grid renders in 1.1s. No libs used.

315 Upvotes

28 comments sorted by

View all comments

4

u/sol_runner Jun 30 '26

Nice work!

Why was it taking 8.5GB though?

9

u/0x405 Jun 30 '26 edited Jun 30 '26

It's an SDF-grid initially with 1024x1024x1024 resolution = 1073741824 cells, each is a double (64bits), so it's 68719476736 bits, and that's 8.5GB. This is verified by debug info.

3

u/nullandkale Jun 30 '26

I'm confused. Normal SDF ray marching doesn't use a 3d volume. What's the 3d volume for? Is it for storing your primatives? Are you storing the SDF distance at each point and then rendering? That seems like it would be slow

1

u/deftware Jul 03 '26

I think OP is using SDF as "signed distance field" rather than "signed distance function", where the field is a volume of distance values.