Announcement

Collapse
No announcement yet.

Runtime texture and normal map

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Runtime texture and normal map

    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):

    IImageWrapperModule& imageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
    IImageWrapperPtr imageWrapper = imageWrapperModule.CreateImageWrapper(EImageFormat::JPEG);

    TArray<uint8> rawFileData;

    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[0].BulkData.Lock(LOCK_READ_WRITE);
    FMemory::Memcpy(designTexData, uncompressedBGRA->GetTypedData(), uncompressedBGRA->Num());
    texture->PlatformData->Mips[0].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

    Click image for larger version

Name:	blueprint.jpg
Views:	1
Size:	208.4 KB
ID:	1167396

    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:
    1) 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;
    2) 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!

    #2
    The answer is: CONVERT YOUR NORMAL MAP TO SET RIGHT COLOR PROFILE (RGB). I use ImageMagic.

    Comment


      #3
      Originally posted by ViktorTanin View Post
      The answer is: CONVERT YOUR NORMAL MAP TO SET RIGHT COLOR PROFILE (RGB). I use ImageMagic.
      Could you please explain this process in detail?

      Comment

      Working...
      X