OpenGL 2d lighting

This topic is 3424 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm working on a 2d isometric game using opengl(using textured quads as sprites), and currently I'm playing around with ideas with which to enhance my lighting system. I currently use dynamic lighting, subdividing quads and lighting them but I'm wondering if there is any way that I could implement a more advanced form of lighting that takes into account the angle between the surface and the light source? I'm fairly new to the whole subject of lighting and I'm basically just looking for some direction as to whether or not this would be feasible(as well as what kind of result it might produce) taking into account the limitations of my project. Here are a couple screens to illustrate my current lighting method. Thanks.

Share on other sites
How are you doing the lighting currently? Are you just attenuating by distance? Are you computing the lighting values yourself, or using OpenGL's lighting system?

Share on other sites
I do not use opengl, I calculate the attenuation myself by distance, each light has has two variables, center_radius and falloff_radius, the center radius is totally bright(1.0) and the falloff radius linearly interpolates between the center radius's brightness(1.0) and whatever the ambient light in the may be.

Share on other sites
Quote:
 Original post by ari556655I do not use opengl, I calculate the attenuation myself by distance, each light has has two variables, center_radius and falloff_radius, the center radius is totally bright(1.0) and the falloff radius linearly interpolates between the center radius's brightness(1.0) and whatever the ambient light in the may be.
Lighting calculations can get more or less arbitrarily complex, but if you just want to add direction into the mix, that's relatively straightforward.

For a point light, what you're interested in is the dot product of the vertex normal and the normalized vector from the vertex to the light's position, e.g.:
vector3 v = normalize(light.position - vertex.point);float d = dot(v, vertex.normal);
If the result of the dot product is negative, there is no contribution from the light; otherwise, you can use the value (which should be in the range [0, 1], more or less) to attenuate the contribution of the light.

(Note: The above is off the top of my head, and I can't guarantee its correctness. This stuff is well documented online though - just Google e.g. 'lighting equations' and you should find plenty of references.)

Once you get that working, you might also try out some different attenuation functions for distance. A linear function will work ok, but it's common for the distance attenuation function to be non-linear.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 13
• 93
• 11
• Forum Statistics

• Total Topics
632972
• Total Posts
3009627
• Who's Online (See full list)

There are no registered users currently online

×