File size: 20,884 Bytes
1a23f33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// v10 photoreal pass (on top of v9; -DatasetV10Photo): every camera-variant look is "photoreal": the scene's opaque materials
// are replaced per (material, semantic class) by M_V10PBR with CC0 photo-scanned PBR sets (Poly Haven / ambientCG; top layer
// for horizontal faces, side layer for walls / cliffs, a noise-masked cover layer of moss / dust / snow on upward faces),
// a cinematic light preset (golden hour, morning mist, overcast, harsh noon, backlit, dusk: sun angle / colour / intensity,
// sky light, height fog + volumetric fog) and a film grade (split toning, grain, vignette, bloom). RGB only: labels, depth
// and whitebox are unchanged; the v9 cut grid, centred camera and capsule labels apply as before.
#include "PipelineCapture.h"
#include "GameDemo.h"
#include "Components/SceneCaptureComponent2D.h"
#include "Components/DirectionalLightComponent.h"
#include "Components/SkyLightComponent.h"
#include "Components/ExponentialHeightFogComponent.h"
#include "Components/MeshComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Engine/Texture.h"
#include "Materials/MaterialInterface.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "EngineUtils.h"
#include "Misc/FileHelper.h"
#include "HAL/IConsoleManager.h"
#include "Misc/Paths.h"
#include "Dom/JsonObject.h"
#include "Serialization/JsonReader.h"
#include "Serialization/JsonSerializer.h"

namespace
{
struct FV10Set{FString Key,Role,Words,C,N,R;};
TArray<FV10Set> GV10Sets;
const TCHAR* V10LightNames[8]={TEXT("golden"),TEXT("mist"),TEXT("overcast"),TEXT("noon"),TEXT("backlit"),TEXT("dusk"),TEXT("night"),TEXT("storm")};
const TCHAR* V10Biomes[7]={TEXT("forest"),TEXT("arid"),TEXT("snow"),TEXT("temperate"),TEXT("wet"),TEXT("meadow"),TEXT("coast")};
const TCHAR* V10BiomeWords[7]={TEXT("forest moss leaves mud bark soil grass fern root"),TEXT("sand desert dry gravel dirt sandstone red cracked"),
    TEXT("snow ice frozen frost"),TEXT(""),TEXT("mud wet puddle moss rain"),TEXT("grass meadow soil mud dirt aerial leaves"),TEXT("sand beach gravel pebble shore coast")};
int32 V10PickKey(const TCHAR* List,FRandomStream& R)
{
    TArray<FString> W;FString(List).ParseIntoArray(W,TEXT(" "));TArray<int32> Hit;
    for(int32 I=0;I<GV10Sets.Num();I++)for(const FString& X:W)if(GV10Sets[I].Key==X){Hit.Add(I);break;}
    return Hit.Num()?Hit[R.RandRange(0,Hit.Num()-1)]:-1;
}
}

bool APipelineCapture::V10LoadSets()
{
    if(V10Loaded)return GV10Sets.Num()>0;V10Loaded=true;
    V10Mat=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V10/Materials/M_V10PBR.M_V10PBR"));
    FString S;if(!FFileHelper::LoadFileToString(S,*(FPaths::ProjectContentDir()/TEXT("Xfer/V10/v10_pbr.json"))))return false;
    TSharedPtr<FJsonObject> O;const TSharedRef<TJsonReader<>> Rd=TJsonReaderFactory<>::Create(S);
    if(!FJsonSerializer::Deserialize(Rd,O)||!O.IsValid())return false;
    const TArray<TSharedPtr<FJsonValue>>* A;
    if(O->TryGetArrayField(TEXT("sets"),A))for(const auto& V:*A)
    {
        const TSharedPtr<FJsonObject> T=V->AsObject();if(!T)continue;
        FV10Set X;X.Key=T->GetStringField(TEXT("key"));X.Role=T->GetStringField(TEXT("role"));X.C=T->GetStringField(TEXT("color"));X.N=T->GetStringField(TEXT("normal"));X.R=T->GetStringField(TEXT("rough"));
        FString W=X.Key;const TArray<TSharedPtr<FJsonValue>>* L;
        for(const TCHAR* F:{TEXT("categories"),TEXT("tags")})if(T->TryGetArrayField(F,L))for(const auto& Q:*L)W+=TEXT(" ")+Q->AsString();
        X.Words=W.ToLower();GV10Sets.Add(X);
    }
    UE_LOG(LogTemp,Display,TEXT("DATASET_V10 photoreal: material=%d pbr sets=%d"),V10Mat!=nullptr,GV10Sets.Num());
    return GV10Sets.Num()>0;
}

int32 APipelineCapture::V10Pick(const TCHAR* WantRole,const TCHAR* Fallback)
{
    const FString Bw=V10BiomeWords[FMath::Clamp(V10Biome,0,6)];TArray<FString> Words;Bw.ParseIntoArray(Words,TEXT(" "));
    TArray<int32> All,Match;
    for(int32 Pass=0;Pass<2&&All.Num()==0;Pass++)
        for(int32 I=0;I<GV10Sets.Num();I++)if(GV10Sets[I].Role==(Pass==0?WantRole:Fallback))
        {
            All.Add(I);for(const FString& W:Words)if(GV10Sets[I].Words.Contains(W)){Match.Add(I);break;}
        }
    if(All.Num()==0)return GV10Sets.Num()?V9Rng.RandRange(0,GV10Sets.Num()-1):-1;
    const TArray<int32>& From=(Match.Num()&&V9Rng.FRand()<.75f)?Match:All;
    return From[V9Rng.RandRange(0,From.Num()-1)];
}

UTexture* APipelineCapture::V10Tex(const FString& Path)
{
    if(UTexture** T=V10TexCache.Find(Path))return *T;
    UTexture* T=LoadObject<UTexture>(nullptr,*Path);V10TexCache.Add(Path,T);if(T)V10Keep.Add(T);return T;
}

void APipelineCapture::V10ApplyPBR()
{
    if(!V10LoadSets()||!V10Mat){UE_LOG(LogTemp,Warning,TEXT("DATASET_V10 PBR sets / material missing, keeping originals"));return;}
    auto R=[&](float A,float B){return V9Rng.FRandRange(A,B);};
    int32 G=V10Pick(TEXT("ground"),TEXT("rock")),P=V10Pick(TEXT("paving"),TEXT("ground")),Rf=V10Pick(TEXT("roof"),TEXT("wall")),K=V10Pick(TEXT("rock"),TEXT("ground"));
    int32 Cv=V10Pick(V10Biome==2?TEXT("top"):(V9Rng.FRand()<.6f?TEXT("top"):TEXT("ground")),TEXT("ground")),Mt=V10Pick(TEXT("metal"),TEXT("wood"));
    const int32 W[3]={V10Pick(TEXT("wall"),TEXT("wood")),V10Pick(TEXT("wood"),TEXT("wall")),V10Pick(TEXT("wall"),TEXT("rock"))};
    float CovBase=V10Biome==2?R(.45f,.8f):R(.1f,.5f);
    if(V10Real)   // v10 real v2: the ground / slope / cover sets of the look's biome variant
    {
        const int32 G2=V10PickKey(*V10VarGround,V9Rng),K2=V10PickKey(*V10VarSide,V9Rng),C2=V10PickKey(*V10VarCover,V9Rng);
        if(G2>=0)G=G2;if(K2>=0)K=K2;if(C2>=0)Cv=C2;CovBase=R(V10VarGCov0,V10VarGCov1);
    }
    V10Theme=FString::Printf(TEXT("ground=%s paving=%s roof=%s rock=%s cover=%s walls=%s,%s,%s"),G>=0?*GV10Sets[G].Key:TEXT("-"),P>=0?*GV10Sets[P].Key:TEXT("-"),
        Rf>=0?*GV10Sets[Rf].Key:TEXT("-"),K>=0?*GV10Sets[K].Key:TEXT("-"),Cv>=0?*GV10Sets[Cv].Key:TEXT("-"),W[0]>=0?*GV10Sets[W[0]].Key:TEXT("-"),W[1]>=0?*GV10Sets[W[1]].Key:TEXT("-"),W[2]>=0?*GV10Sets[W[2]].Key:TEXT("-"));
    auto Make=[&](int32 Top,int32 Side,float CovAmt,float TopTile,float SideTile)->UMaterialInterface*
    {
        if(Top<0||Side<0)return nullptr;
        UMaterialInstanceDynamic* D=UMaterialInstanceDynamic::Create(V10Mat,this);
        const FV10Set& T=GV10Sets[Top];const FV10Set& S=GV10Sets[Side];const FV10Set& C=GV10Sets[Cv>=0?Cv:Top];
        D->SetTextureParameterValue(TEXT("TC"),V10Tex(T.C));D->SetTextureParameterValue(TEXT("TN"),V10Tex(T.N));D->SetTextureParameterValue(TEXT("TR"),V10Tex(T.R));
        D->SetTextureParameterValue(TEXT("SC"),V10Tex(S.C));D->SetTextureParameterValue(TEXT("SN"),V10Tex(S.N));D->SetTextureParameterValue(TEXT("SR"),V10Tex(S.R));
        D->SetTextureParameterValue(TEXT("CC"),V10Tex(C.C));D->SetTextureParameterValue(TEXT("CN"),V10Tex(C.N));D->SetTextureParameterValue(TEXT("CR"),V10Tex(C.R));
        D->SetScalarParameterValue(TEXT("TopTile"),TopTile);D->SetScalarParameterValue(TEXT("SideTile"),SideTile);D->SetScalarParameterValue(TEXT("CovTile"),R(300.f,520.f));
        D->SetScalarParameterValue(TEXT("CovAmt"),FMath::Clamp(CovAmt,0.f,.95f));D->SetScalarParameterValue(TEXT("RMul"),R(.85f,1.15f)*(V10Real?FMath::Lerp(1.f,.62f,V10VarWet):1.f));D->SetScalarParameterValue(TEXT("NStr"),1.f);
        const FLinearColor Warm(1.f,.9f,.78f),Cool(.85f,.92f,1.f);
        D->SetVectorParameterValue(TEXT("Tint"),FLinearColor::LerpUsingHSV(FLinearColor::White,V9Rng.FRand()<(V10Real?.8f:.5f)?Warm:Cool,R(0.f,V10Real?.25f:.35f))*R(.85f,1.08f)*(V10Real?1.f-.25f*V10VarWet:1.f));
        V9MIDs.Add(D);return D;
    };
    TMap<TPair<UMaterialInterface*,int32>,UMaterialInterface*> Map;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)
        {
            const int32 Id=C->CustomDepthStencilValue;
            if(!C->bRenderCustomDepth||Id<1||Id>4||Id==3||C->ComponentHasTag(TEXT("v8fx"))||C->ComponentHasTag(TEXT("v10_scatter")))continue;   // v10 real: scanned assets keep their own materials   // v10b: only terrain / paving / rocks get PBR; buildings, props and (masked) vegetation keep their authored materials
            TArray<UMaterialInterface*> Old;bool Any=false;
            for(int32 S=0;S<C->GetNumMaterials();S++)
            {
                UMaterialInterface* M=C->GetMaterial(S);Old.Add(M);
                if(!M||M->GetBlendMode()!=BLEND_Opaque)continue;
                const TPair<UMaterialInterface*,int32> Key(M,Id);UMaterialInterface** Got=Map.Find(Key);
                if(!Got)
                {
                    UMaterialInterface* N=nullptr;
                    if(V9Rng.FRand()>=V9Cur.Keep)switch(Id)
                    {
                    case 1: N=Make(G,K,CovBase+R(-.1f,.15f),V10Real?R(220.f,380.f):R(250.f,450.f),R(300.f,520.f));break;
                    case 2: N=Make(V9Rng.FRand()<.7f?P:G,V9Rng.FRand()<.5f?K:W[0],CovBase*R(0.f,.6f),R(150.f,320.f),R(200.f,320.f));break;
                    case 3: N=Make(Rf,W[V9Rng.RandRange(0,2)],CovBase*R(0.f,.5f),R(180.f,300.f),R(180.f,320.f));break;
                    case 4: N=Make(K,K,CovBase+R(0.f,.25f),R(250.f,500.f),R(250.f,500.f));break;
                    default: N=Make(W[1],V9Rng.FRand()<.5f?Mt:W[1],CovBase*R(0.f,.3f),R(120.f,220.f),R(120.f,220.f));break;
                    }
                    Got=&Map.Add(Key,N?N:M);
                }
                if(*Got!=M){if(!Any){V9Orig.Add(TPair<TWeakObjectPtr<UMeshComponent>,TArray<UMaterialInterface*>>(C,TArray<UMaterialInterface*>()));Any=true;}C->SetMaterial(S,*Got);}
            }
            if(Any){V9Orig.Last().Value=Old;Comps++;}
        }
    }
    V9MatSwaps+=Comps;
    UE_LOG(LogTemp,Display,TEXT("DATASET_V10 pbr (%s): %d material/class pairs -> %d components | %s"),V10Biomes[FMath::Clamp(V10Biome,0,6)],Map.Num(),Comps,*V10Theme);
}

void APipelineCapture::V10PhotoLook(FV9Look& L)
{
    auto R=[&](float A,float B){return V9Rng.FRandRange(A,B);};
    L.Mode=0;L.Tier=0;L.Mip=0;L.Outline=V9Rng.FRand()<.5f;L.Mat=V9Rng.FRand()<.5f?5:0;L.Keep=V9Rng.FRand()<.3f?R(.05f,.2f):0.f;
    V10Biome=V9Rng.RandRange(0,4);
    if(V10Real){L.Mat=5;L.Keep=0;L.Outline=false;V10Biome=0;V10RealNewVariant(L);}   // v10 real v2: a new biome variant (and re-scatter) per look
    else L.Biome=V10Biomes[V10Biome];
    if(!V10LightInit)
    {
        V10LightInit=true;
        for(TActorIterator<AActor> I(GetWorld());I;++I)
        {
            TArray<UActorComponent*> Comps;I->GetComponents(Comps);
            for(UActorComponent* C:Comps)
            {
                if(auto* D=Cast<UDirectionalLightComponent>(C)){if(!V10Sun.IsValid()||D->Intensity>V10Sun->Intensity)V10Sun=D;}
                else if(auto* S=Cast<USkyLightComponent>(C))V10Sky=S;
                else if(auto* F=Cast<UExponentialHeightFogComponent>(C))V10Fog=F;
            }
        }
        if(V10Sun.IsValid()){V10SunI0=V10Sun->Intensity;V10SunR0=V10Sun->GetComponentRotation();V10Sun->SetMobility(EComponentMobility::Movable);}
        if(V10Sky.IsValid())V10SkyI0=V10Sky->Intensity;
        // v10 real: the host scenes' stylised lights range from 0.12 to 5.2 lux sun and 0.85x to 8x ambient (all the same engine
        // daylight cubemap); photo looks use one absolute rig (scene 07's levels, on which the presets were calibrated)
        if(V10Fog.IsValid())V10FogD0=FMath::Max(V10Fog->FogDensity,.004f);
        if(V10Real){V10SunI0=1.f;V10SkyI0=3.4f;V10FogD0=.004f;if(V10Fog.IsValid())V10Fog->SetFogHeightFalloff(.2f);}   // fog too: 08 / 10 had .018 / .025 with a high falloff (a milky column under the camera)
    }
    const float W=V9Rng.FRand();int32 P=W<.24f?0:W<.40f?1:W<.58f?2:W<.72f?3:W<.86f?4:5;
    if(V10Real&&!V10LightForced.IsEmpty()){for(int32 I=0;I<8;I++)if(V10LightForced==V10LightNames[I])P=I;}   // tests
    else if(V10Real&&!V10VarLights.IsEmpty())   // the light presets that suit the biome variant (incl. night / storm)
    {
        TArray<FString> Ls;V10VarLights.ParseIntoArray(Ls,TEXT(" "));const FString Pk=Ls[V9Rng.RandRange(0,Ls.Num()-1)];
        for(int32 I=0;I<8;I++)if(Pk==V10LightNames[I])P=I;
    }
    L.Light=P;L.LightName=V10LightNames[P];
    float Pitch=-30,Yaw=R(-180.f,180.f),SunMul=1,SkyMul=1,FogMul=1,VolExt=.6f,Scatter=1;FLinearColor SunC(1,1,1),FogC(.6f,.65f,.72f);
    // v10b: sun-and-shadow driven presets (fog only as light aerial haze: in the top-down orthographic view heavy fog just greys the
    // picture), exposure lifted to at least the baseline brightness
    switch(P)
    {
    case 0: Pitch=-R(12.f,22.f);SunMul=R(1.3f,1.8f);SunC=FLinearColor(1.f,R(.68f,.78f),R(.45f,.56f));SkyMul=R(.8f,1.f);FogMul=R(1.f,1.3f);FogC=FLinearColor(.9f,.7f,.5f);VolExt=.4f;Scatter=1.5f;
        L.Temp=R(6800.f,7500.f);L.Sat=R(1.02f,1.12f);L.Ev=R(.3f,.7f);break;
    case 1: Pitch=-R(18.f,30.f);SunMul=R(1.f,1.3f);SunC=FLinearColor(1.f,.9f,.78f);SkyMul=R(.95f,1.15f);FogMul=R(1.6f,2.4f);FogC=FLinearColor(.7f,.74f,.8f);VolExt=.6f;Scatter=2.f;
        L.Temp=6400.f;L.Sat=R(.9f,1.f);L.Ev=R(.4f,.7f);break;
    case 2: Pitch=-R(45.f,70.f);SunMul=R(.3f,.45f);SunC=FLinearColor(.94f,.96f,1.f);SkyMul=R(1.4f,1.8f);FogMul=R(1.f,1.3f);FogC=FLinearColor(.62f,.66f,.72f);VolExt=.4f;
        L.Temp=6500.f;L.Sat=R(.88f,.98f);L.Ev=R(.5f,.8f);break;
    case 3: Pitch=-R(50.f,70.f);SunMul=R(1.3f,1.6f);SunC=FLinearColor(1.f,.97f,.93f);SkyMul=R(.85f,1.f);FogMul=R(.7f,1.f);
        L.Temp=6000.f;L.Sat=R(.98f,1.08f);L.Ev=R(0.f,.3f);break;
    case 4: Pitch=-R(20.f,32.f);Yaw=(Player?Player->CameraBoom->GetComponentRotation().Yaw:0.f)+180.f+R(-35.f,35.f);SunMul=R(1.4f,1.8f);SunC=FLinearColor(1.f,.84f,.66f);
        SkyMul=R(.75f,.95f);FogMul=R(1.2f,1.6f);FogC=FLinearColor(.88f,.74f,.58f);VolExt=.5f;Scatter=2.5f;L.Temp=7000.f;L.Sat=R(1.f,1.08f);L.Ev=R(.4f,.7f);break;
    case 5: Pitch=-R(6.f,12.f);SunMul=R(.5f,.7f);SunC=FLinearColor(.95f,.68f,.62f);SkyMul=R(.6f,.75f);FogMul=R(1.1f,1.5f);FogC=FLinearColor(.45f,.48f,.62f);VolExt=.5f;
        L.Temp=5600.f;L.Sat=.95f;L.Ev=R(.8f,1.2f);break;
    case 6: // v10 real v2: moonlit night (cold, low sun = moon, dark sky; exposure kept low so it stays a night picture)
        Pitch=-R(35.f,65.f);SunMul=R(.08f,.14f);SunC=FLinearColor(.55f,.66f,1.f);SkyMul=R(.25f,.4f);FogMul=R(.8f,1.2f);FogC=FLinearColor(.06f,.08f,.14f);VolExt=.5f;
        L.Temp=R(4300.f,5000.f);L.Sat=R(.6f,.75f);L.Ev=R(.2f,.9f);break;
    default: // v10 real v2: storm (dim flat light, heavy haze, desaturated)
        Pitch=-R(40.f,70.f);SunMul=R(.08f,.16f);SunC=FLinearColor(.85f,.9f,1.f);SkyMul=R(1.f,1.3f);FogMul=R(2.2f,3.2f);FogC=FLinearColor(.42f,.45f,.5f);VolExt=.6f;
        L.Temp=6200.f;L.Sat=R(.7f,.85f);L.Ev=R(.1f,.4f);break;
    }
    FLinearColor SkyC(1.f,1.f,1.f);
    if(V10Real)
    {   // v10 real: the host scenes are lit for a stylised look (1 lux bluish sun, 3.4x bluish ambient cubemap): flat, cyan-grey ground.
        // A photo needs the sun to dominate in sunny looks and a neutral ambient: sun up, sky down, sky tint neutralised
        const float SunBoost=P==0?3.f:P==3?3.5f:P==4?3.f:P==5?2.f:P==1?2.f:P==2?1.5f:1.f;
        const float SkyCut=P==6?1.f:P==7?.8f:P==2?.75f:.45f;
        SunMul*=SunBoost;SkyMul*=SkyCut;
        SkyC=P==0?FLinearColor(.93f,.96f,1.f):P==1?FLinearColor(1.f,.96f,.9f):P==2?FLinearColor(1.f,.95f,.88f):P==3?FLinearColor(1.f,.96f,.9f):
             P==4?FLinearColor(.95f,.97f,1.f):P==5?FLinearColor(1.f,.9f,.88f):P==6?FLinearColor(.75f,.85f,1.f):FLinearColor(.96f,.97f,1.f);   // golden / backlit: cool shadows vs the warm sun
    }
    if(UDirectionalLightComponent* S=V10Sun.Get())
    {
        S->SetWorldRotation(FRotator(Pitch,Yaw,0));S->SetIntensity(V10SunI0*SunMul);S->SetLightColor(SunC);S->SetVolumetricScatteringIntensity(Scatter);
        S->bCastVolumetricShadow=true;if(V10Real)S->SetLightSourceAngle(P==2?R(2.5f,4.f):R(.6f,1.6f));S->MarkRenderStateDirty();
    }
    if(USkyLightComponent* K=V10Sky.Get()){K->SetIntensity(V10SkyI0*SkyMul);if(V10Real)K->SetLightColor(SkyC);K->RecaptureSky();}
    if(UExponentialHeightFogComponent* F=V10Fog.Get())
    {
        F->SetFogDensity(V10FogD0*FogMul);F->SetFogInscatteringColor(FogC);F->SetVolumetricFog(true);
        F->SetVolumetricFogExtinctionScale(VolExt);F->SetVolumetricFogScatteringDistribution(.75f);F->SetVolumetricFogDistance(15000.f);
    }
    L.Con=R(1.04f,1.14f);L.Gam=1.f;L.Gain=FLinearColor::White;
    L.Grain=V10Real?R(.02f,.08f):R(.08f,.22f);L.Vig=R(.2f,.38f);L.Bloom=R(.4f,.75f);   // v10 real: lighter grain (it smeared the fine ground cover)
    if(V10Real&&P<6)
    {   // v10 real: without the distance-field / Lumen halos under the ground cover the frames came out over-exposed, cool and milky
        // (a warm leaf-litter ground rendered pale cyan-grey): less exposure, warmer white balance, a little more saturation, less bloom
        // (calibrated on scene 07 after the sun / sky rebalance above; all scenes now use the same absolute lights / exposure)
        L.Ev-=P==3?1.35f:P==2?1.35f:P==5?0.f:P==1?.2f:P==0?.3f:.55f;
        if(P!=0&&P!=4)L.Temp=FMath::Max(L.Temp,6500.f)+R(100.f,450.f);
        L.Sat=FMath::Min(L.Sat*R(1.04f,1.12f),1.15f);L.Con=R(1.08f,1.18f);L.Bloom=R(.2f,.4f);
    }
    const float Sp=R(0.f,.05f);L.ShTint=FLinearColor(1.f-Sp*.6f,1.f-Sp*.1f,1.f+Sp);L.HiTint=FLinearColor(1.f+Sp,1.f+Sp*.3f,1.f-Sp*.8f);
    L.SunPitch=Pitch;L.SunYaw=Yaw;
}

void APipelineCapture::V10BeforeRGB(USceneCaptureComponent2D* C)
{
    const FV9Look& L=V9Cur;auto& PP=C->PostProcessSettings;
    if(!V10EvInit){V10EvInit=true;V10Ev0=PP.bOverride_AutoExposureBias?PP.AutoExposureBias:0.f;if(V10Real)V10Ev0=1.6f;}   // v10 real: absolute (scene 07: volume 1.0 + art pass .6)
    PP.bOverride_AutoExposureBias=true;PP.AutoExposureBias=V10Ev0+L.Ev;
    PP.bOverride_FilmGrainIntensity=true;PP.FilmGrainIntensity=L.Grain;
    PP.bOverride_VignetteIntensity=true;PP.VignetteIntensity=L.Vig;
    PP.bOverride_BloomIntensity=true;PP.BloomIntensity=L.Bloom;
    PP.bOverride_SceneFringeIntensity=true;PP.SceneFringeIntensity=.15f;
    PP.bOverride_ColorGainShadows=true;PP.ColorGainShadows=FVector4(L.ShTint.R,L.ShTint.G,L.ShTint.B,1.f);
    PP.bOverride_ColorGainHighlights=true;PP.ColorGainHighlights=FVector4(L.HiTint.R,L.HiTint.G,L.HiTint.B,1.f);
    // v10b render quality: higher Lumen gather / scene / reflection quality, stronger AO, contact shadows, a little more sharpening
    PP.bOverride_LumenFinalGatherQuality=true;PP.LumenFinalGatherQuality=4.f;PP.bOverride_LumenSceneLightingQuality=true;PP.LumenSceneLightingQuality=4.f;
    PP.bOverride_LumenSceneDetail=true;PP.LumenSceneDetail=4.f;PP.bOverride_LumenReflectionQuality=true;PP.LumenReflectionQuality=4.f;
    PP.bOverride_AmbientOcclusionIntensity=true;PP.AmbientOcclusionIntensity=.65f;PP.bOverride_AmbientOcclusionRadius=true;PP.AmbientOcclusionRadius=180.f;
    if(V10Real)   // the art pass (v7) flattened local contrast for the stylised scenes; a photo keeps it
    {
        PP.bOverride_LocalExposureHighlightContrastScale=true;PP.LocalExposureHighlightContrastScale=1.f;
        PP.bOverride_LocalExposureShadowContrastScale=true;PP.LocalExposureShadowContrastScale=.92f;
    }
    if(V10Real&&V10AOFix)   // v10 real: dense scanned grass / shrubs went black under the 1.8 m SSAO + Lumen short-range AO; keep a little contact AO only
    {
        PP.AmbientOcclusionIntensity=.25f;PP.AmbientOcclusionRadius=50.f;
        PP.bOverride_LumenAmbientOcclusionIntensity=true;PP.LumenAmbientOcclusionIntensity=.35f;
    }
    if(!V10QualityInit)
    {
        V10QualityInit=true;
        for(const TPair<const TCHAR*,float>& Q:{TPair<const TCHAR*,float>(TEXT("r.Tonemapper.Sharpen"),.7f),TPair<const TCHAR*,float>(TEXT("r.ContactShadows"),1.f),
            TPair<const TCHAR*,float>(TEXT("r.Lumen.ScreenProbeGather.ScreenSpaceBentNormal"),V10Real&&V10AOFix?0.f:1.f),TPair<const TCHAR*,float>(TEXT("r.Shadow.Virtual.ResolutionLodBiasDirectional"),-1.5f)})
            if(IConsoleVariable* V=IConsoleManager::Get().FindConsoleVariable(Q.Key))V->Set(Q.Value,ECVF_SetByCode);
        if(UDirectionalLightComponent* S=V10Sun.Get()){S->ContactShadowLength=.06f;S->MarkRenderStateDirty();}
    }
}

void APipelineCapture::V10LookJson(TSharedPtr<FJsonObject> J)
{
    const FV9Look& L=V9Cur;
    V10RealLookJson(J);
    J->SetStringField(TEXT("light"),L.LightName);J->SetStringField(TEXT("biome"),L.Biome);J->SetStringField(TEXT("pbr_theme"),L.Mat==5?V10Theme:FString());
    J->SetArrayField(TEXT("sun_pitch_yaw"),{MakeShared<FJsonValueNumber>(L.SunPitch),MakeShared<FJsonValueNumber>(L.SunYaw)});
    J->SetArrayField(TEXT("grain_vignette_bloom_ev"),{MakeShared<FJsonValueNumber>(L.Grain),MakeShared<FJsonValueNumber>(L.Vig),MakeShared<FJsonValueNumber>(L.Bloom),MakeShared<FJsonValueNumber>(L.Ev)});
}