Scaling view

Started by
7 comments, last by nullsquared 16 years, 3 months ago
Say that you rendered some point of a scene to a texture. Now that you have that texture, putting it on a small quad would make a "small TV" (for a lack of better term), and putting it on a big quad would make a "big TV". This is because the texture itself isn't changing, it's getting stretched on the quad. OK, so now how can I accomplish this "big TV" or "small TV" if instead I used the stencil buffer (put quad in stencil, render as usual only within quad) to do it? Obviously, making the quad itself bigger or smaller simply increases or decrease the "viewing area". Thus, how can I make it not increase/decrease the amount of space visible, but rather scale it? Thanks to any ideas [smile]
Advertisement
You would just render the scene as you did before, using the stencil buffer to mask what's written. Then when you scale the texture onto your "TV quad", the visible area (what was rendered) will scale as well. There's nothing special about it :)
Right, but the problem is, I'm not using a texture. I'm rendering directly into the colour buffer. Sort of like how stencil mirrors (obviously we're not flipping anything here, though) are done. I want to "scale" the resulting view. So using the mirror example, I'd want it to make stuff appear 2x as large, or 2x smaller, etc.

Thanks for the reply, though, it's appreciated [smile]
Quote:Original post by agi_shi
Right, but the problem is, I'm not using a texture. I'm rendering directly into the colour buffer. Sort of like how stencil mirrors (obviously we're not flipping anything here, though) are done. I want to "scale" the resulting view. So using the mirror example, I'd want it to make stuff appear 2x as large, or 2x smaller, etc.

I see. What you would want to do is manipulate the viewport so that it renders into the area of the framebuffer you want it to. Post-perspective space automatically scales to the viewport. As long as your "TV" is a quad in screen-space, you don't have to use the stencil buffer. You'll have to use the stencil buffer if you want shapes that aren't quads (since the viewport is a quad). Remember that the stencil buffer is just a mask though, so you can't "squeeze" the "TV" into any particular shapes. Parts of it would just be masked away.

However in any case the "TV" - no matter what shape it is - would have to be billboarded, or aligned with the screen, for this method to work. Texture mapping is the only way to get correct perspective skew if it's facing another direction. Basically there are a ton of restrictions on what you can do depending on what the final desired effect is.
I see... so I can't just make things appear bigger or smaller (this "quad" can be aligned in pretty much any way). Is there maybe some matrix trickery I can do? I mean, the final vertex is world * view * projection, so maybe I can "hack something together"?

Here's a good video I found that does an excellent job at explaining what I want to do:
Towards around the middle of it, you'll see two portals that are connected - one big, one small. When you look through the big one, everything looks gigantic since you're seeing through the small one; and vice versa. I'm trying to do the same thing, except I'm using the stencil buffer (as Valve does it), so I'm kind of ... stuck What does that video look like it used?
Quote:Original post by agi_shi
I see... so I can't just make things appear bigger or smaller (this "quad" can be aligned in pretty much any way). Is there maybe some matrix trickery I can do? I mean, the final vertex is world * view * projection, so maybe I can "hack something together"?

You can, but what I'm trying to say is that it won't behave like a TV, which is the example you mentioned in your first post. However you can get portal/mirror behavior pretty easily. The difference is that TVs act as the source of an image, while mirrors/portals are like a means of transforming an image.. it's a bit difficult to explain, you'll have to try and visualize it.

The video looks like it uses textures to get special post-processing effects, but it could also be using the stencil buffer. The idea is that you're not supposed to tell the different ;)
No, I know how portals work and all, and I can clearly visualize the difference between a TV and a portal [grin] (look up Portalized [by nullsquared] on youtube, try to stick to the newer than 0.20 videos).

It's just that with a big portal connected to a small portal... you'd have a "small" view stretched over the whole big portal (and vice versa). As if the whole world was scaled up, know what I'm saying? Well, the video explains it better than me, [lol].

So I need a way to "scale up the world" without touching the world itself, since there's _many_ objects in it. Ideas?
If you already have stencil based portals working then you're 99% there. All you need to do is add a scaling factor to the code that repositions the camera for rendering the scene in the portal. The position of the camera relative to the portal is scaled up or down based on the scale difference. There's nothing tricky about it.

I'll try to illustrate.. Consider the situation where you're looking at "big" portal (size 2u), which looks out of "small" portal (size 1u). Let's say you're 2 units away from the portal and offset to the right by one unit, ie. lined up with the edge of the big portal. Transforming and scaling this to the destination portal puts the new camera position one unit behind the portal and one half unit to the right (your right), Because the portal is half the size. This will make it look like there's a scale change between the portals (the apparent size of the world seen through the portal is doubled).

Switching to a bigger/smaller 3d model when an object passes through is a separate effect, and the possibility of an object stopping halfway through will no doubt lead to interesting problems.
Quote:Original post by Fingers_
If you already have stencil based portals working then you're 99% there. All you need to do is add a scaling factor to the code that repositions the camera for rendering the scene in the portal. The position of the camera relative to the portal is scaled up or down based on the scale difference. There's nothing tricky about it.

I'll try to illustrate.. Consider the situation where you're looking at "big" portal (size 2u), which looks out of "small" portal (size 1u). Let's say you're 2 units away from the portal and offset to the right by one unit, ie. lined up with the edge of the big portal. Transforming and scaling this to the destination portal puts the new camera position one unit behind the portal and one half unit to the right (your right), Because the portal is half the size. This will make it look like there's a scale change between the portals (the apparent size of the world seen through the portal is doubled).


Thanks a BUNCH! SO SO MUCH! Thanks! [smile] [smile]

For anyone else implementing these types of portals, note that this has to be done in local space (local to the portals). Doing it in global space (what had me stumped for a while [embarrass]) doesn't make sense since the scaling can only be "relative" when the portals are aligned with one another.

Quote:
Switching to a bigger/smaller 3d model when an object passes through is a separate effect,

Already implemented [wink]. It works 100% perfectly, exactly as the video shows it. Except that my portals a so flexible, that you can throw a portal through a portal, and it'll scale accordingly (just like a normal object). Dynamically scalable portals... fun stuff [grin]
Quote:and the possibility of an object stopping halfway through will no doubt lead to interesting problems.

Meh. Works fine here. Heck, the object even collides on both sides of the portal - size corrected!

This topic is closed to new replies.

Advertisement