@@ -81,7 +81,7 @@ class FVelocityVS : public FMeshMaterialShader
81
81
const bool bMayModifyMeshes = Parameters.MaterialParameters .bMaterialMayModifyMeshPosition ;
82
82
83
83
// Compile if supported by the hardware.
84
- const bool bIsFeatureSupported = IsFeatureLevelSupported (Parameters.Platform , ERHIFeatureLevel::SM5 );
84
+ const bool bIsFeatureSupported = IsFeatureLevelSupported (Parameters.Platform , ERHIFeatureLevel::ES3_1 );
85
85
86
86
/* *
87
87
* Any material with a vertex factory incompatible with base pass velocity generation must generate
@@ -207,6 +207,26 @@ bool FDeferredShadingSceneRenderer::ShouldRenderVelocities() const
207
207
return bNeedsVelocity;
208
208
}
209
209
210
+ bool FMobileSceneRenderer::ShouldRenderVelocities () const
211
+ {
212
+ if (!FVelocityRendering::IsSeparateVelocityPassSupported (ShaderPlatform) || ViewFamily.UseDebugViewPS ())
213
+ {
214
+ return false ;
215
+ }
216
+
217
+ bool bNeedsVelocity = false ;
218
+ for (int32 ViewIndex = 0 ; ViewIndex < Views.Num (); ViewIndex++)
219
+ {
220
+ const FViewInfo& View = Views[ViewIndex];
221
+
222
+ bool bTemporalAA = (View.AntiAliasingMethod == AAM_TemporalAA) && !View.bCameraCut ;
223
+
224
+ bNeedsVelocity |= bTemporalAA && MobileUseStandaloneTAA ((ShaderPlatform));
225
+ }
226
+
227
+ return bNeedsVelocity;
228
+ }
229
+
210
230
BEGIN_SHADER_PARAMETER_STRUCT (FVelocityPassParameters, )
211
231
SHADER_PARAMETER_RDG_UNIFORM_BUFFER(FSceneTextureUniformParameters, SceneTextures)
212
232
RENDER_TARGET_BINDING_SLOTS()
@@ -331,9 +351,131 @@ void FDeferredShadingSceneRenderer::RenderVelocities(
331
351
}
332
352
}
333
353
354
+ BEGIN_SHADER_PARAMETER_STRUCT (FMobileVelocityPassParameters, )
355
+ SHADER_PARAMETER_RDG_UNIFORM_BUFFER(FMobileSceneTextureUniformParameters, SceneTextures)
356
+ RENDER_TARGET_BINDING_SLOTS()
357
+ END_SHADER_PARAMETER_STRUCT()
358
+
359
+ void FMobileSceneRenderer::RenderVelocities(
360
+ FRDGBuilder& GraphBuilder,
361
+ FRDGTextureRef DepthTexture,
362
+ FRDGTextureRef& InOutVelocityTexture,
363
+ TRDGUniformBufferRef<FMobileSceneTextureUniformParameters> SceneTexturesUniformBuffer,
364
+ EVelocityPass VelocityPass,
365
+ bool bForceVelocity)
366
+ {
367
+ if (!ShouldRenderVelocities ())
368
+ {
369
+ return ;
370
+ }
371
+
372
+ RDG_CSV_STAT_EXCLUSIVE_SCOPE (GraphBuilder, RenderVelocities);
373
+ SCOPED_NAMED_EVENT (FMobileSceneRenderer_RenderVelocities, FColor::Emerald);
374
+ SCOPE_CYCLE_COUNTER (STAT_RenderVelocities);
375
+
376
+ ERenderTargetLoadAction VelocityLoadAction = ERenderTargetLoadAction::EClear;
377
+ FRDGTextureRef VelocityTexture = InOutVelocityTexture;
378
+ bool bVelocityRendered = false ;
379
+
380
+ if (!VelocityTexture)
381
+ {
382
+ VelocityTexture = GraphBuilder.CreateTexture (FVelocityRendering::GetRenderTargetDesc (ShaderPlatform), TEXT (" Velocity" ));
383
+ VelocityLoadAction = ERenderTargetLoadAction::EClear;
384
+ }
385
+
386
+ RDG_GPU_STAT_SCOPE (GraphBuilder, RenderVelocities);
387
+ RDG_WAIT_FOR_TASKS_CONDITIONAL (GraphBuilder, IsVelocityWaitForTasksEnabled ());
388
+
389
+ const EMeshPass::Type MeshPass = GetMeshPassFromVelocityPass (VelocityPass);
390
+
391
+ for (int32 ViewIndex = 0 ; ViewIndex < Views.Num (); ViewIndex++)
392
+ {
393
+ const FViewInfo& View = Views[ViewIndex];
394
+
395
+ if (View.ShouldRenderView ())
396
+ {
397
+ const FParallelMeshDrawCommandPass& ParallelMeshPass = View.ParallelMeshDrawCommandPasses [MeshPass];
398
+
399
+ const bool bHasAnyDraw = ParallelMeshPass.HasAnyDraw ();
400
+ if (!bHasAnyDraw && !bForceVelocity)
401
+ {
402
+ continue ;
403
+ }
404
+
405
+ RDG_GPU_MASK_SCOPE (GraphBuilder, View.GPUMask );
406
+
407
+ if (VelocityLoadAction == ERenderTargetLoadAction::EClear)
408
+ {
409
+ AddClearRenderTargetPass (GraphBuilder, VelocityTexture);
410
+
411
+ if (!View.Family ->bMultiGPUForkAndJoin )
412
+ {
413
+ VelocityLoadAction = ERenderTargetLoadAction::ELoad;
414
+ }
415
+ }
416
+ bVelocityRendered = true ;
417
+
418
+ if (!bHasAnyDraw)
419
+ {
420
+ continue ;
421
+ }
422
+
423
+ FMobileVelocityPassParameters* PassParameters = GraphBuilder.AllocParameters <FMobileVelocityPassParameters>();
424
+ PassParameters->SceneTextures = SceneTexturesUniformBuffer;
425
+ PassParameters->RenderTargets .DepthStencil = FDepthStencilBinding (
426
+ DepthTexture,
427
+ ERenderTargetLoadAction::ELoad,
428
+ ERenderTargetLoadAction::ELoad,
429
+ VelocityPass == EVelocityPass::Opaque
430
+ ? FExclusiveDepthStencil::DepthRead_StencilWrite
431
+ : FExclusiveDepthStencil::DepthWrite_StencilWrite);
432
+
433
+ if (IsParallelVelocity ())
434
+ {
435
+ PassParameters->RenderTargets [0 ] = FRenderTargetBinding (VelocityTexture, ERenderTargetLoadAction::ELoad);
436
+
437
+ GraphBuilder.AddPass (
438
+ RDG_EVENT_NAME (" VelocityParallel" ),
439
+ PassParameters,
440
+ ERDGPassFlags::Raster | ERDGPassFlags::SkipRenderPass,
441
+ [this , &View, &ParallelMeshPass, VelocityPass, PassParameters](FRHICommandListImmediate& RHICmdList)
442
+ {
443
+ Scene->UniformBuffers .UpdateViewUniformBuffer (View);
444
+ FRDGParallelCommandListSet ParallelCommandListSet (RHICmdList, GET_STATID (STAT_CLP_Velocity), *this , View, FParallelCommandListBindings (PassParameters));
445
+ ParallelMeshPass.DispatchDraw (&ParallelCommandListSet, RHICmdList);
446
+ });
447
+ }
448
+ else
449
+ {
450
+ PassParameters->RenderTargets [0 ] = FRenderTargetBinding (VelocityTexture, ERenderTargetLoadAction::ELoad);
451
+
452
+ GraphBuilder.AddPass (
453
+ RDG_EVENT_NAME (" Velocity" ),
454
+ PassParameters,
455
+ ERDGPassFlags::Raster,
456
+ [this , &View, &ParallelMeshPass](FRHICommandListImmediate& RHICmdList)
457
+ {
458
+ Scene->UniformBuffers .UpdateViewUniformBuffer (View);
459
+ SetStereoViewport (RHICmdList, View);
460
+
461
+ ParallelMeshPass.DispatchDraw (nullptr , RHICmdList);
462
+ });
463
+ }
464
+
465
+ }
466
+ }
467
+
468
+ if (!InOutVelocityTexture && bVelocityRendered)
469
+ {
470
+ FSceneRenderTargets& SceneContext = FSceneRenderTargets::Get (GraphBuilder.RHICmdList );
471
+ ConvertToExternalTexture (GraphBuilder, VelocityTexture, SceneContext.SceneVelocity );
472
+ InOutVelocityTexture = VelocityTexture;
473
+ }
474
+ }
475
+
334
476
EPixelFormat FVelocityRendering::GetFormat (EShaderPlatform ShaderPlatform)
335
477
{
336
- return FDataDrivenShaderPlatformInfo::GetSupportsRayTracing (ShaderPlatform) ? PF_A16B16G16R16 : PF_G16R16 ;
478
+ return FDataDrivenShaderPlatformInfo::GetSupportsRayTracing (ShaderPlatform) ? PF_A16B16G16R16 : PF_G16R16F ;
337
479
}
338
480
339
481
FRDGTextureDesc FVelocityRendering::GetRenderTargetDesc (EShaderPlatform ShaderPlatform)
@@ -671,6 +813,7 @@ FMeshPassProcessor* CreateVelocityPassProcessor(const FScene* Scene, const FScen
671
813
}
672
814
673
815
FRegisterPassProcessorCreateFunction RegisterVelocityPass (&CreateVelocityPassProcessor, EShadingPath::Deferred, EMeshPass::Velocity, EMeshPassFlags::CachedMeshCommands | EMeshPassFlags::MainView);
816
+ FRegisterPassProcessorCreateFunction RegisterMobileVelocityPass (&CreateVelocityPassProcessor, EShadingPath::Mobile, EMeshPass::Velocity, EMeshPassFlags::CachedMeshCommands | EMeshPassFlags::MainView);
674
817
FTranslucentVelocityMeshProcessor::FTranslucentVelocityMeshProcessor (const FScene* Scene, const FSceneView* InViewIfDynamicMeshCommand, const FMeshPassProcessorRenderState& InPassDrawRenderState, FMeshPassDrawListContext* InDrawListContext)
675
818
: FVelocityMeshProcessor(Scene, InViewIfDynamicMeshCommand, InPassDrawRenderState, InDrawListContext)
676
819
{}
0 commit comments