Skip to content

Add a project setting to use nearest-neighbor filtering for shadow maps #12510

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

Open
BecketTocci opened this issue May 27, 2025 · 4 comments
Open

Comments

@BecketTocci
Copy link

Describe the project you are working on

A pixel art 3D game.

Describe the problem or limitation you are having in your project

The shadows in 3D are currently always soft. In my game, I would like pixelated shadows. I have tried several settings, and none of them work correctly for my use case.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add an option in Rendering/Lights and Shadows/Directional (and Positional) Shadows/ Soft Shadow Filter Quality
to disable shadow filtering altogether.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This will only take a few lines of code in whatever function samples the shadows. I have never contributed to Godot, so I don't know exactly what to say here.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No. I have tried several times and this is either impossible without modifications to the engine itself or very hard.

Is there a reason why this should be core and not an add-on in the asset library?

There are a lot of games with stylized art direction these days, particularly pixel art.

@clayjohn
Copy link
Member

This is already supported in the project settings. Just set the filter quality to "hard" to disable shadow filtering

Image

@Zireael07
Copy link

That isn't clear at all. If it totally disables, it should say "Off" not "Hard" (IMO, I'm not a native English speaker)

@Calinou
Copy link
Member

Calinou commented May 27, 2025

This can be done easily, but the issue is that pixelated shadow maps generally only look good if you snap them to texel coordinates that match world textures. Minecraft shader packs that have real-time shadows typically have an option for this, which makes the pixelated shadows seem a lot more grounded with the rest of the world. However, this is nontrivial to implement in games where texel density is not known in advance and isn't the same on all materials (which is what nearly all games do).

You can see an example of this on the screenshots in #8671 (comment).

That isn't clear at all. If it totally disables, it should say "Off" not "Hard" (IMO, I'm not a native English speaker)

Hard shadow filtering still uses bilinear filtering, which means shadow edges don't actually appear perfectly sharp. It's a good choice to emulate shadow maps seen in early 2000s games, but it won't give you the chunky shadow appearance OP is looking for.

Hard shadow filter + Bilinear filtering Hard shadow filter + Nearest-neighbor filtering
Image Image

@Calinou Calinou changed the title Ability to disable shadow filtering entirely Add a project setting to use nearest-neighbor filtering for shadow maps May 27, 2025
@BecketTocci
Copy link
Author

BecketTocci commented May 27, 2025

This can be done easily, but the issue is that pixelated shadow maps generally only look good if you snap them to texel coordinates that match world textures. Minecraft shader packs that have real-time shadows typically have an option for this, which makes the pixelated shadows seem a lot more grounded with the rest of the world. However, this is nontrivial to implement in games where texel density is not known in advance and isn't the same on all materials (which is what nearly all games do).

You can see an example of this on the screenshots in #8671 (comment).

Okay. We could also add a setting to use texels at all, but make sure to say it's best to turn it on if you're using low resolution shadow maps and such in the shadow filter settings documentation comment.

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