encyclopegia.org

smoothstep

Smoothstep is a family of sigmoid-like interpolation and clamping functions commonly used in computer graphics, video game engines, and machine learning. The function depends on three parameters, the input x, the "left edge" and the "right edge", with the left edge being assumed smaller than the right edge. The function receives a real number x as an argument. It returns 0 if x is less than or equal to the left edge and 1 if x is greater than or equal to the right edge. Otherwise, it smoothly interpolates, using Hermite interpolation, and returns a value between 0 and 1. The slope of the smoothstep function is zero at both edges. This is convenient for creating a sequence of transitions using smoothstep to interpolate each segment as an alternative to using more sophisticated or expensive interpolation techniques. In HLSL and GLSL, smoothstep implements the \operatorname{S}_1(x) , the cubic Hermite interpolation after clamping: : \operatorname{smoothstep}(x) = S_1(x) = \begin{cases} 0, & x \le 0 \\ 3x^2 - 2x^3, & 0 \le x \le 1 \\ 1, & 1 \le x \\ \end{cases} Assuming that the left edge is 0, the right edge is 1, with the transition between edges taking place where 0 ≤ x ≤ 1. A modified C/C++ example implementation provided by AMD follows.…

Smoothstep is a family of sigmoid-like interpolation and clamping functions commonly used in computer graphics, video game engines, and machine learning. The function depends on three parameters, the input x, the "left edge" and the "right edge", with the left edge being assumed smaller than the right edge. The function receives a real number x as an argument. It returns 0 if x is less than or equal to the left edge and 1 if x is greater than or equal to the right edge. Otherwise, it smoothly interpolates, using Hermite interpolation, and returns a value between 0 and 1. The slope of the smoothstep function is zero at both edges. This is convenient for creating a sequence of transitions using smoothstep to interpolate each segment as an alternative to using more sophisticated or expensive interpolation techniques. In HLSL and GLSL, smoothstep implements the \operatorname{S}_1(x) , the cubic Hermite interpolation after clamping: \operatorname{smoothstep}(x) = S_1(x) = \begin{cases} 0, & x \le 0 \\ 3x^2 - 2x^3, & 0 \le x \le 1 \\ 1, & 1 \le x \\ \end{cases} Assuming that the left edge is 0, the right edge is 1, with the transition between edges taking place where 0 ≤ x ≤ 1. A modified C/C++ example implementation provided by AMD follows. float smoothstep (float edge0, float edge1, float x) { // Scale, and clamp x to 0..1 range x = clamp((x - edge0) / (edge1 - edge0)); return x * x * (3.0f - 2.0f * x); } float clamp(float x, float lowerlimit = 0.0f, float upperlimit = 1.0f) { if (x upperlimit) return upperlimit; return x; } The general form for smoothstep, again assuming the left edge is 0 and right edge is 1, is \operatorname{S}_n(x) = \begin{cases} 0, & \text{if } x \le 0 \\ x^{n+1} \sum_{k=0}^n \binom{n+k}{k} \binom{2n+1}{n-k} (-x)^k, & \text{if } 0 \le x \le 1 \\ 1, & \text{if } 1 \le x \\ \end{cases} \operatorname{S}_0(x) is identical to the clamping function: \operatorname{S}_0(x) = \begin{cases} 0, & \text{if } x \le 0 \\ x, & \text{if } 0 \le x \le 1 \\ 1, & \text{if } 1 \le x \\ \end{cases} The characteristic S-shaped sigmoid curve is obtained with \operatorname{S}_n(x) only for integers n ≥ 1. The order of the polynomial in the general smoothstep is 2n + 1. With n = 1, the slopes or first derivatives of the smoothstep are equal to zero at the left and right edge (x = 0 and x = 1), where the curve is appended to the constant or saturated levels. With higher integer n, the second and higher derivatives are zero at the edges, making the polynomial functions as flat as possible and the splice to the limit values of 0 or 1 more seamless. Ken Perlin suggested an improved version of the commonly used first-order smoothstep function, equivalent to the second order of its general form. It has zero 1st- and 2nd-order derivatives at x = 0 and x = 1: \operatorname{smootherstep}(x) = S_2(x) = \begin{cases} 0, & x \le 0 \\ 6x^5 - 15x^4 + 10x^3, & 0 \le x \le 1 \\ 1, & 1 \le x \\ \end{cases} C/C++ reference implementation: float smootherstep(float edge0, float edge1, float x) { // Scale, and clamp x to 0..1 range x = clamp((x - edge0) / (edge1 - edge0)); return x * x * x * (x * (6.0f * x - 15.0f) + 10.0f); } float clamp(float x, float lowerlimit = 0.0f, float upperlimit = 1.0f) { if (x upperlimit) return upperlimit; return x; } \operatorname{S}_1(x) &&\; = \;&& a_3 x^3 &&\; + \;&& a_2 x^2 &&\; + \;&& a_1 x &&\; + \;&& a_0, & \\ \operatorname{S}_1'(x) &&\; = \;&& 3 a_3 x^2 &&\; + \;&& 2 a_2 x &&\; + \;&& a_1. & \end{alignat} Applying the desired values for the function at both endpoints: \begin{alignat}{13} \operatorname{S}_1(0) &&\; = \;&& 0 \quad&& \Rightarrow &&\quad 0 \;&& + &&\; 0 \;&& + &&\; 0 \;&& + &&\; a_0 &&\; = \;&& 0, & \\ \operatorname{S}_1(1) &&\; = \;&& 1 \quad&& \Rightarrow &&\quad a_3 \;&& + &&\; a_2 \;&& + &&\; a_1 \;&& + &&\; a_0 &&\; = \;&& 1. & \end{alignat} Applying the desired values for the first derivative of the function at both endpoints: \begin{alignat}{11} \operatorname{S}_1'(0) &&\; = \;&& 0 \quad&& \Rightarrow &&\quad 0 \;&& + &&\; 0 \;&& + &&\; a_1 \;&& = \;&& 0, & \\ \operatorname{S}_1'(1) &&\; = \;&& 0 \quad&& \Rightarrow &&\quad 3 a_3 \;&& + &&\; 2 a_2 \;&& + &&\; a_1 \;&& = \;&& 0. & \end{alignat} Solving the system of 4 unknowns formed by the last 4 equations result in the values of the polynomial coefficients: a_0 = 0, \quad a_1 = 0, \quad a_2 = 3, \quad a_3 = -2. This results in the third-order "smoothstep" function: \operatorname{S}_1(x) = -2x^3 + 3x^2. Note that this is one of the basis functions of a cubic Hermite spline. \operatorname{S}_2(x) &&\; = \;&& a_5 x^5 &&\; + \;&& a_4 x^4 &&\; + \;&& a_3 x^3 &&\; + \;&& a_2 x^2 &&\; + \;&& a_1 x &&\; + \;&& a_0, & \\ \operatorname{S}_2'(x) &&\; = \;&& 5 a_5 x^4 &&\; + \;&& 4 a_4 x^3 &&\; + \;&& 3 a_3 x^2 &&\; + \;&& 2 a_2 x &&\; + \;&& a_1, & \\ \operatorname{S}_2(x) &&\; = \;&& 20 a_5 x^3 &&\; + \;&& 12 a_4 x^2 &&\; + \;&& 6 a_3 x &&\; + \;&& 2 a_2. & \end{alignat} Applying the desired values for the function at both endpoints: \begin{alignat}{17} \operatorname{S}_2(0) &&\; = \;&& 0 \;\;\;\;\;&& \Rightarrow &&\;\;\;\;\; 0 \;&& + &&\; 0 \;&& + &&\; 0 \;&& + &&\; 0 \;&& + &&\; 0 \;&& + &&\; a_0 &&\; = \;&& 0, & \\ \operatorname{S}_2(1) &&\; = \;&& 1 \;\;\;\;\;&& \Rightarrow &&\;\;\;\;\; a_5 \;&& + &&\; a_4 \;&& + &&\; a_3 \;&& + &&\; a_2 \;&& + &&\; a_1 \;&& + &&\; a_0 &&\; = \;&& 1. & \end{alignat} Applying the desired values for the first derivative of the function at both endpoints: \begin{alignat}{15} \operatorname{S}_2'(0) &&\; = \;&& 0 \;\;\;\;&& \Rightarrow &&\;\;\;\; 0 \;&& + &&\; 0 \;&& + &&\; 0 \;&& + &&\; 0 \;&& + &&\; a_1 \;&& = \;&& 0, & \\ \operatorname{S}_2'(1) &&\; = \;&& 0 \;\;\;\;&& \Rightarrow &&\;\;\;\; 5 a_5 \;&& + &&\; 4 a_4 \;&& + &&\; 3 a_3 \;&& + &&\; 2 a_2 \;&& + &&\; a_1 \;&& = \;&& 0. & \end{alignat} Applying the desired values for the second derivative of the function at both endpoints: \begin{alignat}{15} \operatorname{S}_2(0) &&\; = \;&& 0 \;\;\;\;&& \Rightarrow &&\;\;\;\; 0 \;&& + &&\; 0 \;&& + &&\; 0 \;&& + &&\; 2 a_2 \;&& = \;&& 0, & \\ \operatorname{S}_2(1) &&\; = \;&& 0 \;\;\;\;&& \Rightarrow &&\;\;\;\; 20 a_5 \;&& + &&\; 12 a_4 \;&& + &&\; 6 a_3 \;&& + &&\; 2 a_2 \;&& = \;&& 0. & \end{alignat} Solving the system of 6 unknowns formed by the last 6 equations result in the values of the polynomial coefficients: a_0 = 0, \quad a_1 = 0 , \quad a_2 = 0, \quad a_3 = 10, \quad a_4 = -15, \quad a_5 = 6. This results in the fifth-order "smootherstep" function: \operatorname{S}_2(x) = 6x^5 - 15x^4 + 10x^3. \operatorname{S}_3(x) = -20x^7 + 70x^6 - 84x^5 + 35x^4. \operatorname{S}_N(x) &= x^{N+1} \sum_{n=0}^N \binom{N+n}{n} \binom{2N+1}{N-n} (-x)^{n} \qquad N \in \mathbb{N}\\ &= \sum_{n=0}^N (-1)^n \binom{N+n}{n} \binom{2N+1}{N-n} x^{N+n+1} \\ &= \sum_{n=0}^N \binom{-N-1}{n} \binom{2N+1}{N-n} x^{N+n+1}, \\ \end{align} where N determines the order of the resulting polynomial function, which is 2N + 1. The first seven smoothstep polynomials, with 0 ≤ x ≤ 1, are \begin{align} \operatorname{S}_0(x) &= x, \\ \operatorname{S}_1(x) &= -2x^3 + 3x^2, \\ \operatorname{S}_2(x) &= 6x^5 - 15x^4 + 10x^3, \\ \operatorname{S}_3(x) &= -20x^7 + 70x^6 - 84x^5 + 35x^4, \\ \operatorname{S}_4(x) &= 70x^9 - 315x^8 + 540x^7 - 420x^6 + 126x^5, \\ \operatorname{S}_5(x) &= -252x^{11} + 1386x^{10} - 3080x^9 + 3465x^8 - 1980x^7 + 462x^6, \\ \operatorname{S}_6(x) &= 924x^{13} - 6006x^{12} + 16380x^{11} - 24024x^{10} + 20020x^9 - 9009x^8 + 1716x^7. \\ \end{align} The derivative of \operatorname{S}_N(x) is \begin{align} \operatorname{d \over dx}{S}_N(x) &= (2N+1)\binom{2N}{N} (x-x^2)^N. \\ \end{align} It can be shown that the smoothstep polynomials \operatorname{S}_N(x) that transition from 0 to 1 when x transitions from 0 to 1 can be simply mapped to odd-symmetry polynomials \operatorname{R}_N(x) = \left(\int_{0}^{1} \big(1 - u^2 \big)^N \,du \right)^{-1} \int_{0}^{x} \big(1 - u^2 \big)^N \,du, where \operatorname{S}_N(x) = \tfrac12 \operatorname{R}_N(2x-1) + \tfrac12 and \operatorname{R}_N(-x) = -\operatorname{R}_N(x). The argument of R N (x) is −1 ≤ x ≤ 1 and is appended to the constant −1 on the left and +1 at the right. An implementation of \operatorname{S}_N(x) in JavaScript: // Generalized smoothstep function generalSmoothStep(N, x) { x = clamp(x, 0, 1); // x must be equal to or between 0 and 1 var result = 0; for (var n = 0; n upperlimit) x = upperlimit; return x; } S_{1}(x) = H(x)\left(3x^{2} - 2x^{3}\right) - H(x - 1)\left(3x^{2}-2x^{3} - 1\right) Performing some algebraic manipulation, S_{1}(x) = H(x)\left(-\frac{12}{6}x^{3} + \frac{6}{2}x^{2}\right) - H(x-1)\left(-\frac{12}{6}\left(x-1\right)^{3} -\frac{6}{2}\left(x - 1\right)^{2}\right) giving a Laplace transform of: S_{1}(s) = \frac{-12 + 12e^{-s}}{s^{4}} + \frac{6 + 6e^{-s}}{s^{3}} This has asymptotic roll off of 60dB/decade (coming from the 1/s^{3} term), as opposed to the 20dB/decade of a Heavyside step, or a 40dB/decade of a linear interpolation ( S_{0}(x) ) - showing that the higher orders of continuity result in a more localized frequency spectra. This can matter for discrete systems, where being band limited is important to reduce aliasing, as per the Nyquist–Shannon sampling theorem. Similar analysis can be performed for each S_{N}(x) , where the roll off is 20(2 + N)dB/decade. \operatorname{InvS}_1(x) = 1/2 - \sin(\operatorname{asin}(1-2x)/3) This arises because the function \operatorname{f}(x) = 1/2 - \sin(3 \operatorname{asin}(0.5-x))/2 is equivalent to the function 3x^2-2x^3=S_1(x) in the range -1/2 \le x \le 3/2 . The inverse, on the other hand, does not have an exact polynomial equivalent. In GLSL: float inverse_smoothstep(float x) { return 0.5 - sin(asin(1.0 - 2.0 * x) / 3.0); }

References

  1. Smoothstep at Microsoft Developer Network . Wikipedia revision 1356968454, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1356968454
    Cite this reference

    MLA "Smoothstep at Microsoft Developer Network . Wikipedia revision 1356968454, retrieved 2026-11-18." Smoothstep at Microsoft Developer Network. 2026-11-17. http://msdn.microsoft.com/en-us/library/bb509658(VS.85).aspx. Accessed 24 November 2026.

    Chicago "Smoothstep at Microsoft Developer Network . Wikipedia revision 1356968454, retrieved 2026-11-18." Smoothstep at Microsoft Developer Network. 2026-11-17. http://msdn.microsoft.com/en-us/library/bb509658(VS.85).aspx.

    APA Smoothstep at Microsoft Developer Network. (2026). Smoothstep at Microsoft Developer Network . Wikipedia revision 1356968454, retrieved 2026-11-18. Retrieved November 24, 2026, from http://msdn.microsoft.com/en-us/library/bb509658(VS.85).aspx

  2. GLSL Language Specification, Version 1.40 . Wikipedia revision 1356968454, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1356968454
    Cite this reference

    MLA "GLSL Language Specification, Version 1.40 . Wikipedia revision 1356968454, retrieved 2026-11-18." GLSL Language Specification, Version 1. 2026-11-17. http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.40.05.pdf. Accessed 24 November 2026.

    Chicago "GLSL Language Specification, Version 1.40 . Wikipedia revision 1356968454, retrieved 2026-11-18." GLSL Language Specification, Version 1. 2026-11-17. http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.40.05.pdf.

    APA GLSL Language Specification, Version 1. (2026). GLSL Language Specification, Version 1.40 . Wikipedia revision 1356968454, retrieved 2026-11-18. Retrieved November 24, 2026, from http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.40.05.pdf

  3. Unity game engine SmoothStep documentation . Wikipedia revision 1356968454, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1356968454
    Cite this reference

    MLA "Unity game engine SmoothStep documentation . Wikipedia revision 1356968454, retrieved 2026-11-18." Unity game engine SmoothStep documentation. 2026-11-17. http://unity3d.com/support/documentation/ScriptReference/Mathf.SmoothStep.html. Accessed 24 November 2026.

    Chicago "Unity game engine SmoothStep documentation . Wikipedia revision 1356968454, retrieved 2026-11-18." Unity game engine SmoothStep documentation. 2026-11-17. http://unity3d.com/support/documentation/ScriptReference/Mathf.SmoothStep.html.

    APA Unity game engine SmoothStep documentation. (2026). Unity game engine SmoothStep documentation . Wikipedia revision 1356968454, retrieved 2026-11-18. Retrieved November 24, 2026, from http://unity3d.com/support/documentation/ScriptReference/Mathf.SmoothStep.html

  4. Hazimeh, Hussein; Ponomareva, Natalia; Mol, Petros; Tan, Zhenyu; Mazumder, Rahul (2020). The Tree Ensemble Layer: Differentiability meets Conditional Computation (PDF) . International Conference on Machine Learning. PMLR. Wikipedia revision 1356968454, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1356968454
    Cite this reference

    MLA "Hazimeh, Hussein; Ponomareva, Natalia; Mol, Petros; Tan, Zhenyu; Mazumder, Rahul (2020). The Tree Ensemble Layer: Differentiability meets Conditional Computation (PDF) . International Conference on Machine Learning. PMLR. Wikipedia revision 1356968454, retrieved 2026-11-18." Hazimeh, Hussein; Ponomareva, Natalia; Mol, Petros; Tan, Zhenyu; Mazumder, Rahul (2020). 2026-11-17. https://proceedings.icml.cc/static/paper_files/icml/2020/2974-Paper.pdf. Accessed 24 November 2026.

    Chicago "Hazimeh, Hussein; Ponomareva, Natalia; Mol, Petros; Tan, Zhenyu; Mazumder, Rahul (2020). The Tree Ensemble Layer: Differentiability meets Conditional Computation (PDF) . International Conference on Machine Learning. PMLR. Wikipedia revision 1356968454, retrieved 2026-11-18." Hazimeh, Hussein; Ponomareva, Natalia; Mol, Petros; Tan, Zhenyu; Mazumder, Rahul (2020). 2026-11-17. https://proceedings.icml.cc/static/paper_files/icml/2020/2974-Paper.pdf.

    APA Hazimeh, Hussein; Ponomareva, Natalia; Mol, Petros; Tan, Zhenyu; Mazumder, Rahul (2020). (2026). Hazimeh, Hussein; Ponomareva, Natalia; Mol, Petros; Tan, Zhenyu; Mazumder, Rahul (2020). The Tree Ensemble Layer: Differentiability meets Conditional Computation (PDF) . International Conference on Machine Learning. PMLR. Wikipedia revision 1356968454, retrieved 2026-11-18. Retrieved November 24, 2026, from https://proceedings.icml.cc/static/paper_files/icml/2020/2974-Paper.pdf

  5. Advanced Real-Time Shader Techniques · retrieved 2022-04-15 · rev 1356968454
    Cite this reference

    MLA "Advanced Real-Time Shader Techniques." Natalya Tatarchuk (2003). 2022-04-15. https://web.archive.org/web/20210530183247/https://developer.amd.com/wordpress/media/2012/10/Tatarchuk-Siggraph2003.pps. Accessed 24 November 2026.

    Chicago "Advanced Real-Time Shader Techniques." Natalya Tatarchuk (2003). 2022-04-15. https://web.archive.org/web/20210530183247/https://developer.amd.com/wordpress/media/2012/10/Tatarchuk-Siggraph2003.pps.

    APA Natalya Tatarchuk (2003). (2022). Advanced Real-Time Shader Techniques. Retrieved November 24, 2026, from https://web.archive.org/web/20210530183247/https://developer.amd.com/wordpress/media/2012/10/Tatarchuk-Siggraph2003.pps

  6. Texturing and Modeling, Third Edition: A Procedural Approach . Wikipedia revision 1356968454, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1356968454
    Cite this reference

    MLA "Texturing and Modeling, Third Edition: A Procedural Approach . Wikipedia revision 1356968454, retrieved 2026-11-18." Texturing and Modeling, Third Edition: A Procedural Approach. 2026-11-17. https://www.amazon.com/Texturing-Modeling-Third-Procedural-Approach/dp/1558608486. Accessed 24 November 2026.

    Chicago "Texturing and Modeling, Third Edition: A Procedural Approach . Wikipedia revision 1356968454, retrieved 2026-11-18." Texturing and Modeling, Third Edition: A Procedural Approach. 2026-11-17. https://www.amazon.com/Texturing-Modeling-Third-Procedural-Approach/dp/1558608486.

    APA Texturing and Modeling, Third Edition: A Procedural Approach. (2026). Texturing and Modeling, Third Edition: A Procedural Approach . Wikipedia revision 1356968454, retrieved 2026-11-18. Retrieved November 24, 2026, from https://www.amazon.com/Texturing-Modeling-Third-Procedural-Approach/dp/1558608486

  7. General smoothstep equation . Wikipedia revision 1356968454, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1356968454
    Cite this reference

    MLA "General smoothstep equation . Wikipedia revision 1356968454, retrieved 2026-11-18." General smoothstep equation. 2026-11-17. https://stackoverflow.com/q/41195063. Accessed 24 November 2026.

    Chicago "General smoothstep equation . Wikipedia revision 1356968454, retrieved 2026-11-18." General smoothstep equation. 2026-11-17. https://stackoverflow.com/q/41195063.

    APA General smoothstep equation. (2026). General smoothstep equation . Wikipedia revision 1356968454, retrieved 2026-11-18. Retrieved November 24, 2026, from https://stackoverflow.com/q/41195063

Cite this article

MLA

"smoothstep." encyclopegia.org, 2026, https://encyclopegia.org/wiki/smoothstep. Accessed 24 November 2026.

Chicago

"smoothstep." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/smoothstep.

APA

encyclopegia.org. (2026). smoothstep. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/smoothstep

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

CC BY-SA 4.0 · tier1-factual · https://en.wikipedia.org/w/index.php?oldid=1356968454 · 0.55 · snapshot smoothstep-849178-efd8601d83325500 · QID Q7546464

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.