Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan: 3D viewport -> 2D sprite rendering no longer works #50327

Closed
rosshadden opened this issue Jul 9, 2021 · 6 comments
Closed

Vulkan: 3D viewport -> 2D sprite rendering no longer works #50327

rosshadden opened this issue Jul 9, 2021 · 6 comments

Comments

@rosshadden
Copy link
Contributor

rosshadden commented Jul 9, 2021

Godot version

4.0.dev (a5b2988)

System information

Arch Linux

Issue description

In Godot 3 one great workflow for rendering 3D scenes in an otherwise 2D world is simply to set the texture property of a sprite to the texture of a viewport. In master, this seems to be broken.

In Godot 4 it actually does do something, but it seems to be loading in or creating a random texture. To me it seems like maybe a pointer problem, loading in a texture from an unexpected memory address, because the images it ends up using as the sprite texture are very weird and artifacted.

The results also seem somewhat nondeterministic, or at the very least I get different results on different monitors. This should obviously have no coupling whatsoever with anything outside Godot itself, which is one thing that made me think it may be a memory address problem. Maybe this is a problem with Godot's vulkan renderer?

Edit: I want to clarify that 3D works very well in Godot 4 for me. So it's not the vulkan renderer itself, nor graphics drivers issues, nor anything else like that. It's really just this very specific case I have found so far.

Godot 3:
image

Godot 4:

  • a 2k monitor
    image
  • both of my 1080p monitors
    image

Steps to reproduce

I have attached two minimal reproduction projects to demonstrate this problem, but the problem is pretty easy to understand even just by looking at code, as the scene tree is pretty self explanatory.

Godot 3:

extends Node2D

onready var sprite: Sprite = $"Sprite"
onready var viewport: Viewport = $"Viewport"

func _ready():
	# works perfectly!
	sprite.texture = viewport.get_texture()

Godot 4:

extends Node2D

@onready var sprite: Sprite2D = $"Sprite2D"
@onready var viewport: Viewport = $"SubViewport"

func _ready():
	# does... something? but definitely not what it should
	sprite.texture = viewport.get_texture()

Minimal reproduction project

Godot 3: godot-3-3d2d.zip
Godot 4: godot-4-3d2d.zip

@Calinou
Copy link
Member

Calinou commented Jul 9, 2021

Related to #50296.

@rosshadden
Copy link
Contributor Author

I made a change to the Godot 4 minimal reproduction project that makes this problem stand out even more. The 3D scene rendered by the viewport is now a separate scene, to demonstrate that running the 3D scene Node3D works as expected. The problem only comes from running the 2D scene which contains the viewport and instanced 3D scene.

This change should just make it a little more clear that it's not the 3D rendering itself not working, or something wrong with my computer (as far as I can tell), but possibly something more specific to the Viewport#getTexture usage.

godot-4-3d2d-2.zip

@GiantBlargg
Copy link
Contributor

GiantBlargg commented Sep 10, 2021

I thought this might be related to #52528. But it does not appear to be fixed by it.

@Calinou Calinou changed the title 3D viewport -> 2D sprite rendering no longer works Vulkan: 3D viewport -> 2D sprite rendering no longer works Sep 20, 2021
@rosshadden
Copy link
Contributor Author

rosshadden commented Dec 6, 2021

By the way I tried this on a couple other computers to make sure it's not just my environment. I have this problem on every computer I have tried it on, though they are all Linux too so I do not know whether it affects other OS's.

@rosshadden
Copy link
Contributor Author

Ooh, breakthrough. I did what @navy-cap-echo said here and set Render Target Update Mode to "Always" and it works.
I'll leave this open so @Calinou can figure out what best to do with it. Looks like there are other related issues open that would cover this so feel free to close. I'm not sure whether having to change that setting from the default is intended but I will do so until I hear otherwise to get around this problem.

@Calinou
Copy link
Member

Calinou commented Dec 6, 2021

Duplicate of #55471 (same cause).

@Calinou Calinou closed this as completed Dec 6, 2021
@Calinou Calinou removed this from the 4.0 milestone Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants