Sign in to follow this  
RuneLancer

Illumination problems

Recommended Posts

I'm having some strange problems setting up lighting in my game and I'm about to start pulling my hair out by the roots. If I set GL_FLAT as a shading mode and set my surface normals, polygons only seem illuminated properly when I stand directly on the first point drawn (at which point it's fully illuminated; my lightsource currently moves with my sprite.) On the other points, it darkens as though I were moving away from it entirely. (Image 1) Now, if I set GL_SMOOTH and use surface normals, well... the scene is properly illuminated. The illumination isn't quite correct but it's more than acceptable. (Image 2) And if I use vertex normals instead, well... (Image 3) What gives? It's not like I'm rendering anything too complex, just a few textured polies with a lightsource hovering about a unit above my sprite...

Share this post


Link to post
Share on other sites
u need to create extra vertices, cause some verts have more than one normal
eg say u have a point on the buildings corner, u need a normal pointing upwards, a normal point forward + a normal pointing to the left.
thus even though physically theres only one point, u (*)need to create 3 points (in the same position)

(*)unless u use immediate mode drawing

Share this post


Link to post
Share on other sites
I don't see why you'd want to use GL_FLAT anyway, but if you're actually considering hardware of different strengths in your target audience, I applaud you.

I don't know if this'll help, but one problem I encountered when I was playing with lighting was that GL would light the wrong side, even though it had the correct normal. Turns out even with the right normal, OpenGL is picky about which way you're drawing the vertices. On my tiled floors, it wouldn't get the GL_FRONT and GL_BACK correct unless I specified the vertices in counter-clockwise order, so keep that in mind even if it's not the solution for your problem at hand.

By the way, those screenshots look fantastic.

Also, I recommend always using vertex normals instead of surface normals, they look much better in just about any situation. You seem to have it down, but this article is very good.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
USE gl_flat with lighting off if you know what i mean. vertex lighting was cool 10 years ago.

Share this post


Link to post
Share on other sites
@zedzeek:
I kinda figured it might be something like that, but the articles I read were pretty sketchy. The most I could get from them was that the vertex normals were calculated by normalizing the sum of the surface normals of every polygon sharing the same point. I'm pretty sure I know how to fix it now, so I'll try a few things... Thanks. :)

@Foobar:
Well, I'm hoping I'll be able to support old hardware, but not legacy hardware. GL_FLAT was mainly a test to see if my surface normals were correct (if that much doesn't work right, I'm quite screwed to begin with ;) ) I'll keep your advice in mind though, that seems to be the problem with my first screenshot. And hey, if I already have GL_FLAT support, I might as well give the user an option to use it... Not that I can see any reason someone would want to.

I'm quite proud of the engine so far, thanks. ;) I've used OpenGL before but this is my first complete game engine.

That article is very insightful; makes me wish I had posted about this before. Thanks!

@AP:
I've also been considering using flat colors instead of textures (texture mapping was nice and fresh in the early 90s, but now everyone's doing it.) I'll see how that goes along with your suggestion of using flat-shading. :)

---

Assuming this works, another quick question. I've heard about simulating light instead of using OpenGL's support for it; are there any advantages to it? I'm not getting any performance issues (far from it, really) though if it offers anything important OpenGL doesn't I might give it a shot...

Thanks for the help! :)

Share this post


Link to post
Share on other sites
That same page I linked you to has an algorithm to simulate lighting instead of using OpenGL's built in stuff, as well as a good rundown of the advantages and disadvantages, plus screenshots of what it looks like. It's on the sidebar.

It's actually worth going through most of what Lighthouse3D's OpenGL section has to offer, it's all very well written, especially the terrain stuff. (My terrain engine uses their smoothing algo and it looks really neat) I can't say I like their heavy use of pseudocode, but at least it makes you think instead of blind copy and paste :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this