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.

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

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

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

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

Okay sorry. I got it. This works perfectly

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…

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