Download code/ue_capture/PipelineCaptureV9.cpp from teawhite/GameCrafter-Data-v10: direct link, hf CLI and curl.
- Browser
- Download file 27.3 kB
-
https://huggingface.co/datasets/teawhite/GameCrafter-Data-v10/resolve/main/code/ue_capture/PipelineCaptureV9.cpp
- Command line
-
hf download hf://datasets/teawhite/GameCrafter-Data-v10/code/ue_capture/PipelineCaptureV9.cpp
-
curl -L -o PipelineCaptureV9.cpp https://huggingface.co/datasets/teawhite/GameCrafter-Data-v10/resolve/main/code/ue_capture/PipelineCaptureV9.cpp
27.3 kB
| // v9 dataset: diversity first. | |
| // * Capsule characters in the labels: the player / boss (and their weapons) appear in the semantic map (ids, class 10 / 11) | |
| // as the articulated capsule whitebox (the same proxies as the whitebox pass), not as their mesh silhouettes. Every frame | |
| // also stores the capsule segments (world cm), so the character condition can be redrawn by code without UE. | |
| // * Closer camera: absolute ortho width range (default 900-1600 cm, 12% wide 2000-3000 cm), wider pitch range, and a | |
| // smoothed framing offset towards the player / boss midpoint during fights. | |
| // * Per camera variant "look" (RGB only, labels / whitebox unchanged): post-process style (toon, kuwahara paint, pixel art, | |
| // comic, duotone, retro dither, sketch, soft low-fi, hue rotation), material randomisation of the scene (material | |
| // shuffle, flat colours, triplanar CC0 / generated textures), render tier (full, no GI, no shadows, unlit), texture mip | |
| // bias, colour grade and outline on / off. | |
| // -DatasetV9 enable (needs -DatasetV8) | |
| // -DatasetV9MeshLabels keep the mesh silhouettes in the labels | |
| // -DatasetV9WMin= / WMax= / WideP= / WideMin= / WideMax= / PitchMin= / PitchMax= | |
| // -DatasetV9NoFraming | |
| // -DatasetV9StyleP=0.65 -DatasetV9MatP=0.5 -DatasetV9UnlitP=0.12 | |
| // -DatasetV9LookSeconds=N (tests) also switch the look every N seconds of output | |
| // -DatasetV9Look=mode:mat:tier (tests) force a look (mode 0-9, mat 0-4, tier 0-3; -1 = random) | |
| namespace | |
| { | |
| const TCHAR* V9ModeNames[10]={TEXT("none"),TEXT("toon"),TEXT("paint"),TEXT("pixel"),TEXT("comic"),TEXT("duotone"),TEXT("dither"),TEXT("sketch"),TEXT("soft"),TEXT("hue")}; | |
| const TCHAR* V9MatNames[6]={TEXT("orig"),TEXT("shuffle"),TEXT("flat"),TEXT("tex"),TEXT("mixed"),TEXT("pbr")}; | |
| const TCHAR* V9TierNames[4]={TEXT("full"),TEXT("nogi"),TEXT("noshadow"),TEXT("unlit")}; | |
| TSharedPtr<FJsonValue> V9Num(double V){return MakeShared<FJsonValueNumber>(V);} | |
| FLinearColor V9Hsv(float H,float S,float V){return FLinearColor(FMath::Frac(H)*360.f,FMath::Clamp(S,0.f,1.f),FMath::Clamp(V,0.f,1.f)).HSVToLinearRGB();} | |
| } | |
| void APipelineCapture::ParseV9Args() | |
| { | |
| const TCHAR* Cmd=FCommandLine::Get(); | |
| V9=V8Chars&&FParse::Param(Cmd,TEXT("DatasetV9")); | |
| if(!V9)return; | |
| V9CapLabels=!FParse::Param(Cmd,TEXT("DatasetV9MeshLabels")); | |
| V9Frame=!FParse::Param(Cmd,TEXT("DatasetV9NoFraming")); | |
| V10Photo=FParse::Param(Cmd,TEXT("DatasetV10Photo")); // v10: every look photoreal (PBR materials, cinematic light / grade) | |
| ParseV10Real(Cmd); // v10 real: photoreal outdoor biome + telephoto camera (PipelineCaptureV10Real.cpp) | |
| FParse::Value(Cmd,TEXT("DatasetV9WMin="),V9WMin);FParse::Value(Cmd,TEXT("DatasetV9WMax="),V9WMax);FParse::Value(Cmd,TEXT("DatasetV9WideP="),V9WideP); | |
| FParse::Value(Cmd,TEXT("DatasetV9WideMin="),V9WideMin);FParse::Value(Cmd,TEXT("DatasetV9WideMax="),V9WideMax); | |
| FParse::Value(Cmd,TEXT("DatasetV9PitchMin="),V9PitchMin);FParse::Value(Cmd,TEXT("DatasetV9PitchMax="),V9PitchMax); | |
| FParse::Value(Cmd,TEXT("DatasetV9StyleP="),V9StyleP);FParse::Value(Cmd,TEXT("DatasetV9MatP="),V9MatP);FParse::Value(Cmd,TEXT("DatasetV9UnlitP="),V9UnlitP); | |
| FParse::Value(Cmd,TEXT("DatasetV9Look="),V9Force); | |
| FParse::Value(Cmd,TEXT("DatasetV9CutGrid="),V9CutGrid);FParse::Value(Cmd,TEXT("DatasetV9CutPhase="),V9CutPhase); | |
| if(V9CutGrid>0){V9CutPhase=FMath::Clamp(V9CutPhase/4*4,0,V9CutGrid-4);if(V9CutGrid<V9CutPhase+4||V9CutPhase<80)UE_LOG(LogTemp,Warning,TEXT("DATASET_V9 cut grid %d/%d cannot hold 81-frame clips"),V9CutGrid,V9CutPhase);} | |
| float Sec=0;if(FParse::Value(Cmd,TEXT("DatasetV9LookSeconds="),Sec)&&Sec>0)V9LookFrames=FMath::Max(16,FMath::RoundToInt(Sec*16.f)); | |
| int32 Seed=0;FParse::Value(Cmd,TEXT("DatasetSeed="),Seed);int32 S2=0;if(FParse::Value(Cmd,TEXT("DatasetV9Seed="),S2))Seed=S2; | |
| V9Rng.Initialize(Seed*7919+911);V9CamRng.Initialize(Seed*104729+57); // camera draws on their own stream: paired runs with other looks keep the same views | |
| V9Neutral=FParse::Param(Cmd,TEXT("DatasetV9NeutralGrade")); | |
| UE_LOG(LogTemp,Display,TEXT("DATASET_V9 on capsule_labels=%d framing=%d width %.0f-%.0f wide %.2f (%.0f-%.0f) pitch %.0f..%.0f styleP %.2f matP %.2f force '%s' lookframes %d"), | |
| V9CapLabels,V9Frame,V9WMin,V9WMax,V9WideP,V9WideMin,V9WideMax,V9PitchMin,V9PitchMax,V9StyleP,V9MatP,*V9Force,V9LookFrames); | |
| } | |
| // --------------------------------------------------------------------------------------------------------------------- | |
| // camera | |
| // --------------------------------------------------------------------------------------------------------------------- | |
| void APipelineCapture::V9Camera(FRotator& R,float& W,bool bDefault) | |
| { | |
| V9Offset=FVector::ZeroVector; | |
| const bool Wide=V9CamRng.FRand()<V9WideP; | |
| W=Wide?V9CamRng.FRandRange(V9WideMin,V9WideMax):V9CamRng.FRandRange(V9WMin,V9WMax); | |
| if(!bDefault)R.Pitch=V9CamRng.FRandRange(V9PitchMin,V9PitchMax); | |
| if(V10Real)V10Fov=V9CamRng.FRandRange(V10FovMin,V10FovMax); | |
| V9PendingLook=true; // a new look with every camera variant (clips never cross a camera change) | |
| } | |
| void APipelineCapture::V9Framing(FMinimalViewInfo& View) | |
| { | |
| if(!V9Frame||!Player)return; | |
| const float Now=GetWorld()->GetTimeSeconds();const float Dt=FMath::Clamp(Now-V9LastFrameT,0.f,.25f);V9LastFrameT=Now; | |
| FVector Want=FVector::ZeroVector;const float W=View.OrthoWidth; | |
| if(AGameDemoFighter* B=Player->Opponent.Get())if(B->Health>0) | |
| { | |
| FVector D=B->GetActorLocation()-Player->GetActorLocation();D.Z=0;const float L=D.Size(); | |
| const float K=1.f-FMath::SmoothStep(.45f*W,.85f*W,L); | |
| Want=D*.5f*K;if(Want.Size()>.3f*W)Want=Want.GetSafeNormal()*.3f*W; | |
| } | |
| V9Offset=FMath::Lerp(V9Offset,Want,1.f-FMath::Exp(-Dt*2.5f)); | |
| View.Location+=V9Offset; | |
| } | |
| // --------------------------------------------------------------------------------------------------------------------- | |
| // looks | |
| // --------------------------------------------------------------------------------------------------------------------- | |
| void APipelineCapture::V9LoadPools() | |
| { | |
| if(V9PoolsLoaded)return;V9PoolsLoaded=true; | |
| V9FlatMat=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V9/Materials/M_V9Flat.M_V9Flat")); | |
| V9TriMat=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V9/Materials/M_V9Tri.M_V9Tri")); | |
| if(UMaterialInterface* L=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V9/Materials/M_V9Look.M_V9Look")))V9LookMID=UMaterialInstanceDynamic::Create(L,this); | |
| // textures: a random subset of the catalog per run (photo CC0 and generated stylised) | |
| FString S;const FString Cat=FPaths::ProjectContentDir()/TEXT("Xfer/V9/v9_tex.json"); | |
| TArray<FString> Photo,Sty; | |
| if(FFileHelper::LoadFileToString(S,*Cat)) | |
| { | |
| TSharedPtr<FJsonObject> O;const TSharedRef<TJsonReader<>> R=TJsonReaderFactory<>::Create(S); | |
| if(FJsonSerializer::Deserialize(R,O)&&O.IsValid()) | |
| { | |
| const TArray<TSharedPtr<FJsonValue>>* A; | |
| if(O->TryGetArrayField(TEXT("textures"),A))for(const auto& V:*A) | |
| { | |
| const TSharedPtr<FJsonObject> T=V->AsObject();if(!T)continue; | |
| (T->GetStringField(TEXT("kind"))==TEXT("stylized")?Sty:Photo).Add(T->GetStringField(TEXT("path"))); | |
| } | |
| } | |
| } | |
| auto Pick=[&](TArray<FString>& From,int32 N) | |
| { | |
| for(int32 I=0;I<N&&From.Num();I++) | |
| { | |
| const int32 K=V9Rng.RandRange(0,From.Num()-1); | |
| if(UTexture* T=LoadObject<UTexture>(nullptr,*From[K]))V9TexPool.Add(T); | |
| From.RemoveAtSwap(K); | |
| } | |
| }; | |
| const int32 NPhoto=V9TexPool.Num();Pick(Photo,36);V9NumPhoto=V9TexPool.Num()-NPhoto;Pick(Sty,16); | |
| // material shuffle pool: every opaque material currently on a labelled scene mesh | |
| TSet<UMaterialInterface*> Seen; | |
| for(TActorIterator<AActor> I(GetWorld());I;++I) | |
| { | |
| if(I->ActorHasTag(TEXT("whitebox"))||Cast<AGameDemoFighter>(*I)||*I==this)continue; | |
| TArray<UMeshComponent*> Cs;I->GetComponents(Cs); | |
| for(UMeshComponent* C:Cs) | |
| { | |
| if(!C->bRenderCustomDepth||C->CustomDepthStencilValue<1||C->CustomDepthStencilValue>6||C->ComponentHasTag(TEXT("v8fx")))continue; | |
| for(int32 K=0;K<C->GetNumMaterials();K++)if(UMaterialInterface* M=C->GetMaterial(K)) | |
| if(M->GetBlendMode()==BLEND_Opaque&&!Seen.Contains(M)){Seen.Add(M);V9MatPool.Add(M);} | |
| } | |
| } | |
| UE_LOG(LogTemp,Display,TEXT("DATASET_V9 pools: flat=%d tri=%d look=%d textures=%d (photo %d) shuffle materials=%d"),V9FlatMat!=nullptr,V9TriMat!=nullptr,V9LookMID!=nullptr,V9TexPool.Num(),V9NumPhoto,V9MatPool.Num()); | |
| } | |
| void APipelineCapture::V9RestoreMaterials() | |
| { | |
| for(auto& P:V9Orig)if(UMeshComponent* C=P.Key.Get())for(int32 K=0;K<P.Value.Num();K++)C->SetMaterial(K,P.Value[K]); | |
| V9Orig.Reset();V9MIDs.Reset(); | |
| } | |
| void APipelineCapture::V9ApplyMaterials() | |
| { | |
| V9RestoreMaterials(); | |
| if(V9Cur.Mat==0)return; | |
| if(V9Cur.Mat==5){V10ApplyPBR();return;} | |
| // one replacement per distinct original material (keeps the scene coherent); a fraction of originals stays | |
| TMap<UMaterialInterface*,UMaterialInterface*> Map; | |
| const float Keep=V9Cur.Keep; | |
| TArray<FLinearColor> Pal;const float H0=V9Rng.FRand();const int32 Scheme=V9Rng.RandRange(0,3); | |
| for(int32 I=0;I<6;I++) | |
| { | |
| const float H=Scheme==0?H0+I*.04f:Scheme==1?H0+(I%2)*.5f:Scheme==2?H0+(I%3)/3.f:V9Rng.FRand(); | |
| Pal.Add(V9Hsv(H,V9Rng.FRandRange(.15f,.8f),V9Rng.FRandRange(.25f,.9f))); | |
| } | |
| const float StyShare=V9Rng.FRand()<.35f?.7f:.15f; | |
| auto MakeFor=[&](UMaterialInterface* Orig)->UMaterialInterface* | |
| { | |
| int32 Mode=V9Cur.Mat==4?V9Rng.RandRange(1,3):V9Cur.Mat; | |
| if(Mode==1&&V9MatPool.Num()>1){int32 K=V9Rng.RandRange(0,V9MatPool.Num()-1);if(V9MatPool[K].Get()==Orig)K=(K+1)%V9MatPool.Num();return V9MatPool[K].Get();} | |
| if(Mode==3&&V9TriMat&&V9TexPool.Num()) | |
| { | |
| UMaterialInstanceDynamic* D=UMaterialInstanceDynamic::Create(V9TriMat,this); | |
| const bool Sty=V9TexPool.Num()>V9NumPhoto&&V9Rng.FRand()<StyShare; | |
| UTexture* T=Sty?V9TexPool[V9Rng.RandRange(V9NumPhoto,V9TexPool.Num()-1)]:V9TexPool[V9Rng.RandRange(0,FMath::Max(0,V9NumPhoto-1))]; | |
| D->SetTextureParameterValue(TEXT("Tex"),T);D->SetScalarParameterValue(TEXT("Tile"),V9Rng.FRandRange(120.f,520.f)); | |
| const FLinearColor Tint=FLinearColor::LerpUsingHSV(FLinearColor::White,Pal[V9Rng.RandRange(0,Pal.Num()-1)],V9Rng.FRandRange(0.f,.45f)); | |
| D->SetVectorParameterValue(TEXT("Tint"),Tint*V9Rng.FRandRange(.8f,1.15f));D->SetScalarParameterValue(TEXT("Sat"),V9Rng.FRandRange(.5f,1.3f)); | |
| D->SetScalarParameterValue(TEXT("Rough"),V9Rng.FRandRange(.45f,.95f));V9MIDs.Add(D);return D; | |
| } | |
| if(V9FlatMat) | |
| { | |
| UMaterialInstanceDynamic* D=UMaterialInstanceDynamic::Create(V9FlatMat,this); | |
| D->SetVectorParameterValue(TEXT("Color"),Pal[V9Rng.RandRange(0,Pal.Num()-1)]*V9Rng.FRandRange(.85f,1.1f)); | |
| D->SetScalarParameterValue(TEXT("Var"),V9Rng.FRandRange(0.f,.3f));D->SetScalarParameterValue(TEXT("Rough"),V9Rng.FRandRange(.4f,1.f));V9MIDs.Add(D);return D; | |
| } | |
| return nullptr; | |
| }; | |
| int32 Comps=0; | |
| for(TActorIterator<AActor> I(GetWorld());I;++I) | |
| { | |
| if(I->ActorHasTag(TEXT("whitebox"))||Cast<AGameDemoFighter>(*I)||*I==this)continue; | |
| TArray<UMeshComponent*> Cs;I->GetComponents(Cs); | |
| for(UMeshComponent* C:Cs) | |
| { | |
| if(!C->bRenderCustomDepth||C->CustomDepthStencilValue<1||C->CustomDepthStencilValue>6||C->ComponentHasTag(TEXT("v8fx")))continue; | |
| TArray<UMaterialInterface*> Old;bool Any=false; | |
| for(int32 K=0;K<C->GetNumMaterials();K++) | |
| { | |
| UMaterialInterface* M=C->GetMaterial(K);Old.Add(M); | |
| if(!M||M->GetBlendMode()!=BLEND_Opaque)continue; // masked / translucent stay: replacing them would change the silhouettes | |
| UMaterialInterface** Got=Map.Find(M); | |
| if(!Got){UMaterialInterface* N=V9Rng.FRand()<Keep?M:MakeFor(M);Got=&Map.Add(M,N?N:M);} | |
| if(*Got!=M){if(!Any){V9Orig.Add(TPair<TWeakObjectPtr<UMeshComponent>,TArray<UMaterialInterface*>>(C,TArray<UMaterialInterface*>()));Any=true;}C->SetMaterial(K,*Got);} | |
| } | |
| if(Any){V9Orig.Last().Value=Old;Comps++;} | |
| } | |
| } | |
| V9MatSwaps+=Comps; | |
| UE_LOG(LogTemp,Display,TEXT("DATASET_V9 materials %s: %d originals -> %d components"),V9MatNames[V9Cur.Mat],Map.Num(),Comps); | |
| } | |
| void APipelineCapture::V9NewLook() | |
| { | |
| V9PendingLook=false;V9LoadPools(); | |
| FV9Look L; | |
| auto R=[&](float A,float B){return V9Rng.FRandRange(A,B);}; | |
| L.Mode=V9Rng.FRand()<V9StyleP?V9Rng.RandRange(1,9):0; | |
| const float MR=V9Rng.FRand();L.Mat=MR<V9MatP?(MR<V9MatP*.2f?1:MR<V9MatP*.45f?2:MR<V9MatP*.8f?3:4):0; | |
| const float TR=V9Rng.FRand();L.Tier=TR<V9UnlitP?3:TR<V9UnlitP+.18f?1:TR<V9UnlitP+.28f?2:0; | |
| const float MB=V9Rng.FRand();L.Mip=MB<.7f?0.f:MB<.9f?1.5f:3.f; | |
| L.Outline=V9Rng.FRand()<.55f;L.Keep=V9Rng.FRand()<.3f?R(.3f,.6f):R(0.f,.15f); | |
| // optional forced look (tests): "mode:mat:tier", -1 = random | |
| if(!V9Force.IsEmpty()){TArray<FString> P;V9Force.ParseIntoArray(P,TEXT(":")); | |
| if(P.Num()>0&&FCString::Atoi(*P[0])>=0)L.Mode=FMath::Clamp(FCString::Atoi(*P[0]),0,9); | |
| if(P.Num()>1&&FCString::Atoi(*P[1])>=0)L.Mat=FMath::Clamp(FCString::Atoi(*P[1]),0,5); | |
| if(P.Num()>2&&FCString::Atoi(*P[2])>=0)L.Tier=FMath::Clamp(FCString::Atoi(*P[2]),0,3);} | |
| if(V10Photo)V10PhotoLook(L); | |
| if(V9Force==TEXT("cycle")&&!V10Photo){L.Mode=V9LookCount%10;L.Mat=(V9LookCount/2)%5;L.Tier=(V9LookCount%7==3)?3:(V9LookCount%5==1?1:0);} | |
| const float H0=V9Rng.FRand(); | |
| switch(L.Mode) | |
| { | |
| case 1: L.P1=(float)V9Rng.RandRange(3,6);L.P2=R(1.f,2.f);break; | |
| case 2: L.P1=R(2.f,3.f);L.P2=R(1.f,1.4f);break; | |
| case 3: L.P1=(float)V9Rng.RandRange(3,8);L.P2=(float)V9Rng.RandRange(4,10);L.P3=R(0.f,1.f);break; | |
| case 4: L.P1=R(4.f,8.f);L.P2=R(1.f,2.f);break; | |
| case 5: L.CA=V9Hsv(H0,R(.3f,.8f),R(.05f,.2f));L.CB=V9Hsv(H0+R(-.15f,.15f)+(V9Rng.FRand()<.4f?.5f:0.f),R(.3f,.8f),R(.4f,.6f));L.CC=V9Hsv(H0+R(-.1f,.1f),R(.05f,.4f),R(.85f,1.f));break; | |
| case 6: L.P1=(float)V9Rng.RandRange(1,2);L.P2=(float)V9Rng.RandRange(3,6);break; | |
| case 7: L.P1=R(.3f,.9f);L.P2=R(1.f,2.f);L.CA=V9Hsv(R(.05f,.6f),R(.03f,.15f),R(.85f,.98f));break; | |
| case 8: L.P1=R(1.f,3.f);L.P2=R(.4f,.9f);L.P3=R(0.f,.25f);L.CA=V9Hsv(H0,R(0.f,.3f),R(.6f,.95f));break; | |
| case 9: L.P1=R(.1f,.9f);L.P2=R(.6f,1.6f);L.P3=V9Rng.FRand()<.5f?0.f:(float)V9Rng.RandRange(4,10);break; | |
| default: break; | |
| } | |
| if(!V10Photo) | |
| { | |
| const float GS=V9Rng.FRand(); | |
| L.Sat=GS<.08f?R(.1f,.4f):GS<.15f?R(1.45f,1.8f):R(.65f,1.3f);L.Con=R(.85f,1.2f);L.Gam=R(.88f,1.12f);L.Temp=R(4800.f,8200.f); | |
| L.Gain=FLinearColor::LerpUsingHSV(FLinearColor::White,V9Hsv(V9Rng.FRand(),1.f,1.f),V9Rng.FRand()<.3f?R(.05f,.18f):0.f); | |
| } | |
| if(V9Neutral&&!V10Photo){L.Sat=1;L.Con=1;L.Gam=1;L.Temp=6500;L.Gain=FLinearColor::White;L.Outline=true;} // baseline renders (v8 look) for comparisons | |
| L.Index=V9LookCount++; | |
| L.Name=FString::Printf(TEXT("%s|%s|%s|mip%.1f|%s"),V9ModeNames[L.Mode],V9MatNames[L.Mat],V9TierNames[L.Tier],L.Mip,L.Outline?TEXT("ol"):TEXT("no")); | |
| if(V10Photo)L.Name=FString::Printf(TEXT("photo|%s|%s|%s|%s"),*L.LightName,*L.Biome,V9MatNames[L.Mat],L.Outline?TEXT("ol"):TEXT("no")); | |
| V9Cur=L;V9LookStartFrame=Frame; | |
| V9ModeHist.FindOrAdd(V9ModeNames[L.Mode])++; | |
| if(IConsoleVariable* V=IConsoleManager::Get().FindConsoleVariable(TEXT("r.MipMapLODBias")))V->Set(L.Mip,ECVF_SetByCode); | |
| V9ApplyMaterials(); | |
| TSharedPtr<FJsonObject> J=MakeShared<FJsonObject>(); | |
| J->SetNumberField(TEXT("index"),L.Index);J->SetNumberField(TEXT("frame"),Frame);J->SetNumberField(TEXT("camera_variant"),CameraVariant);J->SetStringField(TEXT("name"),L.Name); | |
| J->SetStringField(TEXT("style"),V9ModeNames[L.Mode]);J->SetStringField(TEXT("materials"),V9MatNames[L.Mat]);J->SetStringField(TEXT("render_tier"),V9TierNames[L.Tier]); | |
| J->SetNumberField(TEXT("mip_bias"),L.Mip);J->SetBoolField(TEXT("outline"),L.Outline);J->SetNumberField(TEXT("keep_original_share"),L.Keep); | |
| J->SetArrayField(TEXT("style_params"),{V9Num(L.P1),V9Num(L.P2),V9Num(L.P3)}); | |
| J->SetArrayField(TEXT("grade_sat_con_gamma_temp"),{V9Num(L.Sat),V9Num(L.Con),V9Num(L.Gam),V9Num(L.Temp)}); | |
| if(V10Photo)V10LookJson(J); | |
| V9LookLog.Add(MakeShared<FJsonValueObject>(J)); | |
| UE_LOG(LogTemp,Display,TEXT("DATASET_V9 look %d at frame %d: %s"),L.Index,Frame,*L.Name); | |
| } | |
| void APipelineCapture::V9BeforeRGB(USceneCaptureComponent2D* C) | |
| { | |
| if(!C)return; | |
| const FV9Look& L=V9Cur;auto& PP=C->PostProcessSettings; | |
| C->ShowFlags.SetLighting(L.Tier!=3); | |
| C->ShowFlags.SetDynamicShadows(L.Tier<2); | |
| C->ShowFlags.SetAmbientOcclusion(L.Tier==0); | |
| PP.bOverride_DynamicGlobalIlluminationMethod=true;PP.DynamicGlobalIlluminationMethod=L.Tier==0?EDynamicGlobalIlluminationMethod::Lumen:EDynamicGlobalIlluminationMethod::None; | |
| PP.bOverride_ReflectionMethod=true;PP.ReflectionMethod=L.Tier==0?EReflectionMethod::Lumen:EReflectionMethod::None; | |
| PP.bOverride_ColorSaturation=true;PP.ColorSaturation=FVector4(L.Sat,L.Sat,L.Sat,1.f); | |
| PP.bOverride_ColorContrast=true;PP.ColorContrast=FVector4(L.Con*1.04f,L.Con*1.04f,L.Con*1.04f,1.f); | |
| PP.bOverride_ColorGamma=true;PP.ColorGamma=FVector4(L.Gam,L.Gam,L.Gam,1.f); | |
| PP.bOverride_ColorGain=true;PP.ColorGain=FVector4(L.Gain.R,L.Gain.G,L.Gain.B,1.f); | |
| PP.bOverride_WhiteTemp=true;PP.WhiteTemp=L.Temp; | |
| bool Has=false; | |
| for(FWeightedBlendable& B:PP.WeightedBlendables.Array) | |
| { | |
| if(V8OutlineMat&&B.Object==V8OutlineMat)B.Weight=L.Outline?1.f:0.f; | |
| if(V9LookMID&&B.Object==V9LookMID){B.Weight=L.Mode>0?1.f:0.f;Has=true;} | |
| } | |
| if(V9LookMID) | |
| { | |
| if(!Has)PP.WeightedBlendables.Array.Add(FWeightedBlendable(L.Mode>0?1.f:0.f,V9LookMID)); | |
| UMaterialInstanceDynamic* D=V9LookMID; | |
| D->SetScalarParameterValue(TEXT("Mode"),(float)L.Mode);D->SetScalarParameterValue(TEXT("P1"),L.P1);D->SetScalarParameterValue(TEXT("P2"),L.P2); | |
| D->SetScalarParameterValue(TEXT("P3"),L.P3);D->SetScalarParameterValue(TEXT("SS"),(float)V8SS); | |
| D->SetVectorParameterValue(TEXT("CA"),L.CA);D->SetVectorParameterValue(TEXT("CB"),L.CB);D->SetVectorParameterValue(TEXT("CC"),L.CC); | |
| } | |
| if(V10Photo)V10BeforeRGB(C); | |
| } | |
| // --------------------------------------------------------------------------------------------------------------------- | |
| // capsule labels | |
| // --------------------------------------------------------------------------------------------------------------------- | |
| void APipelineCapture::V9BeforeCapture() | |
| { | |
| // tests only (-DatasetV9LookSeconds): forced switches also respect the cut grid (the change shows from this frame on) | |
| const bool GridNow=V9CutGrid<=0||(Frame%V9CutGrid)==(V9CutPhase+1)%V9CutGrid; | |
| if(V9PendingLook||(V9LookFrames>0&&Frame-V9LookStartFrame>=V9LookFrames&&CaptureStart>=0&&GridNow))V9NewLook(); | |
| if(!V9CapLabels)return; | |
| for(APipelineWhitebox* P:WhiteboxCharacters) | |
| { | |
| if(!P||!P->Fighter)continue; | |
| const int32 Id=P->Fighter->IsBoss?11:10; | |
| // weapon capsule: longest axis of the weapon mesh bounds, radius from the other two extents | |
| UStaticMeshComponent* W=(P->Fighter->IsBoss?V8WeaponB:V8WeaponP).Get(); | |
| if(W&&W->GetAttachParent()!=P->Fighter->GetMesh())W=nullptr; | |
| TArray<UStaticMeshComponent*> WP;for(UStaticMeshComponent* X:P->Parts)if(X&&X->ComponentHasTag(TEXT("v9w")))WP.Add(X); | |
| if(WP.Num()==0&&W&&WhiteMaterialRef) | |
| { | |
| for(const TCHAR* A:{TEXT("/Engine/BasicShapes/Cylinder.Cylinder"),TEXT("/Engine/BasicShapes/Sphere.Sphere"),TEXT("/Engine/BasicShapes/Sphere.Sphere")}) | |
| { | |
| UStaticMeshComponent* C=NewObject<UStaticMeshComponent>(P);P->AddInstanceComponent(C);C->SetupAttachment(P->GetRootComponent()); | |
| C->SetStaticMesh(LoadObject<UStaticMesh>(nullptr,A));C->SetMobility(EComponentMobility::Movable);C->SetMaterial(0,WhiteMaterialRef); | |
| C->SetCollisionEnabled(ECollisionEnabled::NoCollision);C->SetGenerateOverlapEvents(false);C->SetCastShadow(false); | |
| C->SetAffectDistanceFieldLighting(false);C->SetAffectDynamicIndirectLighting(false);C->SetVisibleInRayTracing(false);C->SetVisibleInSceneCaptureOnly(true); | |
| C->ComponentTags.Add(TEXT("v9w"));C->RegisterComponent();P->Parts.Add(C);WhiteboxComponents.Add(C);Whitebox->ShowOnlyComponent(C);WP.Add(C); | |
| } | |
| } | |
| TArray<float>& Seg=V9WeaponSeg.FindOrAdd(P);Seg.Reset(); | |
| if(WP.Num()==3) | |
| { | |
| const bool Vis=W&&W->IsVisible()&&W->GetStaticMesh(); | |
| for(UStaticMeshComponent* X:WP)X->SetVisibility(Vis); | |
| if(Vis) | |
| { | |
| const FBox B=W->GetStaticMesh()->GetBoundingBox();const FVector E=B.GetExtent()*W->GetComponentScale().GetAbs();const FVector Ctr=B.GetCenter(); | |
| const int32 Ax=E.X>=E.Y&&E.X>=E.Z?0:(E.Y>=E.Z?1:2); | |
| FVector Dir=FVector::ZeroVector;Dir[Ax]=B.GetExtent()[Ax]; | |
| const FTransform T=W->GetComponentTransform(); | |
| const FVector A=T.TransformPosition(Ctr-Dir),Bp=T.TransformPosition(Ctr+Dir); | |
| const float Len=FVector::Dist(A,Bp); | |
| const float O1=E[(Ax+1)%3],O2=E[(Ax+2)%3]; | |
| const float Rad=FMath::Clamp(.5f*FMath::Sqrt(O1*O2),2.5f,FMath::Max(3.f,.08f*Len)); | |
| const FVector D=Bp-A; | |
| WP[0]->SetWorldLocationAndRotation((A+Bp)*.5f,FQuat::FindBetweenNormals(FVector::UpVector,D.GetSafeNormal())); | |
| WP[0]->SetWorldScale3D(FVector(Rad/50.f,Rad/50.f,FMath::Max(.001f,Len/100.f))); | |
| WP[1]->SetWorldLocation(A);WP[2]->SetWorldLocation(Bp);WP[1]->SetWorldScale3D(FVector(Rad/50.f));WP[2]->SetWorldScale3D(FVector(Rad/50.f)); | |
| Seg={(float)A.X,(float)A.Y,(float)A.Z,(float)Bp.X,(float)Bp.Y,(float)Bp.Z,Rad}; | |
| } | |
| } | |
| for(UStaticMeshComponent* X:P->Parts)if(X&&(!X->bRenderCustomDepth||X->CustomDepthStencilValue!=Id)){X->SetRenderCustomDepth(true);X->SetCustomDepthStencilValue(Id);} | |
| } | |
| } | |
| void APipelineCapture::V9LabelHide(USceneCaptureComponent2D* C) | |
| { | |
| TSet<UPrimitiveComponent*> Proxy; | |
| for(APipelineWhitebox* P:WhiteboxCharacters)if(P)for(UStaticMeshComponent* X:P->Parts)Proxy.Add(X); | |
| for(UPrimitiveComponent* P:WhiteboxComponents)if(!Proxy.Contains(P))C->HideComponent(P); | |
| for(TActorIterator<AGameDemoFighter> I(GetWorld());I;++I){TArray<UPrimitiveComponent*> Cs;I->GetComponents(Cs);for(UPrimitiveComponent* X:Cs)C->HideComponent(X);} | |
| for(UStaticMeshComponent* W:{V8WeaponP.Get(),V8WeaponB.Get()})if(W)C->HideComponent(W); | |
| } | |
| bool APipelineCapture::V9UseCapsules() const {return V9&&V9CapLabels&&WhiteboxCharacters.Num()>0;} | |
| void APipelineCapture::V9WriteFrame(TSharedPtr<FJsonObject> J) | |
| { | |
| TSharedPtr<FJsonObject> O=MakeShared<FJsonObject>(); | |
| O->SetNumberField(TEXT("look"),V9Cur.Index);O->SetStringField(TEXT("look_name"),V9Cur.Name); | |
| O->SetBoolField(TEXT("capsule_labels"),V9UseCapsules()); | |
| O->SetArrayField(TEXT("frame_offset_cm"),{V9Num(V9Offset.X),V9Num(V9Offset.Y),V9Num(V9Offset.Z)}); | |
| TArray<TSharedPtr<FJsonValue>> Caps; | |
| for(APipelineWhitebox* P:WhiteboxCharacters) | |
| { | |
| if(!P||!P->Fighter)continue; | |
| TSharedPtr<FJsonObject> C=MakeShared<FJsonObject>(); | |
| C->SetStringField(TEXT("role"),P->Fighter->IsBoss?TEXT("boss"):TEXT("player"));C->SetNumberField(TEXT("class_id"),P->Fighter->IsBoss?11:10); | |
| TArray<TSharedPtr<FJsonValue>> Ls; | |
| static const TCHAR* LimbNames[11]={TEXT("pelvis_spine"),TEXT("spine_neck"),TEXT("head"),TEXT("l_upperarm"),TEXT("l_forearm"),TEXT("r_upperarm"),TEXT("r_forearm"),TEXT("l_thigh"),TEXT("l_calf"),TEXT("r_thigh"),TEXT("r_calf")}; | |
| for(int32 K=0;K<P->Limbs.Num();K++) | |
| { | |
| const FWhiteboxLimb& L=P->Limbs[K]; | |
| TSharedPtr<FJsonObject> E=MakeShared<FJsonObject>();E->SetStringField(TEXT("name"),K<11?LimbNames[K]:TEXT("limb")); | |
| E->SetArrayField(TEXT("a"),{V9Num(L.A.X),V9Num(L.A.Y),V9Num(L.A.Z)});E->SetArrayField(TEXT("b"),{V9Num(L.B.X),V9Num(L.B.Y),V9Num(L.B.Z)});E->SetNumberField(TEXT("r"),L.Radius); | |
| Ls.Add(MakeShared<FJsonValueObject>(E)); | |
| } | |
| if(const TArray<float>* S=V9WeaponSeg.Find(P))if(S->Num()==7) | |
| { | |
| TSharedPtr<FJsonObject> E=MakeShared<FJsonObject>();E->SetStringField(TEXT("name"),TEXT("weapon")); | |
| E->SetArrayField(TEXT("a"),{V9Num((*S)[0]),V9Num((*S)[1]),V9Num((*S)[2])});E->SetArrayField(TEXT("b"),{V9Num((*S)[3]),V9Num((*S)[4]),V9Num((*S)[5])});E->SetNumberField(TEXT("r"),(*S)[6]); | |
| Ls.Add(MakeShared<FJsonValueObject>(E)); | |
| } | |
| C->SetArrayField(TEXT("capsules"),Ls);Caps.Add(MakeShared<FJsonValueObject>(C)); | |
| } | |
| O->SetArrayField(TEXT("characters"),Caps); | |
| J->SetObjectField(TEXT("v9"),O); | |
| } | |
| void APipelineCapture::WriteV9Result(TSharedPtr<FJsonObject> Result) | |
| { | |
| if(!V9)return; | |
| TSharedPtr<FJsonObject> O=MakeShared<FJsonObject>(); | |
| O->SetBoolField(TEXT("capsule_labels"),V9CapLabels);O->SetBoolField(TEXT("framing"),V9Frame); | |
| O->SetArrayField(TEXT("ortho_width_range_cm"),{V9Num(V9WMin),V9Num(V9WMax)});O->SetNumberField(TEXT("wide_share"),V9WideP); | |
| O->SetArrayField(TEXT("wide_width_range_cm"),{V9Num(V9WideMin),V9Num(V9WideMax)});O->SetArrayField(TEXT("pitch_range_deg"),{V9Num(V9PitchMin),V9Num(V9PitchMax)}); | |
| O->SetNumberField(TEXT("looks"),V9LookCount);O->SetNumberField(TEXT("cut_grid"),V9CutGrid);O->SetNumberField(TEXT("cut_phase"),V9CutPhase);O->SetNumberField(TEXT("resets_deferred_blocks"),V9CutsDeferred); | |
| O->SetStringField(TEXT("clip_rule"),FString::Printf(TEXT("81-frame clips start at multiples of %d; cuts only between frame %d+%d*k and the next"),V9CutGrid,V9CutPhase,V9CutGrid));O->SetNumberField(TEXT("material_swapped_components"),V9MatSwaps); | |
| O->SetNumberField(TEXT("texture_pool"),V9TexPool.Num());O->SetNumberField(TEXT("texture_pool_photo"),V9NumPhoto);O->SetNumberField(TEXT("shuffle_pool"),V9MatPool.Num()); | |
| TSharedPtr<FJsonObject> H=MakeShared<FJsonObject>();for(const auto& P:V9ModeHist)H->SetNumberField(P.Key,P.Value);O->SetObjectField(TEXT("style_histogram"),H); | |
| O->SetArrayField(TEXT("look_log"),V9LookLog); | |
| WriteV10Real(O); | |
| Result->SetObjectField(TEXT("v9"),O); | |
| } | |