Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
texture_utilities.h
Go to the documentation of this file.
1
4// WARNING: do not include this header file in any .cpp file or any .h file that
5// would be included into a .cpp file because tex2D is undefined when compiling
6// with gcc.
7
8#pragma once
9
10#include <math.h>
11
12#include "../global/global.h"
13#include "../utils/gpu.hpp"
14
15inline __device__ float lerp(float v0, float v1, float f) { return fma(f, v1, fma(-f, v0, v0)); }
16
17/* \fn float Bilinear_Texture(cudaTextureObject_t tex, float x, float y)
18 \brief Access texture values from tex at coordinates (x,y) using bilinear
19 interpolation
20*/
21inline __device__ float Bilinear_Texture(cudaTextureObject_t tex, float x, float y)
22{
23 // Split coordinates into integer px/py and fractional fx/fy parts
24 float px = floorf(x);
25 float py = floorf(y);
26 float fx = x - px;
27 float fy = y - py;
28
29 // 0.5 offset is necessary to represent half-pixel offset built into texture
30 // coordinates
31 px += 0.5;
32 py += 0.5;
33
34 float t00 = tex2D<float>(tex, px, py);
35 float t01 = tex2D<float>(tex, px, py + 1);
36 float t10 = tex2D<float>(tex, px + 1, py);
37 float t11 = tex2D<float>(tex, px + 1, py + 1);
38 // The inner lerps interpolate along x
39 // The outer lerp interpolates along y
40 return lerp(lerp(t00, t10, fx), lerp(t01, t11, fx), fy);
41}