0 votes

Hello. I've been trying to create a stereo audio effect based on how many red pixels there are on the screen, with a bias towards the left pixels for the left speaker, and the right pixels for the right speaker. For that, I need to get the red values of each pixel on screen, but I can't figure out how to do so. apparently I need to use lock() after getdata(), but adding it crashes the game and gives the error "Invalid call. Nonexistent function 'getpixel' in base 'Nil'." this is the faulty code in question.

leftamount = (get_viewport().get_texture().get_data().get_pixel(pixelcur.x, pixelcur.y).r) * effectleft
rightamount = (get_viewport().get_texture().get_data().get_pixel(pixelcur.x, pixelcur.y).r) * effectright
Godot version 3.4
in Engine by (31 points)

1 Answer

0 votes

doing getimage on the viewport texture returns the image with the function "getpixel(x,y)"
Replacing getdata with getimage should work but it will lag if it is overused
Note on the viewport texture
"Note: This will fetch the texture data from the GPU, which might cause performance problems when overused."

and another thing you should do to prevent black textures or past textures is wait until
the texture fully loads
"Note: When trying to store the current texture (e.g. in a file), it might be completely black or outdated if used too early, especially when used in e.g. Node.ready(). To make sure the texture you get is correct, you can await RenderingServer.framepost_draw signal."

put await RenderingServer.framepostdraw
before you get the viewport texture to let it load fully, then you can grab the full version of it

by (14 points)

this question is over 1 year old. the game came out in april

I just found your answer 1st on google search, so I answered it incase anyone else was trying to do the same thing

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.