Load normal map at runtime

Hi,

I want to import normal map at runtime but there is issue.
As follow images, left floor is load normal map at runtime and right floor is imported same normal map to Asset.
A light is front of floors, and you can see the specular of right floor is correct, but left one incorrect.


Here is the coed of loading external image:



if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()))
{
  TArray<uint8> UncompressedBGRA;
  if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
  {
    Texture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);

    if (!Texture)
    {
      return false;
    }

    Width = ImageWrapper->GetWidth();
    Height = ImageWrapper->GetHeight();

    void* TextureData = Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
    FMemory::Memcpy(TextureData, UncompressedBGRA.GetData(), UncompressedBGRA.Num());
    Texture->PlatformData->Mips[0].BulkData.Unlock();

    Texture->UpdateResource();
  }
}


Here is the Material node

I tried to finding older post, but it’s cannot resolved my problem.
Thank very much if someone can help.

Can anyone help please.

Try multiplying the normal by 2 and subtracting 1, as I recall normal maps in UE4 need to be -1 to 1.

Thank you for reply, Arkiras

Do you mean this ?


I tried it and seems incorrect.


If that doesn’t work then the only thing I could guess is that there is a conflict between the sampler type of your texture parameter, and the code you’re using as your code looks like it is using uncompressed RGBA. I’m just wildly speculating though.

Thank you Arkiras, It’s work!
Thanks very much.