Added some more useful math functions

This commit is contained in:
Martin committed 2025-01-09 11:53:28 +01:00
1 parent cc8ef12508
commit b107a2a6de
2 files changed
+23

No files matched your search

+16
View File
@@ -44,3 +44,19 @@ __device__ unsigned int packUnorm4x8(float r, float g, float b, float a) {
return u.out;
}
// Clamp a value between a min and max value
__device__ float clamp(float value, float min, float max) {
return fmaxf(min, fminf(value, max));
}
// Normalize a float to the range [0, 1]
__device__ float normalize(float value, float min, float max) {
return (value - min) / (max - min);
}
// Interpolate between two values
template <typename T>
__device__ T interpolate(T start, T end, float t) {
return start + t * (end - start);
}
+7
View File
@@ -7,4 +7,11 @@ __device__ Vec3 computeGradient(float* volumeData, const int volW, const int vol
__device__ unsigned int packUnorm4x8(float r, float g, float b, float a);
__device__ float clamp(float value, float min, float max);
__device__ float normalize(float value, float min, float max);
template <typename T>
__device__ float interpolate(T start, T end, float t);
#endif // MAT_H
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.