Hi!
How should I render a mirror image. Please note I don't ask for opengl or directx commands, what I would like to get are your ideas how it should be done in an engine.
What I have so far:
I have view class which controls the "player" inputs / outputs:
- Inpouts like keyboard, mouse
- Outputs: render result
The view also has a camera manager and the screengraph.
The camera manager is similar to https://gamedev.stackexchange.com/questions/21313/design-of-a-camera-system. (So this way we may have a debug camera or player camera, the user of camera manager doesn't has to know the details)
In each frame the view calls Render(&cameraManager) function of the screen graph.
So the Screen Graph does not has to know which camera is in use (player, debug) it just calls cameraManager->GetActiveCamera()->GetView() / GetProjection() functions.
Right now what I do in the view is:
1) Swtich to mirror frame, call screenGraph.Render(&cameraManager) to render the image to a Texture.
2) Switch to my default frame, call scrteenGraph.Render(&cameraManager)
3) disable depth test and render the Texture created in 1) somewhere on the top of the actual. Of course this way the "mirror" is not a mirror image it just smaller version of the original image.
My ideas:
i) Add a Mirror camera to the camera manager and in step 1) activate that camera, then in step 2) activate the original camera. I don't like this one because I have to add a separate (independent) mirror camera to the camera manager but this mirror camera depends on the player camera (to get the position of the camera, e.g.). Ownership questions come to my mind, etc.
I feel that the mirror should be part of the player camera, but then how will the screen graph know which camera to use, I mean it should just call cameraManager.GetActiveCamera(), it shouldn't know about the fact that we want it to render the mirror this time.
ii) in step 1) call "ptr = cameraManager.GetActiveCamera();" Add this ptr the a newly created temporary mirror camera, then register this mirror camera and activate this mirror camera, then after Render(), next remove this camera from the camera manager and activate the previously used one. This way (removing the mirror camera right after the Render() call) the dependency issue is less relevant.
How would you solve it, any ideas?