# Sunlight theory

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

## Recommended Posts

I was thinking of how to simulate my sun today and in theory if the sun is position in the same height(y-position) as my planet could I just calculate the light direction as this splendid paint image I created:

http://imgur.com/7R25Joo

Or what is the theory around the sunlight hitting a planet?

//Toastmastern

##### Share on other sites

(A rendering thread that's gone unanswered for 2 hours?! This isn't the GameDev that I know and love)

The theory sunlight hitting a planet is the same theory for any light hitting any object. The thing I think you're looking for, though, is Lambert's Cosine Law, which is one of the fundamental concepts in any physically-inspired rendering. Specifically, for any point on your planet, the amount that that place is illuminated is: (brightness of the light) * (cosine of angle between the surface normal and the light source) / (distance from the surface and light source)^2.

Hope that helps!

##### Share on other sites

but for all practical purposes, yes use a directional light on your planet from the sun and not a point light

##### Share on other sites
It should be mentioned that the cosine law can be implemented using the dot product. Angles are for losers. :)

If your planet has an atmosphere, things get much, much trickier.

##### Share on other sites

Yes, all you need is the light direction and the direction the surface faces. Facing into the light receives 100% of the color and facing 90 degrees or more away receives 0% of the color. Any angle in between receives a percentage of the light.

I started to put on my "Angles are for losers!" bumper sticker until I realized that you use angles to calculate the dot product. Doh! ;-)

a ? b = ? a ? ? b ? cos ? ?

Edited by BBeck

##### Share on other sites

I started to put on my "Angles are for losers!" bumper sticker until I realized that you use angles to calculate the dot product. Doh! ;-)   a ? b = ? a ? ? b ? cos ? ?

No, you don't. It's the other way around: That formula is the modern definition of angle!

The way you compute the dot product of vectors a and b is

a ? b = ax bx + ay by + az bz

##### Share on other sites

The sun is a sphere light, but any sphere light can be safely approximated as a point light once you're a certain distance away (I think 5x the sphere's radius is the rule of thumb?), and any point light can be safely approximated as a directional light if you're really far away from it, as at that point all the rays will be pretty much parallel.

##### Share on other sites

The sun is a sphere light, but any sphere light can be safely approximated as a point light once you're a certain distance away (I think 5x the sphere's radius is the rule of thumb?), and any point light can be safely approximated as a directional light if you're really far away from it, as at that point all the rays will be pretty much parallel.

The angular diameter of the sun is about 0.5 degrees. Approximating the sun as a directional light will be acceptable for most purposes, but the shadow of an airplane will look too sharp, for instance. See http://www.gettyimages.com/detail/video/shadow-of-the-airplane-moving-down-stock-footage/485216014

##### Share on other sites
So basically the distance of the "sun" makes the need to calculate a directional light for all vertices? unnecessary. I can just say that the light is aiming at position 0, 0, 0?
Or shoult I choose a position way behind the planet?

//Toastmastern

##### Share on other sites

So basically the distance of the "sun" makes the need to calculate a directional light for all vertices? unnecessary. I can just say that the light is aiming at position 0, 0, 0?
Or shoult I choose a position way behind the planet?

//Toastmastern

Basically, directional lights do not have any positions. In (old) OpenGL, when you set the 4th component of the light position to 0, it is interpreted as its direction.

Edited by _Silence_

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013638
×