r/GraphicsProgramming • u/isandrocks • Apr 01 '26
Does anyone else think Signed Distance Functions are black magic?
I built this and even I barely understand the math behind it anymore. My head hurts I’m going to go stare at a wall for a bit. Take a look at the code. Let me know if I messed anything up!
Disclaimer: I forked the outer box and background from Cube Lines, but the interior box is my own work.
83
u/OldLegWig Apr 01 '26
i always thought SDFs were remarkably simple with great looking results. inigo quilez made me understand how far you can really take them especially when combined with raymarching.
8
u/_michaeljared Apr 01 '26
That dudes blog is mind blowing. Thank you for the reminder for me to go back there!
2
u/robbertzzz1 Apr 01 '26
Check his YouTube channel where he makes some awesome art using just SDFs while explaining his process
17
u/Rockclimber88 Apr 01 '26
The best way to start learning is with a circle. SDF is a 100 dollar name for a 5 dollar concept. It's just the distance from the edge. It's easy to start but the the potential usages are infinite
https://www.shadertoy.com/view/XXdyRr
8
u/inigid Apr 01 '26
Beautiful. Really efficient for implementing robust physics as well. I love SDFs as well, quite a lot.
3
u/Franz_007 Apr 01 '26
I never heard about that kind of functions and wow! the animation looks awesome!
7
u/imlo2 Apr 01 '26
Check out Shadertoy and you will find hundreds of creative (and impressive) examples how SDFs can be used.
3
2
u/Rockclimber88 Apr 01 '26 edited Apr 01 '26
I think there's still a lot to discover in the potential SDFs usages. I added SDF support to my shader-based text effects editor a couple of years ago with a precise bounding shape around each character to start the ray just at the outer "shell" instead of marching from the camera, but then didn't have time to really dive in further. (FSR needs a narrow window to animate properly) https://font.skin/editor/33
3
u/thelemon404 Apr 01 '26
A function that takes in a point in space, and spits out a distance from a hypothetical surface. If it’s inside the surface, the distance is negative, if it’s outside, it’s positive.
1
1
u/DisastrousCry9515 Apr 02 '26
How get the knowledge to build something like This? As a Python programmer for basic things and touchdesigner user i would like to create something in glsl like that but i don’t understand how get the knowledge to project something in glsl , i read a bit of book of shaders and YouTube videos but I would like to get a linear path to study and understand how build graphic code art..
1
u/Ermanator2 Apr 03 '26
How much math do you know?
1
u/DisastrousCry9515 Apr 03 '26
Very basic that’s the point and i never understood which math level is needed and the path to get strong foundations. I would be happy just to do 2d art just to start
2
u/Ermanator2 Apr 04 '26 edited Apr 04 '26
I’d like to help, but my time is limited. I can give some general advice and answer questions you might have. Overall, my recommendation for now is to just browse Shadertoy and stare at the code. Specifically, scroll down and stare at the mainImage() function of as many shaders as you can.
You’ll start to see commonalities. The code can be messy at times, but there are common patterns. If you find a shader that doesn’t have too many lines of code (but not a code golfed shader!) see if you can trace through the execution line by line to get an idea of what’s happening. Remember, the same program is being executed for each pixel on the screen; the only difference is the pixel’s coordinates which come in as input. You don’t have to understand it all, but every bit that you understand is one less bit you’ll have to learn.
If you have questions, just message me and I’ll try to be responsive. As far as math goes, you should at the very least know calc 1, 2, and 3. Linear algebra would help a ton.
If you haven’t gone through calculus and you’re willing to, I recommend Thomas or Stewart calculus. They’re both beautiful books. Do lots of the examples. Alternative to that would be something like Paul’s Online Math Notes or Kahn Academy. Math will carry you so far through this. Traveling these lands without it is laborious and demoralizing. With enough math, you can take flight, lol.
2
u/CriticalEchidna7495 Apr 21 '26
Hey, thanks for this. Im not the original commenter but this is useful to many people
1
u/West_Bobcat9965 Apr 06 '26
I've been playing around with this CAD tool that says it's implicit based. It runs physics in the browser too without meshing although doesn't always run. I assume this is SDF based https://www.lesscad.com/design/0yERWaXk11/basic-water-bottle
39
u/ademdj19 Apr 01 '26
I disagree, they're the only thing that makes sense in the graphics programming world