Is there a quick way to know if a position or object is in the shadows? I guess you have to cast a ray to the light source? But I don’t want to do that everywhere (thinking it would be cool for snow melt and veg growth to be based on whether a position is in the sun). Or maybe that could be fast enough, or I could create a bit grid to store values computed once in a while?
What is recommended?
I don’t think there is a ready way to do so in Castle Engine. Just a few months ago I’ve implemented this kind of thing in Unity, which has a specific API for this usecase LightProbes.GetInterpolatedProbe.Evaluate
and it works like… total trash. I mean it does what it promises - estimates the amount of light at a specific position in 3D space, but the result is rather not useful for game mechanics use. Especially when baked lighting comes into play.
So, what I did, was not just raycast to a light, but create a special non-light 3D objects (just a 3D coordinate) in the scene, manually place them and raycast to them. This allowed fine-tune the gameplay by far better, than getting “very bright” in pitch black areas or “very dim” standing right under the lightbulb.
Raycasting should be relatively “cheap” so especially if you make sure not to have too many “fake lights” in the scene that are used to determine shaded/illuminated area it should be absolutely no problem.
Thanks. Conveniently I already have a sun object to cast to. I don’t care about other lights which are just for seeing in the dark. I think a fast bitlist of whether a terrain vertex is shadowed could be computed every few seconds, and then any surface location could do a quick check if it needed. Or maybe that is overkill and it is fast enough to check as needed.