_h2o
(_h2o)
July 22, 2015, 8:52am
1
Hi, i am trying to get image from ASceneCapture2D spawned when playing. It is like character “selfy”
After character postinitcomponent i call RegenerateIcon(). Then i try to draw this image to screen and i have empty transparent image or it seems there is no image.
UPROPERTY(VisibleDefaultsOnly, Transient, Category = "ISLANIA | Character")
FSlateBrush Icon;
void ATestCharacter::RegenerateIcon()
{
class UTextureRenderTarget2D* lTextureRender = NewObject<UTextureRenderTarget2D>();
if (lTexture)
{
//lTexture->SizeX = 512.f;
//lTexture->SizeY = 512.f;
lTextureRender->InitAutoFormat(512.f, 512.f);
lTextureRender->UpdateResource();
FVector lCamTranslation = FVector(-30.f, 0.f, 50.f);
FVector lCamLoc = GetActorLocation() + lCamTranslation;
class ASceneCapture2D* lSC2DActor = GetWorld()->SpawnActor<ASceneCapture2D>(ASceneCapture2D::StaticClass(), lCamLoc, FRotator::ZeroRotator);
if (lSC2DActor)
{
class USceneCaptureComponent2D* lSCC = lSC2DActor->GetCaptureComponent2D();
if (lSCC)
{
lSCC->Deactivate();
lSCC->TextureTarget = lTexture;
lSCC->bCaptureEveryFrame = false;
lSCC->MaxViewDistanceOverride = 128.f;
lSCC->bAutoActivate = false;
lSCC->DetailMode = EDetailMode::DM_High;
lSCC->UpdateContent();
//lSCC->Activate();
class UTexture2D* lTexture2D = lTexture->ConstructTexture2D(GetWorld(), "Avatar", RF_Transient);
Icon.SetResourceObject(lTexture2D);
GetWorld()->GetFirstPlayerController()->GetHUD()->DrawTextureSimple(lTexture, 512.f, 512.f);
}
}
}
}
other tests:
i tried to send lTexture2D to hud and then to draw it in drawhud() but i had no image on screen
i called RegenerateIcon() in character tick() and then send image to hud in drawhud()
and i newer seen this image on screen.
i tried to create and attach USceneCaptureComponent2D instead of ASceneCapture2D
what am i doing wrong or is there any specific when using SceneCaptureComponent at runtime?
_h2o
(_h2o)
July 24, 2015, 11:22am
2
even just tried just to draw empty icon on screen:
i have added RegenerateIcon() to tick()
void ATestCharacter::RegenerateIcon()
{
class UTextureRenderTarget2D* lTextureRender = NewObject<UTextureRenderTarget2D>(this);
if (lTextureRender)
{
lTextureRender->InitAutoFormat(512.f, 512.f);
lTextureRender->OverrideFormat = EPixelFormat::PF_FloatRGB;
lTextureRender->bNeedsTwoCopies = false;
lTextureRender->AddressX = TA_Wrap;
lTextureRender->AddressY = TA_Wrap;
lTextureRender->ClearColor = FLinearColor::Black;
lTextureRender->UpdateResourceImmediate(true);
FTextureRenderTarget2DResource* TextureResource = (FTextureRenderTarget2DResource*)lTextureRender->Resource;
FCanvas* Canvas = new FCanvas(TextureResource, NULL, 0, 0, 0, GMaxRHIFeatureLevel);
Canvas->SetAllowedModes(FCanvas::ECanvasAllowModes::Allow_Flush);
Canvas->Clear(FLinearColor::Yellow);
FCanvasTileItem Box(FVector2D(512.f, 512.f), lTextureRender->Resource, FVector2D(512.f, 512.f), FLinearColor(1.0f, 1.0f, 1.0f));
Box.BlendMode = SE_BLEND_Opaque;
Canvas->DrawItem(Box);
Canvas->Flush_GameThread();
}
}
and i do not see any black or green or yellow box on screen. what is wrong?
_h2o
(_h2o)
July 28, 2015, 12:36pm
3
It is look like texture was not been updated, render component is waiting for render tick maybe.
_h2o
(_h2o)
July 29, 2015, 6:08am
4
/** Render the scene to the texture */
UFUNCTION(BlueprintCallable,Category = “Rendering|SceneCapture”)
ENGINE_API void UpdateContent();
Look like this function is not immediate, so it is delayed to render thread maybe, thats why render texture is empty.
It will be very good if Engine programmers will add delegate to USceneCaptureComponent2D or ASceneCapture2D when it will finish to update render texture
_h2o
(_h2o)
July 29, 2015, 11:34am
5
Also, how to make unlit capture as it was in UE3? USceneCaptureComponent2D show flags not changes anything.
_h2o
(_h2o)
August 6, 2015, 8:44pm
6
Can engine developers add bind dynamic delegate to UTextureRenderTarget2D or to USceneCaptureComponent2D or to ASceneCapture2D like:
UTextureRenderTarget2D->OnChange()
USceneCaptureComponent2D->OnUpdateTextureTarget()
ASceneCapture2D->OnCapture()
MikeZheng
(MikeZheng)
January 13, 2016, 2:43am
7
ConstructTexture2D is editoronly. I face the same questions.