Log in

View Full Version : Lighting In Opengl


Nick
19-09-2005, 08:56 AM
I wonder, how people achieve such great effect of lighting, for example, in Max Payne. I heard about Phong method of lighting (by default we use Gouraud), but just don't know how to do it in OpenGL. Does anybody know some sources?
Red Book advises to divide large polygons into small ones, but then, when you try to create spotlight, you'll see not round spot, but jagged.

Blood-Pigggy
19-09-2005, 10:06 PM
Max Payne largely was it's own engine, and using that they can incorporate their own lighting and graphics system into it, then allow a 3D card or 3D service to read the data then execute it using all parts such as the 3D renderer and etc.
Otherwise I have no idea how you can actually do it in OpenGL

Nick
04-10-2005, 07:36 PM
Here's what I achieved after reading some literature (actually it was presentation).
Pretty far from life, but it's only beginning... Please, if you have any advises, it would be very good.

Nikson
16-10-2005, 01:46 PM
The Phong model is much more computationally intensive, so it's not used for real-time 3d rendering (like games). OpenGL uses only Gouraud for this reason.
Dividing large polygons into smaller ones will provide a much more accurate lighting effect, since the same surface as before has more detail - specifically, each of the new polygons has its own normal vector that is used to better approximate light reflections and the shading model.


As for your lightmap test -

Notice how when the ball gets close to any wall, the parts of the surface outside the spotlight falloff area become very dark? The simplest way to fix that is to have a small amount of white ambient light in the room.

Nick
16-10-2005, 06:10 PM
Originally posted by Nikson@Oct 16 2005, 01:46 PM
The Phong model is much more computationally intensive, so it's not used for real-time 3d rendering (like games). OpenGL uses only Gouraud for this reason.
Dividing large polygons into smaller ones will provide a much more accurate lighting effect, since the same surface as before has more detail - specifically, each of the new polygons has its own normal vector that is used to better approximate light reflections and the shading model.


As for your lightmap test -

Notice how when the ball gets close to any wall, the parts of the surface outside the spotlight falloff area become very dark? The simplest way to fix that is to have a small amount of white ambient light in the room.
I said before, that dividing polygon into smaller ones results in "jaggs" and we loose in performance. More than that, many modern games use lightmaps (Quake III for example), because we can win in speed - first, because we use lightmaps, thus giving all job to video card instead of processor, and second, we can use multitexturing from video card extension, thus winning in speed more.
You're right, for example, when you create a surface with evaluators or when you rendering a model, loaded from some editor, of course, there's no reason in using lightmaps. But when I tried to divide polygons in one of my program, I got only 24 - 25 FPS plus those jaggs, when I created spotlight, whch light fell on the floor consisted of small polygons.

EDIT: It's better to change texture coordinates instead of polygon's with lightmap. We can keep depth test on in this case. If you use two pass multitexturing, of course.

EDIT EDIT: By the way. Maybe I wrong, but today, when I wrote another prog with lightmaps, I discovered, that lightmap coordinates forestall bubble coordinates in 12.5 times! In that program you can move round bubble with keys, so together with bubble, alter lightmap texture coordinates.

Nikson
16-10-2005, 10:33 PM
I didn't argue about dividing into smaller polygons affecting performance. Obviously, the more objects there are in the scene, the more calculations it takes to render. However, I've never heard of anyone getting a worse image from using more detailed objects, with lightmaps or anything else. Strange.