🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Space game need help with Lighting

Started by
5 comments, last by MARS_999 1 year, 11 months ago

Hello, I currently have directional lighting in my game, but I have a sun in the game and want that to be the source of light…. Now the issue is the sun itself is being illuminated by the directional light so only one side is lit up. So do I use a point light at the sun's location? Do I make the directional light some way follow where the player is looking so the directional light is coming from behind the player? Using Jmonkey if anyone needs to know…

Thanks!

Advertisement

If you're at a distance far enough from the star that you're near the Goldilocks Zone like Earth (far enough away that it isn't burning you up, close enough that you're not frozen) then it's far enough to be a directional light just to save computing power. If you want to spend the few extra cycles make it a point light, but visually the will likely be identical.

For reference, Earth is about 150 million kilometers on the near side of the habitable zone, Mars is about 230 million kilometers on the far side of the habitable zone. Presumably you'd be a somewhat similar distance in your space game. Since meter scale is common, having a light source 200,000,000,000 units away will have no significant difference if it's a point light or a directional light.

The sun, stars, and other objects at an irrelevantly-large distance are usually just drawn as a skybox. That's a texture you draw to the background that completely covers the world's view and usually serves double-duty. Not only is it the “really far away” background, but by setting the depth buffer function to the “always” constant, drawing a skybox overwrites both the depth buffer and the background, eliminating a call to clear().

MARS_999 said:

Hello, I currently have directional lighting in my game, but I have a sun in the game and want that to be the source of light…. Now the issue is the sun itself is being illuminated by the directional light so only one side is lit up. So do I use a point light at the sun's location? Do I make the directional light some way follow where the player is looking so the directional light is coming from behind the player? Using Jmonkey if anyone needs to know…

I'm not sure what you mean by the sun is being illuminated? What is your sun exactly? Some sort of sphere mesh? I would guess you would probably want to use a shader for the sun that doesn't compute illumination and just does whatever sun effect you want. Sorry if that doesn't make sense for jmonkey, I'm not familiar with it.

As for the rest, if you are always stuck on the same planet you can use a directional light. Even if you aren't, your lighting can follow the camera position. If you are viewing some distant planet this may make some slight difference depending on your scale. I use a point light for simplicity, that way I don't have to do anything special, as it more closely represents a sun (although not exactly as the sun is far from one point especially as you get close to it.

MARS_999 said:
Now the issue is the sun itself is being illuminated by the directional light so only one side is lit up. So do I use a point light at the sun's location?

Interpreting your question differently than former posters, i guess what you miss are ‘emissive materials’. So the sun lights itself up, even if no ‘true’ light shines at it.
This is usually achieved in pixel shader, e.g. using some texture channel to mark emissive parts on a model. Like the screen of a computer, or LEDs on some door controller.
So such material is bright, but it does not illuminate nearby objects. A very typical visual glitch, often visible in games if you pay attention.
To counteract, artists often place a light source where the object is, e.g. a point light shining out of the computer screen.
The sun can be modeled in a similar way, by using an emissive sphere and a directional light to illuminate the scene matching the suns direction to the world.

Oh, yes there are plenty of effects that can be added. Light bloom, god rays and light shafts, light flares, light scattering, and other effects are all more complex, added as a mix of shaders and in-scene geometry. They're quite different from the point light versus directional light that was in the question, but hopefully they'll come back and clarify their question.

I am looking more for what JoeJ is suggesting. I think the emissive sphere is the way to go. I have sphere meshes as planets and the sun.

This topic is closed to new replies.

Advertisement