Jump to content
  • Advertisement
Sign in to follow this  
sipickles

In/Out Lerp in one function

This topic is 3808 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!