summaryrefslogtreecommitdiffstats
path: root/math.cginc
diff options
context:
space:
mode:
Diffstat (limited to 'math.cginc')
-rwxr-xr-xmath.cginc8
1 files changed, 8 insertions, 0 deletions
diff --git a/math.cginc b/math.cginc
index 0692440..270ca15 100755
--- a/math.cginc
+++ b/math.cginc
@@ -334,4 +334,12 @@ float3 srgb_to_linear(float3 srgb_color) {
return lerp(lo, hi, step(0.04045f, srgb_color));
}
+float3x3 tbn_from_normal_tangent(float3 normal, float4 tangent) {
+ float3 n = normal;
+ float3 t = tangent.xyz;
+ t = normalize(t - n * dot(n, t)); // Gram-Schmidt to avoid skew
+ float3 b = normalize(cross(n, t)) * tangent.w;
+ return float3x3(t, b, n);
+}
+
#endif // __MATH_INC