Hello
I am trying to do operation on multiple textures. The trick is to forward the output of a material to a render target, and then read the resulting texture on render texture and give it back to the material.
In CPP the code is this :
//TextureInBox have texture pair
UTexture2D* texture1 =texturesInBox[texturesInBox.Num()-1].Key;// = texturesInBox[0];
UTexture2D* texture1_N = texturesInBox[texturesInBox.Num() - 1].Value;
UTexture2D* texture2 = texture1;
UTexture2D* texture2_N = texture1_N;
dynamicMaterial->SetTextureParameterValue(TEXT("TextureB"), texture1);
dynamicMaterial->SetTextureParameterValue(TEXT("TextureB_N"), texture1_N);
for (int32 Index = 1; Index < texturesInBox.Num(); ++Index)
{
//RenderTarget is of type URenderTarget2D
texture1 = (UTexture2D*)renderTarget;
texture1_N = (UTexture2D*)renderTarget_n;
texture2 = texturesInBox[Index].Key;
texture2_N = texturesInBox[Index].Value;
dynamicMaterial->SetTextureParameterValue(TEXT("TextureA"), texture2);
dynamicMaterial->SetTextureParameterValue(TEXT("TextureA_N"), texture2_N);
dynamicMaterial->SetTextureParameterValue(TEXT("TextureB"), texture1);
dynamicMaterial->SetTextureParameterValue(TEXT("TextureB_N"), texture1_N);
this->EventTarget(dynamicMaterial,renderTarget);
renderTarget->UpdateResourceImmediate(false);
}
dynamicMaterial->SetTextureParameterValue(TEXT("TextureA"), texture2);
dynamicMaterial->SetTextureParameterValue(TEXT("TextureA_N"), texture2_N);
Part A of the solution is working : I can see material being drawn to render texture (BP attached)
Part B of the solution is to get the output displayed in renderTarget and use it again in the material
The issue is that, renderTarget is not returning the computed texture (a+b); it only shows the texture it was initialized with.
This is my Blueprint
Any help?