• Advertisement
Sign in to follow this  

In/Out Lerp in one function

This topic is 3628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I often find myself writing conditionals to produce a function which lerps from min to max to min. Eg:

inline float Lerp( const float& a, const float& b, const float& t )
{
	return ( b * t + a * ( 1.0f - t ) );
}

inline float MinMaxMin( const float& a, const float& b, const float& t )
{
	if ( t < 0.5f )
		return Lerp( a, b, t * 2.0f );
	else
		return Lerp( b, a, t * 2.0f - 1.0f );
}


As Lerp() is represented without using a conditional, is there a way to do the same for MinMaxMin()? I could work it out if my head wasn't spinning! Your fresh perspective may help me! Thanks Si

Share this post


Link to post
Share on other sites
Advertisement
If your platform supports a non-branching absolute value instruction you can use a factor of 1-2*abs(t-0.5).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement