Ember

Tangents

Jul 19th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. float3 d1 = v2 - v1;
  2. float3 d2 = v3 - v1;
  3.  
  4. float2 st1 = w2 - w1;
  5. float2 st2 = w3 - w1;
  6.  
  7. float r = 1.0F / (s1 * t2 - s2 * t1);
  8.  
  9. Vector3D sdir((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
  10. Vector3D tdir((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
  11.  
  12. t1[i1] = sdir;
  13. t1[i2] = sdir;
  14. t1[i3] = sdir;
  15. t2[i1] = tdir;
  16. t2[i2] = tdir;
  17. t2[i3] = tdir;
  18.  
  19. // Gram-Schmidt orthogonalize
  20. tangent = normalize(t1 - n * dot(n, t));
  21.  
  22. // Calculate handedness
  23. tangent.w = (dot(cross(n, t), t2) < 0.0F) ? -1.0F : 1.0F;
Advertisement
Add Comment
Please, Sign In to add comment