Godot Version
4.5.1
Question
Hi all!Im looking into merging the output of two camera’s, before going onto to doing some image effect shaders further in my pipeline with the result.
Im trying to overlay the output of one camera, call it “Camera B”, onto another camera, call it “Camera A”. Both cameras are Camera3D.
Heres what I want each camera to render, and what I want to achieve;
Camera A - will render physical objects, eg the Player character, enemies, and any fog effects Ive added.
Camera B - will render objects I want to be able to see essentially through walls (or fog!). Think xray vision to see inside of a treasure chest.
Use case: I want to be able to render any objects (just basic sphere meshes) that might spawn inside of a hollow cube of fog.
Current scene tree situation:
Camera A is a child of the player character (and therefor part of the player character’s scene), with the reason for this being that I want the camera to orbit around the player. Handling the camera input as part of the player character scene was suitable to me at the time of implementation, but I am open to restructuring this.
Camera B is part of the main scene, parented to a SubViewport, and I have attached a basic script for the camera node itself to copy the position and rotation of Camera B every frame
Everything I want Camera A to see, ive assigned to VisualInstance3D layer 1 (now marked physical layer). Camera A’s cull mask is set to layer 1 also.
Everything I want Camera B to see, Ive assinged to VisualInstance3D layer 2 (marked xRay layer). Camera B’s layer cull mask is set to layer 2. The SubViewport Camera 2 is parented to has “Tranparent background” set to true, so ideally it will render ONLY the nodes on visual layer 2.
What I have tried so far:
Writing a custom shader with two Sampler2D, one for Camera A (marked with :hint_screen_texture), and each frame, feeding the texture from Camera B to the 2nd Sampler2D. This shader is assigned to a material on a TextureRect. Unfortunately this still only results in the output of Camera A being rendered to the TextureRect.
Does anyone know the correct way to go about this? Happy to post any code etc for context.
Thanks in advance!