As seen from the screenshot. the frustum defines which objects get cast shadows by the sun, which is alright. I understand that. However the thing I can’t get my head around is that the frustum is bound to the direction of the sunlight. This causes me to have a few issues:
If I parent Sun to the camera and the camera rotates, shadows will also rotate. This should not happen.
If I don’t parent the Sun to the player in anyway, the shadows will be cut off in any other direction than where the sun frustum is.
There is probably no way to control the direction of the frustum separated from the sunlight direction during run time?
It’s easy to handle using python, by setting the sun.worldPosition to the camera .worldPosition (+a small offset) but not changing the sun rotation.
Not sure how you’d fix it with logic bricks though. Maybe put a mesh object parented to the camera and then vertex parent the light to yhat mesh?
That still wont fix it, yes the sun moves with the camera, but if I look other way (other than the direction sun is pointing) the objects outside the Sun light frustum would not have shadows, since the Sun light frustum is pointing towards where the sun is pointing, not where the camera is pointing at.
Should not the light’s frustum be rather bound to the current active camera, than to itself?
Or at least the frustum area for the Sun should be calculated from the center of the sun outwards in all directions (As a expanding box). This should simply allow the shadows to be clipped after reaching a certain direction.
Possible solution:
After fiddling around, I expanded the clip end to 32 and frustum size to 16, then with a script I put the Sun’s worldPosition to match with the player’s worldPosition…BUT with an offset to compensate the frustum area.
This way the player will always remain at the center of the frustum area, and the shadows will be seen in to all directions.
Basically, what you need is a empty parented to the middle of the view area, with your sun lamp vertex parented to it, so the Lamp area overlaps the camera area, always,
Cascaded sun lamps are what the AAA games use, (the shadows near the player are very crisp and high detail, as you get further away they are lower quality, but exist.
I am sorry if I am not explaining the situation enough clearly. I do know that that light is calculated based on the light source. However, when talking about rendering and real time and lights, all that matters (well almost all) is the frustum that camera is able to see during run time. This is why (this is just my personal opinion), it would make more sense if the shadow map frustum would be bound to the camera and not to the light source object.
The problem with that method is that if your shadows are not a very high resolution, you will get a “shimmering” effect on the shadows as the lamp moves. I haven’t found a good work around for that yet.
Also, that approach is very wasteful of the frustum. I think Cypher’s approach is a good one, as you don’t need the areas to the left, right, and behind the camera to be lit or shaded - only the area in front of the camera matters, right?
And the shadows are bound to the light instead of the camera because the shadows are essentially a texture rendered from the light’s perspective. This texture has to be rendered from some point in the game world, so the light’s position makes sense. The engine couldn’t make an assumption of where the shadows should be rendered from just using the currently active camera.
SolarLune. You are right, exactly right. That is what I am trying to say, only the area in front of the camera matters.
If this was any other light type, the current method would make sense. However this is a global sunlight, which should not be handled this way.
I’m sorry to be such a bugger with this issue, but below I have collected some crappy screenshots with my crappy explanations on this issue
I agree with BluePrintRandom. Vertex parent the sun-lamp (which projects the shadow( to the camera (with an helper object as you need a mesh).
This way it is possible to bind the sun-lamp to the camera. The camera will not leave the shadow frustum and the shadow direction will not be bound to the camera.
It is still possible to see objects that are not covered by the shadow frustum (which is not unusual). You can scale the shadow frustum to always cover the camera frustum.
A simple solution is to place the camera into the middle of the shadow frustum and make the frustum twice of the max dimension of the camera frustum.
A more complex solution would be to match the max dimension of the camera frustum and place the sun-lamp in the middle of the camera frustum. I guess this should be possible with vertex parenting and an helper object parented to the camera. But I never tried that.