Runtime Lightmapping Question

Blitz3D Forums/Blitz3D Programming/Runtime Lightmapping Question

ClayPigeon(Posted 2011) [#1]
My skill with using complicated maths in conjunction with programming is limited, and I need to create some method of baking static lighting into my levels at runtime. Before you say it, no. I'm not using any external code that someone else made. So no YAL. Fortunately, this might not be quite as difficult as previously thought, because the bulk of my world is made completely of large cube-like structures aligned to a grid. So, I don't have to deal with any polygon intersections, just AABB's. So the real question is, how do I partition the texture space of my lightmap for all the faces of the mesh? And remember that everything is cubic and grid-aligned.


Yasha(Posted 2011) [#2]
I'm not using any external code that someone else made. So no YAL.


Why not? YAL is public domain.

cube-like structures


Define "cube-like". If they're actual regular boxes, you will be able to cheat in ways that wouldn't be available for arbitrary mesh shapes, but cheating always depends on the details of the restriction!


Kryzon(Posted 2011) [#3]
You'll have better luck in the Graphics Programming and Theory forum of GameDev.Net. Although, there are plenty of questions about it already.

What you're looking for is Bin Packing, a "combinatorial" area of algorithms that deal specifically with this problem of efficiently packing smaller structures into a bigger, limited space.


Rroff(Posted 2011) [#4]
There was a thread recently:

http://www.blitzbasic.com/Community/posts.php?topic=92901

Where jfk EO-11110 and myself were bouncing some code around for doing various real time shadow mapping including a concept test for ICU real time lightmapping - unfortunatly nothing produced acceptable results but you might find some of the code handy for reference purposes.

Video of the sort of stuff here:

http://www.youtube.com/watch?v=ydJCmXEHLrY

Unfortunatly you either have to trade off shadow accuracy or performance and theres no middle ground with OK performance and acceptable quality without using pixel shaders and if we had access to them in B3D then there are miles better ways to do real time shadows but you might find it a good way to quickly build lightmaps for each static light (tho you'd probably need fastext w/ render to texture to get high enough quality).

Last edited 2011


ClayPigeon(Posted 2011) [#5]
Why not? YAL is public domain.


Because:
A. My problem is simpler and YAL is just overkill.
B. I always like to understand how what I'm using works, so I don't want to jump into YAL not understand how it works.

Define "cube-like".

Aligned to a grid. All faces are perfectly square. Imagine Minecraft but the blocks are 4x the size. And this has just given me an idea on how to do the packing. Since all faces are square, I could just create an true/false array and set each occupied square of image to true. This works because the face size is always the same. So I might not even need help with this! Although I'm still not sure how I'll find the collision point between the ray of light and the cube..

Unfortunatly you either have to trade off shadow accuracy or performance and theres no middle ground with OK performance and acceptable quality without using pixel shaders


*facepalm* I knew I should have picked a word for the topic title that looked less like "realtime". I want precalculated lightmaps. But thanks for your contribution anyway and the RT lightmapping you've been working on is pretty amazing!


Rroff(Posted 2011) [#6]
Sorry that comment wasn't exactly aimed at your implementation itself it was just a general comment on the systems tested in that thread - but a lot of them are heavily based on similiar mechanisms to pre-baked lightmaps so the code could be useful to you with some adjustment baring in mind things like quality bias.