summaryrefslogtreecommitdiffstats
path: root/math.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-03-25 17:38:45 -0700
committeryum <yum.food.vr@gmail.com>2025-03-25 17:38:45 -0700
commit2d49d9db4712ae3cbd604ec7c9f8627e4f74bde6 (patch)
treed047130a222bc4464b3e92035019fa38201f7e6d /math.cginc
parent2a5186af2dce81d7d630f2969cfc5bcf2e2ddd66 (diff)
Add shatter wave gimmick
Diffstat (limited to 'math.cginc')
-rw-r--r--math.cginc20
1 files changed, 20 insertions, 0 deletions
diff --git a/math.cginc b/math.cginc
index f44aa74..78b93ec 100644
--- a/math.cginc
+++ b/math.cginc
@@ -207,4 +207,24 @@ float median(float3 x) {
return (x.r + x.g + x.b) - (x_min + x_max);
}
+// Quaternions
+float4 qmul(float4 q1, float4 q2)
+{
+ return float4(
+ q2.xyz * q1.w + q1.xyz * q2.w + cross(q1.xyz, q2.xyz),
+ q1.w * q2.w - dot(q1.xyz, q2.xyz));
+}
+
+// Vector rotation with a quaternion
+// http://mathworld.wolfram.com/Quaternion.html
+float3 rotate_vector(float3 v, float4 r)
+{
+ float4 r_c = r * float4(-1, -1, -1, 1);
+ return qmul(r, qmul(float4(v, 0), r_c)).xyz;
+}
+
+float4 get_quaternion(float3 axis_normal, float theta) {
+ return float4(axis_normal * sin(theta / 2), cos(theta / 2));
+}
+
#endif // __MATH_INC