Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float getValueBilinearClamp( float x, float y ) const
- {
- // Clamp negatives to zero (to get correct sub-pixel offset).
- x = max(0.f, x);
- y = max(0.f, y);
- // Separate floats into wholes (pixels) and fractions
- const int xi = (int)x;
- const int yi = (int)y;
- // Fraction
- const float xFract = (x - xi);
- const float yFract = (y - yi);
- // Clamp to max
- const int w = mapWidth - 1;
- const int h = mapHeight - 1;
- const int xi0 = min(xi, w);
- const int yi0 = min(yi, h);
- const int xi1 = min(xi + 1, w);
- const int yi1 = min(yi + 1, h);
- // Read pixels.
- const float s00 = getValue(xi0, yi0);
- const float s10 = getValue(xi1, yi0);
- const float s01 = getValue(xi0, yi1);
- const float s11 = getValue(xi1, yi1);
- // Bilinear filter
- const float bx0 = lerp(xFract, s00, s10);
- const float bx1 = lerp(xFract, s01, s11);
- return lerp(yFract, bx0, bx1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement