November 30, 2009

Lightmaps and Vertex Buffer Objects

I spent some time familiarising myself a bit more with multipass rendering. I set up a very simple test application where I could do live editing of the major settings and see the effect.

This had a quick win: I figured out that my equation for blending in the lightmaps was wrong. The screenshot above shows the right settings (with the top for the base texture, and the bottom for the lightmap). The screenshot below shows the result when applied to a Quake level.

The scene is much more vibrant now. I think this is how it should have looked from the start. But it's hard to find this kind of information online. It really takes some experimenting to figure it out.

I also put some work in improving the performance. I figured that switching from vertex arrays to vertex buffer objects should be a smart thing to do. This way I could upload the scene data to the graphics card just once, and reuse it as needed. No more continuous streaming of vertex array data. Everything is reduced to a bound id and an offset.

The result isn't bad: an increase in fps of about 50%. So where I got 100fps before, now I see 150fps. In some locations that goes up to about 200fps.

Next I should really do some cleanup of my code. All the hacking and experimenting has degraded the quality somewhat.

November 25, 2009

Lightmaps (ctd.)

I tried to improve the framerates for lightmapping by going for a multipass rendering setup. And it seems to have worked.

Rates are up from about 5fps to around 100fps. Not bad for a multipass-newbie.

But it could be better. I'm thinking 200+fps should be reasonable for simple lightmapping. So the experimentation continues.

All tips are welcome. :-)

November 22, 2009


I got lightmaps working. As you'll see it's very pixelated. I need to set the right texture filters to fix that. It's also very slow, but that's because I'm (again) throwing too many texture switches at the graphics card. Need to fix that as well.

November 17, 2009

Another copy-paste victim

Seems I forgot to remove the following from my code:

try {
} catch (InterruptedException e) {

This also nicely explains the five fps I was getting. :-)

Aaaaaaanyhoo, framerates are obviously up. Seem to be ranging from 150 to somewhat over 200 depending on the part of the scene you're viewing. Quite pleased with that. This gives me a good base to work further from. On the todo-list: lightmaps, patches (the Bezier kind), and fixing the geometry and UV coordinates (Quake 3 BSPs use a different coordinate system from OpenGL).

November 16, 2009

Still got the BSP bug...

so I'm trying to make the most of it.

Here's the story sofar. I'm walking the BSP tree and am using frustum culling to prune the tree down. I'm also using bitmasks to prevent against double rendering of faces. And I'm grouping faces per texture to cut down on texture switches.

The result: the framerate is quite steady, but it is steady at a very low number: just under five fps. This is despite the aggressive culling I have been doing. I just did some profiling and even when drawing only fifteen faces, making use of four textures, my framerates won't cross the five fps border.

At this point I'm thinking the problem is not with the BSP rendering. I'm thinking the problem is with the textures. I remember doing a simple skybox once (that's just six quads, each with one texture) and it was slow even then. And that was just a silly skybox...

If it is the texturing I don't have any immediate ideas on how to fix that. So I think I'll start with trying to verify if it is indeed texturing that's to blame. But given the minimal amount of vertices I'm pushing I don't see what else it could be.

Update: Well, disabling all texturing in the level doesn't help. My framerate is only marginally better, but still no five fps...

November 11, 2009

BSP Rendering (now textured)

With some more work I now have textured BSP levels going. Take a look.

No lightmaps yet. And the psychedelic colours in the previous post were still an error made by me. The real colours are much nicer.

The current rendering is slow as hell (not fps but spf, if you catch my drift). That's mainly because I'm not using the visibility information yet to cut unnecessary clusters. I'm also being quite liberal in switching texturing on and off, and not caching any of the textures. So some obvious improvements to be done.

But that's for another day.

November 10, 2009

BSP Rendering

Yeah. I think I'm doing something wrong. ... lol :-)

Update: well, the vertex data seems correct, at least. I'll need to check that I'm using the correct mesh definitions.

Update: the face data is also correct. So I'm probably doing something wrong when trying to use vertex arrays...

Update: figured out my problem. I was using the "firstVertex" value as if it were a byte offset into the vertices, when it was really saying "the n-th vertex". I.e. I had to multiply it with the size of a vertex to get the real offset in bytes. So now it's looking much better... except for the psychedelic colours. :-) That's not a mistake though. I'm just not using the textures yet.

PS. This tutorial is quite helpful if you're considering of trying this for yourself.