Mirror Scene in OpenGL using Stencil and Object Masking.
To create a mirror in OpenGL, I have used the following approach:
- Create a Mirror Camera UBO and Set the View Matrix to a Mirrored Version of the Main Camera's View Matrix. Formula Given (V * M * R_z * M^-1);
- Create a Real Framebuffer Object (FBO) and Attach a Texture to it for the Real World (Visible in Real View in Display);
- Create a Mirror Framebuffer Object (FBO) and Attach a Texture to it for the Mirrored World (Visible in Mirror View in Display);
- Create a Mask Framebuffer Object (FBO) and Attach a Texture to it (Masking Certain Objects to not be Blurred).
- Compose the Scene together in the Shader to be rendered as a full-quad as the Final Scene. Mirror Scene is Blurred if its not within the Mask (using Gaussian Blur).
Machine Specification : Intel Core i5-1335U, Intel Iris Xe Graphics, 16GB RAM
Scene | FPS CPU-GPU |
---|---|
Composed Scene | 90-250 |