Function Smoothing Explained!

Поділитися
Вставка
  • Опубліковано 23 січ 2025

КОМЕНТАРІ • 101

  • @checkpeck
    @checkpeck 6 років тому +20

    The best part about this is a 5year old can understand it ..pure gold!

    • @brainloading5543
      @brainloading5543 2 роки тому +2

      Well, that might be untrue

    • @bawbak8800
      @bawbak8800 9 днів тому

      It depends on your definition of understanding

  • @yellowmoleproductionss3271
    @yellowmoleproductionss3271 6 років тому +16

    Your tutorials are amazing. Great work.

  • @sendark001
    @sendark001 5 років тому +39

    “Let’s say you’re building a piece of art with mathematics”

    • @dylankuzmick3122
      @dylankuzmick3122 3 роки тому

      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!

  • @jovanrakocevic9360
    @jovanrakocevic9360 5 років тому +1

    Saw the function many times, never understood it until I heard this. Thanks!

  • @Roger-xb7gg
    @Roger-xb7gg 6 років тому +2

    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.

  • @Noizefield
    @Noizefield 7 років тому +9

    Thank you for all your tutorials, they are very good.

  • @sammosel3300
    @sammosel3300 5 років тому +18

    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.

  • @pavolpanisz3251
    @pavolpanisz3251 3 роки тому

    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

  • @remmo123
    @remmo123 5 років тому +1

    You are a great teacher! I learned a lot here.

  • @shoryaagarwal5827
    @shoryaagarwal5827 7 років тому +5

    You sir, make math sound a hell lot more interesting! Keep up the good work :D

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  7 років тому +1

      Aww thanks! Yeah making things visual makes them a lot more fun ;)

  • @jaybhanushali6448
    @jaybhanushali6448 7 років тому +1

    Plain and simple!!
    Thanks for the awesome explaination!!

  • @4.0.4
    @4.0.4 5 років тому

    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.

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому

      Its definitely a neat and very useful trick and yeah Desmos is a gem for shaping 2d functions.

  • @SketchpunkLabs
    @SketchpunkLabs 7 років тому +3

    Love these math tutorials. Need to spend more time playing with desmos.

  • @Margaritaom6
    @Margaritaom6 Рік тому

    A brilliant explanation. Thank you ☀ It made sense

  • @michaelscott2554
    @michaelscott2554 3 роки тому

    Brilliant simplicity.

  • @GglSux
    @GglSux 5 років тому +1

    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.

  • @neur303
    @neur303 5 років тому +3

    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! ❤️

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому

      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!

  • @nameno7032
    @nameno7032 Рік тому

    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?

  • @rileyrileyrileyriley761
    @rileyrileyrileyriley761 Рік тому

    Thanks! Great walkthrough

  • @ilmarsrauda
    @ilmarsrauda 7 років тому +1

    I really like your explanations. Thank you :)

  • @anmaral-sharif1381
    @anmaral-sharif1381 7 років тому

    *BEST UA-cam CHANNEL*

  • @Thepantino
    @Thepantino 4 роки тому

    Wow..It's simply amazing....cool cool cool thanks!!!

  • @strongestraper2818
    @strongestraper2818 3 роки тому +1

    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!

  • @PenguinMaths
    @PenguinMaths 4 роки тому +2

    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 :)

  • @petrostzathas8766
    @petrostzathas8766 4 роки тому +1

    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.

  • @gaborkovacs
    @gaborkovacs 3 роки тому

    great tutorial, thank you!

  • @visualeugen2838
    @visualeugen2838 5 років тому

    Really cool! I've learnt a lot from ur work, thx!

  • @dmitrykolesnikovich
    @dmitrykolesnikovich 5 років тому +1

    this is priceless man thank you so much

  • @tommai78101
    @tommai78101 5 років тому

    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.

  • @galaxyfarmer4742
    @galaxyfarmer4742 4 роки тому

    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!

  • @alejandrocambraherrera8242
    @alejandrocambraherrera8242 4 роки тому

    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
      @TheArtofCodeIsCool  4 роки тому +1

      Yes, you are right. What I was asking is why is it specifically 0.5, and not 0.6?

    • @alejandrocambraherrera8242
      @alejandrocambraherrera8242 4 роки тому

      @@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.’

    • @milanstevic8424
      @milanstevic8424 3 роки тому

      @@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.

    • @ian.ambrose
      @ian.ambrose 3 роки тому

      @@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?

  • @Leruster
    @Leruster 5 років тому +1

    OMG I did find it useful

  • @ChenHuang
    @ChenHuang 6 років тому

    awesome explanation, as always

  • @kafel4796
    @kafel4796 Рік тому

    nice for smooth boolean operations.

  • @michaelolp
    @michaelolp 7 років тому

    Thanks for the tutorial! Very cool!

  • @crazyuniverze
    @crazyuniverze 4 роки тому

    Thanks, that really helps a lot

  • @WindBendsSteel
    @WindBendsSteel 4 роки тому

    0.5 interpolates midway between the corner and the cutout, therefore, ease in-out cutout

  • @LowLifeGraphicsProgrammer
    @LowLifeGraphicsProgrammer 5 років тому

    Amazing tutorial !!! By the way, would you please tell me some website/blogs which talks about techniques of designing these functions for shaders?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому +1

      There aren't very many but a very good website with lots of information is Inigo Quilez' site:
      www.iquilezles.org/www/index.htm

  • @ian.ambrose
    @ian.ambrose 3 роки тому

    Amazing video. Can you please derive the function of Smooth Maximum as well?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  3 роки тому +2

      Using a negative k value makes a maximum instead of a minimum

    • @ian.ambrose
      @ian.ambrose 3 роки тому

      @@TheArtofCodeIsCool Thank you!

  • @antoniopepe
    @antoniopepe Рік тому

    Crazy stuff. 🙌

  • @uvrgb
    @uvrgb 7 місяців тому

    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.

  • @DetectivePoofPoof
    @DetectivePoofPoof 4 роки тому

    I love this

  • @Trooperos90
    @Trooperos90 3 роки тому

    Awesome vid ;)

  • @butjok
    @butjok 5 років тому

    Amazing stuff

  • @anassrazik7506
    @anassrazik7506 7 років тому +1

    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 ?

  • @CalebFaith
    @CalebFaith 5 років тому

    Thank you!

  • @J大侠
    @J大侠 4 роки тому

    amazing!!!!!!!!

  • @ProkopHapala
    @ProkopHapala 5 років тому

    Hi, What web you use for plotting? seems much better than FooPlot I was using till now !

  • @J大侠
    @J大侠 4 роки тому

    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.

  • @RifinTidHamar
    @RifinTidHamar 5 років тому

    Thank you dude

  • @СергейПавлов-в2е
    @СергейПавлов-в2е 3 роки тому

    Handsome man!

  • @СергейФёдоров-щ8ш
    @СергейФёдоров-щ8ш 5 років тому

    very interesting ) thanx!

  • @telotawa
    @telotawa 5 років тому

    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

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому +1

      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.

  • @khorogify
    @khorogify 5 років тому

    great!

  • @rt1097
    @rt1097 4 роки тому

    awsome

  • @TheNinjaDwarfBiker
    @TheNinjaDwarfBiker 7 років тому

    Thanks a lot! Subscribed

  • @donlansdonlans3363
    @donlansdonlans3363 5 років тому +6

    Is nobody going to mention the thumbnail? XD, well, ig that smooth female legs and smooth functions have something in common

    • @SuperNolane
      @SuperNolane 4 роки тому +1

      The art of choosing thumbnail :)

  • @merlinwilson9341
    @merlinwilson9341 2 роки тому

    // 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

  • @lauriran
    @lauriran 4 роки тому +1

    9:25 haha

  • @Trooperos90
    @Trooperos90 3 роки тому

    How cool is that?

  • @VintageGearFreak
    @VintageGearFreak 7 років тому +2

    What a clickbaity thumbnail:) good tutorial

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  7 років тому +1

      Yeah at first I was gonna put a pic of me shaving my own legs! I think you'll agree this is better ;)

    • @VintageGearFreak
      @VintageGearFreak 7 років тому

      The Art of Code Noo let’s have those legs :)

  • @ymi_yugy3133
    @ymi_yugy3133 5 років тому

    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.

    • @ymi_yugy3133
      @ymi_yugy3133 5 років тому

      correction. After more careful consideration it seems to be C¹ smooth at least.

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому +2

      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)

  • @eternalsoul220
    @eternalsoul220 3 роки тому

    please dont swear in a mathematics video.
    just kidding