On lighting, and fudging it

Posted by Astryl on March 15, 2013, 7:37 a.m.

Another development log that is waffling about Exile's engine. Run for ye hills over yonder if you want; that's where we keep the basilisk.

I was on IRC again the other day, and aeron was asking questions about the level editor and lighting system in Exile. So here's a little bit of information.

First of all, there is no lighting in Exile; not in the strictest sense. The GL lighting system was too limited for the type of lighting I wanted to do, and I knew squat about creating a lighting system with GLSL back then.

So what did I do? I fudged it. Cheated. Whatever you want to say.

First of all, I decided to completely drop the standard diffuse formula and focus on the end result: The fact that when things are lit they're bright, and when they're not, you can't see them very well.

So I added a parameter to each tile that represented a light level, and it could be anywhere between 0 and 10 (Inclusive). This was converted into a GL color and added to the ambient 'light' level, and then used to render the tile/block it was associated with.

So in other words, it's not lighting but shading. And it works.

Only one minor problem: It's a lot of work for anybody designing levels. Which means me.

Each level starts off with a base level of 5. Halfway, basically. Then you paint light levels onto tiles with the mouse button. Which sounds fine in theory, but becomes extremely monotonous in practice; especially when you have a 300x300 tile level that has 5 layers. Even if you only use 25% of the available 'space' for your level, that's still 112500 tile spaces that would benefit from lighting.

Now, recently, I tried to add a Per Pixel lighting system to the game via shaders. This introduced a slew of new problems. One of them was speed; the engine isn't designed to use shaders, and it lagged on the first attempt.

Then when I finally got it to run at 60FPS again, it looked weird. I'll put it this way; 2D cutouts and 3D geometry with per-pixel lighting looks really weird.

So anyway, I'm still stuck with the old system. But fortunately for me, I came up with a simple automation system.

I created a program called lprop.exe, that reads in a map file, and performs a simple quadratic 'blur' for each cell, ten times, with simple constant linear attenuation.

And in short, the result is this:

Oh, and I fixed the gamma problems by dropping the fog density and tweaking the ambient lighting levels a bit. If the screenshot is still too dark, I blame it on the contrast on the site :P

Anyway, I added some new scripting commands, such as PRIORITY, which forces a script to stay at the head of the execution queue until completed. There was another one I can't remember. Heh.

I really need to stop screwing around with the engine now and actually finish re-making the game…

Comments