Rendering the mirror image - design

Started by
2 comments, last by thamas_bacsi 1 year, 8 months ago

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?

Advertisement

Think more about geometry and how to render single fragments (how do you tell when a ray hits the mirror? How do you reflect rays?) and less about things that do not exist ("activating" and “registering” “cameras” with a “manager”).

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.

Are you using some incorrect transformation matrix? Post screenshots.

Omae Wa Mou Shindeiru

Hello LorenziGatti,

thanks for your reply, my bad, I wasn't clear when I was asking my question. In short now I am at the point when I try to move from “tutorial” like code from “engine” like code. In tutorial like code it is fine to manually activate a framebuffer and render to its color attachment, then using that “texture” when doing the main render.

However I guess in an engine it should be done differently, but I think my question was to generic, maybe it should be deleted, sorry for this.

This topic is closed to new replies.

Advertisement