summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-12-28 23:59:46 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-12-28 23:59:46 +0000
commitb6af53eeffc6c518248b269ee1839fcc3e9bdf22 (patch)
treea0b8a76b9e7717c452e96b661b21da41376a28dc
parentReduce size of shadow map texture (diff)
downloadilt-b6af53eeffc6c518248b269ee1839fcc3e9bdf22.tar.bz2
ilt-b6af53eeffc6c518248b269ee1839fcc3e9bdf22.tar.xz
ilt-b6af53eeffc6c518248b269ee1839fcc3e9bdf22.zip
Add helper to apply perspective division
Returns vec3 by default, but dimensions can be specified
-rw-r--r--lib/maths.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/maths.h b/lib/maths.h
index 5bb69d3..c651af5 100644
--- a/lib/maths.h
+++ b/lib/maths.h
@@ -80,6 +80,13 @@ ratio(glm::vec<2, T, Q> v)
return ratio<R>(v.x, v.y);
}
+template<glm::length_t L = 3, typename T, glm::qualifier Q>
+inline constexpr glm::vec<L, T, Q>
+perspective_divide(glm::vec<4, T, Q> v)
+{
+ return v / v.w;
+}
+
constexpr inline glm::vec2
operator!(const glm::vec3 & v)
{