Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectionalLight3D shadows don't use the Shadow Max Distance property when the camera is in orthogonal mode (it uses the camera's Far distance instead) #58332

Open
megalobyte opened this issue Feb 20, 2022 · 13 comments

Comments

@megalobyte
Copy link
Contributor

Godot version

499eec1

System information

Arch, Vukan, X11, NVIDIA GeForce GTX 1070/PCIe/SSE2

Issue description

Shadows don't appear to be rendered correctly when using an orthogonal perspective.

Orthogonal:
Screenshot from 2022-02-19 19-05-44

Perspective:
Screenshot from 2022-02-19 19-06-02

Scene uses a directional light.

Steps to reproduce

Any scene with a directional light and an orthogonal camera perspective should recreate the issue, but I've attached a project for convenience.

Minimal reproduction project

Uploading minimal_project.zip…

@Calinou
Copy link
Member

Calinou commented Feb 20, 2022

Judging by the screenshot, the shadows in orthogonal mode look correct to me. You should probably reduce Shadow Max Distance in the DirectionalLight3D node to increase their effective resolution – the default value is tuned for fairly large open worlds, not small-scale games.

Can you try following the same steps in 3.4.2 and see if shadows look better out of the box, with the same Shadow Max Distance value in both projects?

Also, the minimal reproduction project didn't upload (likely because you clicked away from the text field while it was still uploading). Try editing your post and upload it again.

@megalobyte
Copy link
Contributor Author

You are right, except it was the camera's far property that I had to update. Is it too early to update the documentation? I know a lot of things are in flux with 4.0

@Calinou
Copy link
Member

Calinou commented Feb 20, 2022

You are right, except it was the camera's far property that I had to update.

The Far property defaults to 4000 in master to support large open worlds out of the box.

The issue here is that DirectionalLight3D does not use the Shadow Max Distance property when the camera is in orthogonal mode, and uses the camera Far value as the maximum distance instead. Can you check whether this happens in 3.4.2 too?

Is it too early to update the documentation? I know a lot of things are in flux with 4.0

The documentation could be updated, but I feel like the core behavior mentioned above should be changed for 4.0.

@Calinou Calinou changed the title [4.0] Shadows don't render properly with orthogonal perspective Vulkan: DirectionalLight3D shadows don't use the Shadow Max Distance property when the camera is in orthogonal mode (it uses the camera's Far distance instead) Feb 20, 2022
@Calinou Calinou added the bug label Feb 20, 2022
@megalobyte
Copy link
Contributor Author

In 3.4.2, I set the far value to 4000 and this is what I got:
Screenshot from 2022-02-19 21-43-26

I should mention that the Max Shadow distance was the same value for 3.4.2 and 4.0

@Calinou
Copy link
Member

Calinou commented Feb 20, 2022

In 3.4.2, I set the far value to 4000 and this is what I got: Screenshot from 2022-02-19 21-43-26

I should mention that the Max Shadow distance was the same value for 3.4.2 and 4.0

That roughly looks like the shadow resolution you'd get in master. You can compare it more easily by setting the directional shadow filter quality to Hard in the Project Settings.

@megalobyte
Copy link
Contributor Author

About the same resolution, but doesn't have the same blend effect as 3.4.2
Screenshot from 2022-02-20 12-30-58

I'm guessing that's probably just a difference with how the rendering engine works?

@Calinou
Copy link
Member

Calinou commented Feb 20, 2022

I'm guessing that's probably just a difference with how the rendering engine works?

3.4 uses PCF5 shadow filtering by default, while master uses an entirely different approach to shadow map filtering. To compare its shadow resolution with master, you have to set the shadow filter mode to Disabled in the Project Settings (in 3.4.2).

@megalobyte
Copy link
Contributor Author

You are right again :)

Thank you for the help! I've learned a lot

@Calinou
Copy link
Member

Calinou commented Apr 21, 2022

I can confirm this on master f4b0c7a and 3.x 3ba9803 (both GLES3 and GLES2).

master

The DirectionalLight3D's Shadow Max Distance is set to 100 on all screenshots.

Far = 4000 Far = 500 Far = 100
image image image

3.x

The DirectionalLight's Shadow Max Distance is set to 100 on all screenshots.

Far = 4000 Far = 500 Far = 100
image image image

@Calinou Calinou changed the title Vulkan: DirectionalLight3D shadows don't use the Shadow Max Distance property when the camera is in orthogonal mode (it uses the camera's Far distance instead) DirectionalLight3D shadows don't use the Shadow Max Distance property when the camera is in orthogonal mode (it uses the camera's Far distance instead) Apr 21, 2022
@Calinou Calinou moved this to Todo in 4.x Priority Issues Nov 30, 2022
@clayjohn clayjohn modified the milestones: 4.0, 4.x Jan 14, 2023
@clayjohn
Copy link
Member

It looks like shadow_max_distance has been ignored for a long time
(well over 5 years eedb390), so there must be something else causing the issue

@Calinou
Copy link
Member

Calinou commented Sep 27, 2023

This appears to be done on purpose here:

if (shadow_max > 0 && !p_cam_orthogonal) { //its impractical (and leads to unwanted behaviors) to set max distance in orthogonal camera

If you remove the check, shadows will disappear unless you greatly increase Shadow Max Distance in the DirectionalLight3D properties (it must be at least 3,200 or so if the editor camera's Far property is 4,000).

@golddotasksquestions
Copy link

golddotasksquestions commented Oct 6, 2023

Many people are reporting Shadow Mesh LOD not working correctly when they try the "Your first 3D game" official tutorial:

https://www.reddit.com/r/godot/comments/170wqon/weird_shadows_in_godot_3d_tutorial/

There seems to be a relation to orthogonal camera setting

image

@Calinou
Copy link
Member

Calinou commented Oct 6, 2023

@golddotasksquestions This is a different issue, which is tracked in #78422. You can work around the issue by disabling LOD generation on 3D scenes that have problematic shadows in the Import dock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants