Hi!
I’m running UE4.18.1 PCD3D_SM5 on Win10 x64 Fall Creators Update (16299), GPU is GTX 750 Ti.
I develop yet another fog of war and have following code:
void AFogOfWar::BeginPlay()
{
Super::BeginPlay();
this->FogMapTexture = UTexture2D::CreateTransient(30, 60, EPixelFormat::PF_A8);
FogMapTexture->UpdateResource();
if (this->TargetVolume != nullptr)
{
UMaterialInstanceDynamic* MaterialInstance = UMaterialInstanceDynamic::Create(this->PostProcessMaterial, this);
if (MaterialInstance != nullptr)
{
MaterialInstance->SetTextureParameterValue(TEXT("FogMapTexture"), FogMapTexture);
TargetVolume->AddOrUpdateBlendable(MaterialInstance, 1.f);
}
}
}
void AFogOfWar::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
static struct FPayload {
uint8 Data[30 * 60];
FPayload() { memset(Data, 255, 30 * 60); }
} Payload;
static FUpdateTextureRegion2D region(0, 0, 0, 0, 30, 60);
FogMapTexture->UpdateTextureRegions(0, 1, ®ion, 30, 1, Payload.Data);
FogMapTexture->UpdateResource();
}
The problem is, UpdateTextureRegions has no effect on FogMapTexture, but direct modification of texture mip’s BulkData works nice although is not efficient:
void AFogOfWar::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
void* TextureData = FogMapTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
for (uint32 iY = 0; iY < 60; ++iY)
{
FMemory::Memset((uint8*)TextureData + (iY * 30), 255, 30);
}
FogMapTexture->PlatformData->Mips[0].BulkData.Unlock();
FogMapTexture->UpdateResource();
}
I came up with similar questions on AnswerHub and forums, but no proposed solutions seems working for me. How to use UpdateTextureRegions properly?