Skip to content
Navigation Menu
{{ message }}
forked from fuxihao66/ExtraNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostProcessVisualizeBuffer.cpp
More file actions
652 lines (513 loc) · 25.3 KB
/
Copy pathPostProcessVisualizeBuffer.cpp
File metadata and controls
652 lines (513 loc) · 25.3 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
// Copyright Epic Games, Inc. All Rights Reserved.
#include "PostProcess/PostProcessVisualizeBuffer.h"
#include "PostProcess/PostProcessDLSS.h"
#include "PostProcess/MotionVectorAndUsedCount.h"
#include "HighResScreenshot.h"
#include "PostProcessMaterial.h"
#include "PostProcessDownsample.h"
#include "ImagePixelData.h"
#include "ImageWriteStream.h"
#include "ImageWriteTask.h"
#include "ImageWriteQueue.h"
#include "HighResScreenshot.h"
#include "BufferVisualizationData.h"
#include<string>
class FVisualizeBufferPS : public FGlobalShader
{
public:
DECLARE_GLOBAL_SHADER(FVisualizeBufferPS);
SHADER_USE_PARAMETER_STRUCT(FVisualizeBufferPS, FGlobalShader);
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
SHADER_PARAMETER_STRUCT(FScreenPassTextureViewportParameters, Output)
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, InputTexture)
SHADER_PARAMETER_SAMPLER(SamplerState, InputSampler)
SHADER_PARAMETER(FLinearColor, SelectionColor)
RENDER_TARGET_BINDING_SLOTS()
END_SHADER_PARAMETER_STRUCT()
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
{
return IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::ES3_1);
}
};
IMPLEMENT_GLOBAL_SHADER(FVisualizeBufferPS, "/Engine/Private/PostProcessVisualizeBuffer.usf", "MainPS", SF_Pixel);
struct FVisualizeBufferTile
{
// The input texture to visualize.
FScreenPassTexture Input;
// The label of the tile shown on the visualizer.
FString Label;
// Whether the tile is shown as selected.
bool bSelected = false;
};
struct FVisualizeBufferInputs
{
FScreenPassRenderTarget OverrideOutput;
// The scene color input to propagate.
FScreenPassTexture SceneColor;
// The array of tiles to render onto the scene color texture.
TArrayView<const FVisualizeBufferTile> Tiles;
};
FScreenPassTexture AddVisualizeBufferPass(FRDGBuilder& GraphBuilder, const FViewInfo& View, const FVisualizeBufferInputs& Inputs)
{
check(Inputs.SceneColor.IsValid());
FScreenPassRenderTarget Output = Inputs.OverrideOutput;
RDG_EVENT_SCOPE(GraphBuilder, "VisualizeBuffer");
// Re-use the scene color as the output if no override was provided.
if (Output.IsValid())
{
AddDrawTexturePass(GraphBuilder, View, Inputs.SceneColor, Output);
// All remaining passes are load.
Output.LoadAction = ERenderTargetLoadAction::ELoad;
}
// Otherwise, reuse the scene color as the output.
else
{
Output = FScreenPassRenderTarget(Inputs.SceneColor, ERenderTargetLoadAction::ELoad);
}
struct FTileLabel
{
FString Label;
FIntPoint Location;
};
TArray<FTileLabel> TileLabels;
TileLabels.Reserve(Inputs.Tiles.Num());
const int32 MaxTilesX = 4;
const int32 MaxTilesY = 4;
const int32 TileWidth = Output.ViewRect.Width() / MaxTilesX;
const int32 TileHeight = Output.ViewRect.Height() / MaxTilesY;
FRHISamplerState* BilinearClampSampler = TStaticSamplerState<SF_Bilinear, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI();
for (int32 TileIndex = 0; TileIndex < Inputs.Tiles.Num(); ++TileIndex)
{
const FVisualizeBufferTile& Tile = Inputs.Tiles[TileIndex];
// The list can contain invalid entries to keep the indices static.
if (!Tile.Input.IsValid())
{
continue;
}
const int32 TileX = TileIndex % MaxTilesX;
const int32 TileY = TileIndex / MaxTilesX;
FScreenPassTextureViewport OutputViewport(Output);
OutputViewport.Rect.Min = FIntPoint(TileX * TileWidth, TileY * TileHeight);
OutputViewport.Rect.Max = OutputViewport.Rect.Min + FIntPoint(TileWidth, TileHeight);
const FLinearColor SelectionColor = Tile.bSelected ? FLinearColor::Yellow : FLinearColor::Transparent;
FVisualizeBufferPS::FParameters* PassParameters = GraphBuilder.AllocParameters<FVisualizeBufferPS::FParameters>();
PassParameters->Output = GetScreenPassTextureViewportParameters(OutputViewport);
PassParameters->RenderTargets[0] = Output.GetRenderTargetBinding();
PassParameters->InputTexture = Tile.Input.Texture;
PassParameters->InputSampler = BilinearClampSampler;
PassParameters->SelectionColor = SelectionColor;
TShaderMapRef<FScreenPassVS> VertexShader(View.ShaderMap);
TShaderMapRef<FVisualizeBufferPS> PixelShader(View.ShaderMap);
FRHIBlendState* BlendState = TStaticBlendState<CW_RGB, BO_Add, BF_SourceAlpha, BF_InverseSourceAlpha>::GetRHI();
AddDrawScreenPass(
GraphBuilder,
RDG_EVENT_NAME("Tile: %s", *Tile.Label),
View,
OutputViewport,
FScreenPassTextureViewport(Tile.Input),
FScreenPassPipelineState(VertexShader, PixelShader, BlendState),
EScreenPassDrawFlags::None,
PassParameters,
[PixelShader, PassParameters](FRHICommandList& RHICmdList)
{
SetShaderParameters(RHICmdList, PixelShader, PixelShader.GetPixelShader(), *PassParameters);
});
FTileLabel TileLabel;
TileLabel.Label = Tile.Label;
TileLabel.Location.X = 8 + TileX * TileWidth;
TileLabel.Location.Y = (TileY + 1) * TileHeight - 19;
TileLabels.Add(TileLabel);
}
AddDrawCanvasPass(GraphBuilder, RDG_EVENT_NAME("Labels"), View, Output, [LocalTileLabels = MoveTemp(TileLabels)](FCanvas& Canvas)
{
const FLinearColor LabelColor(1, 1, 0);
for (const FTileLabel& TileLabel : LocalTileLabels)
{
Canvas.DrawShadowedString(TileLabel.Location.X, TileLabel.Location.Y, *TileLabel.Label, GetStatsFont(), LabelColor);
}
});
return MoveTemp(Output);
}
bool IsVisualizeGBufferOverviewEnabled(const FViewInfo& View)
{
return View.Family->EngineShowFlags.VisualizeBuffer && View.CurrentBufferVisualizationMode == NAME_None;
}
bool IsVisualizeGBufferDumpToFileEnabled(const FViewInfo& View)
{
static const auto CVarDumpFrames = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.BufferVisualizationDumpFrames"));
const bool bDumpHighResolutionScreenshot = GIsHighResScreenshot && GetHighResScreenshotConfig().bDumpBufferVisualizationTargets;
const bool bFrameDumpAllowed = CVarDumpFrames->GetValueOnRenderThread() != 0 || bDumpHighResolutionScreenshot;
const bool bFrameDumpRequested = View.FinalPostProcessSettings.bBufferVisualizationDumpRequired;
return (bFrameDumpRequested && bFrameDumpAllowed);
}
bool IsVisualizeGBufferDumpToPipeEnabled(const FViewInfo& View)
{
return View.FinalPostProcessSettings.BufferVisualizationPipes.Num() > 0;
}
TUniquePtr<FImagePixelData> ReadbackPixelData(FRHICommandListImmediate& RHICmdList, FRHITexture* Texture, FIntRect SourceRect)
{
check(Texture);
check(Texture->GetTexture2D());
const int32 MSAAXSamples = Texture->GetNumSamples();
SourceRect.Min.X *= MSAAXSamples;
SourceRect.Max.X *= MSAAXSamples;
switch (Texture->GetFormat())
{
case PF_FloatRGBA:
{
TArray<FFloat16Color> RawPixels;
RawPixels.SetNum(SourceRect.Width() * SourceRect.Height());
RHICmdList.ReadSurfaceFloatData(Texture, SourceRect, RawPixels, (ECubeFace)0, 0, 0);
TUniquePtr<TImagePixelData<FFloat16Color>> PixelData = MakeUnique<TImagePixelData<FFloat16Color>>(SourceRect.Size(), TArray64<FFloat16Color>(MoveTemp(RawPixels)));
check(PixelData->IsDataWellFormed());
return PixelData;
}
case PF_A32B32G32R32F:
{
FReadSurfaceDataFlags ReadDataFlags(RCM_MinMax);
ReadDataFlags.SetLinearToGamma(false);
TArray<FLinearColor> RawPixels;
RawPixels.SetNum(SourceRect.Width() * SourceRect.Height());
RHICmdList.ReadSurfaceData(Texture, SourceRect, RawPixels, ReadDataFlags);
TUniquePtr<TImagePixelData<FLinearColor>> PixelData = MakeUnique<TImagePixelData<FLinearColor>>(SourceRect.Size(), TArray64<FLinearColor>(MoveTemp(RawPixels)));
check(PixelData->IsDataWellFormed());
return PixelData;
}
case PF_R8G8B8A8:
case PF_B8G8R8A8:
{
FReadSurfaceDataFlags ReadDataFlags;
ReadDataFlags.SetLinearToGamma(false);
TArray<FColor> RawPixels;
RawPixels.SetNum(SourceRect.Width() * SourceRect.Height());
RHICmdList.ReadSurfaceData(Texture, SourceRect, RawPixels, ReadDataFlags);
TUniquePtr<TImagePixelData<FColor>> PixelData = MakeUnique<TImagePixelData<FColor>>(SourceRect.Size(), TArray64<FColor>(MoveTemp(RawPixels)));
check(PixelData->IsDataWellFormed());
return PixelData;
}
}
return nullptr;
}
BEGIN_SHADER_PARAMETER_STRUCT(FReadbackParameters, )
SHADER_PARAMETER_RDG_TEXTURE(, Texture)
END_SHADER_PARAMETER_STRUCT()
void AddDumpToPipePass(FRDGBuilder& GraphBuilder, FScreenPassTexture Input, FImagePixelPipe* OutputPipe)
{
check(Input.IsValid());
check(OutputPipe);
FReadbackParameters* PassParameters = GraphBuilder.AllocParameters<FReadbackParameters>();
PassParameters->Texture = Input.Texture;
GraphBuilder.AddPass(
RDG_EVENT_NAME("DumpToPipe(%s)", Input.Texture->Name),
PassParameters,
ERDGPassFlags::Copy,
[Input, OutputPipe](FRHICommandListImmediate& RHICmdList)
{
OutputPipe->Push(ReadbackPixelData(RHICmdList, Input.Texture->GetRHI(), Input.ViewRect));
});
}
void AddDumpToFilePass(FRDGBuilder& GraphBuilder, FScreenPassTexture Input, const FString& Filename)
{
check(Input.IsValid());
FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();
if (!ensureMsgf(HighResScreenshotConfig.ImageWriteQueue, TEXT("Unable to write images unless FHighResScreenshotConfig::Init has been called.")))
{
return;
}
if (GIsHighResScreenshot && HighResScreenshotConfig.CaptureRegion.Area())
{
Input.ViewRect = HighResScreenshotConfig.CaptureRegion;
}
FReadbackParameters* PassParameters = GraphBuilder.AllocParameters<FReadbackParameters>();
PassParameters->Texture = Input.Texture;
GraphBuilder.AddPass(
RDG_EVENT_NAME("DumpToFile(%s)", Input.Texture->Name),
PassParameters,
ERDGPassFlags::Copy,
[&HighResScreenshotConfig, Input, Filename](FRHICommandListImmediate& RHICmdList)
{
TUniquePtr<FImagePixelData> PixelData = ReadbackPixelData(RHICmdList, Input.Texture->GetRHI(), Input.ViewRect);
if (!PixelData.IsValid())
{
return;
}
TUniquePtr<FImageWriteTask> ImageTask = MakeUnique<FImageWriteTask>();
ImageTask->PixelData = MoveTemp(PixelData);
HighResScreenshotConfig.PopulateImageTaskParams(*ImageTask);
ImageTask->Filename = Filename;
if (ImageTask->PixelData->GetType() == EImagePixelType::Color)
{
// Always write full alpha
ImageTask->PixelPreProcessors.Add(TAsyncAlphaWrite<FColor>(255));
if (ImageTask->Format == EImageFormat::EXR)
{
// Write FColors with a gamma curve. This replicates behavior that previously existed in ExrImageWrapper.cpp (see following overloads) that assumed
// any 8 bit output format needed linearizing, but this is not a safe assumption to make at such a low level:
// void ExtractAndConvertChannel(const uint8*Src, uint32 SrcChannels, uint32 x, uint32 y, float* ChannelOUT)
// void ExtractAndConvertChannel(const uint8*Src, uint32 SrcChannels, uint32 x, uint32 y, FFloat16* ChannelOUT)
ImageTask->PixelPreProcessors.Add(TAsyncGammaCorrect<FColor>(2.2f));
}
}
HighResScreenshotConfig.ImageWriteQueue->Enqueue(MoveTemp(ImageTask));
});
}
//void AddDumpToFilePass(FRDGBuilder& GraphBuilder, FRDGTextureRef Input, const FString& Filename)
//{
//
// FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();
//
// FIntRect ViewRect;
//
// if (!ensureMsgf(HighResScreenshotConfig.ImageWriteQueue, TEXT("Unable to write images unless FHighResScreenshotConfig::Init has been called.")))
// {
// return;
// }
//
// if (GIsHighResScreenshot && HighResScreenshotConfig.CaptureRegion.Area())
// {
// ViewRect = HighResScreenshotConfig.CaptureRegion;
// }
//
// FReadbackParameters* PassParameters = GraphBuilder.AllocParameters<FReadbackParameters>();
// PassParameters->Texture = Input;
//
// GraphBuilder.AddPass(
// RDG_EVENT_NAME("DumpToFile(%s)", Input->Name),
// PassParameters,
// ERDGPassFlags::Copy,
// [&HighResScreenshotConfig, Input, ViewRect, Filename](FRHICommandListImmediate& RHICmdList)
// {
// TUniquePtr<FImagePixelData> PixelData = ReadbackPixelData(RHICmdList, Input->GetRHI(), ViewRect);
//
// if (!PixelData.IsValid())
// {
// UE_LOG(LogTemp, Warning, TEXT("PixelData is unvalid"));
// return;
// }
//
// TUniquePtr<FImageWriteTask> ImageTask = MakeUnique<FImageWriteTask>();
// ImageTask->PixelData = MoveTemp(PixelData);
//
// HighResScreenshotConfig.PopulateImageTaskParams(*ImageTask);
// ImageTask->Filename = Filename;
//
// if (ImageTask->PixelData->GetType() == EImagePixelType::Color)
// {
// // Always write full alpha
// ImageTask->PixelPreProcessors.Add(TAsyncAlphaWrite<FColor>(255));
//
// if (ImageTask->Format == EImageFormat::EXR)
// {
// // Write FColors with a gamma curve. This replicates behavior that previously existed in ExrImageWrapper.cpp (see following overloads) that assumed
// // any 8 bit output format needed linearizing, but this is not a safe assumption to make at such a low level:
// // void ExtractAndConvertChannel(const uint8*Src, uint32 SrcChannels, uint32 x, uint32 y, float* ChannelOUT)
// // void ExtractAndConvertChannel(const uint8*Src, uint32 SrcChannels, uint32 x, uint32 y, FFloat16* ChannelOUT)
// ImageTask->PixelPreProcessors.Add(TAsyncGammaCorrect<FColor>(2.2f));
// }
// }
//
// HighResScreenshotConfig.ImageWriteQueue->Enqueue(MoveTemp(ImageTask));
// });
//}
void AddDumpToColorArrayPass(FRDGBuilder& GraphBuilder, FScreenPassTexture Input, TArray<FColor>* OutputColorArray)
{
check(Input.IsValid());
check(OutputColorArray);
FReadbackParameters* PassParameters = GraphBuilder.AllocParameters<FReadbackParameters>();
PassParameters->Texture = Input.Texture;
GraphBuilder.AddPass(
RDG_EVENT_NAME("DumpToPipe(%s)", Input.Texture->Name),
PassParameters,
ERDGPassFlags::Copy,
[Input, OutputColorArray](FRHICommandListImmediate& RHICmdList)
{
RHICmdList.ReadSurfaceData(Input.Texture->GetRHI(), Input.ViewRect, *OutputColorArray, FReadSurfaceDataFlags());
});
}
FScreenPassTexture AddVisualizeGBufferOverviewPass(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
const FVisualizeGBufferOverviewInputs& Inputs)
{
const FFinalPostProcessSettings& PostProcessSettings = View.FinalPostProcessSettings;
check(Inputs.SceneColor.IsValid());
check(Inputs.bDumpToFile || Inputs.bOverview || PostProcessSettings.BufferVisualizationPipes.Num() > 0);
FScreenPassTexture Output;
const EPixelFormat OutputFormat = Inputs.bOutputInHDR ? PF_FloatRGBA : PF_Unknown;
TArray<FVisualizeBufferTile> Tiles;
RDG_EVENT_SCOPE(GraphBuilder, "VisualizeGBufferOverview");
const FString& BaseFilename = PostProcessSettings.BufferVisualizationDumpBaseFilename;
for (UMaterialInterface* MaterialInterface : PostProcessSettings.BufferVisualizationOverviewMaterials)
{
if (!MaterialInterface)
{
// Add an empty tile to keep the location of each static on the grid.
Tiles.Emplace();
continue;
}
const FString MaterialName = MaterialInterface->GetName();
RDG_EVENT_SCOPE(GraphBuilder, "%s", *MaterialName);
FPostProcessMaterialInputs PostProcessMaterialInputs;
PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::SceneColor, Inputs.SceneColor);
PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::SeparateTranslucency, Inputs.SeparateTranslucency);
PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::PreTonemapHDRColor, Inputs.SceneColorBeforeTonemap);
PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::PostTonemapHDRColor, Inputs.SceneColorAfterTonemap);
PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::Velocity, Inputs.Velocity);
PostProcessMaterialInputs.OutputFormat = OutputFormat;
Output = AddPostProcessMaterialPass(GraphBuilder, View, PostProcessMaterialInputs, MaterialInterface);
const TSharedPtr<FImagePixelPipe, ESPMode::ThreadSafe>* OutputPipe = PostProcessSettings.BufferVisualizationPipes.Find(MaterialInterface->GetFName());
if (OutputPipe && OutputPipe->IsValid())
{
AddDumpToPipePass(GraphBuilder, Output, OutputPipe->Get());
}
if (Inputs.bDumpToFile) {
// First off, allow the user to specify the pass as a format arg (using {material})
TMap<FString, FStringFormatArg> FormatMappings;
FormatMappings.Add(TEXT("material"), MaterialName);
FString MaterialFilename = FString::Format(*BaseFilename, FormatMappings);
// If the format made no change to the string, we add the name of the material to ensure uniqueness
if (MaterialFilename == BaseFilename) {
MaterialFilename = BaseFilename + TEXT("_") + MaterialName;
}
MaterialFilename.Append(TEXT(".png"));
if (MaterialName == "MotionVector") {
// auto motionVectorOutput = AddVelocityCombinePass(GraphBuilder, View, Inputs.SceneDepth.Texture, Inputs.Velocity.Texture);
FRDGTextureRef motionVectorOutput = AddMotionVectorAndUsedCountPass(GraphBuilder, View, Inputs.SceneDepth.Texture, Inputs.Velocity.Texture);
FScreenPassTexture MotionVectorTexture;
MotionVectorTexture.ViewRect = View.ViewRect;
MotionVectorTexture.Texture = motionVectorOutput;
AddDumpToFilePass(GraphBuilder, MotionVectorTexture, MaterialFilename);
}
/*else if (MaterialName == "PreTonemapHDRColorDiffuse") {
FVector4 tempSpecular = View.SpecularOverrideParameter;
View.SpecularOverrideParameter = FVector4(0.f, 0.f, 0.f, 0.f);
FScreenPassTexture DiffuseOutput = AddPostProcessMaterialPass(GraphBuilder, View, PostProcessMaterialInputs, MaterialInterface);
const TSharedPtr<FImagePixelPipe, ESPMode::ThreadSafe>* OutputPipeDiffuse = PostProcessSettings.BufferVisualizationPipes.Find(MaterialInterface->GetFName());
if (OutputPipeDiffuse && OutputPipeDiffuse->IsValid()) {
AddDumpToPipePass(GraphBuilder, DiffuseOutput, OutputPipeDiffuse->Get());
}
AddDumpToFilePass(GraphBuilder, DiffuseOutput, MaterialFilename);
View.SpecularOverrideParameter = tempSpecular;
}*/
else if (MaterialName == "Matrix") {
FString MatrixFilename = FString::Format(*BaseFilename, FormatMappings);
// If the format made no change to the string, we add the name of the material to ensure uniqueness
if (MatrixFilename == BaseFilename) {
MatrixFilename = BaseFilename + TEXT("_") + MaterialName;
}
MatrixFilename.Append(TEXT(".txt"));
FString output = "";
output += "ClipToView: " + View.CachedViewUniformShaderParameters->ClipToView.ToString() + '\n';
output += "ViewMatrix: " + View.ViewMatrices.GetViewMatrix().ToString() + '\n';
output += "ProjectionMatrix: " + View.ViewMatrices.GetProjectionMatrix().ToString() + '\n';
output += FString::Printf(TEXT("FOV: %g\n"), View.FOV);
output += FString::Printf(TEXT("NearClipDistance: %g\n"), View.NearClippingDistance);
float FarClipDistance = View.SceneViewInitOptions.OverrideFarClippingPlaneDistance > 0.0f ? View.SceneViewInitOptions.OverrideFarClippingPlaneDistance : 0;
output += FString::Printf(TEXT("FarClipDistance: %g\n"), FarClipDistance);
FFileHelper::SaveStringToFile(output, *MatrixFilename);
}
/*else if (MaterialName == "BaseColorAA") {
if (View.PrevViewInfo.TemporalAAGBufferHistory.IsValid()) {
AddDumpToFilePass(GraphBuilder, FScreenPassTexture(GraphBuilder.RegisterExternalTexture(View.PrevViewInfo.TemporalAAGBufferHistory.RT[0]), View.ViewRect), MaterialFilename);
}
}*/
else {
AddDumpToFilePass(GraphBuilder, Output, MaterialFilename);
}
}
if (Inputs.bOverview)
{
FDownsamplePassInputs DownsampleInputs;
DownsampleInputs.Name = TEXT("MaterialHalfSize");
DownsampleInputs.SceneColor = Output;
DownsampleInputs.Flags = EDownsampleFlags::ForceRaster;
DownsampleInputs.Quality = EDownsampleQuality::Low;
FScreenPassTexture HalfSize = AddDownsamplePass(GraphBuilder, View, DownsampleInputs);
DownsampleInputs.Name = TEXT("MaterialQuarterSize");
DownsampleInputs.SceneColor = HalfSize;
FVisualizeBufferTile Tile;
Tile.Input = AddDownsamplePass(GraphBuilder, View, DownsampleInputs);
Tile.Label = GetBufferVisualizationData().GetMaterialDisplayName(FName(*MaterialName)).ToString();
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
Tile.bSelected =
PostProcessSettings.bBufferVisualizationOverviewTargetIsSelected &&
PostProcessSettings.BufferVisualizationOverviewSelectedTargetMaterialName == MaterialName;
#endif
Tiles.Add(Tile);
}
}
//if (Inputs.bDumpToFile)
//{
// // dump MotionVector to file
// const FString MVecName = "MotionVector";
//
// RDG_EVENT_SCOPE(GraphBuilder, "%s", *MVecName);
// TMap<FString, FStringFormatArg> FormatMappings;
// FormatMappings.Add(TEXT("material"), MVecName);
// FString MVecFilename = FString::Format(*BaseFilename, FormatMappings);
// // If the format made no change to the string, we add the name of the material to ensure uniqueness
// if (MVecFilename == BaseFilename)
// {
// MVecFilename = BaseFilename + TEXT("_") + MVecName;
// }
// MVecFilename.Append(TEXT(".exr"));
// auto motionVectorOutput = AddVelocityCombinePass(GraphBuilder, View, Inputs.SceneDepth.Texture, Inputs.Velocity.Texture);
//
// FScreenPassTexture screenPassTexture;
// screenPassTexture.ViewRect = View.ViewRect;
// screenPassTexture.Texture = motionVectorOutput.CombinedVelocity;
// AddDumpToFilePass(GraphBuilder, screenPassTexture, MVecFilename);
// //// dump View Normal and World Position to file
// //const FString ViewNormalName = "ViewNor";
// //const FString WorldPosName = "WorldPos";
// //RDG_EVENT_SCOPE(GraphBuilder, "%s", *ViewNormalName);
// //FormatMappings.Add(TEXT("material"), ViewNormalName);
// //FString ViewNormalFilename = FString::Format(*BaseFilename, FormatMappings);
// //// If the format made no change to the string, we add the name of the material to ensure uniqueness
// //if (ViewNormalFilename == BaseFilename)
// //{
// // ViewNormalFilename = BaseFilename + TEXT("_") + MVecName;
// //}
// //ViewNormalFilename.Append(TEXT(".exr"));
// //FormatMappings.Add(TEXT("material"), WorldPosName);
// //FString WorldPosFilename = FString::Format(*BaseFilename, FormatMappings);
// //// If the format made no change to the string, we add the name of the material to ensure uniqueness
// //if (WorldPosFilename == BaseFilename)
// //{
// // WorldPosFilename = BaseFilename + TEXT("_") + MVecName;
// //}
// //WorldPosFilename.Append(TEXT(".exr"));
// //auto MyOutput = AddWorldNormalToViewPass(GraphBuilder, View, Inputs.SceneTextures.SceneGBufferA, Inputs.SceneDepth.Texture);
// //FScreenPassTexture ViewNormalTexture;
// //ViewNormalTexture.ViewRect = View.ViewRect;
// //ViewNormalTexture.Texture = MyOutput.ViewNormal;
// //AddDumpToFilePass(GraphBuilder, ViewNormalTexture, ViewNormalFilename);
// //FScreenPassTexture WorldPosTexture;
// //WorldPosTexture.ViewRect = View.ViewRect;
// //WorldPosTexture.Texture = MyOutput.WorldPos;
// //AddDumpToFilePass(GraphBuilder, WorldPosTexture, WorldPosFilename);
// //const FString ViewMatrixName = "ViewMatrix";
// //FormatMappings.Add(TEXT("material"), ViewMatrixName);
// //FString ViewMatrixFilename = FString::Format(*BaseFilename, FormatMappings);
// //// If the format made no change to the string, we add the name of the material to ensure uniqueness
// //if (ViewMatrixFilename == BaseFilename)
// //{
// // ViewMatrixFilename = BaseFilename + TEXT("_") + MVecName;
// //}
// //ViewMatrixFilename.Append(TEXT(".txt"));
// //
// //FFileHelper::SaveStringToFile(View.ViewMatrices.GetViewMatrix().ToString(), *ViewMatrixFilename);
//}
if (Inputs.bOverview)
{
FVisualizeBufferInputs PassInputs;
PassInputs.OverrideOutput = Inputs.OverrideOutput;
PassInputs.SceneColor = Inputs.SceneColor;
PassInputs.Tiles = Tiles;
return AddVisualizeBufferPass(GraphBuilder, View, PassInputs);
}
else
{
return Inputs.SceneColor;
}
}
You can’t perform that action at this time.
