Godot: Viewport texture turns black when its assigned to a mesh

Created on 29 May 2018  Â·  8Comments  Â·  Source: godotengine/godot

Godot version:
master / 2ff31bada

OS/device including version:
_Manjaro Linux 17.1_

Issue description:
When creating a viewport texture to a mesh, if you assign it to the mesh's material property rather than that of the parent mesh instance, it would display as black surface upon reopening the scene.

It can be easily reproduced with the gui_in_3d official demo scene.

documentation

Most helpful comment

This is not really a bug, though a warning should probably be added.
The problem is that the ViewportTexture resource should be "local to scene", but to be able to make it one, all resources containing it should be "local to scene" – including the mesh.

All 8 comments

This is not really a bug, though a warning should probably be added.
The problem is that the ViewportTexture resource should be "local to scene", but to be able to make it one, all resources containing it should be "local to scene" – including the mesh.

Thanks for the explanation! I had no idea about the requirement, so probably we should add this to the documentation.

@bojidar-bg I think that's really a bug / a bad design. Until you reopen the scene, in both cases,
the texture is visible in the editor. Then it gets black, no matter where the material is.

A simple gdscript workaround for the MeshInstance material:

tool
extends MeshInstance
func _ready():
    var t = $"../Viewport".get_texture()
    get_surface_material(0).albedo_texture = t

I ran across this issue today, it's still relevant. I had to fiddle around with it quite a bit to make it work consistently.

As of 3.1 stable, it warns about non-local material, but not about non-local mesh (which still results in black texture).

Still happening on 3.1.1., making mesh local does little to help. The workaround works, though.

I'm encountering this issue again and now I can't get it to work at all. Sometimes the texture is black, sometimes the texture is transparent, it doesn't work in the editor.

I have a control root node with two children, a TextureRect and a Viewport, the Viewport has one Camera child, the TextureRect has a ViewportTexture which points to the Viewport, the ViewportTexture is "Local To Scene". The order of nodes does not make a difference (whether the Viewport is the first child or the TextureRect is), and making the Viewport a child of the TextureRect also does nothing.

I am getting these errors seemingly randomly and interchangeably:

 core/image.cpp:1594 - Index p_width - 1=-1 out of size (MAX_WIDTH=16384)
 drivers/gles3/rasterizer_storage_gles3.cpp:1070 - Condition ' !texture->active ' is true. returned: Ref<Image>()

Minimal reproduction project: ViewportTexture.zip (happening with both 3.1.1 and 3.2 beta 5 on Linux).

viewport defaults to a view size of x:0 y:0, which is interpreted literally as 0x0 which means nothing will show. you need to manually specify a resolution to use (like 1280x720).

Would likely be better to treat 0x0 as a special case of "root viewport width/height" as an enhancement/bug fix

Was this page helpful?
0 / 5 - 0 ratings