Skip to main content
GameDev.net gamedev.net
🔒 Locked

PORTALs!!

Started by Esap1 Mar 21, 2000 at 3:22 PM 34 replies 2.3k views
Original Post
Esap1
Esap1
Do any of you know of any portal Tutorials that deal with Hardware Acceleration, or Direct3D. Does anyone have any tips. I understand how to do it if I were writing a software engine, but Im not. Could someone breifly explain to me the steps to do it in using Hardware+Z-Buffer. Or just the steps you might use in DirectX. Thanks in Advance!
Spellbound
Spellbound
I don't quite understand what it is that you're asking. You say that you know how to do it if you're making a software engine, well the only thing OpenGL or DirectX does for you is rendering the triangles and recently DX has also added the ability to clip them for you.

The Z-buffer is just a simple way of sorting the triangles so that the closest ones are visible instead of the others. You can use this to releave the cpu of some of the work of clipping the triangles as you no longer need to clip exactly to the form of the portal.

You should be able to use the knowledge you already have and exchanging the rendering part for their counterpart in DX.

I believe FlipCode has a tutorial on making portalengines but I haven't read it so I cannot say if it will help you or not.

Edited by - Spellbound on 3/21/00 5:26:05 PM
Esap1
Esap1
In a portal engine you check to see if any portals are visible, then draw the cell that that portal connects and clip it to that portal. What Im asking is if you can tell DirectX to clip to a Polygon(get it?). And is there a way for DirectX to tell me if a poly is visible, or will I have to do that myself?
nes8bit
nes8bit
figure it out yourself. The way I did it is I just divided my world into a 2d grid and rendered the poly''s in the players position. I have my triangles. I have an array of indicies in a seperate variable. I have a function that gets which sector you are in and converts it into an index of the SectorIndicies array. Then I loop through all of the SectorIndicies and check which poly is to be rendered. Note: I don''t compile my primitives.
Esap1
Esap1
I think I get it, but how do you find if a portal is visible? And do you render all the polys in a cell behind a portal?, is there a better way?
Spellbound
Spellbound
You need to check if the portal is visible yourself. You can let DX do a check for visibility, but I think it involves checking each pixel against the z-buffer, which in my mind is not that effective.

DX, and OGL for that matter, can only add planes that polygons are clipped to. I''m not how many of these planes that can be added. You need to figure out their position yourself by looking at the position of the camera relative the polygon.

Because clipping can be a bit slow I would recommend that you only clip the cells behind a portal to a bounding box (only 4 clipplanes that are axis aligned) instead of clipping to the edges of the portal. The z-buffer will keep the polygons in the right order.
Esap1
Esap1
I THINK I FINALLY UNDERSTAND WHAT YOU ARE SAYING!!!
Are the 4 Clip Planes Cliping 2D XY Corridinates on a bounding box around the portal?(I HOPE I GOT IT!)
nes8bit
nes8bit
If what esap1 is saying is how to do portals, then I''ve already done it in my game! Nifty.

BTW: I think the moderator modified my gamedev=non y2k compliant thing. I''d like to know why. Oh well, it was funny anyway.
Spellbound
Spellbound
Actually, I think it can be done even more simpler. Just change the viewport to the bounding rect of the portal. It''ll most likely be faster than adding 4 clipping planes. But this is only for rendering purposes. To check if an object (or another portal) is visible through the portal you should check its bounding volume against the visible frustum through the portal. The frustum is made up of the four previously mentioned clipping planes.
SiCrane
SiCrane
quote:
Original post by nes8bit
BTW: I think the moderator modified my gamedev=non y2k compliant thing. I''d like to know why. Oh well, it was funny anyway.


Off topic, but with the Censorship thread going on, I thought I should mention that you are looking at the wrong thread. The thread you were thinking of is called "List of Portal Tutorials." and your comment is still there.

Esap1
Esap1
Wouldnt it just be faster to list through the portals connected to the current sector and project each one(in my own code) and see if the projected points lie on screen. I think that I could right a faster function, as it would only do what I want it to do, and wouldnt have to worry about those silly Direct3D Classes and stuff, just a simple projection Equation, no need for matricies and stuff. Wouldnt that suffice?

PS:Thats so cool that people from Sweden and poeple from US would be talking about Game Programming, Who would of thought(its amazing!)
Spellbound
Spellbound
Unfortunately it is not that easy. You still need to transform the portal''s coordinates with the viewmatrix, otherwise you wouldn''t know if the portal is behind you or not.

But yes, you can transform the portals coordinates to screencoordinates and then check if it is visible. But I believe that it will be slower than to check if the portal is inside the visible frustum in 3D coordinates. Let''s compare computations:

To check if one coordinate is inside the visible frustum without world-to-screen transform:

Four dotproducts (coordinate to clipplane normals)
Four subtractions (clipplanes distances from origo)
Four if cases (to check which side of the planes the coordinate is)

To check if one coordinate is inside the visible frustum
_with_ world to screen transform:

vector-matrix-multiplication (Transform to screen coordinate)
Four subtractions (against the visible rectangle)
Four if cases (to make sure the coordinate is within the rectangle)

Now, if we go into the details of dotproducts and vector-matrix-multiplication we will see that the dotproducts are much faster. (dotproduct: 12 muls, 8 adds against vm-mul: 16 muls, 12 adds, 3 divs)
Esap1
Esap1
You were saying before that it would be faster to set the viewport to a different size, and it might be faster. When I change the size of the viewport it shrinks the screen(ya know?). Is there any way that It will clip the outside of the viewport, so I dont have to set up 4 different clipping planes? Thanks a lot!
Spellbound
Spellbound
If you also change the projection matrix to compensate for the change in viewport size and position you should still be able to use this method. You can use D3DXMatrixPerspectiveOffCenterLH() for the compensation.

Esap1
Esap1
Could I use D3DUtil_SetProjectionMatrix() for the projection matrix?
Spellbound
Spellbound
No, because that one computes a projection matrix that is centered in the viewport. But you can use D3DXMatrixPerspectiveOffCenterLH() without initializing D3DX it is just a function, like D3DUtil... There is no extra overhead with it. Of course you''ll need DX7 to use it but I assume you have that already.

If you some reason still don''t want to use D3DX you''ll have to come up with the matrix yourself. Of course, I could help you, but you have to ask first.

Esap1
Esap1
To use D3DUtil_SetProjectionMatrix() I need to use a D3DXMATRIX, But
SetTransform(D3DTRANSFORMSTATE_PROJECTION, &matProj);
takes a D3DMATRIX, what should I do?
Spellbound
Spellbound
That''s real simple: Just cast the D3DXMATRIX to a D3DMATRIX. I don''t know why Microsoft desided to use a new type for the matrices in D3DX since they look the same internally.

D3DXMATRIX Mtx;
D3DXMatrixPerspectiveOffCenterLH(&Mtx, l, r, t, b, n, f);
pD3DDev->SetTransform(D3DTRANSFORMSTATE_PROJECTION, (D3DMATRIX *)&Mtx);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.