godot: Cannot use a ViewportTexture as PanoramaSky texture
Godot version:
Godot 3.0.2
OS/GPU: Linux GTX 1060
Issue description: If you assign a ViewportTexture as a PanoramaSky texture then the sky becomes black. It doesn’t actually show whatever’s inside the viewport, which is a shame because this would be extremely useful for procedural skyboxes (e.g. dynamic day/night transitions, rotating stars/nebulae, etc).
Steps to reproduce:
- Create a Viewport, set its size to something sensible like 512x512 and put some stuff inside of it (e.g. some sprites)
- Create a WorldEnvironment, set its background mode to Sky, assign a PanoramaSky to it and then set the panorama texture to a new ViewportTexture, using the viewport you created previously
- Notice the sky remains black in the editor and also when you run the game.
Also notice that if you afterwards open the WorldEnvironment node again and open the PanoramaSky, the console is being spammed with this error:
scene/main/viewport.cpp:106 - Condition ' !vp ' is true. returned: Size2()
scene/main/viewport.cpp:106 - Condition ' !vp ' is true. returned: Size2()
scene/main/viewport.cpp:106 - Condition ' !vp ' is true. returned: Size2()
scene/main/viewport.cpp:106 - Condition ' !vp ' is true. returned: Size2()
scene/main/viewport.cpp:106 - Condition ' !vp ' is true. returned: Size2()
scene/main/viewport.cpp:106 - Condition ' !vp ' is true. returned: Size2()
Minimal reproduction project: viewportskybug.zip
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (16 by maintainers)
Replace the following line:
https://github.com/godotengine/godot/blob/3a5b25d5b489ad88c2861c9c37b56469580fbf03/drivers/gles3/rasterizer_scene_gles3.cpp#L2365
With:
and stuff starts working, if you set up the viewport and reference it in the sky:
https://i.imgur.com/B2HjEFk.gif
It only works after messing around with the properties, though, otherwise your console is spammed with things like
I believe the error messages are the result of the ViewportTexture being queried before it had a chance to initialize itself correctly. The above fix seems to work in editor only. Still won’t work in preview.
EDIT: Just to avoid confusion: in the gif I’ve added the viewport’s texture as a material to the sphere for debugging purposes.
Nice job, it seems to work now. For future reference, to get this to work you need to do this:
Note that you must check “Local To Scene” for all resources containing a local to scene resource, such as the viewport texture. (So, that would mean setting the Environment as local to scene and the PanoramaSky too, as well as the SpatialMaterial in @ShyRed’s example)
Unfortunatelly, even after I did that to the example project, the sky continued to be black. On the other hand, setting the material as “local to scene” made the viewport texture appear on the sphere in-game as well.