PointLight shadows with infinite distance?

As @david_bernard_31 in this thread mentions, currently there isn’t a way to use PointLight shadows over an infinite distance, or is there? Setting pointlight.setRadius(0) seems to break the shadow renderer.

I’m trying to create a solar system like light setup where there is a central light that shines over everything on the scene. I’ve been using a directional light up till now, but I’d like to have an actual physical star in the middle.

I just wanted to ask if there is some easy way to get this done before I develop this resonably insane idea on how to solve this problem further. In case that there isn’t a way I’d like some input on it too. Here it goes:

I’d take a PointLight with an infinite radius and set it to remain in the centre of the system, then create an additional DirectionalLight that would have a black color and change its direction to the normalized vector from the star to the player every update and use that as a basis for a directional light shadow renderer. I’d probably have to disable the shadows of the objects on the other side of the system so they don’t interfere, but the basic idea should be close enough.

mhh… gonna look into this…

EDIT, and IMO the best work around is to set a very big radius to the light. like 10000

Well in that case I’d probably need to set it around 200000 or so due to the scale I have… (I’ll try it out)

EDIT: Tried that, shadows just stop working after like 1000 units or so.

ha yes… I guess that’s the default cam frustum for the shadow cams…
You’re gonna have some trouble to have accurate shadows with that kind of scale anyway… and you may have some depth fighting at big distance.
If you don’t intent to land on a planet I’d suggest that you lower the scale a lot.

I have a better idea:

Create a Node for each planet.
Attach a DirectionalLight to each planetNode.
If two planets come near each other, attach them both to twoPlanetsNode (or better: the planetNode of the “inner planet” which is more close to the sun).
When the one planet went across the other planet, attach the “outer planet” to its own planetNode again).
Problem solved.
(actually many problems solved at once)

DirectionalLight is okay because this “point light” is very far away (shadow angle is close to zero).
DirectionalLight is okay because this “sun sphere” has a very small diameter compared to distance.

@nehon Well I’ll have a lograithmic z-buffer implemented eventually but the scale has to stay at least in the current divided by 10 ballpark since I have ship building TerraTech style, where each module is 1 unit large atm.

@Ogli That might be a partial solution, but I’m not going to move planets. Instead your tiny ship is going to pass into some planet’s shadows, so they need to be local at least which could be done with a single directional light that follows your position.

Well, then it’s even easier:

If more far away from sun than planet X do this:
Get the axis sun-to-planet (it’s a line - or actually a ray).
Determine how far away you are from that axis.
If closer to axis than planet’s radius - dark, else - not dark.

Well yes that’d work very well for planets, but I think I haven’t been exactly clear enough about what I want shaded. There are other ships, floating debris, asteroids and alike, so I’d be best to use something general.

Yes, for the minor stuff you can use DirectionalLight and a shadow thing.

It depends on the scale - will it be like in the picture and the ship will be like some Millions of kilometers in diameter? Or will it be like real sizes ?:
a) either you can’t see the ship because it is way too small (planets are very small too) and you must use a PointLight
b) or you see the ship and everything else is so large that you can use DirectionalLight for the sub scene that you watch).
It is not clear from your description.
If it’s like in the image then it’s fantasy (planets are way too big).

Also, consider this:
As long as you don’t have a binary star system (only one sun) you can write a very simple ray-tracing shader for the shadows (i.e. like the thing that I wrote in the last post - will work for the ship and the Saturn rings). And for the planets just take the scalar product (dot product) and render everything with > 90 degrees as “dark” (as is usual in Phong - very simple).
If you have more than one star, they still most certainly are very close together - and if not, then you can extend the simple shader by another sun (you just need the sun-position).

I don’t see the problem… :chimpanzee_confused:

I know it’s not quite clear, but its really more of the b) option. I’ll most likely go with a mix of the two.

For now I’m not really looking into binary stars yet, but thanks for the idea :stuck_out_tongue:

If you go from solar system to any kind of humanly perceivable scale you’ll not get around adapting the scale (especially of the scene graph) in your game when you go from one to the other. Check out the WorldOfInception test class as an example.


1 Like

Hah, I knew that inception thing. It’s really cool.

And Floats (single precision) are evil. Hate them and they are becoming a problem once you span multiple scales in your game (e.g. “a galaxy far away” → “dagobar system” → “swamp planet” → “Yodas home”). It’s not that easy if you want to make it right. :chimpanzee_wink:

So that’s how people make landable planets…actually doesn’t seem so incredibly impossible anymore.

Yes, and I made the experience: Everything that great companies and “great engines” can do is possible for me and jME too. Just not creating thousands of detailed custom 3D assets or good 2D assets. That’s where paid teams shine. That’s where you must fallback to open CC0-like stuff. That’s where procedural generation rules.

Never start to think that you are too small or don’t know how to do it - because you will know it soon. And if you think your custom solutions are stupid - then just think of how nice your planets look with their Aura effect (still love this trick!). So writing that “pseudo raytracer” that I mentioned is easy to achieve and will look fabulous.

1 Like