Custom light shader's shadow

Godot Version

4.3

Question

I’m currently trying to make a custom light shader that makes the transition between lit and unlit immediate, no in-between color. It can be controlled with a threshold. Here’s a simplified version of the script:

void light() {
	vec3 view_dir = normalize(VIEW);
	vec3 normal = normalize(NORMAL);
	vec3 light_dir = normalize(LIGHT);

	float NdotL = dot(normal, light_dir);
	// Final output
	DIFFUSE_LIGHT = step(threshold, NdotL) * LIGHT_COLOR;
}

That works on its own. But when I combine all objects in the final scene, I noticed it didn’t cast shadow on each other. Then I realize that my script doesn’t consider that at all.

I tried using a StandardMaterial3D as the parent material, use the built-in shader and set my custom shader script as the next pass with blend_mul. The problem, it only apply itself based on the dot of light direction and its normal. The shadow that is casted isn’t being modified by my script, because my script doesn’t know which part is shadowed.

Is there a way to get that shadowed value? I literally can’t find anything discussing this. Maybe I’m just dumb, hopefully.

Found the solutions, just got to multiply the LIGHT value with ATTENUATION, and it works. ATTENUATION have the shadowed value, I didn’t even know what that word means, lol.

vec3 light = normalize(LIGHT) * ATTENUATION;

Here’s the article that answers it for me, in case anyone stumble on this post and have the same problem: