|
Posted by metlslime on 2007/08/08 04:57:56 |
This is a counterpart to the "Mapping Help" thread. If you need help with QuakeC coding, or questions about how to do some engine modification, this is the place for you! We've got a few coders here on the forum and hopefully someone knows the answer. |
|
|
#1095 posted by spike on 2013/10/04 12:03:40
4-byte alignment, not 4-byte length.
Figured
#1096 posted by ALLCAPS on 2013/10/04 15:14:34
I finishes up extracting and parsing entities before I passed out, and everything seems to be working! Good to have clarification, though; thank you. This is my first time ever trying to decode/parse a binary blob like this, so I'm learning as I go.
SharpBSP Is Born
#1097 posted by ALLCAPS on 2013/10/05 05:00:52
Here it is. Not finished, but getting there.
https://github.com/mikezila/SharpBSP
Once I have it working well and maybe crank out a winforms application that shows some info about a loaded .bsp I'll make a thread/news post about it.
I use C# instead of C++ partly because Unity3D uses it, and it'll make pulling this data into a Unity game/scene very easy, and partly because I'm a scrub that can't handle C++.
Not that anybody cares, but it's free to take/use/copy/modify.
Bezier Calculation
#1098 posted by ALLCAPS on 2013/10/08 03:56:20
I've made some pretty great strides in parsing and rendering Quake 3 maps. I've hit a snag, though, and that snag is bezier patches.
Here's a video showing what I have so far, and my issue with the patches:
http://youtu.be/8RfwLP0BrSI
Textures, texture mapping/coords are working 100%. Only textures provided by shaders are not working. Animated textures and billboards aren't implemented yet, either.
But issue is that the code to calculate bezier patches is code I lifed from an article on render Quake 3 maps, and did my best to port from what I assume is C++, to C#.
I used these two documents to parse the .bsp and to try rendering the bezier curves
http://www.mralligator.com/q3/ - Map format details
http://graphics.cs.brown.edu/games/quake/quake3.html - Details on converting the vertex systems/scale and bezier curve code
I'm really stuck, as I don't understand enough about bez curves to write my own implementation. Anyone here worked on rendering them that could lend a hand/advice?
#1099 posted by Spike on 2013/10/08 07:21:37
you don't need patches (they're evil), just use q3map2's -patchmeta argument when compiling maps for your game.
q3map2 will then generate trisoup instead.
Aces
#1100 posted by ALLCAPS on 2013/10/08 07:55:27
That's great to know, and I'll use that for sure if I develop a Q3 .bsp intending to load it into uQuake instead of actual Quake, but I'm tackling the issue of rendering the patches for the sake of being able to render existing Quake 3 maps that use them.
ALLCAPS
#1101 posted by metlslime on 2013/10/08 08:45:18
why not look at the quake 3 source code to see how it tesselates bezier patches?
#1102 posted by ALLCAPS on 2013/10/08 13:43:31
My raw understanding of the patches (and C/C++) is very limited, but I will likely have to do that. Right now I'm working on rendering multi-patch faces without any tessellation, just the reference points. I can render single-patch faces, but I'm working on how to extract the 9 reference points from the face, and making an individual patch out of that when there is more than one patch in the face.
Once that is done and references are rendering correctly, the only piece of code that will need changing to have beziers 100% working will be the method that takes those control points and fills the patches vertex and triangle strip data. Getting closer.
Okay....
#1103 posted by metlslime on 2013/10/08 21:11:11
well if your problem is the theory behind it, maybe i can help a little bit.
First, quake3 patches use bezier curves, which are parametric equations. This means that to generate a point on the surface you need to input a parameter. The parameter can go from zero to one, and as it moves from zero to one the point generated moves along the curve from the start to the end. The parameter is usually called "t".
Second, quake3 patches use quadratic curves, not cubic curves (which are more common i think), so that means they have 3 points to define a curve instead of 4. The three points are startpoint, control point, endpoint.
Third, how to solve a quadratic curve? First, look at this picture:
http://upload.wikimedia.org/wikipedia/commons/2/2d/Bezier_2_big.gif
P0,P1, and P2 are the three control points. Green stuff is intermediate calculations, and the red line is the final curve.
So to solve for the black point (a point on teh curve) you first find a point on the line from p0 to p1, call that A, then find a point on P1 to p2, call that B, then find a point on the (green) line from A to B, that point is your solution (black dot.) In all three cases, when you "find a point" you are finding the point using t -- if t is 0.5, find the halfway point. if t is 0.25, find the point 1 quarter of the way from the first point to the second point.
Okay, assuming you understand all that... the quake 3 patches are 2-dimentional surfaces, not just single lines. So instead of 3 points, they have 9. To solve it you need to do multiple tasks like the one above (solving a simple 3-point curve.) Since it's two-dimensional, to find a point you need two parameters instead of 1 -- instead of t, you need s & t.
Imagine the 9 points are arranged in a 3x3 grid. First row is 1,2,3, second row is 4,5,6, last row is 7,8,9. First solve three horizontal curves using s -- 123 is the first curve, 456 is the second curve, and 789 is the third. Each uses s as the input parameter. Each gives you one new point -- A,B,C. Now solve curve ABC with parameter t. Now you have found a point!
Okay, so now you can find any point on the surface of the patch using s,t coordinates. How to render a patch? What you do is divide the patch into a grid of quads. The vertexes of the quads are determined by inputting s & t. If you want N * M quads, you need (N+1) * (M+1) points. The first point is 0,0 and the last point is 1,1. Intermediate points are evenly spaced in between.
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.
|
|
You must be logged in to post in this thread.
|
Website copyright © 2002-2024 John Fitzgibbons. All posts are copyright their respective authors.
|
|