I’m looking for a way to write to a texture in my landscape material.
I got this working with static meshes by creating an actor which takes in a mesh and a material that contains the texture i want to modify, during initialization i create a dynamic material and apply it to the mesh.
UMaterialInstanceDynamic* DynamicMaterialInstance = UMaterialInstanceDynamic::Create(MasterMaterial, this);
RenderedTexture = CastChecked<UScriptedTexture>(StaticConstructObject(UScriptedTexture::StaticClass()));
RenderedTexture->AddToRoot();
RenderedTexture->ClearColor = FLinearColor::White;
RenderedTexture->bNeedsTwoCopies = false;
RenderedTexture->bHDR = false;
RenderedTexture->InitAutoFormat(1024, 1024);
RenderedTexture->SetOnScriptedTextureRender(this); //James uses callbacks for this but i prefer interfaces so i modified his implementation of ScriptedTexture.
CanvasItem = new FCanvasTileItem(FVector2D(0.0f, 0.0f), Texture->Resource, FLinearColor::White);
DynamicMaterialInstance->SetTextureParameterValue(FName("WriteableTextureParam"), RenderedTexture);
Mesh->SetMaterial(0, DynamicMaterialInstance);
I don’t see a way to do add a landscape to a class blueprint like we can with static meshes… I noticed that i can get a reference to my terrain in the level blueprint, but there is currently no way to get access to the material and create a dynamic version of it to propagate it to my actor which does the texture writing. I thought about adding functionality to expose the terrain material to the level blueprint but it looked like Epic hid this functionality from us on purpose as they implemented it as an editor only feature as seen in Landscape.h (Is there any reason why i shouldn’t expose this functionality to the landscape blueprint?);
#if WITH_EDITOR
virtual UMaterialInterface* GetLandscapeMaterial() const OVERRIDE;
...
#endif
My next route was to use Material Parameter Collections to achieve my goal but noticed that there is currently no support for using texture paramaters (only scalers and vectors). I started to implement support for texures but stopped as there is some refactoring that needs to be done because memory alignment is important in their current implementation and adding texture params would throw it off.
Has anyone ran into this problem? Is there an existing way to dynamically update textures on landscape materials?