Greetings to all readers. I decided to summarize and translate a wonderful series of articles "Ray-Casting Tutorial For Game Development And Other Purposes" by F. Permadi on the study of ray-casting technology.
This publication touches upon and combines What is Ray-Casting and Ray-Casting vs Ray-Tracing For Game Development original articles.
It is worth noting that in an effort to create a pseudo-three-dimensional engine (which you can also write an article about), I thoroughly studied this tutorial.
Well ... Let's start!
What is ray-casting?
Ray-casting (hereinafter referred to as casting) is a technology that converts a limited set of data (a maximally simplified map, or a floor plan) into a 3D projection by "casting rays" from the point of view over the entire field of view. For example, the picture below shows how throwing transforms something 2-D A into something almost 3-D B.
Ray-casting and ray-tracing
Like ray-casting, ray-tracing "defines the visible portion of a surface by casting imaginary rays of light from the viewpoint toward an object in the scene."
The previous two definitions make it appear that throwing and tracing are the same thing. In fact, some books use both terms interchangeably. But nevertheless, from the point of view of gamedev-programmers, throwing rays should be considered as a special case of tracing implementation.
Throwing faster than tracing. This is possible due to the fact that it uses some geometric constraints to speed up the rendering process. For example, walls are always perpendicular to the floor (this can be seen in games like Doom or Wolfenstein 3D). If it were not for such restrictions, the throwing technology would not have been possible.
The following paragraphs provide a global comparison of throwing and tracing. The main thing to remember is that "throwing uses fewer rays than tracing because of certain geometric constraints." Or else that "throwing is a specialized implementation of tracing."
Principle
Throwing : Rays are thrown and move in groups based on some geometric constraints. For example, on a screen with a resolution of 320x200, the "ray generator" will release only 320 pieces of them (we get this number from the corollary that a screen with a width of 320 pixels has 320 vertical columns).
Trace : each ray is calculated separately, that is, each point on the monitor screen (usually a pixel) is traced by one of its own rays. For example, on a screen with a resolution of 320x200, we need 64 thousand (320 * 200 = 64000) rays, which is 200 times slower compared to throwing.
Formula
As a rule, when throwing, errors in calculations are permissible. When routing, everything should be as accurate as possible.
Speed
Throwing is many times faster than tracing and is suitable for real-time processes. Tracing is not suitable in any way (unless we have a PC with a frequency of 500 GHz).
Quality
When dropped, we get an image of medium / poor quality. You can notice the division into block elements. When tracing, the picture is as realistic as possible - sometimes even too much.
Scene from Wolfenstein 3D. Notice the picture is divided into rectangular blocks. Objects (weapons) and enemies (dog) are simply transparent bitmaps that are scaled and drawn over the background.
A scene from the game 7th Guest. The rendering result is amazing. However, the player's movements are limited to previously defined paths (this is due to the fact that the number of pre-rendered images is limited).
External world
When throwing, we are geometrically limited and only simple shapes are available. When tracing, any shape can be rendered.
Memory
Throwing : Rendered images are not saved to disk. Usually, only the scene map itself is stored on the medium, and the corresponding images are generated on the fly.
Trace : The rendered images are saved to disk and loaded from there when needed. Currently, there is no such hardware part that would be able to render the result of ray tracing on the fly.
Examples of
Throwing:
- Wolfenstein 3D (iD Software)
- Shadow Caster (Raven)
- Arena (Bethesda)
- Doom (iD Software)
- Dark Forces (LucasArts)
Trace:
- 7th Guest (Trilobyte)
- Critical Path (Mechadeus)
- 11th Hour (Trilobyte)
- Myst (Cyan)
- Cyberia (Xatrix)