x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Resource->ReadPixels is very slow... faster way?

I have set up a 2DSceneCapture component and using c++, I access the render target and read the pixels, like so:

 void MyActor::UpdateBuffer( )
 {

 TArray<FColor> ColorBuffer;

 if (RenderTarget != NULL)
 {

     FTextureRenderTarget2DResource* textureResource = (FTextureRenderTarget2DResource*)RenderTarget->Resource;

     unsigned int ReadPixelsTimer = clock();

     if (textureResource->ReadPixels(ColorBuffer))
     {
     }

     long ReadPixelsDuration = clock() - ReadPixelsTimer;
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("ReadPixels run time: %d"), ReadPixelsDuration));
 }
 }

I notice that my ReadPixels takes ages to complete... So, I would like to know if there is a faster way that I can do this?

What I really want, is to access the camera view data, but as I can't find a way to do that, I resorted to the RenderTarget method as described here: https://wiki.unrealengine.com/Render_Target_Lookup

I've also read this post: https://answers.unrealengine.com/questions/25594/accessing-pixel-values-of-texture2d.html#answer-73443 but I have no idea how to get MyTexture2D.

Any advice?

Product Version: UE 4.10
Tags:
more ▼

asked Jan 25 '16 at 10:23 PM in C++ Programming

avatar image

rich2020
122 15 30 29

avatar image flipswitchingmonkey May 27 '16 at 06:18 PM

Have you ever worked something out? Because I have the same problem, ReadPixels() is just crazy slow makes up for 80% of all the time my entire function uses. There must be some way to get to the raw data quickly?

I tried using ReadPixelsPtr() instead and then copy the array around, but that is just as slow.

avatar image rich2020 May 27 '16 at 08:04 PM

Nope. No further. Unfortunately, the support for this engine is not very good so despite my best efforts, I had to give up in the end. Let me know if you figure something out!

avatar image flipswitchingmonkey May 27 '16 at 08:54 PM

Well the only thing I noticed was an absolute massive difference if HDR was activated in the Render Target. That slowed things down a lot.

You could also look into running things asynchronously using Async, but that may not be viable, depending on what you are trying to do.

Otherwise, no, it seems we are stuck with ReadPixels()....

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

I know this question is getting quite old, but I showed up when I was looking for a solution to the same problem.

I think found a way around this by modifying ReadPixels so it does not block the game thread. I've added a description to the wiki (https://wiki.unrealengine.com/Render_Target_Lookup) in case anyone is interested.

more ▼

answered Jan 04 '17 at 12:40 PM

avatar image

larsjsol
24 3 4

avatar image Spiris Mar 02 '18 at 01:56 AM

Great article, It was actually a launch point for this class in my code. Which I also wrote an article for. Enjoy!
https://wiki.unrealengine.com/Slowly_Read_A_RenderTarget

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I also looking for a faster solution than ReadPixels, this is really important for many tasks.

more ▼

answered Jan 12 '17 at 08:30 AM

avatar image

qiuwch
56 4 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I have not found a faster solution than ReadPixels, but, as I explained in my own post here, you can speed ReadPixels up a lot by disabling HDR on the render target and setting the render target's resolution to match the active camera's resolution. Otherwise, the renderer has to re-allocate resources every time it reads from the render target.

more ▼

answered Jul 18 '17 at 07:59 PM

avatar image

mrpropellers
11 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hey Guys. I share my solution.

Did you guys set the "bGPUSharedFlag"?? This value is belonging to "UTextureRenderTarget2D" class.

In my case, when I set this value to "true", ReadPixels() was faster than before!

This is my code. I sincerely hope it helps.

alt text

bgpusharedflag.png (15.0 kB)
more ▼

answered Mar 03 '19 at 12:50 PM

avatar image

Hongj990
1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question