Renderer.txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. To get it to compile:
  2. - Add dummy material that will be used when material is not loaded
  3. - Actually implement core render methods in Renderer
  4. - Go through all changes on commit and see if anything else needs doing
  5. Next stage:
  6. - Track material changes
  7. - Figure out how to update material data buffers only when material actually changes (shader or parameters)
  8. - Should each object have their own set of buffers instead of just updating material ones per frame? Probably.
  9. - Although I should still have an option to use a shared block that isn't per object.
  10. - Add sort type, priority and separable pass options to Shader (and its RTTI)
  11. - Implement RenderQueue sorting with support for sort type, priority and separable pass
  12. - Document elements marked with TODO UNDOCUMENTED
  13. - Add Renderer <-> Material interface matching
  14. - Allow parameter blocks to be specified as one-time, per-frame, per-object, etc.
  15. - Actually add frustum culling
  16. Finally
  17. - Refactor/rename everything so it makes more sense. Possibly lay out a design diagram.
  18. - Get rid of Camera::getIgnoreSceneRenderables it can be doing using layers
  19. - Delete RenderOperation as I don't think I use it anymore
  20. -----------------------------------------
  21. While I am on this also consider working on how will parameter matching between Renderer and Material work (e.g. when rendering with
  22. shadows or lighting the renderer will expect materials to have certain parameters used for those effects)
  23. - Make it a separate GPU param buffer? RendererOneTime, RendererPerFrame, RendererPerObject
  24. Each renderer can specify which Renderable types it supports.
  25. - Renderable can have various options like shadow, no shadow, animation, etc.
  26. - Together those options result in an Enum describing the type of Renderable
  27. Each renderer can specify a set of parameters it needs from a material, per Renderable type
  28. - e.g. "Matrix4 viewProjTfrm" for BasicRenderable type
  29. When a Material is hooked up to a Renderable is will check if the Material has the required parameters.
  30. - If not that object will be drawn using a dummy (most basic) shader.
  31. - Optionally the parameters are grouped into parameter blocks e.g. RendererOneTime, RendererPerFrame, RendererPerObject.
  32. - If a parameter block is detected by the renderer it will only update those parameters once when they are needed, and reuse
  33. them in all materials. If no parameter block is detected the parameters will be updated on all objects whenever it is changed.
  34. - I will potentially need to add parameter block semantic to Shader in order to make the user able to specify which blocks
  35. are for the renderer. (And so that Material knows not to create those buffers manually)
  36. ---------------------------
  37. Just notes for later potentially:
  38. - I can only update entire Mesh at once.
  39. - I keep bounds for the entire mesh and not per-submesh
  40. - I don't serialize bounds and they are recalculated whenever a mesh is loaded
  41. OLD:
  42. Since DrawHelper needs to queue render commands together with scene objects (in order for transparency to work okay), I will need to implement the RenderOperation approach I thought about earlier.
  43. Rename current RenderOperation to SubMeshData
  44. Real render operations contains SubMeshData + layer (can be filtered per-camera) + queue (each mesh has a queue and another queue by camera) + Pass
  45. (Remove Camera->rendersSceneObjects and replace it with layer)
  46. (Make sure to set up preset queues, like opaque, transparent, etc)
  47. Then I can hook up GUIManager, OverlayManager and DrawHelper with a callback that is used by Renderer to retrieve their operations
  48. Attempt to move all sorting (including by render target) out of forward renderer and into an overridable sorter class
  49. - Create a hash list with key(containing type, queue, layer, etc.) used for sorting
  50. Add "materialGroup" to material. It can be used for sorting similar materials together, instead of using some automatic way of determining it.
  51. Issues with my render operation system:
  52. Sorting by depth is impossible because I don't provide any position info with my RenderOperation
  53. For each frame I will need to calculate world bounds and world position. I cannot do it each time I retrieve a RenderOperation so it should be cached somewhere and reused throughout the frame.
  54. - Unity keeps it with Renderable
  55. - What happens when the Mesh resource is updated?
  56. - How do I do it for non-renerables though?
  57. ---------------------
  58. RenderOpSorter:
  59. - (Before we send RenderOps to the sorter we first filter them by camera)
  60. - Accepts parameters whether to sort back-to-front, front-to-back or ignore depth (depth ignored with skybox and overlay)
  61. - Another parameter is whether to sort by pass (transparent ops can't be sorted by pass)
  62. - Then we sort:
  63. - If back to front
  64. - We sort by depth and that's it. We could also sort by material by that only makes sense if two elements have exact same depth which will almost never happen
  65. - If front to back
  66. - Sort by material first. We call materialSimilarity() method which returns lesser value depending how similar two materials are. We do a pass over all unsorted materials and if similarity is below some threshold we add it to the current bucket. If there are no more similar materials we create a new bucket.
  67. - Within bucket we sort by similarity as well (as the elements are added)
  68. - Then finally we sort the buckets by depth front to back
  69. - No depth
  70. - Same as front to back, without the depth sort
  71. - Sorter should operate directly on provided render op array