[LWJGL] [JOML] Shadow Map to an Ortographic View

Hello,

I’m adding and studying about shadows and I’ve came across a lot with tutorials that use something like this for the LightView Ortho matrix:
new Matrix4f().setOrtho(-10.0f, 10.0f, -10.0f, 10.0f, -1f, 20.0f);

Playing with the values and the light I got this values as “good” values:
new Matrix4f().setOrtho(-50.0f, 50.0f, -50.0f, 50.0f, -1f, 200.0f);

I’ve tried different values and approaches with the distance of light trying to understand what is happening…

My question is: there is a way to compute this ortho matrix based on my current camera properties?

Thanks in advanced … this forum is the best :stuck_out_tongue:

[edit] I’ve updated the image with more objects in the scene.
Current result:

What do you mean? The position of the camera that is used to generate the shadow?

Sorry if I wasn’t clear…

My question is how to compute (which values must be used) for the ortographic projection for the camera view.

I’m considering the distance 100 in the example with the values cited before. But according with the scene size I think this values must change… How to get this values?

Also, I’ve noted a lot the increase/decrease of quality according with the ortographic matrix and I want avoid it to get always the same result in smaller and bigger scenes.

Most, if not all game engines use a fixed value for the shadow distance because calculating these per scene basis will give very bad consistency, small scenes will have sharp shadows and bigger ones soft because the resolution is not the correct for each ortho matrix.

The most performance/quality method is to use cascaded shadow maps, they work by rendering the scene multiple times using multiple ortho matrix (from small to big size).

Thanks for the answer,

I’m updating the code to cascade shadow maps but I still with a problem to calculate the ortho matrixes.

I found this awesome example http://ogldev.atspace.co.uk/www/tutorial49/tutorial49.html

But the code/framework is different of mine and when I update to this approach I got a problem, probably because ortho calculation isn’t correct.

Question:
What I’ve tried is to put fix sizes of ortho projections and transforming it according to camera position, is that correct?

This is the problem that I’m getting … running shadows just for red area.