Jump to content
  • Advertisement
Sign in to follow this  
ari556655

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.

If you intended to correct an error in the post then please contact us.

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. pic1 pic2 pic3

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by ari556655
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.
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!