Hello, my dear friends! My name is Viktor. I need of your help to solve next problem:
In my UE4 project I should: 1) create few simple meshes; 2) load textures and normal maps for them at runtime.
The first task was solved with Procedural Mesh Component and simple Blueprint Function Library (C++) that load mesh data (vertices, normals, …) from a file - Ok. Then I’d created other Blueprint Function Library, that load texture and normal map from files (code from web example):
[FONT=Courier New]IImageWrapperModule& imageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName(“ImageWrapper”));
IImageWrapperPtr imageWrapper = imageWrapperModule.CreateImageWrapper(EImageFormat::JPEG);
if (FFileHelper::LoadFileToArray(rawFileData, textureFileName))
if (imageWrapper.IsValid() && imageWrapper->SetCompressed(rawFileData.GetData(), rawFileData.Num()))
const TArray<uint8> uncompressedBGRA = NULL;
if (imageWrapper->GetRaw(ERGBFormat::BGRA, 8, uncompressedBGRA))
UTexture2D* texture = UTexture2D::CreateTransient(imageWrapper->GetWidth(), imageWrapper->GetHeight(), PF_B8G8R8A8);
void* designTexData = texture->PlatformData->Mips.BulkData.Lock(LOCK_READ_WRITE); FMemory::Memcpy(designTexData, uncompressedBGRA->GetTypedData(), uncompressedBGRA->Num()); texture->PlatformData->Mips.BulkData.Unlock(); texture->UpdateResourceW(); return texture; } }
Normal map (created in Photoshop NVIDIA plugin) loaded by the same function. After loading I apply it to existing “parent material” with two named prepared “texture parameters”: for texture and for normal map
Textures loaded well and I can see meshes with them in a scene, but I think that normal maps loaded incorrectly. I have two reasons to think so:
- lighting is incorrect when I use these runtime-loaded normal maps (at first I thought that I have invalid mesh), but when I use design-time-imported normal map, all is Ok;
- I suspect that normal map may be should be loaded with other parameters, but which of them? Pixel format? ERGBFormat? Something other?
Excuse me for my english. I hope for your help, my friends. Thank you!