Advertisement

How to adjust a projection matrix to product the same size render, but on a smaller texture?

Started by August 27, 2022 11:57 PM
1 comment, last by Aerodactyl55 2 years, 2 months ago

Hi everyone. I'm trying to create a picture-in-picture effect. The idea is to render the scene twice, once on the normal framebuffer, and then again on a smaller texture. I'll do some visual effects to the smaller texture (as well as render some extra stuff) and the idea is to let the player look through a “magic window” that can reveal hidden things.

I could accomplish this by rendering it full size and clipping to the target area, but because I need to glRead the texture's pixels for other reasons, I want to use a smaller texture for speed.

The intended effect is something like this:

Mockup, not real

My problem: I cannot for the life of me make the render on the smaller texture match 1:1 with the full-size framebuffer image. I've tried lots of kludges, they all come with some price to pay, such as a slightly different perspective, or the image fading into the fog on the texture, even.

The data I have to play with:

  1. Resolution of the big render
  2. Resolution of the smaller texture
  3. World/View/Project matrices from the big render
  4. Viewport from the big render
  5. The XY coordinate that I want to “pan” to on the smaller texture.

How can I rearrange all these to produce a projection matrix for the smaller render that is zoomed and scaled to match the big one?

Perhaps you should try using a scissor rectangle for this. With this method you would set scissor rectangle to the full backbuffer and render the normal scene, then set the scissor rectangle to the “magic window” portion of the backbuffer and render the “magic view”.

This topic is closed to new replies.

Advertisement