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)
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]
How does TextureRenderTarget2D get TArray<uint8> type data?
Why does the REMOVE method of map container remove elements have memory leaks?
How to delete some elements correctly when deleting an array loop?
What is the cause of the packaging error falling back to 'GameUserSettings' in ue5?
What does the number (2152,1-34) in glsl error mean?
How does TArray loop correctly remove elements in blueprints?
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-84648 in the post.
2 |
Component | UE - Rendering Architecture - RHI |
---|---|
Affects Versions | 4.23.1, 4.24, 4.25 |
Created | Nov 18, 2019 |
---|---|
Resolved | Aug 27, 2021 |
Updated | Aug 27, 2021 |