godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91k stars 21.17k forks source link

ViewportTexture doesn't update (either pink or unresponsive to changes in it's material) #72616

Open marcarneg opened 1 year ago

marcarneg commented 1 year ago

Godot version

4 beta 17

System information

Windows 10, GTX 970

Issue description

When rendering a instanced 2D scene as a child of a SubViewport, there are conditions when either the SubViewport-texture stays pink (in my case: on a MeshInstance3D/PlaneMesh/LocalMaterial/Albedo), or won't update changes in the "LocalMaterial"s material (like metallic or roughness).

grafik

Trees: grafik grafik

Some bugs seem to be related to the "Viewport Texture must be set to use it."- error- but not always in consistent ways. grafik

The bugs are occuring on the "Mobile" renderer, independently of the SubViewports "Clear Mode" and "Update Mode".

Steps to reproduce

  1. Create scene 2D
  2. add label-control to it
  3. (optional: -> add naive @tool-script, which live-updates a rendered string on the label. The one in the example project is naively written, but the editor should handle it nevertheless.)

`@tool extends Control

@export var thing_to_write : String = "Test" : set = set_thing_to_write func set_thing_to_write(str : String) -> void: thing_to_write = str $Panel/Label.text = thing_to_write `

  1. Create scene 3D

  2. add SubViewport

  3. add 2d scene as instance (child of SubViewport)

  4. add MeshInstance3D

  5. new PlaneMesh

  6. new Material

  7. make Material local to scene

  8. set Albedo to "NewViewportTexture"

  9. set Viewport Path to "SubViewport"

Minimal reproduction project

RenderingportBug.zip

Zireael07 commented 1 year ago

I don't think this method works. However, doing the rough equivalent in script works.

marcarneg commented 1 year ago

Not sure what exactly you mean by that- I was able to use this method on another project (where I encountered the bug initially). I successfully projected 2d controls on a 3d plane with exactly this method- it worked, I was able to change the texture via script (via setter on a @exported resource file-variable) until it suddenly broke.

vpellen commented 1 year ago

I've encountered various iterations of this issue myself, though in a slightly different form. There's something screwy going on with the way viewport textures are linked in the editor. I think you can do it at runtime through code by calling get_texture on the subviewport, and I think you might be able to do that in the editor using a tool script, but this is definitely a recurring issue with viewport textures in the editor.

Rindbee commented 1 year ago

Similar to #68088, see https://github.com/godotengine/godot/issues/68088#issuecomment-1321067723.