PDA

View Full Version : Earth Shadow How To



PaulKTM
05-06-2003, 03:34 AM
I'm trying to make a earth that has the sun shadow cast on it. I have the earth textured map part fine but now the OpenGL light part to make the sunshine is giving me troubles, so just how do I do this sun light thing? I want it to look like some view of the earth from space. Thanks.

knackered
05-06-2003, 03:47 AM
Does the sun cast a shadow in Australia? http://www.opengl.org/discussion_boards/ubb/smile.gif

PaulKTM
05-06-2003, 03:52 AM
No the sun does not cast the shadow, I guess I worded this wrong. Ok how about the sun lite side of the earth vs the dark side, I want to make this model using the earth/Sun positions and use OpenGL lighting in the process. I do not care if the moon gets in this model but I could add that also I guess. I'm having trouble with the OpenGL light parts.

VikingCoder
05-06-2003, 06:19 AM
If I were you, I would just make a shadow texture, that you then blend in to the texture you have for the surface of the Earth. You have to do a little work to make the shadow part of your texture always face away from the sun, but it shouldn't be that hard. You can re-use that shadow texture for any other planets (or moons) you want to render, too. That's how I would do it.

PaulKTM
05-06-2003, 06:26 AM
Thanks for the hints VikingCoder and I have looked into this method. The problem with this is I also want to have the solar lighting for earth satellites so a texture map is not going to cut it. I know the math to do the sun/earth/satellite positions and alike it is the OpenGL lighting part that is not very clear to me.

rgpc
05-06-2003, 06:48 PM
Originally posted by knackered:
Does the sun cast a shadow in Australia? http://www.opengl.org/discussion_boards/ubb/smile.gif

It does, but being "Down under" it's opposite. Here our shadows are brighter rather than darker.

What PaulKTM appears to be asking is how does he set up BASIC Opengl lighting. (You know, Enable lighting, enable light, position light, add normals)

Perhaps PaulKTM could have a look at this tutorial... (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=07)

147-2
05-07-2003, 12:13 PM
Shadows, that tutorial has none.

He seems to be looking for a way to create the earth's shadow on whatever is floating behind the earth. I suggest using stencil shadows if you aren't worried about semi-umbral zones. If you are, then maybe it would be a better solution to adjust the lighting for the object depending on it's position behind the earth.

SergeVrt
05-07-2003, 10:08 PM
QUOTE]Originally posted by PaulKTM:
Thanks for the hints VikingCoder and I have looked into this method. The problem with this is I also want to have the solar lighting for earth satellites so a texture map is not going to cut it. I know the math to do the sun/earth/satellite positions and alike it is the OpenGL lighting part that is not very clear to me.[/QUOTE]


No you are not quite right

as you claim you may compute satellite earth and sun pos then you may compute sun terminator , yeah?

there are computational routines to determine if the satellite is lit by sun light or not ( if you could compute satelite pos you should know these are basic satellite pos computational routines http://www.opengl.org/discussion_boards/ubb/smile.gif )

take a look at code here http://celestrak.com/software/tskelso-sw.shtml

after you computed if a satellite is lit or not you may place your ligh source to illuminate the satellite.

or instead draw unlit satellites which are in earth shadow - so it it will look quite OK.

But
it is just hard to imagine to me that
without additional efforts just using standard lights you would achive great result. such that - satelite hides in shadow then appear in light ....

OpenGl is just not about to model solar system - it has ways to light scenes but has not all you would like out of specific funcitons ( for ex light sources)
( this is my IMHO as I just use OpenGL and not a guru ) but I see your question is not about OpenGL but about what you want from OpenGL. So itis possible to answer tech part and not answer your intentions ( especially for those who do not model satellite flights http://www.opengl.org/discussion_boards/ubb/smile.gif )

PS quite a time ago I wrote a satellite tracking program OrbSat which is now off the Net ( I though to make it open source but lacked time to bring code to readable condition ( I have a custom to write a code which is OK for me but requires some some more work ( commenting and cleaning) so that others could get idea of this.

The program has some attempts to
1) develop shadow for the earth ( quite nasty to say the truth... but I seen some examples in for ex NVIDIA sdk which gives more reliable results.
2) could give an answer if the satelite is in shadow or not.
my computational code is mostly based on Dr Kelso code ( which I already linked above) but if you wish I might send you the code of the program ( as I wrote it old days the code is Dx 7 based ... but hope you will see how to deal in OpenGL) on the basis you would not disclosure any part of code to anyone else ( I just do not like badly commented code to leak onto the Net http://www.opengl.org/discussion_boards/ubb/smile.gif )


finally sorry for my english - but hope things are readable.


[This message has been edited by SergeVrt (edited 05-08-2003).]

PaulKTM
05-08-2003, 02:43 AM
SergeVrt, thanks for the reply I have been working in the space and satellite fields for nearly 15 years now, and in fact I have several programs to track satellites now. (http://home.hiwaay.net/~wintrak/) I have been working with OpenGL and rocket trajectory animations far many years now also and see the power of OpenGL. I would like to add the OpenGL graphics methods to several programs as I can see a real need for this. Please look at the calculation graphic I'm working to show in a OpenGL setting. (http://home.hiwaay.net/~wintrak/shadow.jpg) I have 90% of this working but having trouble with getting the sun light to position correctly (the sun location routines are fine it is the OpenGL part). What I need is a method/routine to take the sun position (as seen on earth at some time/date point) and make the OpenGL stuff to make the sun light hit the earth and the earth cast a shadow so the satellite can see the earth (and sun maybe) in the "light" is should be at that point. I'm not so worried about making a satellite model and then light that model. It is the earth and sun that is important.

BTW TS and I are friends and have been in contact for many years.

Thanks, Paul

rgpc
05-08-2003, 03:01 AM
So are you after the method for calculating the shadow volume or are you after the method for actually rendering the shadows?

I am assuming that you are working in 3D...

I would presume the latter, which can be done a number of ways. The more common methods are stencil shadows and shadow buffers. I can't speak for shadow buffers (jwatte sings their praise at the drop of a hat - but I've never implemented them). Stencil shadows are "relatively" easy to implement. An excellent document on the subject can be found here (http://developer.nvidia.com/view.asp?IO=robust_shadow_volumes) .

You can also find documents on shadow buffers, example code etc. through the above link.

PaulKTM
05-08-2003, 03:06 AM
Thanks for the reply rgpc, I will look over the link and materials you listed. Yes I'm after the render the shadow part of this. I'm kind of new to OpenGL (I have used it for several years but I do not have a command of the methods and terms used) and sometimes have trouble knowing what to ask for. I know what I want, it is how to get OpenGL to do that!

SergeVrt
05-08-2003, 03:44 AM
Originally posted by PaulKTM:
Thanks for the reply rgpc, I will look over the link and materials you listed. Yes I'm after the render the shadow part of this. I'm kind of new to OpenGL (I have used it for several years but I do not have a command of the methods and terms used) and sometimes have trouble knowing what to ask for. I know what I want, it is how to get OpenGL to do that!

sorry maybe I miss what you ask for.

but what I see in respect to shadows ( on earth)
please correct me if I say simething in wrong way.

you were suggested a solution
to use a rendered texture of shadow which you apply onto earth as a second texture.

But you replied
>
The problem with this is I also want to have the solar lighting for earth satellites so a texture map is not going to cut it.
>
so you may compute terminator on earth having earth and sun pos OK?
thus you migh draw this terminator image into texture ( 3D texture) and apply it as a second texture ( blend them)

or maybe I miss what you need.
But this way you would see the shadow on earth from satellite or?

here is now the question -
how to render to texture or achive the proper second texture - it depends....
but here where OpenGL guys might help http://www.opengl.org/discussion_boards/ubb/smile.gif
maybe they might advise some pixel or vertex shader ( as actually rendering to pixel buffer as a 2D image then bind as texture and then wrap a sphere sometimes gives not quite pleasant result

so sorry still do not get idea - what you would like to see from satellite ...

PaulKTM
05-08-2003, 04:07 AM
SergeVrt, I'm thinking I will have to go with the blended texture for the earth and then IF I want the satellite to have solar lighting affects I will deal with that by OpenGL lighting. I'm not real thrilled with this method but I do not see another way right now. I'm sure there are other ways but I'm not an OpenGL expert and do not want to take 6 months to learn some method to do this either. The blended textures does not sound real hard to do, but I have not tried it either! Thanks.

PaulKTM
05-08-2003, 04:28 AM
Thinking about OpenGL some more, would it be possible to make a OpenGL Sun model (with OpenGL lighting props.) to make a light with props. like that of the Sun, then place the earth in it correct position around that light (rotated to the correct time of day) and have the Sun light up the earth model? Then add the satellite in orbit and have the Sun light/shadow from the earth (whatever is the case at this time) and show the view from some camera location. (Say on the satellite or some other point.) Now that would be what I'm looking for. I do not know about the results with OpenGL and I know the Sun/earth distance is a problem spot to deal with but that could be scaled to make this work I hope. Paul

SergeVrt
05-08-2003, 04:58 AM
Originally posted by PaulKTM:
Thinking about OpenGL some more, would it be possible to make a OpenGL Sun model (with OpenGL lighting props.) to make a light with props. like that of the Sun, then place the earth in it correct position around that light (rotated to the correct time of day) and have the Sun light up the earth model? Then add the satellite in orbit and have the Sun light/shadow from the earth (whatever is the case at this time) and show the view from some camera location. (Say on the satellite or some other point.) Now that would be what I'm looking for. I do not know about the results with OpenGL and I know the Sun/earth distance is a problem spot to deal with but that could be scaled to make this work I hope. Paul

Take a look here http://www.asahi-net.or.jp/~yw3t-trns/opengl/samples/fshphong/index.htm http://www.asahi-net.or.jp/~yw3t-trns/public/opengl/fshphong1001.zip
http://www.asahi-net.or.jp/~yw3t-trns/opengl/samples/fshbump/index.htm http://www.asahi-net.or.jp/~yw3t-trns/public/opengl/fshbump1001.zip

it is japan but code is english http://www.opengl.org/discussion_boards/ubb/smile.gif
( the last though requires linked libs)

it phong lightning -
and also bummapping it might be useful

( also try to find info on spherical textures).

I never tried to draw to them but seems spherical textures would allow to avoid that nasty 2D - sphere transitions artefacts. Maybe someone here could shed light on approach.

SergeVrt
05-08-2003, 10:23 AM
Take a look here
http://www.shatters.net/celestia/download.html

it seems it has the things you are looking for.

See the code get ideas
so it will take not 6 months to learn but less http://www.opengl.org/discussion_boards/ubb/smile.gif . And we will have one more OpenGl enabled program http://www.opengl.org/discussion_boards/ubb/smile.gif

gstrickler
05-08-2003, 11:38 AM
I've developed over the past few years an app that does just what you're describing. We use it internally (at Boeing) for satellite visualization.

My earth is a 20 sided sphere recursively subdivided to 1280 triangles. I have a tool that takes the big 2Kx1K earth images everyone downloads from the net and creates 20 texture triangles (square textures with triangular pieces of the earth), one for each earth segment. I render the earth with normal fixed function lighting, but I control the ambient light level so users can give the back side of the earth some unrealistic lighting just so it does not disappear completely. Just using the normal opengl lighting model provides an "ok" visualization, but I really need to use a planet shader that will sharpen the terminator.

As we propogate the satellites, we compute where the satellite is relative to the sun (has line of sight or not) and the terminator. If a satellite does not have line of sight to the sun, it does not receive direct lighting, and is in the earth shadow. But don't use shadowing to do this - we just disable the main light source. You can use some user controlled ambient lighting here too so the vehicle does not disappear in the dark. And on-vehicle spotlights are cool for those night time rendevouz missions.

If a satellite has line of sight to the sun, it receives direct lighting. We compute an earth glow factor based on the satellite's position relative to the terminator. As the satellite moves to the lit side the factor goes from zero to 1. This earth glow number is used for backlighting the vehicle. You can use it to ramp up ambient lighting so the earth side of the satellite is no longer dark. I use a lighting shader to do two things. I use the sun as a shadow casting light (projective textures) and the earth as a shadow fill light. So my vehicles receive harsh shadowing from the sun, and glow lighting from the earth.

I don't use any shadow texture on the round earth. But my flat earth display uses both a day image and the "earth at night with lights" image (also downloaded from the net). I splice the two images together along the terminator. But this is just some brute force texturing, and not opengl lighting.

gstrickler


[This message has been edited by gstrickler (edited 05-08-2003).]

PaulKTM
05-09-2003, 06:34 AM
gstrickler, thanks for the reply, I have the same "problems" or ones like what you had also. I have attached 2 images of what I have now, it is OK but needs a great deal of work. I use a 2048x1024 earth texture mapped to a sphere I create in OpenGL, it looks pretty good I guess. I also have vector data of the countries and such to help make the map look better. Paul
http://home.hiwaay.net/~wintrak/shad1.jpg http://home.hiwaay.net/~wintrak/shad2.jpg