No mipmap support for Dynamic Texture 2D

anonymous_user_0dafa81b
Tue, 24 May 2016 04:58:50 +0000
Asset Creation

I’m trying to set material onto object at run-time from texture, normal map, displacement map etc. located in the hard disk. To achieve this i need to create dynamic material instance and set the parameter to the material by loading the image file at run-time.

I’m creating material from texture & displacement map image file. These image files are loading from folder using Victory Plugin’s “Victory Load Texture 2D from File” Node.

I’m creating the material instance dynamic of the “test material”. Now I’m setting the texture and displacement parameter as shown in figure 4.
After creating material instance dynamic, I’m setting this material to the object.

figure[1] test material:

figure[2] texture:

figure[3] displacement map:

figure[4] Method:

Now here is the problem.

When I directly create material in material editor from texture and displacement map and set it onto object. It doesn’t generate** moiré pattern.**

But when I run-time set the material onto object using figure [4]. It will generate moiré pattern.

Here are the sample screen shots of both.

figure[5]: Material Editor result:

figure[6]: Runtime result: Imgur: The magic of the Internet

I think the “Load Texture 2D from File” nodes is not calculating the Mip Map correctly.

I tried with following nodes but the result is same.
1> “Victory Load Texture 2D from File” (Created by rama)
2> “Load Texture 2D from File by Extension” (Created by you)
3> “Victory Load Texture 2D from File Pixels” (Created by rama)

For MipMap Calculation I modified the plugin file VictoryBPFunctionLibrary.cpp.

Here is the function that I’m using without any success.

UTexture2D* UVictoryBPFunctionLibrary::Victory_LoadTexture2D_FromFile(const FString& FullFilePath,EJoyImageFormats ImageFormat, bool& IsValid,int32& Width, int32& Height)
{

IsValid = false;
UTexture2D* LoadedT2D = NULL;

IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(GetJoyImageFormat(ImageFormat));

//Load From File
TArray<uint8> RawFileData;
if (!FFileHelper::LoadFileToArray(RawFileData, *FullFilePath)) return NULL;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//Create T2D!
if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()))
{
	const TArray<uint8>* UncompressedBGRA = NULL;
	if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
	{
		LoadedT2D = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);
		LoadedT2D->MipGenSettings=TMGS_FromTextureGroup;

		//Valid?
		if(!LoadedT2D) return NULL;
		//~~~~~~~~~~~~~~

		//Out!
		Width = ImageWrapper->GetWidth();
		Height = ImageWrapper->GetHeight();

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

		//Update!
		LoadedT2D->UpdateResource();
	}
}

// Success!
IsValid = true;
return LoadedT2D;

}

I also tried with

LoadedT2D->MipGenSettings=TMGS_Blur1;

to

LoadedT2D->MipGenSettings=TMGS_Blur5;

LoadedT2D->MipGenSettings=TMGS_Sharpen0;

to

LoadedT2D->MipGenSettings=TMGS_Sharpen10;

LoadedT2D->MipGenSettings=TMGS_SimpleAverage;

After so many attempts result is same.

While playing the game when event occur, it closes the editor without any prompt or crash report.

I think engine is not able to set the mipmap at runtime.

13 posts - 8 participants