scene-abstraction.txt 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. Create a new scene organisation that follows some rules:
  2. - Be extendable from outside AnKi
  3. - Has a simple interface and correct containers
  4. - Be able to fast cast and fast check type (llvm isa<>)
  5. Every scene node has a few properties that are actually interfaces. This interfaces are:
  6. +========================+==================+===================================+=====================+
  7. | Class name | Base class | Interface | Used |
  8. +========================+==================+===================================+=====================+
  9. | BaseRenderable | - | - getVao(level, type) | - |
  10. | | | - getVertIdsNum(level, type) | |
  11. | | | - getModelMatrix(level, type) | |
  12. +------------------------+------------------+-----------------------------------+---------------------+
  13. | Renderable | BaseRenderable | - getMaterial | PatchNode |
  14. | | VisibleCheckable | - getMaterialRuntime (Mutable) | |
  15. | | | - getMaterialRuntime (Const) | |
  16. | | | - renderInMs (its not virtual) | |
  17. +------------------------+------------------+-----------------------------------+---------------------+
  18. | DebugRenderable | BaseRenderable | - | Camera, Light |
  19. +------------------------+------------------+-----------------------------------+---------------------+
  20. | IsRenderable | BaseRenderable | getShaderProgram | Light |
  21. +------------------------+------------------+-----------------------------------+---------------------+
  22. | VisiblesContainable | - | - getVisiblesInfo | Camera, Light |
  23. | | | - testFrustum(VisibleCheckable) | |
  24. +------------------------+------------------+-----------------------------------+---------------------+
  25. | VisibleCheckable | - | getCollisionShape | Camera, Light, |
  26. | | | | ModelNode, SkinNode,|
  27. | | | | PatchNode |
  28. +------------------------+------------------+-----------------------------------+---------------------+
  29. | RenderablesContainable | - | - getRenderables | ModelNode, SkinNode |
  30. | | | - nodesInheritCollisionShape | |
  31. +------------------------+------------------+-----------------------------------+---------------------+
  32. | Projectable | - | - getViewMatrix | Light, Camera |
  33. | | | - getProjectionMatrix | |
  34. +------------------------+------------------+-----------------------------------+---------------------+
  35. - VisibleCheckable
  36. - getCollisionShape [virtual]
  37. - getVisible
  38. - setVisible
  39. - getVisibilityGroup
  40. - Renderable
  41. - material [virtual]
  42. - getVao(level, passType) [virtual]
  43. - Light (aka IsRenderable)
  44. - getMaterialRuntime [virtual]
  45. - getVao() [virtual]
  46. - VisiblesContainable
  47. - N * M sceneNodes where N is 4 (renderables and lights) and M is the number of the scene nodes
  48. - testFrustum(VisibleCheckable)
  49. - RenderablesContainable
  50. - N * SceneNode
  51. - nodesInheritCollisionShape
  52. PatchNode: Renderable, VisibleCheckable
  53. Light: IsRenderable, VisibleCheckable, VisiblesContainable
  54. Camera: VisibleCheckable, VisiblesContainable
  55. ModelNode: VisibleCheckable, RenderablesContainable
  56. Rendering passes:
  57. - Level n
  58. - Color
  59. - Depth
  60. - DepthParaboloid
  61. - Debug
  62. Other classes:
  63. **BaseRenderableInfo**: Contains a class with public interface of:
  64. -
  65. **VisiblesInfo**: Contains the lists of:
  66. - Renderables
  67. - renderables in MS
  68. - renderables in BS
  69. - IsRenderables
  70. - point lights
  71. - spot lights
  72. ==================
  73. Visibility testing
  74. ==================
  75. In visibility testing we gather the visible renderables of MS and BS and the lights for IS. Also for every visible light we gather the renderables.
  76. Real flow:
  77. function test(cam)
  78. for
  79. endfunction
  80. ::
  81. function test(Camera cam)
  82. for node in scene's nodes
  83. set node not visible
  84. endfor
  85. for rcn in all scene's renderablesContainableNodes
  86. if rcn not inside cam's frustum
  87. break
  88. endif
  89. set rcn to visible
  90. # eg skin
  91. if rcn renderablesInheritContainingCollisionShape
  92. for renderable in rcn's renderables
  93. set renderable visible
  94. put renderable in cam's container
  95. endfor
  96. # eg model node
  97. else
  98. for renderable in rcn's renderables
  99. if renderable inside cam frustum
  100. put renderable in cam's container
  101. endif
  102. endfor
  103. endif
  104. endif
  105. endfor
  106. for l in all scene's lights
  107. if l inside cam's frustum
  108. put l in cam's container
  109. if l is shadow caster
  110. test(l)
  111. endif
  112. endfor
  113. endfor
  114. endfunction
  115. - Find all the octree nodes that are inside the given frustum
  116. - Norrow down them using the Renderer and other tests
  117. - For all those octree nodes get the scene nodes
  118. - Resolve buckets
  119. - Finaly call SceneNode::visibleUpdate() for all visibles
  120. Method declaration: void performVisibilityTests(const Octree&, const Frustum&, const Renderer&, uint passMask);
  121. The Renderer is for hardware occlusion queries
  122. =========
  123. Rendering
  124. =========
  125. ::
  126. function render(VisiblesContainable obj, PassType pt)
  127. for renderable obj's renderables
  128. level = calc from distance of obj and renderable
  129. setupShaderProgram for obj in pt and level
  130. render using vao of level
  131. endfor
  132. endfunction
  133. ========
  134. Problems
  135. ========
  136. - All properties should contain the world transform
  137. - What happens in a second pass for other camera (for split screen for example). Now the renderings happen sequential so no problem. It may fuck up the visibility vectors
  138. ====
  139. ToDo
  140. ====
  141. - Move update redesign
  142. - First update the world transforms for all nodes
  143. - then for the nodes that have moved (we allready keep the previ world transform) call the SceneNode::moveUpdate
  144. ===
  145. xxx
  146. ===
  147. Scene
  148. - N x SceneNode
  149. - 1 x Octree
  150. - Update transforms
  151. - Call move updates if moved
  152. SceneObject
  153. StaticObject: SceneObject
  154. SceneNode: SceneObject
  155. - static | moving
  156. - TRF
  157. - parent & children
  158. Renderable
  159. - stage? MS | BS | LS | DBG
  160. - material
  161. - world transform [for moving]
  162. - collision shape [for moving]
  163. Frustum
  164. - N x renderables