Mirrors and portals

How are mirrors and portals implemented i Q3 and Unreal? I believe none of them are using stencil or destination-alpha. Regarding Q3 I read something about a single extra clip plane…

Yeah, q3 is most probably using a clip plane that lies over the “portal”, since it isn’T a native portal engine, while unreal is a native sector/portal engine, where the sectors don’t intersect. However, these from the front a portal from the back solid portals also have to do some tricks, to only draw where the portal is.

Originally posted by Michael Steinberg:
Yeah, q3 is most probably using a clip plane that lies over the “portal”, since it isn’T a native portal engine, while unreal is a native sector/portal engine, where the sectors don’t intersect. However, these from the front a portal from the back solid portals also have to do some tricks, to only draw where the portal is.

I thought unreal was bsp based. But polygons do overlap if you dont do an expensive 2d-convex-polygon clipping for every single polygon. Is there a unreal spec available anywhere?

I dont understand the rest of your english/german

Actually quake 3 renders a “reflection texture” for each mirror, then when rendering the scene, it can treat the mirrors as regular textured polys. Im not sure where I read it, but I THINK it only updates the texture every other frame or so (as a way of amortizing the cost of the “render-to-texture” over multiple frames).

[This message has been edited by LordKronos (edited 02-17-2001).]

No, quake 3 is not using textures for the portals. If you switch on r_showtris, you can see that there are triangles.
Unreal seems to be a funny mixture of both, though I think it supports portals natively. In quake 3 that is only an ugly fix. These transport portals (beamers?) are really ugly. You can achieve really great effects when supporting portals which don’t lie on the same plane physically. That are leaks in the space it’s like moving in another room but you may have moved a lot further.

And polygons may overlap, but do not intersect! In every sector there aren’T any overlapping polys, since the sectors have to be convex. Then, you can depth sort the sectors (ie. draw the one behind the farthest away portal).

Originally posted by LordKronos:
[b]Actually quake 3 renders a “reflection texture” for each mirror, then when rendering the scene, it can treat the mirrors as regular textured polys. Im not sure where I read it, but I THINK it only updates the texture every other frame or so (as a way of amortizing the cost of the “render-to-texture” over multiple frames).

[This message has been edited by LordKronos (edited 02-17-2001).][/b]

Yes it could be done that way, though one should think there are better ways. This principle is so expensive, that I find it hard to believe. It would be simpler to:

  1. Set the scissorbox to an appropirate area. Render the portal view
  2. Clear the z buffer
  3. Render the portal-polygon with writing to the framebuffer turned off
  4. Render the normal view

Any better suggestions?

Michael: It could still be a texture, if it was generated with this triangle feature on as well.

But what about this single user clipping plane?

I suspect Quake3 uses the user clipping plane to prevent the scene geometry in the portal from poking out beyond the plane of the portal.

Which resolution of a texture would result in pixel exact triangle-lines? quake3’s using the user clipping plane and resets the depth buffer after having rendered the portal. Afterwards it just blends a totally transparent portal there, to set the z-values of the portal.

Originally posted by Michael Steinberg:
Which resolution of a texture would result in pixel exact triangle-lines? quake3’s using the user clipping plane and resets the depth buffer after having rendered the portal. Afterwards it just blends a totally transparent portal there, to set the z-values of the portal.

Good point with the texture-thing. The r_showtris dons not work on my Q3???

Generally you have a communication problem. What does “quake3’s using the user clipping plane and resets the depth buffer after having rendered the portal” mean?

Yeah, I’m sorry for my bad english. I should be trying harder to explain myself better. What I meant is this:
In quake 3, portals are something like cameras whose images can be seen on a plane. Now, to any camera belongs a target. The target is a directed point or plane somewhere in the world. Now, when you want to display the image on the screen, you must cut away the pieces of the world, that would be lying between the screen and the player. That can be done with a user clipping plane, which lies exactly in the plane which the screen (the image of the camera or what you called portal earlier) describes. Now, you’ve got rendered only the image of the camera. But you rendered parts of the image, which don’t lie on the screen, so there’s also z information saved which makes it tricky to render the world around the player. Also, there may be parts of the real world around the player which intersect with the image of the camera. A solution is, to clear the z-buffer, and draw poly which is the screen completely transparent. This way, you set the z-information only inside the camera image and the real world can overwrite the picture buffer all outside the camera screen. You will also have set the nearest z there, so the real world will not intersect with the image.

I tend to name it camera, since it doesn’t give the feeling that it is part of the world, something like a structural anomaly. It’s just a camera screen, and when you get nearer, you get teleported to its target.

[This message has been edited by Michael Steinberg (edited 02-17-2001).]

Hi!
Michael: Where did you get all this info from? Are you just guessing or do you have some other info?

Greets, XBTC!

[This message has been edited by XBCT (edited 02-17-2001).]

There exists an OpenGL wrapper that catalogs all the OpenGL functions as they are called. So it is possible to use that tool to reconstruct at least the order of operations. From that info and the details of the scene, it is possible to draw educated guesses. That is at least what I did.

Some of us also have access to the source code to said game.

  • Matt

Im not guessing here. I actually read that quake3 uses textures for MIRRORS (not portals).

For portals, from what I read, no it does not use textures. BUT, just because you can see triangle outlines through the portal does NOT automatically mean that texture arent used. Think about it…if you have r_tris on when you build the texture, you will see the triangle outlines in the texture instead of the textured polys.

I think what you read is incorrect. If it used a texture, it would be slower than rendering directly, and there would be no use for the user clip plane. And JC has already publicly stated that he uses the user clip plane when rendering a portal. And the only obvious reason to use it is to clip geometry in the portal scene to prevent poke through. A simple texture would not have a poke through problem at all since it is just 2D to begin with. And a mirror in Quake3 is the same thing as a portal in Quake3, the portal target is simply implied.

[This message has been edited by DFrey (edited 02-17-2001).]

OK first of all, When I was thinking “portal” I was thinking the “doorway” between 2 connecting rooms. These do not use textures for rendering. If you are talking about the teleportation portals, I think these MIGHT use textureslike the mirrors (although what I remember reading was specifically talking about mirrors.

Also, when rendering the texture, you can use a user clip plane to make sure only the correct geometry shows up in the texture. So the fact that he uses the clip plane doesnt automatically mean he doesnt use textures for mirrors

And as for the speed, as I said before, if you dont update the texture every frame, you will make up the speed difference.

Here is possibly more supportive evidence that textures are used for portals. This is from http://www.quake3arena.com/news/glopt.html

The only weird thing we do with geometry is enabling a single user clip plane when looking through a portal in the game. This usually punts drivers to an unoptimized path, so we don’t use it very often

If he knows that clip planes are usually unoptimized in the drivers, he might figure that it would be best to perform the unoptimized clip-plane-rendering once every several frames and then just use a normal texture the rest of the time.

I guess there is only one thing to do…try to track down the document where I read this. Oh yeah, that will be fun, but I’ll try.

I wouldn’t believe that LordKronos.
XBCT: It’s just logical guessing. I’m always good in guessing, but I’ve a hard time to get practical if you know what I mean.

I once ran q3 in 1024*768 (quite slow on my comp…), and the triangle outlines did not blur. For me that is evidence that there is not texture being used.
I’ll buy a new comp on my birthday!!! I will use my old TNT then and wait for the NV20, since NVidia always does a good job. That one goes also to you Matt!

Well, to get to english. Can one “poke” another one? Is that murdering? In case somebody knows.

[This message has been edited by Michael Steinberg (edited 02-18-2001).]

I’m sure q3 uses clip plane.
q3 logs all opengl calls in file
just type in console :
devmap q3dm0
r_logfile 1
Take a look at the gl.log file.

mfugl,steps to render flat mirror are:
assume mirror is in world space
set clip plane
pushMatrix
glMultMatrixf(mirrorMatrix);
reverse face orientation
compute reflected cam position
draw scene from new cam position
restore face orientation
popMatrix
disable clip plane
clear depth buffer
render mirror to depth buffer
or blend it with reflected scene
continue with normal scene

Portal is equivalent,the only difference I can see,is how to compute new cam position and new modelview matrix.

Where is a good document about mirrors TimHall_Reflections
you will easy find it or I can email it.

About stencil buffer.q3 doesn’t need it
Since q3 always renders portals or mirrors first and then clears depth buffer,parts of
reflected scene outside mirror polygon will be overwriten by normal scene or black sky
(on space map,q3tourney6 for example).
Also,you can create mirror mask with depth buffer.

I don’t anything about Unreal.

Sorry for my ugly english.
Michail.