Is it possible to render a surface as the environment background?

Godot Version

Godot 4.7

Question

Hi, I've been experimenting with shaders for a bit, and I couldn't figure out how to render a surface as the environment background. What I mean by this is something similar to making it invisible, but instead of just being invisible, it occludes the geometry behind it as if it were opaque, effectively culling obscured geometry. It's for open windows in my game where other exposed parts of the level might be visible from the view, which I want to not be seen.

The effect I want would be similar to what Meta and Apple do with your hands on their XR headset's passthrough, culling the geometry when the hand is in front so that the passthrough looks like it's on top. (I'm not making a VR game, it's just the best comparison to what I'm trying to do)

Example mockup in blender:

Can you make a visual mockup?

Thanks for replying. I’ve added a mockup.

So all geometry in the scene that’s covered by the mask objects gets a hole?
What exactly are you using this for?

As I described in my post, it’s for windows in a game set entirely in an interior. The windows are an important game mechanic, so being able to tell it’s a valid window or not is important, and to visually communicate that I want them to directly render the skybox. While it might make sense to just leave it as a hole, the problem is that the levels often have geometry behind where a window hole is cut out, and since there is no “exterior” model, you’re just seeing the backside of another part of the level. I want to make a shader that always renders the background skybox culling anything that might be behind it so no matter what, you always see “sky” when looking at it.

Render the skybox into a separate viewport and sample that in the shader that renders window geometry.

Here’s a demo:

shader_type spatial;
render_mode unshaded;

uniform sampler2D env: source_color;

void fragment() {
	ALBEDO = texture(env, SCREEN_UV).rgb;
}

The script just copies scene/editor camera transforms and viewport size to the subviewport.

Hope you’re not cloning Shut, where windows are the principal game mechanic :smiley:

Thanks, that’s exactly the effect I’m looking for. And no, I’m not cloning anything. The game is an ape-escape-like platformer where you guide NPCs to the windows, which sort of function like goal posts.