Advertisement
Guest User

Tetrahexacontree Voxel Volume Raymarching

a guest
Aug 3rd, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. variables
  2.  
  3. tree bounding box (bounds)
  4. tree root node index
  5. nodes -- array of tree nodes
  6. volumes -- array of tree voxel volumes:
  7. far -- far clipping plane distance
  8. near -- near clipping plane distance
  9. origin -- ray origin
  10. direction -- ray direction
  11. t -- t distance along ray (starts at near)
  12. ray location -- origin + (direction * t)
  13. width -- width of child node bounds
  14. bounds0 -- bounds of current node
  15. bounds1 -- bounds of voxel volume
  16. stack -- stack of bounding boxes (bounds) and tree node indices
  17. frame -- current bounding box (bounds) and tree node index
  18. current node -- tree.nodes[index] or tree.nodes[frame.index]
  19. current volume -- tree.volumes[index]
  20.  
  21. algorithm
  22.  
  23. * if tree bounds does not contain ray
  24. * updated ray with intersection of ray with tree bounds
  25. * if fails
  26. * return far
  27. * initialize width with tree bounds width divided by four
  28. * initialize stack
  29. * push tree bounds and tree node root index on to stack
  30. * set frame equal to value from top of stack
  31. * while true
  32. * set bounds0 to bounds of current node based on width and ray location -- use ray location aligned by width to calculate min and max of bounds
  33. * calculate octlet of child node based on frame bounds, ray location and width
  34. * if current node's child (nodes[frame.index].chilren[octlet]) is that of a valid child node (not null sentinal)
  35. * adjust frame bounds based on ray location
  36. * set frame index to index of child node
  37. * if width equal to four times that of a voxel volume width
  38. * while true
  39. * calculate bounds (bounds1) of voxel volume based on width divided by four
  40. * calculate octlet of voxel volume based on frame bounds, ray location and width divided by four
  41. * if current node's child (nodes[frame.index].chilren[octlet]) is that of a valid child node (not null sentinal)
  42. * get volume based on frame index and octlet (volumes_[nodes_[frame.index].child(octlet)]
  43. * initialize digital differential (dda) analizer from ray's origin, direction and t
  44. * while true -- step through volume's voxel using dda
  45. * convert dda's location to volume coordinates
  46. * if non-air voxel hit in volume at converted coordinates
  47. * return t and hit location
  48. * increment dda
  49. * if dda t greater than far, return far
  50. * if location of dda beyond bounds of volume (bounds1)
  51. * break from loop
  52. * set ray's t to that of dda's t
  53. * if ray location outside frame bounds
  54. * if ray's t greater than far or ray location outside of tree bounds
  55. * return far
  56. * break from loop
  57. * else
  58. * calculate intersection of next potential volume using volume's bounds (bounds1) and update ray location
  59. * if intersection fails, ray t greater than far or ray location outside of tree bounds
  60. * return far
  61. * if ray location outside of frame bounds, break from loop
  62. * if stack size == 1
  63. * set frame to value at top of stack (frame = stack.top())
  64. * else
  65. * pop from stack into frame until frame has ray location multiplying width by four for each pop
  66. * else
  67. * push frame onto stack
  68. * divide width by four
  69. * else
  70. * calculate intersection of next potential node using current node's bounds (bounds0) and update ray location
  71. * if intersection fails, ray's t greater than far or ray location outside of tree bounds
  72. * return far
  73. * if stack size == 1
  74. * set frame to value at top of stack
  75. * else
  76. * if ray location outside of frame bounds
  77. * pop from stack into frame until frame has ray location multiplying width by four for each pop
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement