Skip to main content
gamedev.net
🔒 Locked

2d lighting

Started by ari556655 2 replies 1.2k views
Original Post
ari556655
ari556655
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
Zakwayda
Zakwayda
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?
ari556655
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.
Zakwayda
Zakwayda
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.