AI Traffic: Difference between revisions

Jump to navigation Jump to search
m
Cleanup
(Add info on the modern ground traffic rendering approach is, in case detailed ground traffic becomes a part of the base package in future years - i.e. what the modern way of rendering a lot of animated objects has been since 2010 and earlier. The context is recent discussion on scenery slowdown and animation on the mailing list.)
m (Cleanup)
Line 287: Line 287:


== Ground traffic rendering ==
== Ground traffic rendering ==
''19th November 2021.''


=== Performance ===
=== Performance ===


* CPU: Currently having a lot of nodes in the OSG scene-graph will rapidly make FlightGear CPU bound. A lot of separately animated ground traffic objects mean a lot of nodes. Static objects i.e. non-animated objects can be put into one mesh, hence one scnegraph node, with the current system
* CPU: Currently having a lot of nodes in the OSG scene-graph will rapidly make FlightGear CPU bound. A lot of separately animated ground traffic objects mean a lot of nodes. Static objects (i.e. non-animated objects) can be put into one mesh - meaning one scenegraph node with the current system.
* GPU: Having fewer draw calls is fast. Having fewer state changes is fast.  
* GPU: Having fewer draw calls is fast. Having fewer state changes is fast.  
* The fast path for both CPU and GPU is creating a way to combine multiple animated objects in one mesh - this is how modern 3d applications do lots of objects with animations fast.
* The fast path for both CPU and GPU is creating a way to combine multiple animated objects in one mesh - this is how modern 3d applications do lots of objects with animations fast.
Line 303: Line 304:
* The vertex shader can trivially look at the object ID, path segment, the starting time, speed scaling factor, and current time to position each object. If the current time is past the end of the path,  
* The vertex shader can trivially look at the object ID, path segment, the starting time, speed scaling factor, and current time to position each object. If the current time is past the end of the path,  
* The buffers can be a Uniform Buffer Object (UBO), a Texture Buffer Object (TBO), or a texture looked up in a vertex shader.
* The buffers can be a Uniform Buffer Object (UBO), a Texture Buffer Object (TBO), or a texture looked up in a vertex shader.
* Each path segment is x,y,z position at regular times - e.g. [10m, 20m, 0m elevation] at t = 1s. [20m, 25m, 0m] at t=2s . [30m, 30m, 0m] at t= 3s. 16 bit integers are enough. If a texture is used it can be 16bit RGB - R=x, G=y, B=z.  2 consecutive 8 bit values can also be read from a texture.16 bit integers can cover an ground traffic area of ~65km with a spacing of 1m. 16bits can give a ~13km ground traffic area with an accuracy of 20cm. The accuracy of the positions doesn't matter too much - the vertex shader can look at 2-3+ path positions and create a smooth interpolation (a smooth curve joining the points). The time steps can also be large.  If a path has a slowly moving segment, it will take up more points. If a path segment takes a short amount of time, it can have a special xyz numner to indicate path has ended - otherwise the path start/end information can be stored as uniforms or in a UBO. Vehicles that move faster can have a hgiher speed scaling.
* Each path segment is x,y,z position at regular times - e.g. [10m, 20m, 0m elevation] at t = 1s. [20m, 25m, 0m] at t=2s . [30m, 30m, 0m] at t= 3s. 16 bit integers are enough. If a texture is used it can be 16bit RGB - R=x, G=y, B=z.  2 consecutive 8 bit values can also be read from a texture.16 bit integers can cover an ground traffic area of ~65km with a spacing of 1m. 16bits can give a ~13km ground traffic area with an accuracy of 20cm. The accuracy of the positions doesn't matter too much - the vertex shader can look at 2-3+ path positions and create a smooth interpolation (a smooth curve joining the points). The time steps can also be large.  If a path has a slowly moving segment, it will take up more points. If a path segment takes a short amount of time, it can have a special xyz numner to indicate path has ended - otherwise the path start/end information can be stored as uniforms or in a UBO. Vehicles that move faster can have a higher speed scaling.
* Both ground vehciles, and taxxing aircraft can be done this way. It's possible to replace a conventional AI aircraft model, with a fast ground traffic model once an aircraft starts taxiing.
* Both ground vehicles, and taxiing aircraft can be done this way. It's possible to replace a conventional AI aircraft model, with a fast ground traffic model once an aircraft starts taxiing.
* If models use animations, they should ideally use a vertex shader that can handle all these animations - so having multiple draw calls per model and CPU-side animation is avoided.
* If models use animations, they should ideally use a vertex shader that can handle all these animations - so having multiple draw calls per model and CPU-side animation is avoided.


Line 314: Line 315:
''"Personally I use them for instanced rendering by storing the model-view matrix and related information of each and every instance in a common uniform buffer and use the instance id as an index to this combined data structure. This usage performs very well on my system.''
''"Personally I use them for instanced rendering by storing the model-view matrix and related information of each and every instance in a common uniform buffer and use the instance id as an index to this combined data structure. This usage performs very well on my system.''


''Also uniform buffers can be used to store the matrices of bones and use them for implementing skeletal animation, however, I personally prefer using normal 2D textures for this purpose to take advantage of the free interpolation thanks to the dedicated texture fetching units but that’s another story." - Rastergrid blog[https://www.rastergrid.com/blog/2010/01/uniform-buffers-vs-texture-buffers/][https://web.archive.org/web/20211119134448/https://www.rastergrid.com/blog/2010/01/uniform-buffers-vs-texture-buffers/]''
''Also uniform buffers can be used to store the matrices of bones and use them for implementing skeletal animation, however, I personally prefer using normal 2D textures for this purpose to take advantage of the free interpolation thanks to the dedicated texture fetching units but that’s another story." - Rastergrid blog, 2010 [https://www.rastergrid.com/blog/2010/01/uniform-buffers-vs-texture-buffers/][https://web.archive.org/web/20211119134448/https://www.rastergrid.com/blog/2010/01/uniform-buffers-vs-texture-buffers/]''


This is from a 2010 blog - this general approach has been the way to do lots of animated objects for a long time.
This is from a 2010 blog - this general approach has been the way to do lots of animated objects for a long time.
1,746

edits

Navigation menu