Lights in Lightbound

Posted by Astryl on Sept. 25, 2013, 3:04 a.m.

So, I accidentally spent time on my other competition entry. I'm still undecided as to which one I'm going to finish, so I'm working on both.

As for how I accidentally spent time working on it… I was going to play some Minecraft last night, but I kinda missed the launcher (By about ten inches).

Anyway, this is where I was, post 7DFPS:

I had introduced GLSL shaders to Exile's engine, and was doing a great job of borking simple lighting calculations. Also, everything was too shiny.

So last night, I opened the project again (And branched it), and decided to start working on the Lightbound side of things.

Lightbound has an emphasis on light and dark, so I basically decided that if I had made no progress in my lighting code by the end of the night, I'd ditch the idea.

In GM I had fudged the lighting by using fog. The results couldn't be called great.

Anyway, Exile's engine.

Even though I've added shaders to the game thanks to SFML 2 supporting them (almost) fully now, I was still limited in what I could do.

SFML still lacks a way of sending attributes to shaders, something that is very useful when working with lighting (Can send in several attributes per vertex for a light source, or an array of light sources).

I can still access the attributes mechanism via the normal OpenGL functions, but if I'm going to do that, I'm rewriting my code to load the shaders itself. Which I'm going to do; I want full access to the OpenGL 3.2 specification.

The only way SFML provides for passing information to a shader is via Uniform variables. Uniforms, though, are more or less intended to pass information that doesn't change per object.

Using it per-vertex is slow as heck (I've tried it before).

So I decided to use a bit of trickery.

First of all, I implemented some basic Hemispheric lighting, to set the ambient levels. That didn't require much in the way of work or data being passed around.

Then, I created a function that took a vertex position, and calculated the nearest/strongest light source nearby using a simplified distance calculation, then returned a value between 0.0F and 1.0F.

From there, I called this per-vertex and passed the return value to glVertex4f, then trimmed the w value in my shaders to calculate lighting intensity per vertex.

Here are the results so far:

And if you think I'm having saturation issues… nope. Both of the textures I used for the test map are similar shades of gray.

Then I took some of Lightbound's original tiles and dropped them into a test map.

Anyway, the lighting isn't perfect. Far from it. I'd love to implement something a bit more complex (And with real shadows), but I'll take what I've got so far and ride with it.

There is something I need to do. You'll notice in the first screenshot of the new lighting code that the back wall isn't lit. This is because the light is positioned at the corner of the grid position instead of in the middle of the grid position. Fortunately for me, that's a simple fix.

Now, on the surface the lighting doesn't really look that useful/interesting. But with the system I have now, I can finally add dynamic lights, which is one of the backbones of the game.

Comments

death 11 years, 2 months ago

only thing i can point out is it's kinda hard to tell where the light is coming from. it also seems to go from well lit to very dark a bit too quickly.

Astryl 11 years, 2 months ago

The problem with the light sources will be resolved when I add entities that can represent light sources; I could, and have done while testing this, draw a little halo of light around the area the light is positioned.

But I'd rather have certain objects render at the same intensity as the light and appear to be the light source.

As for the second problem, that involves tweaking the attenuation, which I'm doing.

death 11 years, 2 months ago

well once you gets those problems ironed out i think this is going to look pretty decent. It's about as far as i've ever gotten with lighting. Fairly simple but gets the job done, all you gotta do is watch out for the performance impact. That's my main problem with my own lighting scripts and Normals is my problem with GM lighting. >_>

also tip: light sources look better in pairs or in the center of rooms.

Cesque 11 years, 1 month ago

I think it's looking pretty slick. I also think it interacts rather well with the pixelly graphics. For some reason, the last screenshot is how I imagine Amnesia would have looked if it was released in 1996. It'd be great to, you know, actually see it in action :3

Quote:
only thing i can point out is it's kinda hard to tell where the light is coming from.

It's coming outta the goddamn walls!

Astryl 11 years, 1 month ago

Quote:
It'd be great to, you know, actually see it in action :3

Maybe when I've got some more game in the game. At the moment it's a fancy walking-into-walls demo. :P

Charlie Carlo 11 years, 1 month ago

Mega, your avatar.

You look like a bad-ass.

Astryl 11 years, 1 month ago

Everybody needs to start using their real faces as their avatar, so we can have "Most Badass Programmer/Musician/Artist/Writer/Etc" contests.

JuurianChi 11 years, 1 month ago

No

Astryl 11 years, 1 month ago

Heheh. Somebody has something to hide. :P

Castypher 11 years, 1 month ago

I'm shit at picture-taking, but if I get a good one, you're on, and your clones won't save you this time.