setViewCull.lua 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. return {
  2. tag = 'pipeline',
  3. summary = 'Enable or disable view frustum culling.',
  4. description = [[
  5. Enables or disables view frustum culling. When enabled, if an object is drawn outside of the
  6. camera view, the draw will be skipped. This can improve performance.
  7. ]],
  8. arguments = {
  9. enable = {
  10. type = 'boolean',
  11. description = 'Whether frustum culling should be enabled.'
  12. }
  13. },
  14. returns = {},
  15. variants = {
  16. {
  17. arguments = { 'enable' },
  18. returns = {}
  19. }
  20. },
  21. notes = [[
  22. View frustum culling is disabled by default.
  23. Objects will be culled against all views in the Pass. The pose and projection for these views
  24. is controlled using `Pass:setViewPose` and `Pass:setProjection`.
  25. View frustum culling will increase CPU usage, but will reduce GPU usage depending on how many
  26. objects get culled and how many vertices they have.
  27. For most scenes that draw objects all around the camera, frustum culling will usually result in
  28. large speedups. However, it's always good to measure to be sure. For example, if every object
  29. drawn is in view, then frustum culling will only make things slower, because LÖVR will spend
  30. time checking if objects are in view without actually culling any of them.
  31. `Pass:getStats` will return `draws` and `drawsCulled` fields. The `submitTime` and `gpuTime`
  32. fields (with `lovr.graphics.setTimingEnabled`) are a good way to measure the impact of culling.
  33. To cull an object against a view frustum, LÖVR needs to know the object's bounding box. The
  34. following types of draws have bounding boxes:
  35. - `Pass:plane`
  36. - `Pass:roundrect`
  37. - `Pass:cube`
  38. - `Pass:box`
  39. - `Pass:circle`
  40. - `Pass:sphere`
  41. - `Pass:cylinder`
  42. - `Pass:cone`
  43. - `Pass:capsule`
  44. - `Pass:torus`
  45. - `Pass:draw` (see notes below for `Model` and `Mesh` objects)
  46. The following draws do **not** currently have bounding boxes, and will not be culled:
  47. - `Pass:points`
  48. - `Pass:line`
  49. - `Pass:text`
  50. - `Pass:skybox`
  51. - `Pass:fill`
  52. - `Pass:mesh`
  53. `Model` objects only compute their bounding box when they're loaded, using the initial node
  54. transforms. If a node's transform changes, either manually with `Model:setNodeTransform` or from
  55. an animation, then the bounding box will become out of sync and culling will not work properly.
  56. View culling should be disabled when rendering these models.
  57. `Mesh` objects will not have a bounding box by default. Meshes with a storage type of `cpu` can
  58. compute their bounding boxes using `Mesh:computeBoundingBox`, which should be called after
  59. creating the Mesh or whenever its vertices change. Any type of Mesh can have its bounding box
  60. set manually using `Mesh:setBoundingBox`. This can be faster than `Mesh:computeBoundingBox` if
  61. the bounding box is already known, and is the only way to give a `gpu` Mesh a bounding box.
  62. ]],
  63. related = {
  64. 'Pass:setCullMode',
  65. 'Mesh:computeBoundingBox',
  66. 'Mesh:setBoundingBox',
  67. 'Pass:setViewPose',
  68. 'Pass:setProjection'
  69. }
  70. }