3D camera render to panorama sky?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Andrea

I’m trying to use the rendering of a 3D camera as background for a panorama sky in a world environment node.
The tree structure is the following

-Environment

-3Dmeshes objects
-3DCamera
-Viewport_for_background

-Other3D Meshes
-3DCamera_for_background

Now, the camera for background does create a texture i can see in the viewport preview, but as i connect the viewport texture to the panorama sky of the environment, things go mad and i can only see a black background.

What am i doing wrong?

Edit: sometime i get the result in the editor, but as soon as i click play the background turns black, and if I then switch editor scene and come back, the editor updates and the background turns black.

You might want give the Viewport it’s own world, as you’re grabbing the camera feed of the world you’re in for the background of the world you’re in. This results in an infinite loop.

TheNormandyProject | 2023-02-24 15:30

I’d read: Using Viewports — Godot Engine (stable) documentation in English

TheNormandyProject | 2023-02-24 15:37

Yes i’ve done that, the world in the viewport is separated from the one in the environment. The docs are not helping, i already went through them

Andrea | 2023-02-24 16:47

I’ve just measured that it looks like there’s a small delay between the ViewportTexture being set and the Panorama Sky being set so it resources in a null response to the fallback environment.

You may be successful with this method?:

Reddit - Dive into anything

TheNormandyProject | 2023-02-24 18:03

i used below code both in _ready and in _process, but it didnt work.

environment.background_sky.panorama=$Viewport.get_texture()

i suppose this feature is bugged cause i keep having not consistent results (sometimes it updated only in the editor, sometimes its all black, sometimes in game it updates the ambient lights but not the panorama itself)

Andrea | 2023-02-24 18:44

Yeah I tried for an hour to get it working and it doesn’t work.

Maybe try a shader?

shader_type spatial;
uniform sampler2D viewport_texture;

void fragment () {
    vec4 viewport_texture_albedo_and_alpha = texture(viewport_texture, UV);
    ALBEDO = viewport_texture_albedo_and_alpha.rgb;
    ALPHA = viewport_texture_albedo_and_alpha.a;
}

TheNormandyProject | 2023-02-24 23:59

I can’t get the shader to work either. Hmmm, maybe worth an ask on /r/godot

TheNormandyProject | 2023-02-25 00:06

It doesn’t work with shaders in Godot 4 either, hm

TheNormandyProject | 2023-02-25 00:08

:bust_in_silhouette: Reply From: Andrea

Not a real solution, i followed this tutorial to get a similar effect