Rendering a 2d light to a subviewport

Godot 4.3

So I would like to do visibility using a point light on the player that casts shadow from my staticbody level geometry to make a lookup texture things can just tap to see if they’re in sight or not.

The trouble is, if I put the light under a subviewport node, it stops interacting with light occluders that are above the subviewport in the scene tree.

Is there a way to get that point light drawing to the subviewport without duplicating all my level geometry / light occluder nodes under the subviewport?


Above is my scene tree before starting the game. The level geometry is static bodies with light occluders instanced under the Geo node. The visibility camera and visiblity light are locked to the player’s position from script. The result in Visbility viewport is a texture that has the light centred on it:

which I draw on the screen under the main camera in the “Visiblity viewport visual” sprite. As ou can see it’s a plain circle right now, because there’s no geometry there, but when I add the geometry:

The light is unaffected. I’ll show how it looks if the point light is in the main scene:

As you can see, the light is now affected by the level geometry.

Any ideas how to do this?

I guess I could reparent only the light occluder nodes to the subviewport, as I don’t want to use them in the main scene for lighting anyway. I’ll try that.

1 Like

Yesssssss

Thanks everyone

Turns out this is a really bad idea anyway, as getting the image from the viewport texture is extremely slow. I’ll do it with ray casts.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.