Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. implicit cube-to-simplex subdivision
  3.  
  4. fn cube-simplex (pred)
  5. """"ivec3 ivec3 ivec3 ivec3 <- ivec3
  6. for three coordinate predicates
  7. r: y <= z, g: z < x, b: x < y
  8. return the two defining vertices of the simplex that the coordinate is in
  9. and the four planes required for computing barycentric coordinates
  10. the resulting simplex has the corners (0 0 0) v1 v2 (1 1 1)
  11. the planes are ordered so that each plane is opposite each defining vertex
  12. e1 := pred.gbr
  13. e2 := 1 - pred.brg
  14. p1 := e1 & e2
  15. p2 := e1 | e2
  16. plane0 := -p1
  17. plane1 := p1 * 2 - p2
  18. plane2 := 2 * p2 - p1 - 1
  19. plane3 := 1 - p2
  20. return p1 p2 plane0 plane1 plane2 plane3
  21.  
  22. fn cube-simplex-bary (p)
  23. """"vec4 ivec3 ivec3 <- vec3
  24. for a cube coordinate in the range (0..1 0..1 0..1)
  25. return the barycentric coordinate within the sub-simplex of the cube
  26. as well as the two defining vertices of the simplex with
  27. corners (0 0 0) v1 v2 (1 1 1)
  28. pred :=
  29. ivec3
  30. ? (p.y <= p.z) 1 0
  31. ? (p.z < p.x) 1 0
  32. ? (p.x < p.y) 1 0
  33. let p1 p2 n0 n1 n2 n3 = (cube-simplex pred)
  34. let w0 w1 w3 =
  35. (dot p (vec3 n0)) + 1.0
  36. dot p (vec3 n1)
  37. dot p (vec3 n3)
  38. w2 := 1.0 - w0 - w1 - w3
  39. return (vec4 w0 w1 w2 w3) p1 p2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement