Problem masking remote players with vision cone

Godot Version

4.2.2

Question

I am trying to mask remote players using a PointLight2D as a vision cone. In this first image the the black head and shoulders on the remote player should be transparent while still being able to see the bottom torso and legs as shown.


In this second image I would Ideally not see the remote player at all. So the black outline would be removed to be transparent with the background.

The issue I have been having is that I am using a player scene configured as shown below.


When I create a shader and use a Subviewport and the gradient texture (within a Sprite2D shown below) from the DirectionalLight2D to mask the remote players AnimatedSprite2D from within the player scene it attaches the position and rotation of the of the Subviewport and the gradient texture to the remote player rather than the local player.

At first glance this seems like it is working. Although I don’t know where the black box around the remote player is coming from.

But when I look closer the shading isn’t matching up rotational and positional with the local players vision cone but rather it is coming from the local player causing funky behavior like this.

The reason that all of this is happening within the player scene is because I have the DirectionalLight2D following the local players mouse movements giving a directed vision cone feel, and I need the masking to update at the same time as everything else in the _physics_process() update function within the player scene. Is there any other way I can go about this? I just don’t want local players to see remote players unless they are within the vision cone and I need it to update quickly

Can’t you just use the light_only render-mode on the remote-player sprites?
You can either do this with a CanvasItemMaterial or by setting

render_mode light_only;

in a custom canvas-item shader.

Thank you! This worked:
shader_type canvas_item;
render_mode light_only;

void light() {
LIGHT = mix(
vec4(LIGHT_COLOR. rgb * COLOR. rgb * LIGHT_ENERGY, LIGHT_COLOR.a),
vec4(0.0),
step(LIGHT_COLOR.r,0.0)
);
}