View Full Version : Directional Light
04-13-2002, 10:01 AM
Ok, I want to make a light for my program which has a fixed point and cast a directional light from there, like the sun would, so if i have a cube, the side facing the light would be a lot lighter than the side opposite of the light, and if i move the view the light doesn't move with me. If there is a tutorial, or anything that could help me I would very much appreciate it. Thanks.
04-13-2002, 01:19 PM
Try the beginner's board. Or some of the tutorials at nehe.gamedev.net which do this in five easy steps.
First, directional lights have a W component of 0.
Second, the sun it not a directional light. Just look at the sun and see for yourself, it's not an infinitely small point, but a large disk (sphere to be correct) emitting light.
[This message has been edited by Bob (edited 04-14-2002).]
04-14-2002, 04:36 AM
Are you suggesting that the suns light attenuates over the earth? Have you bionic eyes? http://www.opengl.org/discussion_boards/ubb/smile.gif
A directional light has parallel light rays. The light rays form the sun is hitting the earth in different directions (not counting reflectios). And the difference in direction is, in my oppinion, a little bit too large to be considered a directional light source. The reason for this is that the sun is so large that the relative distance to the sun becomes small.
For the attenuation part, the earth is too small to see any distance attenuation worth mention.
04-14-2002, 07:21 AM
hm.. i think the curvature of the earth would be visible first.. and all the games use flat planes http://www.opengl.org/discussion_boards/ubb/wink.gif
really, i don't think the difference between a directional lightsource and a point-light would be measurable in floatingpoint-values for square fields of possibly 1km size.. (and thats enough for most games http://www.opengl.org/discussion_boards/ubb/wink.gif)
You are talking about the direction from a point on the earth to the center of the sun. Sure, the difference in direction over a 1x1 km square is small.
However, the sun is large, and not a samll point. Take a look at this piece of high quality art.
sun | O <- earth
The light rays are no parallel. Rays from the top of the sun hits the earth, as do the rays from the bottom of the sun. Just look at the sun a sunny day, see how large it is (for example, with a ruler on an armlength distance), and measure the angle between the top of the sun, your eyes, and the bottom of the sun. Any decent calculator should have the precision needed to calculate it.
04-14-2002, 08:49 AM
But the upshot of all this is that the sun can more than adequately be approximated using a directional light.
Sure you can approximate it well with a directional light. I just don't think it IS a directional light, casue the rays are not parallel.
04-14-2002, 10:01 AM
Reality check: The scattering of the atmosphere is at least 10x more important to visual quality than the difference between "area light" vs "direction light" for the sun.
04-14-2002, 10:08 AM
exactly.. nope, 11.24x as important..
there's a nice ati-paper about this.. looks very cool..
04-14-2002, 12:30 PM
Should be using cube maps to do outdoor lighting anyway... http://www.opengl.org/discussion_boards/ubb/smile.gif
Bob, your diagram is horribly misleading because it's SOOOO far out of scale. With the distance between your earth and sun, you probably wouldn't be able to visibly see either one of them.
Here's a quick calculation to see just how "not parallel" rays arriving at the earth from different sides of the sun are:
Sun radius = r = 7.0x10^8 m
Distance from earth to sun = d = 1.5x10^13 m
Angle between two light rays arriving at earth - one from the top and one from the bottom of the sun = 2.0f * atan(r / d) = .005 degrees.
Wow, .005 degrees. While you may be able to represent that with a float, you would never ever notice it.
I'd also like to point out that this is moot anyway because you guys are arguing in reverse. OpenGL's positional lighting doesn't account for the fact that a light source may be distributed in space. It still considers the light source to be an infinitely small point. It just doesn't make the assumption that all the rays are parallel (i.e. the light is infinitely far away).
04-14-2002, 02:38 PM
Ok, my mistake, i thought a directional light was a light coming from a certain direction, whatever, forget the names I used, how bout this... I want a sun, which makes the side facing it lighter than the side not facing it. That's it... Does anyone know how to do that?
04-14-2002, 10:17 PM
yes. with a directional light looking in direction of the sun http://www.opengl.org/discussion_boards/ubb/wink.gif
Zeno, can you tell me where you got those numbers from? As far as I remember, the distance to the sun is 1 AU = approx 150x10^6 km = 1.5x10^11 m. Your distance is 100 times longer than mine. I agree on the radius though.
With that distance, I get an angle of 0.53 degrees.
And yes, my diagram was out of scale for the simple reason than I couldn't draw an ASCII picture with proper scale. I made the sun larger so I could easily demonstrate what I meant.
04-15-2002, 03:10 AM
This thread made me laugh. This has to be the most pedantic yet wrong headed discussion I've seen in a long time.
While across the Earth there may be some *slight* directional variation, in any scene it is minimal. The fact that the Sun is a disk viewed from the Earth does not make it non directional, the fact that the Earth is a disk viewed from the Sun makes it non directional (adopting the same line of reasoning), this is significant because the Earth is MUCH smaller than the Sun, and local effects across the smaller area are diminished. The Sun seen as a disk from Earth makes it an area light source, which isn't supported in any OpenGL lighting equations, local or distant.
No light source is ever infinitely distant, they are all local lights in practice (and area lights too). The concept of an infinitely distant and infinitely small light is an approximation (and a practical impossibility in both respects), designed to model distant light sources quickly, the primary and most distant light source being the Sun.
The Sun is the most distant light source we generally see contributing to the reflected light from surfaces worth modelling.
If you want to better approximate the disc of the sun in the scene then consider multiple infinitely distant light sources, but you might want to consider better surface descriptions, shadows, indirect illumination from surfaces and the sky and a few other much more substantial effects before you waste time on deciding that you need to better approximate the Suns direct illumination. When you compute your shadows you can worry about soft shadows. Modelling the localviewer effects of the Sun is certainly a waste of time. Modelling it's area light source effects less so (mainly because of penumbras), but there are much better things to worry about.
[This message has been edited by dorbie (edited 04-15-2002).]
Doh! You're right about the length of the astronomical unit. I read the decimals as regular digits by accident whe I looked it up. Sorry about that.
Also, I realize it isn't possible for your drawing to be to scale, but you should mention that when using it to illustrate a point about angles. If it were to scale, you wouldn't be able to see any angles.
Dorbie - About the OpenGL lights: You are just repeating what I said in my last paragraph.
Uhm, yeah, I should probably have mentioned it, sorry.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.