3

I'm trying to get some results to plot on a graph by using the Smoothstep function provided by AMD which was fount on this Wikipedia page Smoothstep. Using the;

A C/C++ example implementation provided by AMD[4] follows.

float smoothstep(float edge0, float edge1, float x)
{
    // Scale, bias and saturate x to 0..1 range
    x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
    // Evaluate polynomial
    return x*x*(3 - 2 * x);
}

The problem is that I am not able to use this method due to the static method clamp not being available.

I have imported the following;

#include <math.h> 
#include <cmath> 
#include <algorithm>  

Yet there is no clamp method defined.

My maths skill is not the best, but is there a way to implement the Smoothstep function just like there is way to implement a LERP function;

float linearIntepolate(float currentLocation, float Goal, float time){

    return (1 - time) * currentLocation + time * Goal;
}
hippietrail
  • 15,848
  • 18
  • 99
  • 158
Moynul
  • 635
  • 1
  • 8
  • 30

1 Answers1

4

Perhaps it was just the namespace "std" which was missing : here is my code that compile :

#include <algorithm>

float smoothstep(float edge0, float edge1, float x) {
    // Scale, bias and saturate x to 0..1 range
    x = std::clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
    // Evaluate polynomial
    return x * x * (3 - 2 * x);
}