• 2D
  • How to do I get the Viewport Texture from a Node2D?

I'm trying to get multiple 2D layer textures and use it in a TextureRect with the shader's Sampler2D parameters so that I can achieve creating the god rays effect like this:

Does anybody know any alternative ways to get textures from Node2Ds or any other node you could suggest?

5 days later

You can use a Viewport with black background and add a sprite for the sun and a sprite for each object that casts a shadow with modulate set to black. So the viewport texture will look like the second image. Then use get_texture() to get the ViewportTexture and use it for the shader.