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"

Getting Texture2D Texel color

I'm trying to retrieve the texel colors from a UTexture2D so that I can use it as a type of map.

I've recently posted in an old thread on the topic (https://answers.unrealengine.com/questions/25594/accessing-pixel-values-of-texture2d.html), but I figured I should start my own on this question.

I followed the directions in the post given above, but the colors I'm getting back are wrong (eg. an all black DXT1 texture is getting (R=170,G=170,B=170,A=170) for some texels).

     FTexture2DMipMap* mipMap0 = &Texture->PlatformData->Mips[0];
     FByteBulkData* raw = &mipMap0->BulkData;
     auto mipData = static_cast<FColor*>(raw->Lock(LOCK_READ_ONLY));
 
     INT32 TextureWidth = mipMap0->SizeX, TextureHeight = mipMap0->SizeY;
     for (int y = 0; y < TextureHeight; ++y)
     {
         for (int x = 0; x < TextureWidth; ++x)
         {
             auto str = mipData[y*TextureWidth + x].ToString();
             UE_LOG(BabylonLog, Display, _T("%s"), *str);
         }
     }
     raw->Unlock();


Any help is appreciated.

Product Version: Not Selected
Tags:
more ▼

asked Jan 22 '15 at 05:06 PM in C++ Programming

avatar image

Grogger
797 49 62 94

avatar image illunara Mar 11 '16 at 05:57 PM

Can you give me the full code of getting texture color pixel please? I stuck with the function parameters, and ue keep crashing

avatar image Grogger Mar 11 '16 at 07:04 PM

The above really is the full code for that section, the "Texture" variable above is a UTexture2D*

avatar image illunara Mar 12 '16 at 06:14 AM

Okay sorry. I got it. This works perfectly

avatar image MarekArtist Mar 17 '17 at 02:10 PM

Is there a way to achieve this in blueprints? To read the color of a particular texel? Thx in advance :)

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

1 answer: sort voted first

You need to make sure the texture is uncompressed. Set the compression settings as TC_VectorDisplacementmap

more ▼

answered May 17 '15 at 11:54 PM

avatar image

srkibria
23 1 5 10

avatar image Grogger May 18 '15 at 12:22 AM

Compression was the problem, thanks. I ended up solving this a while ago using the ColorLookupTable texture group (No compression or mips)

avatar image pemcode Oct 13 '16 at 05:36 AM

Wow that's insane. My first impression of UE4 is that there's a lot of documentation and community support, but this took me a while to find... I don't see Texture Groups documented. I'm starting to wonder if we're expected to look at the UE4 engine source code for some things...

(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