I’m trying to create a plugin for the Unreal(5.0.3) editor that changes two channels of a texture already existing in the Editor. It is important that I also manually change these channels on all their mip levels(This data will be used for an algorithm I’m implementing), and that the two remaining channels remain unchanged.
I’ve already managed to write the data properly to the texture, but I then realized the way in which the Mip Levels in unreal are calculated is not the same as the one I was using(blur+downsample) for the other two channels that should remain unchanged, either that or I was not managing to get the proper tuning for the arguments, leading to blocky mip levels. So I decided to try and get the data calculated by unreal for the texture, my code looks like this:
TArray<FColor> GetMipMapContent(UTexture2D* Relief_Map, int MipLevelWidth, int MipLevelHeight, int MipLevel)
{
int Num_Pixels = MipLevelWidth * MipLevelHeight;
TArray<FColor> MipContent;
MipContent.SetNumZeroed(Num_Pixels);
FTexture2DMipMap& Mip = Relief_Map->PlatformData->Mips[MipLevel];
TArrayView<uint8> RawData = Mip.BulkData.GetCopyAsBuffer(0, false).GetView();
for (int i = 0; i < Num_Pixels; i++)
{
FColor Pixel;
int Pixel_Index = 4 * i;
Pixel.R = RawData[Pixel_Index + 2];
Pixel.G = RawData[Pixel_Index + 1];
Pixel.B = RawData[Pixel_Index + 3];
Pixel.A = RawData[Pixel_Index + 3];
MipContent[i] = Pixel;
}
return(MipContent);
}
I loop over the mip levels like this:
std::vector<TArray<FColor>> MipLevels;
for (int i = 0; i < NumMips; i++)
{
MipLevels.push_back(GetMipMapContent(Relief_Map, CurrentWidth, CurrentHeight, i));
CurrentWidth /= 2;
CurrentHeight /= 2;
}
However, it seems that the first Mip levels(all levels until the resolution is 64x64) do not have data on them, which halts me from getting their data.
Of an important note is that, if I add the following lines to the code, I am able to get the first mip Level, but, not any other mip(cuz they are erased or ignored by unreal) :
Relief_Map->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
Relief_Map->UpdateResource();
Anyone knows what might be the issue? Or how could I go around doing the same Mip level calculation as Unreal so I don’t have to rely on the stored data?