Godot Version
4.6
Question
I’ve been trying to implement lighting into my game, and I though the idea of pixelated lights and shadows sounded very neat. If you don’t already know, there is a shader already on the documentation that’s supposed to do this. I applied this shader onto a PointLight2D through a shader material to see if it would work but literally nothing happened. I tried a couple other shaders too to see if that one was just outdated but it still didn’t work, heck I don’t even know if light was going through the shader. I’ve heard that godot’s shadows are scaled based off of the viewport’s size (or something to that effect please correct me if I’m wrong), and that you could downscale the shadows through a sub-viewport, but idk how to implement it nor do i know how it would affect the rest of development. If I’m just missing something important than please let me know.
Here is the code for the shaders
//The shader from the docs
shader_type canvas_item;
uniform float pixel_size = 4.0;
void fragment() {
// Snap lighting and shadows to pixel grid.
LIGHT_VERTEX.xy = floor(LIGHT_VERTEX.xy / pixel_size) * pixel_size;
SHADOW_VERTEX = floor(SHADOW_VERTEX / pixel_size) * pixel_size;
// Normal rendering.
COLOR = texture(TEXTURE, UV);
}
//A pixelization shader from godot shaders
//link : https://godotshaders.com/shader/2d-post-process-pixelate/
shader_type canvas_item;
uniform int amount = 8;
void fragment()
{
vec2 grid_uv = round(UV * float(amount)) / float(amount);
vec4 text = texture(TEXTURE, grid_uv);
COLOR = text;
}
//A shader I found from an issue thread on the godot github page
//link : https://github.com/godotengine/godot/issues/76266#issuecomment-3316324075
shader_type canvas_item;
uniform vec2 pixel_size = vec2(32.0, 32.0);
void fragment() {
NORMAL_MAP = vec3(-0.5, 1.0, 1.0);
vec2 snapped = floor(VERTEX.xy / pixel_size) * pixel_size + 0.5 * pixel_size;
LIGHT_VERTEX = vec3(snapped, 0.0);
COLOR = texture(TEXTURE, UV);
}