Jump to content
  • Advertisement
Sign in to follow this  
Toastmastern

Sunlight theory

This topic is 636 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 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 this post


Link to post
Share on other sites
Advertisement

(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 this post


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


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


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


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


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


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

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!