Sir you are a beast. Everytime my googling about raymarching gets concrete you appear in the results. Phenomenal work and resources you put out there, thank you so much!
I echo the sentiment in the comments that I would adore a series of these videos covering each primitive, getting progressively more complex and building on previous videos! Thanks for the amazing work, IQ.
i love how the expression involves vectors, so it doesnt matter what are the dimensions, i love the elegance of this whole thing, thanks for explaining it!!
Are you planning on doing a series of these for the other primitives on your website? Would be really useful for basic understanding - as it's a lot better than just copying formulas. Also I don't have the brains to derive these myself! They aren't obvious, to me a least, but with explanation really make sense.
I wanted to mention one little thing which I myself seem to have noticed for the first time, watching this video -- I think music, the right kind of music (which I guess is subjective, admittedly), will help one learn better. It relaxes the mind and helps you put your mind closer to the "zone". At least that's my impression. Either that or it's Inigo's soft Spanish accent that he speaks with, or simply his method of explaining the difficult using simpler terms. Anyway, think about it -- music as a catalyst of learning math...
I really wish you would do more videos, in fact I wish you would do an entire course right here on youtube. There's so much many of us could learn from you.
I'll have to raise my bar so I can follow along! Mr. Quilez I can't think of a better course I'd love to watch than something produced by yourself. Thank you.
I found it easier when trying to think of an SDF for a box to just intersect boxes of infinite volume and simplify from there. i.e. for 3D use 6 versions of sdInfiniteBox(vec3 p, float height) { return h - p.y; }, inline them, and then try to minimize the formulas. Ends up reducing to a few max and min operations if I remember correctly. I do like how your approach generalizes to more dimensions though, that is really cool.
The intersection of infinite boxes won't work in most applications. What you get is a bound for the distance, not a real (euclidean) distance. That might be okey for some types of colission detection or slow marching, but generally you want the exact distance to the box, not just an approximation.
You should have mentioned that this is pretty much the sphere function but using chebychev distance instead of euclidean distance. A curve that has equal euclidean to a point forms a circle, while using chebychev forms a square- and manhattan distance forms a smaller square rotated by 45 degrees.. or a "diamond"
Are you planning to bring the theme of voxels? Im very interested in this theme. There are some experiments and tech demos coming out recently that are showing how far can you go in realtime with this things. But most of the sources are written in a very technical lingo. I saw your video and I understood box collision logic immediatly. I would like to see something like this in voxels. pls
This is amazing. One question though. At 5:28, what is the value of R? I understood the equation before it and how we are generalizing it but to go to the next equation, we'll need the direction of vector P to get the value of R right?
@@InigoQuilez Hmm. I think I got confused. abs(P) I assumed as the magnitude of P. So are we basically subtracting a point on the edge of the surface to some extension of the same point?
No, abs(p) is the component-wise absolute value of p. It's still a vector. The magnitude is length(p). Basically abs is |x| and length is ||x||. It's not necessarily the most logical, but that's how GLSL and most graphics programming languages call things.
@@InigoQuilez Makes so much sense. Yeah, abs(p) is nothing but the abs value of each element. My bad that I confused it with what "length" does. And now, it makes perfect sense how ||abs(p)-R|| (length(abs(p)-R)) gives us what we want.
The SDF of a box is the distance from any point in space to the box ? What must be learned to get to this point in mathematics; unless a break down video can be created ?
I am a professional Instructional Designer with 3D as a hobby. I would love to help you on creating full blown 3D courses for free. Learning from you would be invaluable for me.
Hi Iq! thx for all these aswesomness, I want to dive some deeper in sdf functions, and would like to use the plane shading used in this example. Could you share that in a shadertoy with a 3d sdf drawing the gradient on a 3d plane?
Hey iq, While experimenting with offline SDF rendering, i noticed that the sdf for a box is almost exactly the same as the one for the elongation operation… as in the datatypes, math operations and function calls are all identical besides the length() and „primitive()“ calls in each. Trying to figure out how that can be interpreted. Is it similar to how the SDF of a capsule is basically an elongated sphere? If yes, what exactly would be a non-elongated primitive in a box?
Hey Inigo Quilez! I looked at your 6 hour tutorial and repeated everything. I got -50% fps for every added primitive. Is SDF rendering really faster than polygonal rendering? Is SDF useful in videogames? Can i get more perfomance using SDF?
Why is it that you use the absolute value of P instead of just P in the q = abs(P) - R? I tried without the abs in the shadertoy example in your website but couldn't notice a visible difference.
But this doesn't really get rid of the branching, they are just hidden in the max funcions! Still nice, there are intrinsincs that perform max very quicly.
like this? mov eax, dword [esp+8] mov ebx, dword [esp+4] cmp eax, ebx cmovl eax, ebx ret I'm not sure the max/min functions from the standard library uses this trick tho
Yhat's old school, but yes,I guarantee wr haven't done bramches for min/max many decades. Same for GPU, it's a hardware instruction since forever. In fact it's the other way around, and many if() statements are simulated with min/max.
@@InigoQuilez that is very interesting! I know there are sse intrinsics like _mm_max_ps() that emit direct cpu instructions for doing it wide, so yeah it makes sense. Thank you!
The GPU can compute the max of two numbers without branching, like it can compite the addition or subtraction of two numbers without branching. It's most likely a combinatorial circuit.
All the references are in the desctiption of the video, in particular iquilezles.org/www/index.htm is where I have all the tutorials and maths realted to SDFs.
06:27 I'm sorry, but how can the distance function ever be less than 0 in this case where if you add a parameter to the length function can only yield a positive value
q's components can be negative and maxcomo(q), the largest component of q can be negative. So when adding it to the lengrh (which is zero in the interior of the box), you get a negative value for the SDF.
I dont suppose a follow up on why or how this used could be forthcoming. I found it interesting but the shriveled and aged maths side of my Brain was wondering how it is used or useful.
If you mean a direction when recieving a „sphere“ during sphere tracing, the first derivative of the distance function will give you the gradient / slope -> you can get the direction from the signs
How you made the animation at the start of the video? You made a shader for that? Are you working on a framework or something? Cant think of someone doing that thing in ShaderToy.
Nice video. However, using background music for math videos is IMO counterproductive. The listener is supposed to be be maximally focused while listening to you, and the music is distracting
I don’t think music is inherently out of place in math videos. Just look at 3Blue1Brown. If the pinnacle of mathematics education on RUclips uses background music, then surely it can’t always be a bad thing. I do think there’d an issue with the audio mixing though. The music changes volume throughout the video (although I think I remember watching a video saying that RUclips uses auto-gain so it may not be intentional) and the music is a little too loud during the speaking parts of the video. Perhaps a different style of background music might lend itself better to the video as well, the techno music is a bit busy.
The escalation to "visualizing the SDF of a 3D projection of a 4D box" near the end was quick :)
That's the best explanation I've seen so far... Thank you!
Sir you are a beast. Everytime my googling about raymarching gets concrete you appear in the results. Phenomenal work and resources you put out there, thank you so much!
Thanks. I have more coming!
No kidding man! i don't think anyone would know how to do raymarching without this guy
That was great. The visual going from 2D to 3D to 4D was fantastic!
hello
Great explanation, wonderful visualization, what a resource! Keep it up!
You are a true wizard, my friend. Continue to share the magic of numbers, as this wizardry is contagious to the mind of fellow thinkers.
So well explained! Why didn’t I have teachers like this growing up. thank you!
Thanks, this was great, even the shading of the outside and inside of the shape, in the end, was purposeful.
Excellent animations there. I bet it was a lot of work, but it shows in the result.
I echo the sentiment in the comments that I would adore a series of these videos covering each primitive, getting progressively more complex and building on previous videos! Thanks for the amazing work, IQ.
i love how the expression involves vectors, so it doesnt matter what are the dimensions, i love the elegance of this whole thing, thanks for explaining it!!
Thank you for the clear explanation. The graphics are stunning!!
My god. These are some top notch quality videos :O Thank you :)
Are you planning on doing a series of these for the other primitives on your website? Would be really useful for basic understanding - as it's a lot better than just copying formulas. Also I don't have the brains to derive these myself! They aren't obvious, to me a least, but with explanation really make sense.
I have many videos in the pipe, and a few are about deriving SDFs, yes!
OMG YOU'RE ON RUclips!!! I SAW YOUR WORK ON SHADERTOY!!!
the most powerful compact explanation and formula I've seen so far!!
Stunning!!, absolutely amazing!
How is it possible there’s only 10k subscribers to this channel. This is one of the most interesting and educational channels ever!
I wanted to mention one little thing which I myself seem to have noticed for the first time, watching this video -- I think music, the right kind of music (which I guess is subjective, admittedly), will help one learn better. It relaxes the mind and helps you put your mind closer to the "zone". At least that's my impression. Either that or it's Inigo's soft Spanish accent that he speaks with, or simply his method of explaining the difficult using simpler terms. Anyway, think about it -- music as a catalyst of learning math...
Great video! I have learned so much from reading your articles over the years, very happy that you are expanding to videos as well!
Cool thank you, can't wait for the next one !
I really wish you would do more videos, in fact I wish you would do an entire course right here on youtube. There's so much many of us could learn from you.
I'm on it! My goal is to lower the quality bar a bit so I can make more and more quickly. As I said, I'm on it
I'll have to raise my bar so I can follow along! Mr. Quilez I can't think of a better course I'd love to watch than something produced by yourself. Thank you.
Deeply appreciated! Hope to see more derivations in the future!
You are one incredible teacher, thank you for this, it's amazing!
Nice one! Great visualizations!
Mind blowing is the right thing to say! Thank you to make complicated thing very easy to understand.
You're an inspiration, man! Thank you for all of your work and resources.
thank you.. Finally understood the df I used so many times without thinking about it :)
Cool tut. Thanks a lot, Inigo!
Looking to give 3 blue 1 brown some competition I see!
I love this explanation! please do more!
Very elegant formula! Saludos desde Colombia
Do you have cocaine ?
@@rongovard6761 So funny, shame that thousands of people suffer from a war to take drugs to richer countries.
Was just talking about your video tut abilities over lunch! And you drop this craziness around the same time haha.
I'm learning for sure! Also, telepathy? See you soon!
The math is fascinating. Would love if you did a course.
"SIGNED distance field" somewhere on the page/in the content ;)
thank you for the explanation
THESE ARE AWESOME VIDEOS!! THANKS SO MUCH!!
Very nice explanation!
Really helpful, thank you!
good video man
I found it easier when trying to think of an SDF for a box to just intersect boxes of infinite volume and simplify from there.
i.e. for 3D use 6 versions of sdInfiniteBox(vec3 p, float height) { return h - p.y; }, inline them, and then try to minimize the formulas. Ends up reducing to a few max and min operations if I remember correctly.
I do like how your approach generalizes to more dimensions though, that is really cool.
The intersection of infinite boxes won't work in most applications. What you get is a bound for the distance, not a real (euclidean) distance. That might be okey for some types of colission detection or slow marching, but generally you want the exact distance to the box, not just an approximation.
Subscribed! Amazing!
You should have mentioned that this is pretty much the sphere function but using chebychev distance instead of euclidean distance. A curve that has equal euclidean to a point forms a circle, while using chebychev forms a square- and manhattan distance forms a smaller square rotated by 45 degrees.. or a "diamond"
you are amazing
Cool! Just, simply cool!
Thank you
Stop blowing my mind, aaaaaaijoasih
Really cool ! :)
Would this be more optimal? it only makes a call to length when necessary
float sdf_rect(vec3 p, vec3 s) {
vec3 adj = abs(p) - s;
return vmin(adj)
Oh cool a saquare!
Ingo: "Look, it's a cube now!"
Oh cool!
Ingo: "Now a tesseract!"
AHHHHHHHHHH!
brilliant!
Perfect🔥❤️
Nice!
omg that's so cooll!!!!!!!!
distance to parabola and quadraticBezier next!
Are you planning to bring the theme of voxels? Im very interested in this theme. There are some experiments and tech demos coming out recently that are showing how far can you go in realtime with this things. But most of the sources are written in a very technical lingo. I saw your video and I understood box collision logic immediatly. I would like to see something like this in voxels. pls
This is amazing. One question though. At 5:28, what is the value of R? I understood the equation before it and how we are generalizing it but to go to the next equation, we'll need the direction of vector P to get the value of R right?
R is just the dimension of the box, it's a constant vector. In 2D, it would be R = (Rx, Ry)
@@InigoQuilez Hmm. I think I got confused. abs(P) I assumed as the magnitude of P. So are we basically subtracting a point on the edge of the surface to some extension of the same point?
No, abs(p) is the component-wise absolute value of p. It's still a vector. The magnitude is length(p). Basically abs is |x| and length is ||x||. It's not necessarily the most logical, but that's how GLSL and most graphics programming languages call things.
@@InigoQuilez Makes so much sense. Yeah, abs(p) is nothing but the abs value of each element. My bad that I confused it with what "length" does. And now, it makes perfect sense how ||abs(p)-R|| (length(abs(p)-R)) gives us what we want.
Спасибо!
The SDF of a box is the distance from any point in space to the box ? What must be learned to get to this point in mathematics; unless a break down video can be created ?
Sir!
I am a professional Instructional Designer with 3D as a hobby. I would love to help you on creating full blown 3D courses for free. Learning from you would be invaluable for me.
Hi Iq! thx for all these aswesomness,
I want to dive some deeper in sdf functions, and would like to use the plane shading used in this example.
Could you share that in a shadertoy with a 3d sdf drawing the gradient on a 3d plane?
What is abs()?
Absolute of components or length of v from 0?
Hey iq,
While experimenting with offline SDF rendering, i noticed that the sdf for a box is almost exactly the same as the one for the elongation operation… as in the datatypes, math operations and function calls are all identical besides the length() and „primitive()“ calls in each.
Trying to figure out how that can be interpreted. Is it similar to how the SDF of a capsule is basically an elongated sphere? If yes, what exactly would be a non-elongated primitive in a box?
BTW very good quality video. A couple more like this and way less noobs on the streams will be asking what is NDotL.
What is the benefit of this?
Where it is used?
Hey Inigo Quilez! I looked at your 6 hour tutorial and repeated everything. I got -50% fps for every added primitive. Is SDF rendering really faster than polygonal rendering? Is SDF useful in videogames? Can i get more perfomance using SDF?
What is maxcomp()?
The largest component of a vector.
maxcomp(v) = max(v.x, max(v.y, ...))
@@InigoQuilez thank you, i already found it on your website.
Bob Saget is one of his patreon supporters??
Why is it that you use the absolute value of P instead of just P in the q = abs(P) - R? I tried without the abs in the shadertoy example in your website but couldn't notice a visible difference.
Fantastic stuff! But isn't the max() operator implemented with if/else statements?
No, not at all. MAX is like ADD, SUB or CMOV, it's a branchless instruction of the processor.
But this doesn't really get rid of the branching, they are just hidden in the max funcions!
Still nice, there are intrinsincs that perform max very quicly.
No, the max() function doesn't use branching, it uses a CMOV instruction which does NOT jump but use masking to combine bits. That's the whole point.
like this?
mov eax, dword [esp+8]
mov ebx, dword [esp+4]
cmp eax, ebx
cmovl eax, ebx
ret
I'm not sure the max/min functions from the standard library uses this trick tho
Yhat's old school, but yes,I guarantee wr haven't done bramches for min/max many decades. Same for GPU, it's a hardware instruction since forever.
In fact it's the other way around, and many if() statements are simulated with min/max.
@@InigoQuilez that is very interesting! I know there are sse intrinsics like _mm_max_ps() that emit direct cpu instructions for doing it wide, so yeah it makes sense.
Thank you!
how does length() work?
sqrt(Px² + Py²)
isn't the max() usually implemented with a branch operation?
No, unless you don't really have any other choice and have to do it that way.
Why isn’t the max function considered a branch? Doesn’t it have to compare 2 numbers internally?
Shader units have a built-in max() function that is a single instruction.
The GPU can compute the max of two numbers without branching, like it can compite the addition or subtraction of two numbers without branching. It's most likely a combinatorial circuit.
can you add some reference in the description to read something about it? for now i will simply go with the google flow XD
All the references are in the desctiption of the video, in particular iquilezles.org/www/index.htm is where I have all the tutorials and maths realted to SDFs.
06:27
I'm sorry, but how can the distance function ever be less than 0 in this case where if you add a parameter to the length function can only yield a positive value
q's components can be negative and maxcomo(q), the largest component of q can be negative. So when adding it to the lengrh (which is zero in the interior of the box), you get a negative value for the SDF.
I dont suppose a follow up on why or how this used could be forthcoming. I found it interesting but the shriveled and aged maths side of my Brain was wondering how it is used or useful.
all i wanted was to mask a texture so the edges are soft but ohwell. unreal
Is there a way to derive a direction from this?
If you mean a direction when recieving a „sphere“ during sphere tracing, the first derivative of the distance function will give you the gradient / slope -> you can get the direction from the signs
Amazing, but this function does not make a difference for inside or outside the box. It always returns a positive value.
Vous avez mis le SDF où ????????
لا اله الا الله
WHO WATCHES THIS?!??!?!?!??!?!
hi
How you made the animation at the start of the video? You made a shader for that? Are you working on a framework or something? Cant think of someone doing that thing in ShaderToy.
I actually made it in Shadertoy. I modified my original Greek Temple shader and added the animations, it was pretty quick to do.
Nice video. However, using background music for math videos is IMO counterproductive. The listener is supposed to be be maximally focused while listening to you, and the music is distracting
I don’t think music is inherently out of place in math videos. Just look at 3Blue1Brown. If the pinnacle of mathematics education on RUclips uses background music, then surely it can’t always be a bad thing. I do think there’d an issue with the audio mixing though. The music changes volume throughout the video (although I think I remember watching a video saying that RUclips uses auto-gain so it may not be intentional) and the music is a little too loud during the speaking parts of the video. Perhaps a different style of background music might lend itself better to the video as well, the techno music is a bit busy.
Objectively wrong
Omg