-
-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Image captured from viewport results in garbled png when saved #56687
Comments
Script from the MRP for the record: extends Spatial
func _ready():
yield(VisualServer, "frame_post_draw")
var texture = $Viewport.get_texture()
($MeshInstance.mesh.surface_get_material(0) as SpatialMaterial).albedo_texture = texture
var image = texture.get_data()
image.save_png("user://hello-world.png")
I'm not 100% sure why but evidently when Probably related, you can see that if you put a Edit: It also works without any yield if you move the Capture node up the tree. The problem is likely that when your Capture node is "ready", the Camera and DirectionalLight nodes aren't yet, as the scene tree is initialized in reverse tree order. Waiting one frame ensures that the whole scene tree is ready, and not just Capture and its children. |
Hi,
neither of these changes do fix it for me, still getting garbage... Maybe an OS- and/or hardware-specific problem? Cheers -- |
Does it work if you use |
Tried that already... Nope, it doesn't make any difference, no matter how many times I use any of the two versions of the yield call -- once, twice or like a dozen times. Cheers -- |
I am too having this issue, but instead of trying to save the texture to a file I'm trying to project it onto a Sprite3D. The project works without issue in the editor but after export the texture always gets garbled. I have tried exporting to windows too and running under wine, but I get the same result. The garbled texture changes with whatever unrelated code the script contains. I have Included a demo to test this. The demo has two cameras both filming a moving object, the objects are there to show that the image projected onto a Sprite3D is not moving when it should, but everything else still works. Sometimes instead of a garbled texture you just get black, seems to only happen when there are two instances running (eg. a debug build in the editor and an exported binary, or two exported binaries simultaneously) Any ideas on how to fix this? Demo: Godot4Sprite3DBugReport.zip Here's an image from my personal project too, just in case: |
We observed something similar with Godot 4.0. For us it seems like on initialisation the viewport texture is filled with random garbage. We've had it on Linux and Windows with two wholly different setups except for the graphics card being from Nvidia. |
Can confirm that this issue persists on my laptop with integrated AMD Radeon graphics. Will ask my friend with a dedicated desktop Radeon GPU to test this out. |
Godot version
3.4.2
System information
Debian Linux 11 "Bullseye", ATI RX580, GLES3
Issue description
I'm using a viewport containing some GUI controls for creating a texture for a mesh. This works great so far, but when I try to save the viewport's texture as PNG image, I seem to get some random noise rather than the texture image.
Here's a screenshot of the minimal reproduction project, showing the GUI viewport's texture applied to the mesh's albedo:
And here's what the exported PNG looked like in three consecutive launches:
I would, of course, expect the saved PNGs look exactly like what's visible on the mesh.
Steps to reproduce
Just launch the provided minimal reproduction project and have a look in your Godot user folder.
Minimal reproduction project
viewport-capture-test.zip
The text was updated successfully, but these errors were encountered: