godot: PointLight2D doesn't respect Nearest texture filter for normal-maps or shadows
TLDR - jump to this post: https://github.com/godotengine/godot/issues/76266#issuecomment-1751739538
Godot version
4.0.2.stable.official
System information
Linux & Windows, various hardware
Issue description
We can see the expected behavior for PointLight2D - each pixel of the Sprite2D is shaded without any interpolation or filtering, when we zoom in.

When the light texture is scaled down, we can see that the shading actually happens for each pixel of the scaled light texture, even if pixels of the Sprite2D are bigger. I assume this is also expected behavior.

But when we use the CanvasTexture with NormalMap, suddenly the lighting is being interpolated for each screen pixel (the light pixels suppose to be the same size as sprite’s). Setting the texture filter to Nearest does not fix this.

It seems that the light() shader is being run for each screen pixel (despite Camera2D zooming), which besides some performance impact, would be acceptable on its own. But this also causes the CanvasTextures to look ugly for pixel-art games with in-game zooming (and it looks even worse for some custom shaders).
Steps to reproduce
- Add Sprite2D and set it’s texture to CanvasTexture
- Load some Diffuse and NormalMap textures
- Add Camera2D and zoom it in to see individual pixels clearly
- Add PointLight2D with some texture
- Set texture filter to Nearest for all components (and observe there is no difference)
Minimal reproduction project
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 30 (15 by maintainers)
What is the status for this issue? If it is considered a bug/feature I would like to give it a try 😊
I’m working on adding the option to switch, it turned out to be more complicated than I imagined but I think I managed to do it.
https://github.com/user-attachments/assets/3948d8b5-20c9-4aa4-af7b-effce4b2fa4d
As for why it didn’t work for you, you probably already know this but, if you changed the canvas.glsl after building the project it won’t work because it actually uses the canvas.glsl.gen.h file which is generated from canvas.glsl. Either rebuild it or change canvas.glsl.gen.h directly to test it. If you already did this and it didn’t work then it’s interesting why it didn’t work for you.
To create pixelized shadows, you could use a
light()function in a custom shader that modifies vertex position in the fragment shader to affect where light is sampled. This is essentially the 2D counterpart to https://github.com/godotengine/godot-proposals/issues/974.However, this functionality isn’t implemented in the engine yet.
This is already supported. This is what the
viewportstretch mode achieves 🙂Movement and physics still occurs at the same precision level regardless of stretch mode (it only affects visuals).