Skip to main content
gamedev.net
🔒 Locked

Bsp rendering

Started by blueshogun96 3 replies 1.6k views
Original Post
blueshogun96
blueshogun96
Hey all, does anyone know a thing or two about Quake 3 BSP rendering? I'm using Direct3D to be specific but it doesn't really matter what you use since my problem is not related to any specific API. I have already written my BSP rendered and it works fine for most maps, but not the maps I want to render. Since I'm on my iPhone at a wifi hotspot, I can't share any screens of my problem right now. I can however tell you the problem at hand. My code is based off of the game tutorials.com code which works rather well and was the most straightforward example I could find. Every other tutorial was either too confusing, or had gone C++ class crazy!

My code renders all BSP faces and meshes using triangle fans which works fine for most maps but for more complex maps that I want to use in my game, the geometry is completely distorted! Triangle fans don't work, and I can't figure out how to re-organize the vertices into triangle lists. For those who want to know, I am trying to render the Simpsons map. So far, it is the most complex and most memory intensive map I have ever seen ( and yes, more complex than Pyramid of the Magician which also has the same problem) so I am not surprised. So far, it has over 300,000 vertices and takes up over 200mb of memory on my PC and requires 128mb of VRAM to render. Right now, I'd like to figure out some way to reorganize the vertices to render them properly. I don't have the slighest clue of what to do here, but I tried analyzing the vertices generated by the map. I was particularly looking for polygons that were 4 vertices. The trees render correctly, but the windows don't. Here are some vertices generated from a 4 vert polygon.

v0 = {-1971,-92,4696}
v1 = {-1971,-184,4700}
v2 = {-1971,-184,4696}
v3 = {-1971,-92,4700}

I tried playing around with the vertex order, but never got consistant results. Usually, it looks worse when I try to fix it.

So if any of you have experience with Quake 3 maps or have any ideas, please tell me your thoughts because I'm a few days away from going nuts!

Btw, I don't have Internet at my place atm so I won't be able to readily dl anything for a while. And if you don't know what map I'm talking about, you can do a quick search for Simpsons Q3 on YouTube. So far, I have never seen a single BSP loader render that map correctly, period. Some do a fairly decent job and and the gfx don't get distorted, but there is missing geometry everywhere. So far only quake 3 itself is the only loader that renders it properly.

Thanks for reading.
Zakwayda
Zakwayda
This might be a silly question, but are you tessellating the Bezier patches?

I wrote a Q3 renderer at one point that handled all the Q3 maps just fine, but I can't remember off the top of my head how the planar surfaces are represented. When you're able to, maybe you could post some images showing the problem - that might help.

Does your renderer already render all the Q3 maps correctly? (If so, that would answer my first question...)
21st Century Moose
21st Century Moose
This might also be a silly question, but have you looked at the Quake III source code? I believe that the BSPs actually store faces as triangle lists to begin with.

Converting a triangle fan to a list is easy, by the way. Just take vertexes 0, 1, 2, and that's your first triangle, 0, 2, 3 is your second, 0, 3, 4 your third and so on until you run out of vertexes. For better performance you can index them.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
blueshogun96
blueshogun96
Okay, here's a screenshot of the problem:



Now that I remember, I did post a thread about this a long time ago, sorry about that =( Even then, I didn't get an answer to my question.

@jyk, I don't have Quake III installed on my machine. I do have a copy of it, but it's in another part of the country with 2/3 of all my stuff (I just fairly recently moved) so I can't test against that. I guess I could always download a demo copy of Q3 and try that instead. I've tried several maps floating around the net (most of them work just fine).

Oh, and right now, I'm only rendering Polygons and Meshes, not Patches and Billboards. The reason for this is because my main focus is getting the more important parts working okay; not that patches aren't important, but most of the distortion comes from the first two primitive types.

@mhagain, I'm going to download another copy of the quake3 source today and look at that. Hopefully it doesn't get too confusing =(

I'll try reordering the triangles into triangle lists with the methods you specify. Right now, I've thrown everything into a vertex buffer and optionally use the index buffer. I'm doing a cross-platform game just for fun (the other platform is Xbox) and so far the Xbox version uses indexed primitives because D3DDevice::DrawPrimitive won't work with that map. So far, DrawPrimitive is faster than DrawIndexedPrimitive, but that's probably because I'm not doing it properly.

Other loaders I've tried are Paul baker's and another one using the Sipogen engine. Paul's does a decent job, but still gets a few distorted polygons. The Sipogen version renders it perfectly with the exception of a few garbage polygons (about 5 that stretch across the entire map), but without textures; only light maps. There's one more I found that appears to render it correctly using Direct3D, but doesn't render all the geometry because it's designed to skip any polygons that have no texture. In order to render this map correctly, I have to implement the shader files too (I think). I'll have to experiment with the code a bit, but this one is the most confusing of them all! =(

Btw, anyone have any links on BSP patches, billboards and shader files? Thanks.
Zakwayda
Zakwayda
Quote:
Btw, anyone have any links on BSP patches, billboards and shader files? Thanks.
For what it's worth, Q3-style patches are covered in detail in one of the Watt and Policarpo books (if you're looking for code examples, that is, and if books are an option).

You may already know all this, but the patches are nets of quadratic Bezier patches, with adjacent patches sharing control points. So for example, a surface made of 4 patches in a 2x2 configuration would have 5x5 control points.

Tessellating Bezier patches is fairly straightforward. With the right parametric values I think shared edges *should* match up exactly (even when floating-point error is considered), but I think when I did my Q3 renderer I 'stitched' adjacent patches together, just to be safe.

Patches also allow for basic level-of-detail support, in that you can tessellate them to different levels (either pre-computed or on the fly) based on factors such as distance to the camera. (IIRC, in Q3 the LOD algorithm actually doesn't take the camera zoom factor into account, so if you look at a curved patch from a distance but zoom in on it, it'll still be rendered at the lowest LOD :)

Topic Locked

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

Sign in to reply to this topic.