What A Scholar
#1104 posted by ALLCAPS on 2013/10/10 05:32:58
That helped me so much, that using that info, some time and study, and some patience I have perfected parsing, tessellating, and rendering (with textures!) Quake 3's bezier patches. Huzzah!
http://imgur.com/a/i470V
Textures that are provided by shaders in Quake 3 aren't working for obvious reasons. I also need to debug lightmap ripping/application, but those are pretty minor issues. Unity's realtime and baked lights look better anyway.
Thanks a ton.
UQuake
#1105 posted by ALLCAPS on 2013/10/10 05:51:40
Here is a link to the github of the project. It's free to do with as you please.
https://github.com/mikezila/uQuake
Don't want to keep mucking up the coding help thread, so if/when I make videos and take screenshots to show it off I'll probably make a new thread.
#1106 posted by metlslime on 2013/10/10 07:42:32
Nice, you got it working! Glad to help.
Neat!
Is this a quake 1 engine??
Unity3D
#1108 posted by ALLCAPS on 2013/10/10 15:04:28
The engine itself is Unity3D, which is a freely available engine that you can use for almost anything. I've built a reader for .bsp files, and a "renderer" that creates the level as Unity gameobjects. It's not a "true" bsp engine because only the geometry is used, things like leafs, nodes, the bsp tree itself, and vis data is not used. Unity handles those things on its own at runtime.
Right now it only supports Quake 3 maps, but I want very much to add support for Quake 1 maps. Once I get lightmaps working on Quake 3 maps I'll set to support Quake 1 maps. My original goal was actually Quake 1 maps, but extracting the geometry from them is a little more complex than Quake 3 maps, so I did this first as a warm up and to see if it was possible.
Very Cool
#1109 posted by necros on 2013/10/12 00:03:03
nice work figuring it out!
It's Time For Q1 Support To Begin!
#1110 posted by ALLCAPS on 2013/10/13 03:14:47
Alrighty, Quake 3 lightmap support is done. The colors aren't as vibrant as they should be because Unity's RGB lightmap shaders are lame, but the data is ripped and applied correctly. I also replace shader-modified textures with non-shader versions at runtime. Like on the strange flesh-spire and lava here.
http://imgur.com/tO3SSUP
But like the title says, it's time for Quake 1 support. The most comprehensive guide to the Q1 .bsp specs is here:
http://www.gamers.org/dEngine/quake/spec/quake-spec34/qkspec_4.htm#CBSPG
Is this still current? It's really old, and says it matches the .bsp version used in Quake shareware. Is there a more detailed or updated guide on the .bsps produced by modern compilers?
Q3 Lightmaps.
#1111 posted by Spike on 2013/10/13 05:07:34
q3 has overbrighting. the lightmap scales between logical rgb values of 0 to 4 rather than 0 to 1. The lazy way to deal with that is to just multiply the values by 4 and clamp to 255. The real way to deal with it is to scale your vertex colours by 4 instead, or to put the same scaling in glsl.
This nonsense allows bright areas to oversaturate textures, thus textures which are grey colours can brighten up to become more white in bright areas.
Software vanilla Quake has a similar feature. vanilla glquake just clamps.
Check some engine's bspfile.h, like that markv_bsp2 zip I hacked together recently if you're after bsp2 support. Otherwise bsp29 is still the same bsp29 that's documented in your link.
Trianges?
#1112 posted by ALLCAPS on 2013/10/13 20:17:41
Was studying the BSP29 document some, and I realize that nowhere is there a list of triangles for any of the faces. Is there something I'm not seeing, or does it fall to me to figure that out using sorcery?
I Don't Think Bsp29
Works like that. It's the .map file that has that info and that is then compiled into a scrambled file?
Process
#1114 posted by ALLCAPS on 2013/10/13 20:38:34
When I was reading the Q3 .bsp into Unity my process was like this.
Take a face. A face has a list of vertices, and a list of triangle indexes into that faces vertex list. So to make a mesh out of a face all I had to do was make a mesh, and set it's vertex and triangle arrays to the data I pulled out of the face. Each vertex object has data about it's position, texture coords, color, and lightmap coords. The whole process was actually pretty slick.
In Quake 1 it seems like every surface has a list of edges, and each edge has two vertices. Using some simple rules and maths getting a list of verts and the texture mapping info for those verts doesn't seem too hard. So I make a mesh and add the verts and texture coords. But how do I form triangles? In Quake 3 that data was provided for me, but here it's not.
Is each face only going to be three verts? That doesn't seem right. Are the faces always going to specify their verts in the order needed to form triangles out of every three verts?
#1115 posted by Spirit on 2013/10/13 21:39:31
Noesis can load bsp files, you might be able to find well readable code in there. http://oasis.xentax.com
ALLCAPS:
#1116 posted by metlslime on 2013/10/14 04:36:14
you have to triangulate it yourself, i think. All the faces are convex polygons, so it shouldn't be too hard to triangulate them. Only down side is there may be some degenerate triangles due to extra verts added for tjunctions. I guess you should keep these because otherwise you may get visible cracks.
#1117 posted by ALLCAPS on 2013/10/14 04:40:50
Dang, really? The renderer back in the day mashed out the tris for the whole map each time it loaded? That's unreal.
#1118 posted by metlslime on 2013/10/14 05:39:25
actually the software renderer directly rasterized polygons, so it never needed triangles. Later opengl versions would use GL_POLYGON primitive type, so they didn't need triangles either.
Well...
#1119 posted by ALLCAPS on 2013/10/14 07:23:31
I guess since every poly is going to be convex I can just ham-hand it and make tris using a pivot point and casting to each other vertex. 0-1-2, 0-2-3, 0-3-4, etc. It's the least efficient way possible, but I guess it's sure to cover the full face. Come to think of it when I r_showtris in some engines it looks like that's what it's doing.
Efficiency
How is this "least efficient"? I don't see a more efficient way to generate triangles from convex polygons.
#1121 posted by ALLCAPS on 2013/10/14 19:41:17
Honestly I just assumed it was the least efficient/elegant way since it was the first solution I thought of. Probably because it's simple. I just figured there'd be a more complex, "better" way.
#1122 posted by Spike on 2013/10/14 20:11:26
each edge has two sides. pick one vertex from each edge based upon the side of the edge you're using. side is determined by whether the edge index is negative or not. this will get you a convex polygon (aka: a triangle fan). more modern renderers can trivially generate triangles from that.
the whole thing is just triangle fans. software kept it like that because its easier to clip+frustum cull, which is part of how it managed to avoid all overdraw from bsps.
remember, these face polygons are never concave. there's no holes or anything. its pretty trivial because of that.
Efficience Of Triangle Fans
#1123 posted by Preach on 2013/10/14 22:04:35
Strictly speaking there may be an inefficiency there in rendering>/i> those triangle fans. According to a half-remembered article I read a while back, long, thin triangles are slightly less efficient to render than evenly proportioned ones. I'd hazard a guess that's due to better cache-coherence properties of the latter.
I wouldn't worry about it though, primarily because it's a tiny difference. Also because almost all the polygons in quake maps will be 6 sides or less, so there's not a great deal of difference between the best and worst choices.
#1124 posted by JneeraZ on 2013/10/15 00:58:42
This is where I've had the nagging thought that I'll bet modern engines could just create large, texture sorted buckets of triangles representing the entire level and just throw it at the video card. Odds are that on even a mid-level machine, it would run fine.
Keep the BSP for collision checks and line-of-sight stuff, but in terms of raw rendering I wonder if parsing through the VIS data is actually a detriment these days.
You Know...
#1125 posted by Spiney on 2013/10/15 01:20:53
Brute forcing winning over the elegance of a BSP traversal algorithm always felt like an aesthetic unfairness to me.
Not that I mind scraping the vis times.
Almost Reads Like A Carmack Tweet
#1126 posted by Spiney on 2013/10/15 01:23:22
I need to get some sleep
BSP
#1127 posted by Preach on 2013/10/15 08:42:09
Remember that visibility tests aren't used exclusively by rendering - they're also used by the ai as the first step of deciding if the player can be seen or not. So you will take a double hit on performance as every monster in the level starts doing traceline visibility test every frame.
Of course, it's pretty easy to test the hypothesis that vis is unnecessary - just build a map, saving a copy of the un-vised BSP file as you go. Then compare performance across the two files. You could even run vis at all the different levels and have multiple points of data. I don't know if there's any hard data on how much of a fps gain you get from making vis more accurate, it might be thaat they highest levels don't provide a good return on investment.
TrenchBroom Does The Brute Force Thing
It just throws texture-sorted triangles at the GPU, and it's pretty fast. The only drawback is that you have to reupload a lot of data to the GPU when the user changes the geometry, but since usually only a few brushes are selected at a time, just uploading the selected geometry is fast enough.
|