Need help with Portal Texturing

Started by
8 comments, last by nullsquared 14 years, 8 months ago
Hello, i want to programm a portal based system like in "Portal" from valve, by rendering the view through the portal in a texture and than map this on a plane. I know that i have to render this perspectivly correct, but it doesnt work. I have my normal View Matrix, and i have a calculated a other portalViewMatrix to render the right scene into a texture. My rendered texture looks fine, i saw the right room. But now i want to place it correctly of the portal plane in my current view. For this i used the perspective texuring shader for mirrors, but it does not work. I try to post here a archive with screenshots and the shader code. I hope anybody can help me, because I need this stuff and think about this for to much time :) LINK: http://medieninformatik-berlin.de/Portal Problem.zip
Advertisement
It looks like you've been rendering your portal orthogonally and not perspectivelly.

I haven't read the shader, but IMNSHO it should be mapped not projectively, but with standart texture mapping too (althought it looks like you're mapping it using projective texture mapping from camera, which is wrong way to go.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Don't use render-to-texture, use the stencil buffer and a pixel shader to properly set Z buffer values where the portal is rendered.
Thanks for you help guys.

I figured out that my second view Matrix for the shader program was unnecessary.
If i give the mirror View the same Matrix as the normal View, all is perfect.

I have to analyse it by myself, why it works, but it works. :)

@PVSector: How i use the stencil buffer? Can I render something to a postion, where it is not in the real world coordinates? Becuase this is my goal. It is not a normal portal, where the rooms are physicaly neigbours.

Why it is better with stencil buffer?.
Quote:Original post by FelixF

Why it is better with stencil buffer?.


I can't remember exactly why, but Valve do it that way too. If you have Portal noclip through the levels with the developer commentary on, one of those talks about it [smile].
The rough gist of it is that Valve actually rendered the whole scene from the portal POV using a virtual camera, then masked out the portal itself using some sort of decal alpha test and stencil-increment combo. They then drew everything normally from the player POV, making sure that the write would fail if the stencil buffer had a nonzero value at the current location. The net result is that you had this little oval 'cut out' where you could see through to the image from the virtual camera. The glowing edges were simply a matter of alpha-blending a decal of some sort over the original and optionally resetting the stencil buffer for later use.

If you're feeling especially clever, the technique can be repeated ad infinitum, recursively rendering the scene from an additional virtual camera each time.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Quote:Original post by InvalidPointer
The rough gist of it is that Valve actually rendered the whole scene from the portal POV using a virtual camera, then masked out the portal itself using some sort of decal alpha test and stencil-increment combo. They then drew everything normally from the player POV, making sure that the write would fail if the stencil buffer had a nonzero value at the current location. The net result is that you had this little oval 'cut out' where you could see through to the image from the virtual camera.
Not sure I see why this is better than render-to-texture from the portal's point of view, followed by rendering from the player perspective? You can render recursively either way, and it shouldn't make much difference from a performance standpoint...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Stencil method pros:

- antialiasing
- no additional texture memory
- direct rendering (render main scene, render portal scenes, recurse)
- as a result of direct rendering, post processing is made simple

(I'm the guy behind portalized)

Just do stencil mirror rendering without really mirroring anything.
Quote:Original post by nullsquared
Stencil method pros:

- antialiasing
- no additional texture memory
- direct rendering (render main scene, render portal scenes, recurse)
- as a result of direct rendering, post processing is made simple

(I'm the guy behind portalized)

Just do stencil mirror rendering without really mirroring anything.


Hi,

ok I had a closer look to stencil buffering and I agree that it is better than render-to-texure. I like the technique of the mask. :) The main pro is that no additional texure memory is used and I think you can better perform view-culling through the portals. But I thinks the post-processing is the same.

If I want to use stencil buffer, I have to search recurse the portal in view and than drawing from the farthest portal first. Is it right? But I have to draw every portal the new mask to the stencil buffer? I hate and love recurse algorithm :)

Quote:Original post by nullsquared
(I'm the guy behind portalized)


I love the stuff you are doing. :) How you can transfer objects through portal? Do you split the object or duplicate it and insert it to each cell?
Quote:Original post by FelixF

If I want to use stencil buffer, I have to search recurse the portal in view and than drawing from the farthest portal first. Is it right? But I have to draw every portal the new mask to the stencil buffer? I hate and love recurse algorithm :)

You can either do it that way or you can recurse from the closest portal down. Whatever you find easier/more useful.
Quote:
Quote:Original post by nullsquared
(I'm the guy behind portalized)


I love the stuff you are doing. :) How you can transfer objects through portal? Do you split the object or duplicate it and insert it to each cell?


Nope, it's the same object literally in two places. Legit. No smoke and mirrors at all. [wink]

This topic is closed to new replies.

Advertisement