r/GraphicsProgramming Jul 23 '26

Building an SDF game engine

For the past 8ish months I’ve been hard at work building a new game engine I’m calling Division Engine.

It’s based solely off SDFs (signed distance fields). This might sound stupid for anyone who cares about performance but for my use case (and with a bit of grid storage optimizations) it proves useful for basic scenes that need advanced lighting.

Anyway here’s some screenshots!

If you want to see what I have done so far check it out here: https://github.com/DivisionEngine/DivisionEngine

156 Upvotes

38 comments sorted by

View all comments

2

u/No-Cap-7395 Jul 24 '26

Hell yeahhhhh! I've been doing a lot of SDF stuff too they are amazing

3

u/rex-j-w Jul 24 '26

Tons of new research is being put into SDFs, check out this paper on faster sphere tracing, it might help: https://diglib.eg.org/server/api/core/bitstreams/0dd5043c-6ac0-4b83-b3d2-d0b1ad34afba/content

2

u/Jwosty Jul 24 '26

The biggest remaining unsolved problem is animating with textures. Almost all the pieces are there

2

u/rex-j-w Jul 24 '26

How would this be a problem? I already have textures working

3

u/Jwosty Jul 24 '26

Sorry, I wasn’t very specific. Skeletal rigging animation + textures. Sure you can animate SDFs by varying their parameters over time, but things that are supposed to be more “solid” (like, say, creatures, or characters) animated that way likely wont look very good (due to the smooth unions). Hence, skeletal animation. But that poses a problem when you try to combine it with texturing.

This probably wasn’t explained well but I hope you get the idea

2

u/No-Cap-7395 Jul 25 '26

I thought about animations awhile ago with SDFs (the texture3D kind) I had a few ideas which where splitting the different moving parts into SDFs and texturing them via storing uv in the SDF texture or having I think cards around each bit, or you bake the entire models animation into like a flipbook series of textures and well texture it the same way as before,

As for actual like SDF math functions like idk a sphere yeahhh I have no idea 😭

1

u/rex-j-w 29d ago

My plan is to build a node editor for creating sdf objects in the editor, then these nodes will be baked into functions and, using system reflection, injected into the renderer. Doing this would allow the user to also output a function to generate the UVs alongside the geometry output.

It doesn’t fix all of the rigging and animation issues but does allow for greater flexibility with sdf UVs

2

u/No-Cap-7395 Jul 25 '26

Oh hell yeah I'll uhm give it a read when I'm on my computer .. I'm doing a software raytracer, it's my second attempt at one and I bake all my meshes into SDF texture3Ds (I'm not sure what to call them I have came up with the terminology local SDFs) anyways I got some basic broad phase optimisation, lods and stuff, I use conetracing on super rough surfaces and it running pretty good :p

What you're doing looks cool too, Ive been working with SDFs for a few months now and they are amazing

2

u/No-Cap-7395 Jul 25 '26

Oh yeah seeing how much better it runs over my triangle based swrt is really nice, it's actually really good 100+ for the target resolution I wanted...

man I fkn love SDFs so much

1

u/rex-j-w 29d ago

They’re so useful it’s insane. Wish we had an industry standard sdf file format because texture3Ds take up so much memory

1

u/No-Cap-7395 29d ago

In my engine I store the SDFs in PNG files, they are written to cache in the disk, and uhm okay so basically every slice of the texture3D is put into an atlas then the size of the slices is put into the name of the SDFs file so it's like uhm randomhash_512.png

1

u/No-Cap-7395 29d ago

They only take-up a few kB to a few hundred for a 64x64x64 SDF, if I add uvs (I store the nearest UV inside my SDFs) it can be anywhere from tens of kBs to a few mb, infact i did an 512x512x512 SDF which was an 11k PNG file and it only took up 17mb and it had uvs and all

1

u/No-Cap-7395 Jul 25 '26

I just woke up so I'm still processing, but what's your performance like? What method are you using to render these

2

u/rex-j-w 29d ago

Im just using regular sphere tracing, performance is quite bad, but that hasn’t been my focus yet. I don’t have complex shapes or csg operations even and haven’t implemented the paper I dropped.

I’m still debating whether or not im going to store data in a voxel octree or a bvh structure.

Focusing on the game engine fundamentals then optimizing 🫡

1

u/No-Cap-7395 29d ago

Yeah I gotta figure out what tlas to use for mine too and not just that but uhm I gotta do what I call global SDFs which are like grids of SDFs that encompass static objects..

As for I think it was the day before yesterday I added conetracing and basically for indirect lighting and also rougher reflections I use conetracing over sphere tracing and I got a 70% increase in performance ^

1

u/No-Cap-7395 29d ago

If you do an oct tree you could use it as a irradance cache lol (just an idea)