Sign in to follow this  

Sun light in space

This topic is 2050 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 am not sure what I should be using to do this, but I have a star in space, and want it to be the source of light for all the planets and such. Do I want to use a point light for this? Or is there some better way? I am guessing directional isn't what I want due to the star should emit in all directions...

Problem is I would also like the sides of the planets that aren't facing the sun to be somewhat light so the player can see them easier....

Any ideas on this?

Thanks!

Share this post


Link to post
Share on other sites
It kind of depends on how you are representing your solar system.

If you are going for some kind of realistic sim approach, then due to the distances involved you're probably not going to want to draw all your planets in one 3d space anyway. You'd probably be better off rendering all but the very nearby objects to billboards with directional lighting and only updating them when the player/planet/sun angle changes by some amount (which will be fairly infrequent).

If your solar system is a bit more abstract, with shorter distances and larger planets so you can see more detail on screen at once, you would possibly be better off using the directional light.

For lighting the dark sides, tweak the ambient light values. Alternatively, look into some kind of rim lighting or atmosphere effect to give you a really dark 'dark side' but still making the outline visible.

Share this post


Link to post
Share on other sites
[quote name='MARS_999' timestamp='1336194921' post='4937554']
I am not sure what I should be using to do this, but I have a star in space, and want it to be the source of light for all the planets and such. Do I want to use a point light for this? Or is there some better way? I am guessing directional isn't what I want due to the star should emit in all directions...
[/quote]

The distance between star and planets makes directional lighting realistic. A player would not, generally, travel enough distance to change the vector of light, unless they were traveling FTL.


[quote]
Problem is I would also like the sides of the planets that aren't facing the sun to be somewhat light so the player can see them easier....
[/quote]

Ambient lighting.

Share this post


Link to post
Share on other sites
ok, but what I am failing to understand is, with the sun at position(0,0,0) and say earth at 15,0,0 and it rotates around the sun the earth should be lit always when facing the sun, but with a directional light I don't see how this can be when I state a directional light of say 1,1,1 wouldn't I need a directional light of -1,-1,-1 also?

Share this post


Link to post
Share on other sites
It should probably be modelled as a point light, emitting in all directions, you obtain the light direction by subtracting the world position of the pixel to light with the point light's position. Basically the light direction to a point P will be the vector going from the point light to P (normalized, if needed).

Directional light only makes sense if the light source is very, very far away and you cannot see any point with a significantly different directional vector to the light source. This works if you are an observer on the Earth, looking at the sun, as there is nothing to see "behind the sun", but it doesn't work if you are in space, as you will be able to see planets rotating around the Sun, which will break down the illusion.

But this is for a realistic simulation, you may be able to get away with directional lighting, it depends. But why would you want to? It's not like directional lighting is infinitely cheaper than other alternatives.Directional lighting is just an extreme case of a point light, in which the latter is located infinitely far away from the observer in the appropriate direction, which allows some simplifications.

Share this post


Link to post
Share on other sites
I would say it depends on the number of other light sources in the scene. If your sun is the only light source (or one of very few sources), then it's probably fine to use a point light, as it would be closest to simulating what you want. This way you can give more time to rendering a higher-resolution light map from that one point light, to compensate for the large distances / comparatively small items involved. If there are a lot of lights then a directional system is probably best, and simply update the light direction when your position moves sufficiently.

If you're also dealing with a lot of objects all around the star you could use the following in the vertex shader before your lighting stage:

[CODE]const float3 sunPosition //sun position, I've used a constant here because I assume it doesn't move.
float3 position //untransformed position at that point

float3 lightDirection = normalize(position - sunPosition); //gets the direction the light will be travelling towards your object from the sun - push this to the pixel shader to get per-pixel light directions for each rendered pixel, then simply run the standard direction light code.[/CODE]

Even better: put the sun at the origin (0,0,0) and you don't have to do that initial calculation. simply normalize the position of the vertex in the world. Edited by NickUdell

Share this post


Link to post
Share on other sites

This topic is 2050 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this