Description

Creating a UTexture2D the following way does not properly process gradients in the texture:

------
bool Atexture_test_actor::LoadRawFileTest(
/* output */ UTexture2D*& image) {

TArray<short> values;
values.SetNum(512 * 512);
for (int y = 0; y < 512; ++y) {
const short value = (short)FMath::Clamp((int)(((float)65535 / 511) * y - 32768), -32768, 32767); // -32768 to 32767
for (int x = 0; x < 512; ++x) {
values[y * 512 + x] = value;
}
}

// For Check
for (int y = 0; y < 512; ++y) {
UE_LOG(LogTemp, Warning, TEXT("%d"), values[y * 512]);
}

image = UTexture2D::CreateTransient(512, 512, /*EPixelFormat::PF_G16*/ EPixelFormat::PF_R16_SINT);
image->CompressionSettings = TextureCompressionSettings::TC_Grayscale;
image->Filter = TextureFilter::TF_Bilinear;
image->SRGB = false;
image->AddToRoot();

#if WITH_EDITOR
image->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
image->CompressionNone = true;
#endif

void* locked_bulk_data = image->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(locked_bulk_data, values.GetData(), sizeof(short) * 512*512);
image->PlatformData->Mips[0].BulkData.Unlock();

image->UpdateResource();

return true;
}
------

Tested in 4.23.1 (CL - 9631420), 4.24 P2 (CL - 10091930), 4.25 (CL - 10236406)

Steps to Reproduce

1. Download the attached project
2. PIE

Expected: In the top left corner of the viewport, a texture with a gradient going from black to grey should appear

[Link Removed]

Result: There is a hard cutoff between the two colors on the texture
[Link Removed]

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-84648 in the post.

2
Login to Vote

Won't Fix
CreatedNov 18, 2019
ResolvedAug 27, 2021
UpdatedAug 27, 2021