|
@ -6,8 +6,14 @@ |
|
|
# include "gp/math/fp_math.hpp"
|
|
|
# include "gp/math/fp_math.hpp"
|
|
|
#endif
|
|
|
#endif
|
|
|
#include "gp/algorithm/repeat.hpp"
|
|
|
#include "gp/algorithm/repeat.hpp"
|
|
|
|
|
|
#include "gp/algorithm/min_max.hpp"
|
|
|
|
|
|
|
|
|
namespace gp { |
|
|
namespace gp { |
|
|
|
|
|
template<typename T> |
|
|
|
|
|
T lerp(T input, T low, T high) { |
|
|
|
|
|
return low + (high - low) * input; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
template<typename T, size_t fixed_passes = 16> |
|
|
template<typename T, size_t fixed_passes = 16> |
|
|
T fixed_sqrt(T value) { |
|
|
T fixed_sqrt(T value) { |
|
|
if(value == 0) return 0; |
|
|
if(value == 0) return 0; |
|
@ -101,6 +107,10 @@ namespace gp { |
|
|
T ilen = fast_isqrt(x*x+y*y); |
|
|
T ilen = fast_isqrt(x*x+y*y); |
|
|
return {x*ilen, y*ilen}; |
|
|
return {x*ilen, y*ilen}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
T length() { |
|
|
|
|
|
return fixed_sqrt(x*x+y*y); |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
template<typename T = gp_config::rendering::default_type> |
|
|
template<typename T = gp_config::rendering::default_type> |
|
@ -175,6 +185,10 @@ namespace gp { |
|
|
T ilen = fast_isqrt(x*x+y*y+z*z); |
|
|
T ilen = fast_isqrt(x*x+y*y+z*z); |
|
|
return {x*ilen, y*ilen, z*ilen}; |
|
|
return {x*ilen, y*ilen, z*ilen}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
T length() { |
|
|
|
|
|
return fixed_sqrt(x*x+y*y+z*z); |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
template<typename T = gp_config::rendering::default_type> |
|
|
template<typename T = gp_config::rendering::default_type> |
|
@ -260,8 +274,41 @@ namespace gp { |
|
|
T ilen = fast_isqrt(x*x+y*y+z*z+w*w); |
|
|
T ilen = fast_isqrt(x*x+y*y+z*z+w*w); |
|
|
return {x*ilen, y*ilen, z*ilen, w*ilen}; |
|
|
return {x*ilen, y*ilen, z*ilen, w*ilen}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
T length() { |
|
|
|
|
|
return fixed_sqrt(x*x+y*y+z*z+w*w); |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
template<typename T> |
|
|
|
|
|
auto sphere_sdf(vec3_g<T> center, T radius) { |
|
|
|
|
|
return [=](vec3_g<T> position) -> T const { |
|
|
|
|
|
auto p = position - center; |
|
|
|
|
|
return p.length() - radius; |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<typename T, typename lhs, typename rhs> |
|
|
|
|
|
auto union_sdf(lhs _l, rhs _r) { |
|
|
|
|
|
return [=](vec3_g<T> position) -> T const { |
|
|
|
|
|
return gp::min(_l(position), _r(position)); |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<typename T, typename lhs, typename rhs> |
|
|
|
|
|
auto intersect_sdf(lhs _l, rhs _r) { |
|
|
|
|
|
return [=](vec3_g<T> position) -> T const { |
|
|
|
|
|
return gp::max(_l(position), _r(position)); |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<typename T, typename lhs, typename rhs> |
|
|
|
|
|
auto difference_sdf(lhs _l, rhs _r) { |
|
|
|
|
|
return [=](vec3_g<T> position) -> T const { |
|
|
|
|
|
return gp::max(_l(position), -_r(position)); |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
template<typename T> |
|
|
template<typename T> |
|
|
vec2_g<T> operator*(vec2_g<T> p, T v) { |
|
|
vec2_g<T> operator*(vec2_g<T> p, T v) { |
|
|
return {p.x*v, p.y*v}; |
|
|
return {p.x*v, p.y*v}; |
|
|