Jump to content

Graphics: Difference between revisions

179 bytes added ,  20 October 2021
m
copy-edit on existing material
m (link fixes)
m (copy-edit on existing material)
Line 24: Line 24:


==Frustum==
==Frustum==
:See [[BSL:Frustum_and_fog]] on how to alter the far clip plane and field-of-view (FOV) using [[BSL]].
:See [[BSL:Frustum_and_fog|Frustum and fog]] on how to alter the far clip plane and field-of-view (FOV) using [[BSL]].
:''In 3D computer graphics, the viewing frustum or view frustum is the region of space in the modeled world that may appear on the screen; it is the field of view of the notional camera. The exact shape of this region varies depending on what kind of camera lens is being simulated, but typically it is a frustum of a rectangular pyramid (hence the name). The planes that cut the frustum perpendicular to the viewing direction are called the near plane and the far plane. Objects closer to the camera than the near plane or beyond the far plane are not drawn.'' -- [[wikipedia:Viewing_frustum|"Viewing frustum"]], Wikipedia
:''In 3D computer graphics, the viewing frustum or view frustum is the region of space in the modeled world that may appear on the screen; it is the field of view of the notional camera. The exact shape of this region varies depending on what kind of camera lens is being simulated, but typically it is a frustum of a rectangular pyramid (hence the name). The planes that cut the frustum perpendicular to the viewing direction are called the near plane and the far plane. Objects closer to the camera than the near plane or beyond the far plane are not drawn.'' [[wikipedia:Viewing_frustum|"Viewing frustum"]], Wikipedia


;Field of view (FOV)
;Field of view (FOV)
Line 41: Line 41:
Culling speeds up the drawing process, but runtime detection of objects that need to be culled also takes time... One generally adopts a hierarchical subdivision of the scene, whereby the children (subparts) of a large object are automatically culled if their parent (the large object) is detected as hidden or out of sight.
Culling speeds up the drawing process, but runtime detection of objects that need to be culled also takes time... One generally adopts a hierarchical subdivision of the scene, whereby the children (subparts) of a large object are automatically culled if their parent (the large object) is detected as hidden or out of sight.


Oni's solution is the combination of two algorithms: oct-trees and ray casting.
Oni's solution is the combination of two algorithms: oct trees and ray casting.


;Oct-trees
;Oct trees
:Unlike the more common "visibility groups" placed manually by the level designer, Oni uses an automatic partition of the visible space into smaller and smaller cubes, until each "leaf" cube holds no more than a certain small number of polygons (see [[OTLF]] for details). Environment polygons (as well as characters, particles, etc) will only be drawn if they are in a leaf node of the oct-tree, and if that leaf node is detected as visible. The detection of whether a leaf node is visible is done with ray casting.  
:Unlike the more common "visibility groups" placed manually by the level designer, Oni uses an automatic partition of the visible space into smaller and smaller cubes, until each "leaf" cube holds no more than a certain small number of polygons (see [[OTLF]] for details). Environment polygons (as well as characters, particles, etc) will only be drawn if they are in a leaf node of the oct tree, and if that leaf node is detected as visible. The detection of whether a leaf node is visible is done with ray casting.  


;Ray casting
;Ray-casting
:Wikipedia: [[wikipedia:Ray_casting|Ray casting]]
:Wikipedia: [[wikipedia:Ray_casting|Ray casting]]
[[Image:Ray-casting failure.jpg|thumb|right|If you've ever thought that you briefly saw flashes of color while turning the camera, now you know why.]]
[[Image:Ray-casting failure.jpg|thumb|right|If you've ever thought that you briefly saw flashes of color while turning the camera, now you know why. Wherever a polygon is not rendered, the level's skybox will be visible.]]


It's an original algorithm that achieves both view frustum and occlusion culling. During each frame (i.e. 60 times per second), 20 rays are shot from the camera into the environment, distributed randomly in the frustum. Along the path of each ray, the engine first determines the relevant leaf node of the oct-tree (either by navigating the oct-tree or using the information on the neighbors of the previously traversed leaf node), then the ray is tested for collision with non-transparent environment quads intersecting that node (if the ray is stopped by a quad, then its further path is ignored). An overview of the algorithm is presented in the following paper:<br>
It's an original algorithm that achieves both view frustum and occlusion culling. During each frame, 16-20 rays (depending on graphics quality) are shot from the camera into the environment, distributed randomly in the frustum. Along the path of each ray, the engine first determines the relevant leaf node of the oct tree (either by navigating the oct tree or using the information on the neighbors of the previously traversed leaf node), and then the ray is tested for collision with non-transparent environment quads intersecting that node (if the ray is stopped by a quad, then its further path is ignored). Quads thus detected with collision will be drawn. An overview of the algorithm is presented in the paper [http://oni.bungie.org/archives/brent_gdc00.html An Algorithm for Hidden Surface Complexity Reduction and Collision Detection Based On Oct Trees] by [[Credits|Brent H. Pease]] (note that figure 1 and 2 are mixed up).
[http://oni.bungie.org/archives/brent_gdc00.html An Algorithm for Hidden Surface Complexity Reduction and Collision Detection Based On Oct Trees] (figure 1 and 2 are mixed up) by [[Credits|Brent H. Pease]]
:Just a side note: the ray-casting feature which handles occlusion/frustum is not to be confused with the common term "[[wikipedia:Ray_tracing_(graphics)|ray-tracing]]", a CG rendering method where a ray is cast for every rendered pixel, achieving a high degree of photorealism. This method is very CPU-intensive and is typically used only for still images, short video sequences or CG movies such as Pixar's ''Cars''. Implementations of real-time ray-tracing for gaming are underway, but still need to be complemented with the standard [[wikipedia:Scanline_rendering|scanline rendering]] and [[wikipedia:Rasterisation|rasterisation]] approaches for performance reasons.
:Just a sidenote: the ray-casting engine that handles occlusion/frustum is not to be confused with the common term "[[wikipedia:Ray_tracing_(graphics)|ray-tracing]]", a CG rendering method where a ray is cast for every rendered pixel, achieving a high degree of photorealism. This method is very CPU-intensive and is typically used only for still images, short video sequences or CG movies such as Pixar's ''Cars''. Implementations of real-time ray tracing for gaming are underway, but can not yet compete with the standard [[wikipedia:Scanline_rendering|scanline rendering]] and [[wikipedia:Rasterisation|rasterisation]] approaches.
Pease acknowledges that even ray-casting was too CPU-intensive until they lowered the number of rays being emitted and started altering their emission angles even when the camera remained still, in order to catch any polygons that the first emission of rays missed; this is why distant polygons, when suddenly revealed by the camera, sometimes are culled at first (pictured, right) and then appear a moment later: because the rays didn't hit them on the first pass. A distant face in the environment can be accidentally culled if it's only visible through a narrow slit, because the rays have a low probability of passing through the slit and hitting the objects behind it. A similar problem occurs when modders experiment with outdoor levels that have uneven ground (natural terrain): many of the ground polygons will be culled, making the map look like there are holes everywhere.
Pease acknowledges that even occlusion testing was too CPU-intensive until they lowered the number of rays being emitted and started altering their emission angles even when the camera remained still, in order to catch any polygons that the first emission of rays missed; this is why distant polygons, when suddenly revealed by the camera, sometimes are culled at first and then appear a moment later (pictured, right): because the rays didn't hit them on the first pass. More generally, a distant object can be accidentally culled if it's only visible through a narrow slit, because the rays have a low probability of passing through the slit and hitting the objects behind it. A similar problem occurs when modders experiment with outdoor levels that have uneven ground (natural terrain): many of the ground polygons will be culled, making the map look like there are holes everywhere.


[[Category:Engine docs]]
[[Category:Engine docs]]