Game Development Community

Moon Phases

by JohnT · in Torque Game Engine · 12/03/2006 (7:56 am) · 16 replies

Hello,

I'm trying to implement a realistic 3D moon in my game that will go through phases like the real thing (crescent, quarter, full, new moon). In order to make the moon look more realistic, I need to place the moon about 1500 units out from the player and have a light source hit it from various angles.

The problem that I'm getting is that the light source needs to be at least as large as the moon object and projecting its light rays parallel to each other as it strikes the moon.

I've looked over the documentation and I don't see an ability to create a light source larger then a point projection out in a cone.

Hope someone has some ideas!

#1
12/03/2006 (8:27 am)
I'd recommend creating a new renderable object. Look at how fxSunLight works and try something similar to that.
#2
12/04/2006 (9:06 pm)
You could custom code a light thats always 1500 units from the player, but a dynamic light that size will really kill performance and a static light won't change intensity and color during the phase transitions. Ideally the lighting should be directional, so if you can get away with static lighting using the sun would work the best.
#3
12/04/2006 (9:59 pm)
Have you tried using a sgDecalProjector to project a black circle onto the moon? I'm not sure how well this would work, but it's something that is probably worth a shot.
#4
12/05/2006 (3:38 am)
Thanks for your suggestions. I'll play around with each and see what looks best.
#5
12/05/2006 (3:56 am)
I would think the best way to get a good looking moon would be to fake it. Use something like THIS, then use FXsun to get it moveing across the sky. As far as the phases go, you may need to edit the graphix then update the FXsun once a game day.
#6
12/05/2006 (5:16 am)
Thanks Caylo, but I found a texture map and created some custom code already to create a sphere and wrap/ orient things correctly. I figure this will give me a more realistic shading effect on the moon (if I figure out the lighting) as well as other planets that I'm going to be adding.

This is how things look so far.
www.futurearcade.com/moon.jpg
#7
12/05/2006 (5:32 am)
Ya that do look very good. Im very curious as to how this turns out for you. As i also have been thinking about ways to get a moon into my night time environments. Course i already posted the only cheep-n-easy way i could think of doing it, but have not tried it until i finish fixing all the bugs for the things i DO have in game....
#8
12/05/2006 (8:06 am)
Ah, I thought you wanted to illuminate the player - it sounds like you're trying to use lighting to change the moon phases instead?

There are two ways to do this that jump to mind; using multiple texture maps each showing a different phase (maybe with transition maps) and slowly blend between them, or use a semi-circular normal map and use bump mapping with the sun's direction relative to the moon to create realtime accurate phases.
#9
12/05/2006 (8:26 am)
@John - Yes, I am trying to rotate a parallel light source around the object and create the various phases.

As far as using the semi-circular normal map with bump mapping, do you know of any resources that would be useful as a reference? I looked around but am not finding anything that looks helpful.

Thanks Again!
#10
12/06/2006 (7:56 am)
Went back to the basics and instead of using the lighting kit (sorry John ;) ) I used the straight OpenGL lighting within the object I render my moon in. This gives me an easy ability to swing the light to match the location of the sun and produce the correct shading.

Only thing I'm still not happy with is the jagged edges on the limb of the moon. I've tried all kinds of smoothing without any improvement.

www.futurearcade.com/phases.jpg
#11
12/06/2006 (8:08 am)
Wow! Ya that looks much better then a quick and dirty 'fake' it job. So your using a textured sphere mesh? Or a disk? or just a flat plain?
#12
12/06/2006 (8:15 am)
Thanks, it is a texture-mapped sphere. I also have a matching bump map that I'd love to add to it but will probably need to wait until I port things over to TSE for that.
#13
12/06/2006 (8:59 am)
This might sound silly, and it just might be. But if you made the sphere in MAX or something like it, you could try flipping the normals so it it inside out. That 'might' get rid of your "jagged edges". (might need to make it a bowl shape also...) Its a trick i have used with other engines to soften alias edges, but it runs the risk of making it look Gouraud shaded.
#14
07/06/2007 (8:54 pm)
i129.photobucket.com/albums/p220/lmaceleighton/Moonshot.jpg
made this just by replacing the corona in the demo, making so you can control the brightness, and it looks pretty good, and follows you like the moon should, is this what you are looking for? i might show this to the people im working with:)
#15
07/22/2007 (8:52 am)
Would it be possible to get a resource on this? creating a moon object is a awesome thing, did you place itlike a second sun object? for that matter is it even possible to place a second son object to match time of day and such?
#16
08/02/2007 (11:02 pm)
I'll see what I can do...well would anyone want a resource on this??, its not that hard and i am by no means an expert really, but I do this well anyway:)