0 votes

I'd like to use Godot to render visualizations to be overlayed on a video stream in real-time, and I need a way to get the frames out of godot with the alpha channel intact.

However, I'm not sure about the where to to go to pull image data off the GPU. I don't mind writing a module if need be, but I don't know how I can hook in to the render pipeline to call glReadPixels or something.

Any suggestions? Are there better ways to go about this that I'm missing?

Thanks!


Ideally I'd like to be able to do the rendering off-screen as well.

in Engine by (28 points)

1 Answer

+1 vote

I know you can download the last drawn frame from a Viewport to main memory by using Viewport.get_texture().get_data(). This will return an Image object containing the pixel data.
Note that this is a very expensive operation, it can lag a bit if the resolution is too big.

Each Godot game runs under a main viewport representing the screen, which you can get with get_viewport().
You can render offscreen by putting your scene under a custom viewport, and making it render always (by default I think it won't render if not being made visible by a viewpot container node).

As for hooking up in the renderer itself, I don't know. Maybe there is another way involving modification of rasterizer_gles3.cpp?
If the destination of the frame is to be rendered using the same graphics card, I imagine there should be a better way than having to download the screen from it 60 times per second.

by (29,092 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.