How to perform ray tracing in a shader? The problem is that many ray tracing algorithms are designed to run on a processor, while at the same time there is not much useful information about their implementation on the GPU. As far as I know the principles of tracing, the beam emanating from the camera deep into the screen is checked for intersection with the scene objects, and if such an intersection is detected, the pixel color of the object with which the intersection of the ray actually occurred is drawn. Otherwise, the pixel remains the background color. Next comes the second beam, and the algorithm repeats again. How to implement all this on the GPU? How are scene objects depicted on screen? How do we say, for example, to portray a standard sphere?

  • And what is, in fact, a significant difference from a similar implementation on the CPU? - D-side

1 answer 1

And what's the point in such a trace? As far as I know, tracing is used for drawing surfaces that distort and / or scatter light rays (glass, translucent surfaces, shorter for modeling the complex behavior of light rays) or for displaying smooth analytic surfaces (long live Matan and analyte. Geometry). For such simple cases, the trace will be resource intensive.

Threat In one article about tracing on GLSL (I don’t remember the author and don’t remember the name), a method was described for drawing the tissues of the human body. The author of the article writes a renderer for MRI tomographs. He said that a tamograph provides him with a 3D texture (aka voxel graphic) with an object. In this texture, each voxel contains info about the density of the tissue (bone, meat, skin, etc.). Further, it transfers this texture to a fragmentary shader, and there it already beams. If more: he took the plane (normal QUAD) and drew it with the included fragmentary shader in front of the screen. Further, when the next pixel of this quad was drawn, it took the pixel radius vector and ran a ray along it. Then he checked every voxel of the 3D texture at the intersection with the ray. But I checked by layers, from near to far. So he was able to achieve translucency of soft tissues.