Lerp

Math | Sunday 5 October 2008 6:57 pm

Lerp is the procedure to interpolate between two vectors with a specified weight. An example below

float weight; // the weight for lerping
 
vec2 input1, input2; // the inputs to lerp between
 
vec2 lerpResult = input1(1.0-weight)+input2(weight);

In GLSL it’s named mix( genType, genType, float ) instead of lerp which can be misleading. But when testing, it actually works to use lerp instead of mix in GLSL shaders when running them on a Nvidia GeForce 8800GTS although it’s not recommended.

Here’s the OpenGL GLSL quick reference guide which contains all functions you can use inside of a shader (and much more).
 http://www.opengl.org/sdk/libs/OpenSceneGraph/glsl_quickref.pdf

Please share:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Current
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • StumbleUpon
  • Twitter
  • Reddit
  • Technorati
  • Yahoo! Bookmarks

4 Comments »

  1. Comment by ancestral — February 7, 2009 @ 11:42 am

    Oh my god. This was a life saver.

    I’ve been playing around with NVIDIA’s cg, modifying game files for Europa Universalis III and let me tell you, cg/glsl info is kind of hard to get.

    Thank you for this page.

  2. Comment by Dave — May 23, 2009 @ 7:49 pm

    x*(1-s) + y*s can equivalently be written as x + s(y-x)
    Doing this saves an operation.

  3. Comment by admin — May 23, 2009 @ 11:59 pm

    Yes, nice catch. But it was merely an example of showing how lerp is done, and I tried to do it as simple as possible.

  4. Comment by marc dion — July 30, 2010 @ 1:27 am

    Thanks..I was gonna do it the hard way. lerp() is mix() ha! Thanks.

RSS feed for comments on this post. TrackBack URI

Leave a comment