We send rays, that match every pixel on the screen. Then, with the help of Signed Distance Functions of all objects we detect each of them. Phong shading helps us to draw shadows.
You can read more there:
Article in English
English WIKI about Phong Shading
English WIKI about Rotation matrix
Article in Russian
Russian WIKI about Phong Shading
Russian WIKI about Rotation matrix