OpenGL Lighting Options

Started by
10 comments, last by Krypt0n 13 years, 2 months ago
Hello,


I am currently in the process of creating my own OpenGL based 3D game engine (with FPS in mind) but am running into problems with the lighting. Take a look at this screenshot (actually taken in the 3D model editor but the problem is the same):

2d0kzd5.jpg

As you can see, there are problems with the gourad shading on the front handguard of the weapon (the plastic bit). I tried phong lighting but this didn't really work, the problem areas still looked like individual triangles.
Take a look at a conceptually similar weapon in DICE's Battlefield BC2:

943199379d1264603300-bad-company-2-pc-beta-screenshots-bfbc2ss.jpg


What can I do in OpenGL? Can I use environment maps to simulate lighting? How do proffesional games acheive their near-realistic lights and shadows? Is Phong really an option? Phong-Blinn? Can I create light based environment maps?

Thanks

mikenovemberoscar
Advertisement
It looks like some of your normals may be wrong or facing the wrong direction.
Have you tried rendering the normals for the vertices as a sanity check?
Thanks for the reply, I looked at both face and vertex normals and re-calculated them but they seem to be OK. I also noticed that the surface looks fine when viewed from around 30º perpendicular to the normal, i.e. the triangles only appear when not viewed side-on.

Edit: This is the weapon modeled, you can see how the green plastic looks 'matte', and how the lighting looks smoother on the plastic parts: L98A1.JPG
It looks like the problem comes from the vertex normal generation .
You are running something like this?

for all vertex normals { Set to zero }
for all triangles { Add the face normal to the vertex normals used by this triangle }
for all vertex normals { Normalise normal }

There are a few techniques that will get you a better result from just triangle data. Checking the angle between adjacent triangles, and only use the face normal across the edge if less than something will probably get you a better result.

Best is of course to get an artist to create the model with normals for you.

-Morten-
Well, thanks for the input, I will try that, also, is there an alternative to gourad shading? I can't imagine that tweaking the normals would improve the actual lighting?
When your normals are totaly wrong, as in your picture. Then you have to fix them, as simple as that.
Two (conceptually related) things that DICE does that you don't-- normal maps and per-pixel lighting. I'd be willing to bet you're using the standard (per-vertex) OpenGL fixed-function pipeline-- this quite frankly won't cut it if you want the end result to look decent in any way. While I'm not an OpenGL expert, I believe you actually have two options here; you can look into a fixed-function implementation-- DOT3 bump mapping, as I believe it's called-- or actually do things yourself via shaders. The second option would be considerably more flexible, but this can be a bit of a leap in complexity, especially if you aren't used to them.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Looks like you used smooth-shading (Blender terminology for averaging normals) on sharp edges. In Blender, to create sharp edges among smooth surfaces, you need to duplicate the sharp edges.

I agree with Danny02. No lighting model (apart from no light at all) will fix this problem.
Well, thanks all for the helpful replies. I tried using the 'edgesplit' modifier in the 3D modeler (duplicates it's 'sharp' edges, similar to Ohforf sake's solution) and this solves the initial problem temporarily:
zk4yv9.png

I can obviously tweak the mesh to remove artifacts such as those on the rear of the pistol grip, but if you look at the photo of the real weapon above there is a round soft highlight running the length of the handguard. I take it that this lighting can be produced with Invalid Pointer's DOT3 bump maps and per-pixel lighting?


if you want to get smoother lighting without going into normalmaps/fragmentprograms/perpixellighting, then you could simply tesselate your geometry. most games are fragment bound and your simple shading won't hurt it, so you can easily tesselate your models finer.

This topic is closed to new replies.

Advertisement