I implemented to render shadow from 15, July 2020 to 26, Jully 2020. I had two options to render shadow.
It uses depth value from light source. The depth value is the distance from near plane of 6 plane box. When you render 3d object, the library kept depth value each pixels to decide which pixel was writen over other pixel from another primitive shape. You need to render 2 times to create one scene.
It creates 3d objects to render shadow which are named shadow volumen. The shadow volume was made from original rendering object which you want to produce shadow. The shadow volume was created by extending light direction away each coordinates. You need to render 4 times to create one scene.
I used shadow mapping to render shadow. Because It seems to be firster processing than shadow volumes.
Shadow mapping way is followings.
I used sun lighting model to render shadow rather than interior lighting. You could think the sun ray is almost parallel light. The shadow shape on objects would be same size becase of parallel light. To calculate these kind of shadow, you use orthographic projection rather than perspective projection. The orthographic project matrix is following.
You apply 6 planes bounding box into each 6 parameters. 6 planes value is calculated by every vertex coordinates going to be when you play this game. It was easy for me to give followings.
It tooks some minutes to give rest of 2 parameters(near and far). I had each depth values as minus. It likes followings.
Why do you have to pass value in range \([-1, 1]\)? It is another open-gl specification. Each coordiates from vertices are clipped in range \([-1, 1]\).
That is all for me to render game scene with shadow. Here is the result with shadow.
I noticed the aliasing at some pixels, I would like to improve scene with anti-aliasing someday.