That sir, is exactly what I was able to do after watching this video. I now have rounded bricks thanks to smooth min. Amazing tutorial, was amazed at the simplicity!
Coolest video on the internet. This is how maths should be taught to kids in schools. Just lol at having a teacher stand up in front of a whiteboard talking about a function and drawing squiggly waves and holding a damn ruler through the curve and no one even understands what the word function means yet.
I think that the 0.5 is because m has an h^2 term in it, which results in a^2 and b^2 terms (of various amplitudes) when h is in the range between 1 and 0. Taking the derivative of these to get the slope, you get a 2x factor when the square comes down into the linear term in h'. Correcting with 0.5 makes the slope continuous.
Wow, that is really clever. This was so playful and intuitive. I love how you also aren't sure why it works. Once I had to make easing functions for video scripting with Avisynth and at the time I coded a small function viewer in HTML with a canvas just to see "what worked". This Desmos thing looks so fun I want to find some problem to use it, haha. My first thought at the beginning of the video was "I'd blur the curve by averaging a few points close to x", but this solution is so much more elegant.
How cool is that ? ... I would like to answer but I think I'm lost for words.... ;) Not least by the way You showed and explained it. O how I wish that someone had demonstrated and explained these concepts as well as You do back when I studied these things !! Best regards.
Very very cool function and interesting construction. Intuitively it seems right, but a functional analysis would be cool. I miss the necessary mathematical tools for this but there seems to subtly more going on. Would you be interested in giving tutorials on different splines? Also I think it would be cool to have the links you refer to in the video also in the description so I do not have to follow right away or scroll back later. It's not much but I joined your patreon minimum tier and will stay there for a while ;) Hope you will get more viewers/support and enjoy creating! ❤️
I do a quick explanation of a hermite spline (used in the smoothstep function) in my video about interpolation. Perhaps bezier splines would also be cool to do a video on. Great idea to put other videos I'm referencing in the description as well. I will do that from now on. And last but not least: Thanks for the support! I really appreciate it!
Mind = BLOW! Explanation is very clear and concise. Please make more of this math thingy. Can you suggest where can i find those math related material to study? What is this field called?
Thank you for the brilliant video! Excuse me, I have a question, have you now figured out how multiplying function ''m'' with 0.5 creates the curve at 7:35 ? The comments mentioning it are interesting but I would love to hear your expert's opinion. Thanks!
Here is why the constant should be 1/2. Let the final smoothed function be called f, and let a and b be any differentiable functions. If there is a number n_1 such that h(n_1) = 1, then we want f'(n_1) = a'(n_1) since this means that f and a have the same derivative at this point so a transitions smoothly into f. f = h*a + (1-h)*b-c*m for some constant c, which is what we're trying to find. So assume h(n_1) = 1. lim x->n_1 h(n_1)=0 from the left (since we're clamping to 1) and lim x->n_1 h(n_1)=b'-a' from the right. So then we must find a constant c such that f'(n_1) = a'(n_1) in both cases. From the left: f'(n_1) = h'a + ha' + b' - h'b - hb' - cm' = h'a + ha' + b' - h'b - hb' - c(h'(1-h) + h(-h')) Replace h' with 0 to obtain = 0 + ha' + b' - 0 - hb' - 0 Replace h with 1 to obtain = a' And so f'(n_1) = a'(n_1) from the left. Notice that the constant c disappears here so this would be true for any c. From the right: f'(n_1) = h'a + ha' + b' - h'b - hb' - cm' = h'a + ha' + b' - h'b - hb' - c(h'(1-h) + h(-h')) Replace h' with (b' - a') to obtain = (b' - a')a + ha' + b' - (b' - a')b - hb' - c((b' - a')(1-h) + h(-(b' - a'))) Replace h with 1 to obtain = (b' - a')a + a' + b' - (b' - a')b - b' + c(b' - a') = a' + (b' - a')(a - b + c) and remember that h = b - a + 1/2, and also h(n_1) = 1. Therefore b(n_1) - a(n_1) = 1/2. Using this fact we obtain a' + (b' - a')(a - b + c) = a' + (b' - a')(-1/2 + c). So then we choose c = 1/2 to get our desired property that f'(n_1) = a'(n_1) from the right. You can verify that 1/2 also gives us the other desired property that if h(n_2) = 0 then f'(n_2) = b'(n_2) but I'll stop here :)
I think the following formulation provides some intuition behind the 0.5 magic. Essentially we apply the first idea, which is using h as the interpolation parameter, but for the derivatives of the original functions instead of the functions themselves. If the apostrophe denotes the derivative what happens is that we construct a continuous function given by: h*(a' - b') + b' and then we integrate to get the resulting smooth minimum.
I could be wrong. The 0.5 value is to set so the middle of the curve along the X-axis and offset down to the mid-point between the 2 discontinuities (the sharp edges) as shown at 6:00, where the (1, 1) is on the X-axis. In other words, if you move the (1, 1) dot at 6:00 in the video down so it's both halfway to the slope of the angle of the line segment. The line segment starts from the starting blue curve meeting the purple line, and ends at the ending blue curve meeting the black line. Or the 0.5 is just a constant that the math function requires it.
Great work! The thought that interpolate a and b near the intersection really solved my confusion. As for the magic number "0.5", it may have something to do with the smooth minimum tutorial made by inigo quilez? It introduces a Quadratic polynomial way.(and man! it just impossible to understand, for it contains no explanation for how this method come up). Any way, like your whole youtube channel! Hoping to see more insightful and humorous(yeah I can get it) video!
Thinking about the _* 0.5_ you apply to _m_ around 7:50, I'd say it is added there because when you subtract _m_ without that factor, it doesn't actually return a straight cut as you say: it looks slightly concave. So basically, you are multiplaying _m_ by _0.5_ so that its values get smaller and thus the smoothing remains convex, which is what we expect from a function like this. I guess you could parametrise that value to allow you to adjust the convexity/straightness/concavity of the cut.
@@TheArtofCodeIsCool After looking a bit more into it, I think it is due to that value being the only one that makes the smoothed function derivable, i.e. it is the only value that makes its derivative continuous. I’ve tried to prove it mathematically, but the combined expression from the formulas you use is quite horrible: a compound function with fourth-degree polynomials, radicals and things like those, if my algebra didn’t betray me. At least the derivative looks continuous in GeoGebra. I don’t know where you took that value from, but it would make sense since it is the value that makes the curvature change without ‘jumping.’
@@alejandrocambraherrera8242 you don't need the initial functions to do this. you can use two simple intersecting lines, no exponents involved, the rest of the math still applies.
@@TheArtofCodeIsCool Sorry, 1 year late. It can be 0.6 ! But 0.6 makes it less curvy, 0.7 even less curvy, 0.8, 0.9... and then 1 it would not form a curve. On the other hand, anything less than 0.5 would make it even more curvy. It's possible that they chose 0.5 because it looks best, not too curvy and not too flat. Someone might want to choose 0.6 or 0.2 to fit their aesthetic. I personally think the question should be how multiplying those numbers to function m affect the smoothness of the curve? (I don't know anything about this and am looking for answer myself). What do you think?
Adding .5 in the formula is to make the smooth function unrelated to a and b. When expanding h*a + (1-h)*b, adding .5 ensures the equation has symmetry. The equation becomes 1/k(b-a)(a-b) + 0.5a + 0.5b.
thanks a lot m8 i appreciate what you share with us so keep up, i'm working now on a raymarcher but i'm not satisfied with the results, please can you please show us how to write a good raymarcher ?
up until 4:05 ish i was with you, but then i disagree with where you went with it from there, with the function that takes the positive numbers to ~1 and the negative numbers to ~0 and the zeroes to 0.5 a sigmoid curve (like the logistic function) does that perfectly well. maybe it's not as computationally efficient (i don't actually know) but from a math perspective i like it a lot more i think i probably prefer these because the functions going into them are all continuous, which is a personal preference, but it's not a huge importance
When it comes to practical applications I would only consider functions smooth that are at least 2 times differentiable. The one you showed is clearly not. In a mathematical the term is applied even more narrowly and refers to infinitely diffdifferentiable functions. I haven't proven it but I think your function is not even C¹ smooth.
This function is most commonly used to blend two shapes together when generating raymarched images. For this purpose the approach is fine. Just don't let your rocket guidance system depend on it ;) You could make it smoother by doing a smoothstep (hermite) interpolation on h. -> h = h^2(3-2h)
The best part about this is a 5year old can understand it ..pure gold!
Well, that might be untrue
It depends on your definition of understanding
Your tutorials are amazing. Great work.
“Let’s say you’re building a piece of art with mathematics”
That sir, is exactly what I was able to do after watching this video. I now have rounded bricks thanks to smooth min. Amazing tutorial, was amazed at the simplicity!
Saw the function many times, never understood it until I heard this. Thanks!
Coolest video on the internet. This is how maths should be taught to kids in schools. Just lol at having a teacher stand up in front of a whiteboard talking about a function and drawing squiggly waves and holding a damn ruler through the curve and no one even understands what the word function means yet.
Thanks!
Thank you for all your tutorials, they are very good.
Thank you!
I think that the 0.5 is because m has an h^2 term in it, which results in a^2 and b^2 terms (of various amplitudes) when h is in the range between 1 and 0. Taking the derivative of these to get the slope, you get a 2x factor when the square comes down into the linear term in h'. Correcting with 0.5 makes the slope continuous.
That makes sense. Thanks!
i was curious about how this works, so i looked it up on youtube, hoping you'd have a video on this. indeed you did and it did not disappoint
You are a great teacher! I learned a lot here.
You sir, make math sound a hell lot more interesting! Keep up the good work :D
Aww thanks! Yeah making things visual makes them a lot more fun ;)
Plain and simple!!
Thanks for the awesome explaination!!
Thanks Jay!
Wow, that is really clever. This was so playful and intuitive. I love how you also aren't sure why it works. Once I had to make easing functions for video scripting with Avisynth and at the time I coded a small function viewer in HTML with a canvas just to see "what worked". This Desmos thing looks so fun I want to find some problem to use it, haha.
My first thought at the beginning of the video was "I'd blur the curve by averaging a few points close to x", but this solution is so much more elegant.
Its definitely a neat and very useful trick and yeah Desmos is a gem for shaping 2d functions.
Love these math tutorials. Need to spend more time playing with desmos.
Thanks man! Yeah Desmos is a real gem.
A brilliant explanation. Thank you ☀ It made sense
Brilliant simplicity.
How cool is that ? ... I would like to answer but I think I'm lost for words.... ;)
Not least by the way You showed and explained it.
O how I wish that someone had demonstrated and explained these concepts as well as You do back when I studied these things !!
Best regards.
Very very cool function and interesting construction. Intuitively it seems right, but a functional analysis would be cool.
I miss the necessary mathematical tools for this but there seems to subtly more going on.
Would you be interested in giving tutorials on different splines?
Also I think it would be cool to have the links you refer to in the video also in the description so I do not have to follow right away or scroll back later.
It's not much but I joined your patreon minimum tier and will stay there for a while ;) Hope you will get more viewers/support and enjoy creating! ❤️
I do a quick explanation of a hermite spline (used in the smoothstep function) in my video about interpolation. Perhaps bezier splines would also be cool to do a video on.
Great idea to put other videos I'm referencing in the description as well. I will do that from now on.
And last but not least: Thanks for the support! I really appreciate it!
Mind = BLOW!
Explanation is very clear and concise. Please make more of this math thingy.
Can you suggest where can i find those math related material to study? What is this field called?
Thanks! Great walkthrough
I really like your explanations. Thank you :)
Cool :) And thank you for watching!
*BEST UA-cam CHANNEL*
Awww thanks!
Wow..It's simply amazing....cool cool cool thanks!!!
Thank you for the brilliant video!
Excuse me, I have a question, have you now figured out how multiplying function ''m'' with 0.5 creates the curve at 7:35 ? The comments mentioning it are interesting but I would love to hear your expert's opinion. Thanks!
Here is why the constant should be 1/2. Let the final smoothed function be called f, and let a and b be any differentiable functions. If there is a number n_1 such that h(n_1) = 1, then we want f'(n_1) = a'(n_1) since this means that f and a have the same derivative at this point so a transitions smoothly into f. f = h*a + (1-h)*b-c*m for some constant c, which is what we're trying to find.
So assume h(n_1) = 1. lim x->n_1 h(n_1)=0 from the left (since we're clamping to 1) and lim x->n_1 h(n_1)=b'-a' from the right. So then we must find a constant c such that f'(n_1) = a'(n_1) in both cases.
From the left:
f'(n_1) = h'a + ha' + b' - h'b - hb' - cm'
= h'a + ha' + b' - h'b - hb' - c(h'(1-h) + h(-h'))
Replace h' with 0 to obtain
= 0 + ha' + b' - 0 - hb' - 0
Replace h with 1 to obtain
= a'
And so f'(n_1) = a'(n_1) from the left. Notice that the constant c disappears here so this would be true for any c.
From the right:
f'(n_1) = h'a + ha' + b' - h'b - hb' - cm'
= h'a + ha' + b' - h'b - hb' - c(h'(1-h) + h(-h'))
Replace h' with (b' - a') to obtain
= (b' - a')a + ha' + b' - (b' - a')b - hb' - c((b' - a')(1-h) + h(-(b' - a')))
Replace h with 1 to obtain
= (b' - a')a + a' + b' - (b' - a')b - b' + c(b' - a')
= a' + (b' - a')(a - b + c)
and remember that h = b - a + 1/2, and also h(n_1) = 1.
Therefore b(n_1) - a(n_1) = 1/2. Using this fact we obtain
a' + (b' - a')(a - b + c) = a' + (b' - a')(-1/2 + c). So then we choose c = 1/2 to get our desired property that f'(n_1) = a'(n_1) from the right.
You can verify that 1/2 also gives us the other desired property that if h(n_2) = 0 then f'(n_2) = b'(n_2) but I'll stop here :)
I think the following formulation provides some intuition behind the 0.5 magic. Essentially we apply the first idea, which is using h as the interpolation parameter, but for the derivatives of the original functions instead of the functions themselves. If the apostrophe denotes the derivative what happens is that we construct a continuous function given by: h*(a' - b') + b' and then we integrate to get the resulting smooth minimum.
great tutorial, thank you!
Really cool! I've learnt a lot from ur work, thx!
this is priceless man thank you so much
I could be wrong. The 0.5 value is to set so the middle of the curve along the X-axis and offset down to the mid-point between the 2 discontinuities (the sharp edges) as shown at 6:00, where the (1, 1) is on the X-axis. In other words, if you move the (1, 1) dot at 6:00 in the video down so it's both halfway to the slope of the angle of the line segment. The line segment starts from the starting blue curve meeting the purple line, and ends at the ending blue curve meeting the black line.
Or the 0.5 is just a constant that the math function requires it.
Great work! The thought that interpolate a and b near the intersection really solved my confusion. As for the magic number "0.5", it may have something to do with the smooth minimum tutorial made by inigo quilez? It introduces a Quadratic polynomial way.(and man! it just impossible to understand, for it contains no explanation for how this method come up). Any way, like your whole youtube channel! Hoping to see more insightful and humorous(yeah I can get it) video!
Thinking about the _* 0.5_ you apply to _m_ around 7:50, I'd say it is added there because when you subtract _m_ without that factor, it doesn't actually return a straight cut as you say: it looks slightly concave. So basically, you are multiplaying _m_ by _0.5_ so that its values get smaller and thus the smoothing remains convex, which is what we expect from a function like this. I guess you could parametrise that value to allow you to adjust the convexity/straightness/concavity of the cut.
Yes, you are right. What I was asking is why is it specifically 0.5, and not 0.6?
@@TheArtofCodeIsCool After looking a bit more into it, I think it is due to that value being the only one that makes the smoothed function derivable, i.e. it is the only value that makes its derivative continuous. I’ve tried to prove it mathematically, but the combined expression from the formulas you use is quite horrible: a compound function with fourth-degree polynomials, radicals and things like those, if my algebra didn’t betray me. At least the derivative looks continuous in GeoGebra. I don’t know where you took that value from, but it would make sense since it is the value that makes the curvature change without ‘jumping.’
@@alejandrocambraherrera8242 you don't need the initial functions to do this. you can use two simple intersecting lines, no exponents involved, the rest of the math still applies.
@@TheArtofCodeIsCool
Sorry, 1 year late. It can be 0.6 ! But 0.6 makes it less curvy, 0.7 even less curvy, 0.8, 0.9... and then 1 it would not form a curve.
On the other hand, anything less than 0.5 would make it even more curvy. It's possible that they chose 0.5 because it looks best, not too curvy and not too flat. Someone might want to choose 0.6 or 0.2 to fit their aesthetic.
I personally think the question should be how multiplying those numbers to function m affect the smoothness of the curve? (I don't know anything about this and am looking for answer myself).
What do you think?
OMG I did find it useful
awesome explanation, as always
Thank you :)
nice for smooth boolean operations.
Thanks for the tutorial! Very cool!
I'm glad you like it :)
Thanks, that really helps a lot
0.5 interpolates midway between the corner and the cutout, therefore, ease in-out cutout
Amazing tutorial !!! By the way, would you please tell me some website/blogs which talks about techniques of designing these functions for shaders?
There aren't very many but a very good website with lots of information is Inigo Quilez' site:
www.iquilezles.org/www/index.htm
Amazing video. Can you please derive the function of Smooth Maximum as well?
Using a negative k value makes a maximum instead of a minimum
@@TheArtofCodeIsCool Thank you!
Crazy stuff. 🙌
Adding .5 in the formula is to make the smooth function unrelated to a and b. When expanding h*a + (1-h)*b, adding .5 ensures the equation has symmetry. The equation becomes 1/k(b-a)(a-b) + 0.5a + 0.5b.
I love this
Awesome vid ;)
Amazing stuff
thanks a lot m8 i appreciate what you share with us so keep up,
i'm working now on a raymarcher but i'm not satisfied with the results, please can you please show us how to write a good raymarcher ?
Thanks! The raymarcher will come, I promise ;)
ua-cam.com/video/PGtv-dBi2wE/v-deo.html
Thank you!
amazing!!!!!!!!
Hi, What web you use for plotting? seems much better than FooPlot I was using till now !
www.desmos.com. It's awesome
I think m*0.5 means the first curve's output tangent = second curve's input tangent, only equal, the final cuve would be smooth, ref to Bezier curve.
Thank you dude
Handsome man!
very interesting ) thanx!
up until 4:05 ish i was with you, but then i disagree with where you went with it from there, with the function that takes the positive numbers to ~1 and the negative numbers to ~0 and the zeroes to 0.5
a sigmoid curve (like the logistic function) does that perfectly well. maybe it's not as computationally efficient (i don't actually know) but from a math perspective i like it a lot more
i think i probably prefer these because the functions going into them are all continuous, which is a personal preference, but it's not a huge importance
Hmm yeah a sigmoid function could probably work. I mostly use this in shaders though where performance is a must and second order derivatives are not.
great!
awsome
Thanks a lot! Subscribed
Thank you for subscribing!
Is nobody going to mention the thumbnail? XD, well, ig that smooth female legs and smooth functions have something in common
The art of choosing thumbnail :)
// Polynomial smooth minimum by iq
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5*(a-b)/k, 0.0, 1.0);
return mix(a, b, h) - k*h*(1.0-h);
}
h range:(a-b)/2k ∈(-0.5,0.5), so : 0.5+(a-b)/2k
9:25 haha
How cool is that?
What a clickbaity thumbnail:) good tutorial
Yeah at first I was gonna put a pic of me shaving my own legs! I think you'll agree this is better ;)
The Art of Code Noo let’s have those legs :)
When it comes to practical applications I would only consider functions smooth that are at least 2 times differentiable. The one you showed is clearly not.
In a mathematical the term is applied even more narrowly and refers to infinitely diffdifferentiable functions.
I haven't proven it but I think your function is not even C¹ smooth.
correction. After more careful consideration it seems to be C¹ smooth at least.
This function is most commonly used to blend two shapes together when generating raymarched images. For this purpose the approach is fine. Just don't let your rocket guidance system depend on it ;)
You could make it smoother by doing a smoothstep (hermite) interpolation on h. -> h = h^2(3-2h)
please dont swear in a mathematics video.
just kidding
fk fk fk fk fk fk fk fk