You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb None ========================== MAJOR FEATURES + CHANGES ========================== Change 3358140 on 2017/03/22 by Rolando.Caloca DR - Fix copy to cube face - Compile fix when using dump layer - Add new error enum Change 3358301 on 2017/03/22 by Mitchell.Wilson Initial check in of LODs in InfiltratorForward. First pass on optimization in level. Adding a visibility track for SceneCapture2D in tunnel section. Change 3358477 on 2017/03/22 by Mitchell.Wilson Updating Skeletal Mesh DPW_Robot_Export to resolve screen size being too low for LOD1. Cleaned up LOD1 which was showing some visible popping when transitioning. Change 3358529 on 2017/03/22 by Mark.Satterthwaite Globally disable clang's "constant-logical-operand" warning when running under Distcc - it is much easier and less invasive than constantly fixing the code. Change 3358745 on 2017/03/22 by Mark.Satterthwaite Disable another warning (parentheses-equality) under Distcc because again the separation of preprocessing from compilation means it turns up where it isn't expected. Change 3358837 on 2017/03/22 by Joe.Graf Merge of pull request #3214 for the RenderDocPlugin #CodeReview: matt.kuhlenschmidt, marcus.wassmer #rb: marcus.wassmer Change 3359112 on 2017/03/22 by Ben.Salem Update perf monitor to include frame time by default. Also, use only game/PIE world timers when in editor, instead of all worlds combined. #tests Ran several Showdown test runs with plugin! Change 3359363 on 2017/03/22 by Joe.Graf First pass at non-unity & no pch compilation Change 3359449 on 2017/03/22 by Joe.Graf Added missing null check when exporting a EXR on Linux (UE-40268) #CodeReview: dmitry.rekman #rb: n/a Change 3360349 on 2017/03/23 by Guillaume.Abadie Fixes TAA's AA_FORCE_ALPHA_CLAMP causing DOF layouts. #jira UE-42920 Change 3360405 on 2017/03/23 by Marcus.Wassmer Better method for detecting Kepler Change 3360718 on 2017/03/23 by Daniel.Wright Planar reflections handle views smaller than the render target in a general way * Fixes planar reflections with adaptive pixel density (ViewFamily size larger than actual views combined) * Planar reflections are now supported in splitscreen Change 3360758 on 2017/03/23 by Daniel.Wright [Copy] Added new light property bCastVolumetricShadow, which defaults to true for directional and sky lights, but false for point / spot lights as supporting volumetric fog shadowing has significant GPU overhead Change 3360762 on 2017/03/23 by Daniel.Wright [Copy] Texture flags are now properly routed to RHICreateTexture3D from the render target pool Change 3360768 on 2017/03/23 by Daniel.Wright [Copy] Disabled GPUProfiler histogram by default, controlled by r.ProfileGPU.ShowEventHistogram Change 3360770 on 2017/03/23 by Daniel.Wright [Copy] Disabled fast clears on CustomDepth, saves .2ms on xbox Change 3360771 on 2017/03/23 by Daniel.Wright [Copy] Particle lights no longer force tiled deferred lighting. Tiled deferred lighting is only used if enough unshadowed lights + particle lights are on screen. Saves 1.5ms Xbox with one particle light. Change 3360774 on 2017/03/23 by Daniel.Wright [Copy] Distance field cvar comments Change 3360782 on 2017/03/23 by Daniel.Wright [Copy] Disabled selection color on Volume materials Change 3360795 on 2017/03/23 by Daniel.Wright [Copy] Volume materials now specify Albedo and Extinction, which is more intuitive than Scattering and Absorption. Albedo is [0-1] reflectance, while Extinction is a world space density. Change 3360799 on 2017/03/23 by Daniel.Wright [Copy] Cinematic scalability levels get 2x volumetric fog resolution in x and y Change 3360806 on 2017/03/23 by Daniel.Wright [Copy] Fixed volumetric fog being offset when viewport min is not 0 Change 3360809 on 2017/03/23 by Daniel.Wright [Copy] Volumetric fog now adds a bias to the inverse squared light falloff denominator, prevents extreme aliasing from the hotspot. Can be controlled with r.VolumetricFog.InverseSquaredLightDistanceBiasScale. Change 3361651 on 2017/03/23 by Brian.Karis Higher quality sharp SSR at quality 4 Change 3361678 on 2017/03/23 by Brian.Karis Fresnel darkens diffuse for clearcoat. Change 3361683 on 2017/03/23 by Brian.Karis Fixed SSR artifact Change 3361691 on 2017/03/23 by Brian.Karis Chagned min roughness limit Change 3361707 on 2017/03/23 by Brian.Karis Added inverse film tone map Change 3361726 on 2017/03/23 by Brian.Karis Better precision inverse Change 3361758 on 2017/03/23 by Brian.Karis Material flag normal curvature to roughness is no longer forward only. Change 3361765 on 2017/03/23 by Brian.Karis Update ACES Change 3361774 on 2017/03/23 by Brian.Karis Cleaned up alpha support and disabled screen edge clipping. Change 3362478 on 2017/03/24 by Guillaume.Abadie Cherry pick 3316084's PostProcessing.cpp: Fixes a bug in Circle DOF where the apply pass was no longer using the downres DOF's TAA output. #author Brian.Karis #jira UE-42920 Change 3362738 on 2017/03/24 by Rolando.Caloca DR - Hide scene capture on IF Change 3362890 on 2017/03/24 by Guillaume.Abadie Renames r.SceneAlpha to r.PostProcessing.PropagateAlpha Change 3363665 on 2017/03/24 by Mark.Satterthwaite PR #3414: Add command line option "-noheartbeatthread" to disable heart beat thread (Contributed by JeffRous) Change 3363866 on 2017/03/24 by Arne.Schober DR - Updated NVAPI #RB Marcus.Wassmer Change 3364300 on 2017/03/24 by Brian.Karis SSR use dynamic velocity Change 3364372 on 2017/03/24 by Brian.Karis Fix changing off axis projection velocities. Change 3364373 on 2017/03/24 by Brian.Karis Enabled velocity drawing in scene captures Change 3365531 on 2017/03/27 by Guillaume.Abadie Computes the material's screen position material expression directly from the pixel shader SvPosition Change 3365764 on 2017/03/27 by Chris.Bunner Lowering severity of crash for missing values in scalability.ini. #jira UE-41331 Change 3365916 on 2017/03/27 by Guillaume.Abadie Exposes the viewport offset within the view property material expression Change 3365979 on 2017/03/27 by Brian.Karis Fixed skylight intensity from double applying Change 3365987 on 2017/03/27 by Brian.Karis Stopped post process indirect lighting intensity from scaling skylight reflections Change 3365991 on 2017/03/27 by Brian.Karis Fix for static analysis Change 3366028 on 2017/03/27 by Daniel.Wright Volumetric fog supports static shadowing from Stationary lights * Using bilinear on static shadowmap depths + 1 PCF to smooth out results Change 3366029 on 2017/03/27 by Daniel.Wright Static shadow depth maps for Stationary point and spot lights are 2x higher res by default (4x more texels), which is more appropriate for volumetric fog Change 3366055 on 2017/03/27 by Guillaume.Abadie Cherry picks 3251469: Implements scene capture component's CaptureSortPriority to control GPU execution order in order to manage inter dependencies. Change 3366447 on 2017/03/27 by Simon.Tourangeau Fix IES light profile importer. - Bug in the LM-63-1986 format importer. Change3366836on 2017/03/27 by Brian.Karis ClearUAV now supports int types Change 3367435 on 2017/03/28 by Benjamin.Hyder Submitting Decal Automation map for initial approval Change 3367572 on 2017/03/28 by Chris.Bunner Changed ClampedPow {max(abs(x),0.00001)} to PositiveClampedPow {max(x,0)} to give more expected results to Power node in material graphs. #jira UE-42989 Change 3367756 on 2017/03/28 by Olaf.Piesche Niagara material usage flags Change 3367835 on 2017/03/28 by Marcus.Wassmer Fix crash when TileRenderer runs before anything else. Make explicit behavior when rendering at a time when there is no valid scene. Change 3367837 on 2017/03/28 by Marcus.Wassmer Missed a file. Change 3367838 on 2017/03/28 by Richard.Wallis Updated items from original shelved version by Mark Satt: - Added MetalBackend.cpp to change main function string to have an initial crc + code length zero's **Description below taken from Mark Satt's original verison of this in CL3343280** Updated for Dev-Rendering's PSOs & integrates Richard's work on RHI shader libraries. Replace the FShaderCache's cook-time binary shader cache with Dmitriy Dyomin's standalone FShaderCodeLibrary that saves all shader byte-code arrays to files named by the FSHAHash. This de-duplicates shaders so we only ever store the byte code once. Includes optional support for generating a platform specific library file - which Metal implements to provide a single Metal library. The platform-native implementation can perform more de-duplication and in the case of Metal has lower file overheads and will compress more efficiently. - All of the support code for the FShaderCache's cook caching is gone, which affects all platforms. The FShaderCodeLibrary is currently supported by Cook-By-The-Book but can be used with iterate or child cookers - only DLC cooking requires further work. - With further modifications it should be possible to support Cook-on-the-Fly as well (output directories would be needed in FShaderCodeLibrary::InitForCooking) and the file-access pattern should be changed to use async. IO so that Material loading is not considered complete until all required byte-code arrays are loaded into the FShaderCodeLibrary. - For Metal archiving shaders this way will compile with debug information and the FShaderCodeLibrary, with some help from extensions to IShaderFormat, will save the debug information out into separate files during cooking - these can then be used to debug the game without having to locally recompile, recook & repackage but the shipped byte-code is stripped. Global shader caches are also subject to de-duplication in the library in order to support Metal's shader stripping. - File Move operations need to respect the 'Replace' flag - for FShaderCodeLibrary to work we need Move to be atomic. - This bumps the object version and will cause all content to recook. - Native library support is optional - only Metal currently implements one, but so could Vulkan and D3D12. For Metal the big advantages are further de-duplication where different materials generate the same MetalSL text but a different FSHAHash, that the single Metal library has lower overhead and that as a single file it all compresses far better (esp. with LZMA - 5x smaller). Change 3367854 on 2017/03/28 by Mark.Satterthwaite Don't track or record draw call resources for non-OpenGL shader platforms in the shader-cache as it is unnecessary and makes it slower on the CPU than it needs to be. Change 3367877 on 2017/03/28 by Brian.Karis Fixed linux build hopefully Change 3368001 on 2017/03/28 by Mark.Satterthwaite Compile fixes from Richard's checkin caused by not having visibility to all platforms from my original shelves. Change 3368019 on 2017/03/28 by Mark.Satterthwaite And another fix for Windows compilation of MetalShaderFormat. Change 3368042 on 2017/03/28 by Mark.Satterthwaite And a couple of simpler MSVC errors. Change 3368271 on 2017/03/28 by Mark.Satterthwaite Make SceneRenderTargets compile again. Change 3368691 on 2017/03/28 by Daniel.Wright [Copy from BenW] Renamed r.Shadow.MaxCSMShadowResolution to r.Shadow.MaxCSMResolution to match scalability inis Change 3369689 on 2017/03/29 by Marcus.Wassmer Fix non editor compile for now Change 3369862 on 2017/03/29 by Marcus.Wassmer Get the rest of the things compiling again. Change 3369896 on 2017/03/29 by Chris.Bunner Enabling AMD HDR support by default. #jira UE-42113 Change 3370535 on 2017/03/29 by Marcus.Wassmer DR - Fix template explicit instantiation for ClearUAV permutations #RB Brian.Karis, Arne.Schober Change 3370704 on 2017/03/29 by Rolando.Caloca DR - Rewrote GPU Skin Cache - Per section buffers - Limited memory per non-editor worlds (control with r.SkinCache.SceneMemoryLimitInMB) Copied from 3370529 Change 3371389 on 2017/03/30 by Richard.Wallis Remove temp working directories after archive packages built. Change 3371641 on 2017/03/30 by Rolando.Caloca DR - Copy 3371640 (fix mem leak) Change 3372436 on 2017/03/30 by Uriel.Doyon Added flags in UPrimitiveComponent to keep track of its state in the streaming manager. This allows to avoid unnecessary callback and processing in begin destroy reattach and being destroy logic. Removed the limitation of only processing UMeshComponent when handling spawed primitive. This releases the level manager from having to manage dynamic primitives. This improves performance by not having to manage dynamic references in the level manager. Primitives managed as dynamic now have a callback when ever their proxy is udpated, handling many cases automatically where previously a manual callback to notify would have been required. Fixed an issue where primitives with no reference to streaming textures would loose they dynamic state because of lack of references in the streamer. Change 3372740 on 2017/03/30 by Chris.Bunner [Experimental] Partial compute post process pipeline (r.PostProcess.PreferCompute). StencilSceneTexture added to deferred list. A few known issues to be fixed in a follow-up CL. Change 3372765 on 2017/03/30 by Uriel.Doyon Disabled concurrent call to NotifyPrimitiveUpdated while we don't have a safe concurrent update Change 3372979 on 2017/03/30 by Richard.Hinckley #jira UE-43501 The stencil buffer can now use single-channel bitmasks that ignore depth. This makes it possible to detect overlaps between stencil objects. Change 3373053 on 2017/03/30 by Simon.Tourangeau LPV Fade support - mostly integrated from CL 2959511 Change3373272on 2017/03/30 by Uriel.Doyon Added support for the concurrent update of dynamic primitives by the streaming manager. Change 3373450 on 2017/03/30 by Rolando.Caloca DR - FNT - Fix bad data for odd texcoord channels used on skin cache passthrough factory Copy 3373364 #jira UE-43492 Change 3373470 on 2017/03/30 by Marcus.Wassmer Nvidia Aftermath support Change 3374187 on 2017/03/31 by Chris.Bunner Volume texture support for CombineLUTs/Tonemap compute pass. Refactored common param code to shared sub-class in CombineLUTs and Tonemap PS/CS. Skip compute post process out-of-bounds writes. Unsigned type conversion fixes. Trimmed compute post process shader inputs. Change 3374233 on 2017/03/31 by Chris.Bunner Removed several redundant post process compute fences and resource transitions. Added testing CVar to force compute post processes to async (r.PostProcess.ForceAsyncDispatch). Change 3374412 on 2017/03/31 by Rolando.Caloca DR - Fix static analysis Change 3374544 on 2017/03/31 by Richard.Wallis FShaderCache Parallel-Context-Aware Merged with FShaderCache Single Library. Future Work - This was done before Engine PSO were in so this now needs a refector in the recording and playback on pipeline states instead an emulate PSO in OpenGL Driver. - Remove FShaderCacheState and replace the logic with FGraphicsPipelineStateInitializer which should be able to record from the RHI current pipeline state - This would reduce the Locking required as it's naturally per thread/context and only the final record would need a lock Change 3374588 on 2017/03/31 by Richard.Wallis Windows Compile Fixes Change 3374810 on 2017/03/31 by Benjamin.Hyder updating recommended GPU drivers Change 3375207 on 2017/03/31 by Rolando.Caloca DR - vk - Fixed swapchain format selection for some Linux platforms Change 3375248 on 2017/03/31 by Rolando.Caloca DR - vk - Prefer D32S8 Change 3375495 on 2017/03/31 by Rolando.Caloca DR - vk - Update to sdk 1.0.42.2 Change 3375496 on 2017/03/31 by Rolando.Caloca DR - Force compiling with updated Vulkan SDK Change 3375636 on 2017/03/31 by Mark.Satterthwaite Copying Metal improvements from task stream, with some modifications: - Off-by-default implementations for MTLFence & MTLHeap, including some small changes to the RHI interface for parallel contexts. - Support for Apple's Instruments "Points of Interest" tool. - Consolidation of some Mac & iOS compiler, memory and thread handling code. - Fixes for Metal not having implicit buffer SRV typecasting for DistanceField effects. - Improvements to the internal FMetalDebug layer, still off by default. - Limited support for Xcode automatic code-signing for iOS/tvOS. - Minimisation of render-target changes in some rendering code, esp. SceneOcclusion, DBufferDecals. - Added RHISetResourceAliasability_RenderThread to FDynamicRHI for RHIs to implement simple render-target aliasing. - Added FApplePlatformObject, a custom block allocator for Objective-C types (with NSZombie support) which is now used in MetalRHI to decrease allocation costs of Objective-C types. - Smattering of lesser fixes. Change 3375654 on 2017/03/31 by Mark.Satterthwaite Incremental Windows build fix. Change 3375656 on 2017/04/01 by Mark.Satterthwaite Correct extern declaration, including the module export macro which Mac unhelpfully doesn't enforce (for now...). Change 3375797 on 2017/04/01 by Mark.Satterthwaite Nullability qualifiers to fix Mac build-farm compilation: perversely this is not a problem for local builds... Change 3375798 on 2017/04/01 by Mark.Satterthwaite Fix the first mis-merge in ParticleGpuSimulation - these changes clearly weren't properly resolved in the task-stream. Change 3375835 on 2017/04/01 by Mark.Satterthwaite Try again with nullability and fix the occlusion changes as the PSO work wasn't merged correctly. Change 3376143 on 2017/04/02 by Mark.Satterthwaite Switch back to flat dSYMs for Dev-Rendering - they don't work with Instruments etc. but they are required by our build system. Change 3376324 on 2017/04/03 by Chris.Bunner Fixed cvar re-registration log spam and flagged a testing-only cvar as such. Change 3376726 on 2017/04/03 by Benjamin.Hyder Submitting initial HDR test map (WIP) Change 3376756 on 2017/04/03 by Guillaume.Abadie Fixes scene captures ordering's backward compatibility. Before, 2d scene captures were rendered before cube scene captures. The CaptureSortPriority broke backward compatibility by settings this new member to 0 in the USceneCaptureComponent's constructor. Since it is a higher come first policy, this CL set the default of this value to 1 in USceneCaptureComponent2D's constructor. Change 3377378 on 2017/04/03 by Arne.Schober DR - Fix ShaderRecompiling over and over again #RB Chris.Bunner Change 3377512 on 2017/04/03 by Daniel.Wright [Copy] Fixed profilegpu in d3d12 - initialize FLongGPUTaskPS when it is safe to do so, and fixed FSlateRHIRenderer's incorrect usage of draw events Change 3377518 on 2017/04/03 by Daniel.Wright [Copy] Distance field atlas coalesces updates to reduce RHIUpdateTexture3D memory overhead on d3d12 Change 3377526 on 2017/04/03 by Daniel.Wright [Copy] "Ran out of GPU queries!" log only happens once Change 3377535 on 2017/04/03 by Daniel.Wright [Copy] Fixed unreferenced local variable Change 3377539 on 2017/04/03 by Daniel.Wright [Copy] Xbox One RHIGetResourceInfo takes ESRAM into account - fixes render target pool 'VRamInKB request failed' messages Change 3377546 on 2017/04/03 by Daniel.Wright [Copy] Added r.LightMaxDrawDistanceScale for local light scalability Change 3377553 on 2017/04/03 by Daniel.Wright [Copy] Removed NEW_ESRAM_ALLOCATOR define and old unused path Change 3377560 on 2017/04/03 by Daniel.Wright [Copy] Fixed two d3d12 refcounting bugs causing -norhithread crashes Change 3377565 on 2017/04/03 by Daniel.Wright [Copy] Fixed Xbox One deleting GPU resources before the GPU is done reading from them (GRHINeedsExtraDeletionLatency was false) Change 3377572 on 2017/04/03 by Daniel.Wright [Copy] Disabled point / spot lights with MaxDrawDistance on LowPC Change 3377586 on 2017/04/03 by Daniel.Wright Fixed compile error Change 3377699 on 2017/04/03 by David.Hill FFT Code. Moved over from raven and refactored #review-3374589 @guillaume.abadie Change 3377910 on 2017/04/03 by David.Hill GPU FFT: Fix Linux Build adding a missing template<> to an IMPLEMENT_SHADER_TYPE Change 3378751 on 2017/04/04 by Marcus.Wassmer HQ particle lights now spawn attached to the same socket as their parent module. Change 3378819 on 2017/04/04 by Richard.Wallis Should be no need to protect shader cache against RHI thread now. Change 3378823 on 2017/04/04 by Richard.Wallis FRHIShaderLibrary Opaque Type - Base FRHIShaderLibrary has no Create*Shader functions and is passed to Overloaded RHICreate*Shader functions instead of creation directly through the library. - Assumed that only Native libraries will end up in the RHICreate*Shader functions. - ShaderCache and ShaderCode Libraries now inherit from a common factory interface. Change 3378883 on 2017/04/04 by Arne.Schober DR - Fix DCC build Change 3378885 on 2017/04/04 by Richard.Wallis Metal resource cast compile fix post merge. Change 3378946 on 2017/04/04 by Chris.Bunner SM4 assert fix. Change 3378953 on 2017/04/04 by Chris.Bunner Fixed type-correctness on legacy BreakMA material nodes and set more flexible formats to global attributes which should result in much more forgiving graphs for users. Allowed material nodes to opt out of mask-based pin coloration. #tests Compiled most Paragon materials + QAGame test maps. #jira UE-39885 Change 3379189 on 2017/04/04 by Arne.Schober DR - Fix aftermath staging Change 3379229 on 2017/04/04 by Arne.Schober DR - Fix missing include Change 3379374 on 2017/04/04 by Mark.Satterthwaite Revert an accidentally merged change in MacPlatformProcess that relies on further changes from the Metal task stream. Change 3379505 on 2017/04/04 by Rolando.Caloca DR - Fix mismatched interpolators Change 3379539 on 2017/04/04 by Mark.Satterthwaite No FFT for any hlslcc platform - the IR for one or more RWTexture2D isn't quite right... #jira UE-43626 Change 3379561 on 2017/04/04 by Rolando.Caloca DR - Fix root signature issues on D3D12 PC Change 3379590 on 2017/04/04 by Mark.Satterthwaite Back out changelist 3379539 & change the shader slightly instead, the HLSLCC library generates bogus IR when you have an inout RWTexture. #jira UE-43626 Change 3379917 on 2017/04/04 by Uriel.Doyon Fix to input mismatch Change 3380578 on 2017/04/05 by Chris.Bunner Shader type fixes. #jira UE-43652 Change 3380639 on 2017/04/05 by Rolando.Caloca DR - Expose GetOrCreate PSO and document Change 3380821 on 2017/04/05 by Guillaume.Abadie Fixes a crash in USceneCaptureComponent::UpdateDeferredCaptures() #jira UE-43642 Change 3381092 on 2017/04/05 by Guillaume.Abadie Cherry pick 3362517: Implements TAA's scene color unpremultiplication from alpha channel to reduce DOF alpha channel temporal ghosting. This CL take the oportunity to transform AA_ALPHA to an compile time enumeration, and add a basic TAA compile time configuration validation to improve readability of the different TAA passes' configurations. Change 3381300 on 2017/04/05 by Mark.Satterthwaite Quick fix for changes to MetalRHI's render-thread safe texture creation not correctly handling AVFoundation video player handing us an IOSurface. #jira UE-43597 Change3381359on 2017/04/05 by Guillaume.Abadie Back out changelist 3381092 Change 3381421 on 2017/04/05 by Mark.Satterthwaite Amended CL #3380995 from Richard Wallis to address crash in the Material Editor under the validation layer - when there are no textures bound the default pass descriptor assigns store actions, which means we can't override them with our deferred store actions. #jira UE-43689 Change 3381422 on 2017/04/05 by Mark.Satterthwaite Absolute time queries can't be batched in Metal but I also can't rely on them being started with a call to BeginQuery - only EndQuery. #jira UE-43691 Change3381503on 2017/04/05 by Daniel.Wright More intuitive controls for Volumetric Fog * Removed ScatteringScale / AbsorptionScale on Exponential Height Fog and added Albedo / Extinction * InscatteringColorCubemap is now supported by Volumetric Fog * Particle lights have a default VolumetricScatteringIntensity of 0 to avoid trailing * Tweaked GVolumetricFogDepthDistributionScale better for nearby details * Volume Materials have twice the interpolators available Change 3381527 on 2017/04/05 by Mark.Satterthwaite Disable Private GPU storage for PVRTC texture formats on iOS Metal - these require more changes to the blit-encoder usage as PVRTC has strange requirements. Change 3381671 on 2017/04/05 by Mark.Satterthwaite Better error message for failure to compile shaders remotely from PC for Metal. Change 3381769 on 2017/04/05 by Rolando.Caloca DR - Added lock texture array 2d on Vulkan Change 3382003 on 2017/04/05 by Mark.Satterthwaite Remove the automatic Metal aliasing/re-use when releasing some resource types as it doesn't work as intended. Change 3382030 on 2017/04/05 by Zachary.Wilson Fix compiling Metal text shaders from PC broken in merge from task stream. #submitter mark.satterthwaite #jira UE-43652 Change 3382880 on 2017/04/06 by Mark.Satterthwaite Michael Trepka's CL #3379927: VolumetricFogVoxelization implementation for Mac Change 3383315 on 2017/04/06 by Mark.Satterthwaite Partially revert CL #3382003 - the emulated Metal heaps require invoking makeAliasable in order to reclaim memory. #jira UE-43739 Change 3384639 on 2017/04/07 by Marcus.Wassmer Move ShaderResource version bump to RenderingObjectVersion Change 3384704 on 2017/04/07 by Mark.Satterthwaite Compile fix for merge. Change 3384933 on 2017/04/07 by Rolando.Caloca DR - Fix skin cache crash with BP (copy 3384714) Change 3385104 on 2017/04/07 by Mark.Satterthwaite Fix MetalRHI's abs(int2) handling - it can't be translated to fabs(int2) as that won't compile. Also rebuild hlslcc for my sanity. #jira UE-43783 Change 3385105 on 2017/04/07 by Mark.Satterthwaite Force a shader rebuild to ensure that everybody picks up the fix for #jira UE-43783 #jira UE-43783 Change 3385118 on 2017/04/07 by Arne.Schober DR - [OR-37359] - Fix disapearing Decals when StencilLod Fade is enabled #RB none Change 3385149 on 2017/04/07 by Marcus.Wassmer Fix skincache motion blur Change 3385189 on 2017/04/07 by Rolando.Caloca DR - Fix swapchain format for editor on Vulkan Change 3385287 on 2017/04/07 by Mark.Satterthwaite Enable SM5 on Intel as of 10.12.4 and later. Change 3385347 on 2017/04/07 by Rolando.Caloca DR - Temp fix for GL4 corruption on editor #jira UE-43785 Change 3385363 on 2017/04/07 by Rolando.Caloca DR - Actually fix all win platforms for GL bug #jira UE-43785 Change 3385557 on 2017/04/07 by Arne.Schober DR - [UE-43205] - Fix mesh paint #RB none Change3385608on 2017/04/07 by Daniel.Wright Fixed SampleCmp being used on a non-depth texture, causing a d3d error Change 3385980 on 2017/04/10 by Rolando.Caloca DR - Remove transition functions RHIClearColor* RHIClearDepthStencilTexture Change 3386042 on 2017/04/10 by Rolando.Caloca DR - Fix metal merge issue Change 3386157 on 2017/04/10 by Rolando.Caloca DR - Remove VS2013 libs generation off hlslcc & glslang (to match main) Change 3386356 on 2017/04/10 by Chris.Bunner Resolving merge errors. Change 3386414 on 2017/04/10 by Chris.Bunner Resolved merge issue in RendererScene.cpp. Change 3386700 on 2017/04/10 by Mark.Satterthwaite Silence documentation warnings. Change 3387178 on 2017/04/10 by Chris.Bunner Removed invalid mask correction on MakeMA material nodes. Change 3388177 on 2017/04/11 by Marcus.Wassmer Disable ensure that is no longer relevant now that we bind clear colors on texture creation Change 3388261 on 2017/04/11 by Chris.Bunner Static analysis fix. [CL3388266by Chris Bunner in Main branch]
3229 lines
117 KiB
C++
3229 lines
117 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
SceneVisibility.cpp: Scene visibility determination.
|
|
=============================================================================*/
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "HAL/ThreadSafeCounter.h"
|
|
#include "Stats/Stats.h"
|
|
#include "Misc/MemStack.h"
|
|
#include "HAL/IConsoleManager.h"
|
|
#include "Misc/App.h"
|
|
#include "Async/TaskGraphInterfaces.h"
|
|
#include "EngineDefines.h"
|
|
#include "EngineGlobals.h"
|
|
#include "RHIDefinitions.h"
|
|
#include "SceneTypes.h"
|
|
#include "SceneInterface.h"
|
|
#include "RendererInterface.h"
|
|
#include "PrimitiveViewRelevance.h"
|
|
#include "MaterialShared.h"
|
|
#include "SceneManagement.h"
|
|
#include "ScenePrivateBase.h"
|
|
#include "PostProcess/SceneRenderTargets.h"
|
|
#include "SceneCore.h"
|
|
#include "LightSceneInfo.h"
|
|
#include "SceneRendering.h"
|
|
#include "DeferredShadingRenderer.h"
|
|
#include "DynamicPrimitiveDrawing.h"
|
|
#include "ScenePrivate.h"
|
|
#include "FXSystem.h"
|
|
#include "PostProcess/PostProcessing.h"
|
|
|
|
/*------------------------------------------------------------------------------
|
|
Globals
|
|
------------------------------------------------------------------------------*/
|
|
|
|
static float GWireframeCullThreshold = 5.0f;
|
|
static FAutoConsoleVariableRef CVarWireframeCullThreshold(
|
|
TEXT("r.WireframeCullThreshold"),
|
|
GWireframeCullThreshold,
|
|
TEXT("Threshold below which objects in ortho wireframe views will be culled."),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
float GMinScreenRadiusForLights = 0.03f;
|
|
static FAutoConsoleVariableRef CVarMinScreenRadiusForLights(
|
|
TEXT("r.MinScreenRadiusForLights"),
|
|
GMinScreenRadiusForLights,
|
|
TEXT("Threshold below which lights will be culled."),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
float GMinScreenRadiusForDepthPrepass = 0.03f;
|
|
static FAutoConsoleVariableRef CVarMinScreenRadiusForDepthPrepass(
|
|
TEXT("r.MinScreenRadiusForDepthPrepass"),
|
|
GMinScreenRadiusForDepthPrepass,
|
|
TEXT("Threshold below which meshes will be culled from depth only pass."),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
float GMinScreenRadiusForCSMDepth = 0.01f;
|
|
static FAutoConsoleVariableRef CVarMinScreenRadiusForCSMDepth(
|
|
TEXT("r.MinScreenRadiusForCSMDepth"),
|
|
GMinScreenRadiusForCSMDepth,
|
|
TEXT("Threshold below which meshes will be culled from CSM depth pass."),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
static TAutoConsoleVariable<int32> CVarTemporalAASamples(
|
|
TEXT("r.TemporalAASamples"),
|
|
8,
|
|
TEXT("Number of jittered positions for temporal AA (4, 8=default, 16, 32, 64)."),
|
|
ECVF_RenderThreadSafe);
|
|
|
|
#if PLATFORM_MAC // @todo: disabled until rendering problems with HZB occlusion in OpenGL are solved
|
|
static int32 GHZBOcclusion = 0;
|
|
#else
|
|
static int32 GHZBOcclusion = 0;
|
|
#endif
|
|
static FAutoConsoleVariableRef CVarHZBOcclusion(
|
|
TEXT("r.HZBOcclusion"),
|
|
GHZBOcclusion,
|
|
TEXT("Defines which occlusion system is used.\n")
|
|
TEXT(" 0: Hardware occlusion queries\n")
|
|
TEXT(" 1: Use HZB occlusion system (default, less GPU and CPU cost, more conservative results)")
|
|
TEXT(" 2: Force HZB occlusion system (overrides rendering platform preferences)"),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
static int32 GVisualizeOccludedPrimitives = 0;
|
|
static FAutoConsoleVariableRef CVarVisualizeOccludedPrimitives(
|
|
TEXT("r.VisualizeOccludedPrimitives"),
|
|
GVisualizeOccludedPrimitives,
|
|
TEXT("Draw boxes for all occluded primitives"),
|
|
ECVF_RenderThreadSafe | ECVF_Cheat
|
|
);
|
|
|
|
static int32 GAllowSubPrimitiveQueries = 1;
|
|
static FAutoConsoleVariableRef CVarAllowSubPrimitiveQueries(
|
|
TEXT("r.AllowSubPrimitiveQueries"),
|
|
GAllowSubPrimitiveQueries,
|
|
TEXT("Enables sub primitive queries, currently only used by hierarchical instanced static meshes. 1: Enable, 0 Disabled. When disabled, one query is used for the entire proxy."),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
static TAutoConsoleVariable<float> CVarStaticMeshLODDistanceScale(
|
|
TEXT("r.StaticMeshLODDistanceScale"),
|
|
1.0f,
|
|
TEXT("Scale factor for the distance used in computing discrete LOD for static meshes. (defaults to 1)\n")
|
|
TEXT("(higher values make LODs transition earlier, e.g., 2 is twice as fast / half the distance)"),
|
|
ECVF_Scalability | ECVF_RenderThreadSafe);
|
|
|
|
static TAutoConsoleVariable<float> CVarHLODDistanceScale(
|
|
TEXT("r.HLOD.DistanceScale"),
|
|
1.0f,
|
|
TEXT("Scale factor for the distance used in computing discrete HLOD for transition for static meshes. (defaults to 1)\n")
|
|
TEXT("(higher values make HLODs transition farther away, e.g., 2 is twice the distance)"),
|
|
ECVF_Scalability | ECVF_RenderThreadSafe);
|
|
|
|
static int32 GOcclusionCullParallelPrimFetch = 0;
|
|
static FAutoConsoleVariableRef CVarOcclusionCullParallelPrimFetch(
|
|
TEXT("r.OcclusionCullParallelPrimFetch"),
|
|
GOcclusionCullParallelPrimFetch,
|
|
TEXT("Enables Parallel Occlusion Cull primitive fetch."),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
static int32 GILCUpdatePrimTaskEnabled = 0;
|
|
static FAutoConsoleVariableRef CVarILCUpdatePrimitivesTask(
|
|
TEXT("r.Cache.UpdatePrimsTaskEnabled"),
|
|
GILCUpdatePrimTaskEnabled,
|
|
TEXT("Enable threading for ILC primitive update. Will overlap with the rest the end of InitViews."),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
static int32 GDoInitViewsLightingAfterPrepass = 0;
|
|
static FAutoConsoleVariableRef CVarDoInitViewsLightingAfterPrepass(
|
|
TEXT("r.DoInitViewsLightingAfterPrepass"),
|
|
GDoInitViewsLightingAfterPrepass,
|
|
TEXT("Delays the lighting part of InitViews until after the prepass. This improves the threading throughput and gets the prepass to the GPU ASAP. Experimental options; has an unknown race."),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
/** Distance fade cvars */
|
|
static int32 GDisableLODFade = false;
|
|
static FAutoConsoleVariableRef CVarDisableLODFade( TEXT("r.DisableLODFade"), GDisableLODFade, TEXT("Disable fading for distance culling"), ECVF_RenderThreadSafe );
|
|
|
|
static float GFadeTime = 0.25f;
|
|
static FAutoConsoleVariableRef CVarLODFadeTime( TEXT("r.LODFadeTime"), GFadeTime, TEXT("How long LOD takes to fade (in seconds)."), ECVF_RenderThreadSafe );
|
|
|
|
static float GDistanceFadeMaxTravel = 1000.0f;
|
|
static FAutoConsoleVariableRef CVarDistanceFadeMaxTravel( TEXT("r.DistanceFadeMaxTravel"), GDistanceFadeMaxTravel, TEXT("Max distance that the player can travel during the fade time."), ECVF_RenderThreadSafe );
|
|
|
|
|
|
static TAutoConsoleVariable<int32> CVarParallelInitViews(
|
|
TEXT("r.ParallelInitViews"),
|
|
#if WITH_EDITOR
|
|
0,
|
|
#else
|
|
1,
|
|
#endif
|
|
TEXT("Toggles parallel init views. 0 = off; 1 = on"),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
float GLightMaxDrawDistanceScale = 1.0f;
|
|
static FAutoConsoleVariableRef CVarLightMaxDrawDistanceScale(
|
|
TEXT("r.LightMaxDrawDistanceScale"),
|
|
GLightMaxDrawDistanceScale,
|
|
TEXT("Scale applied to the MaxDrawDistance of lights. Useful for fading out local lights more aggressively on some platforms."),
|
|
ECVF_Scalability | ECVF_RenderThreadSafe
|
|
);
|
|
|
|
/*------------------------------------------------------------------------------
|
|
Visibility determination.
|
|
------------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
* Update a primitive's fading state.
|
|
* @param FadingState - State to update.
|
|
* @param View - The view for which to update.
|
|
* @param bVisible - Whether the primitive should be visible in the view.
|
|
*/
|
|
static void UpdatePrimitiveFadingState(FPrimitiveFadingState& FadingState, FViewInfo& View, bool bVisible)
|
|
{
|
|
if (FadingState.bValid)
|
|
{
|
|
if (FadingState.bIsVisible != bVisible)
|
|
{
|
|
float CurrentRealTime = View.Family->CurrentRealTime;
|
|
|
|
// Need to kick off a fade, so make sure that we have fading state for that
|
|
if( !IsValidRef(FadingState.UniformBuffer) )
|
|
{
|
|
// Primitive is not currently fading. Start a new fade!
|
|
FadingState.EndTime = CurrentRealTime + GFadeTime;
|
|
|
|
if( bVisible )
|
|
{
|
|
// Fading in
|
|
// (Time - StartTime) / FadeTime
|
|
FadingState.FadeTimeScaleBias.X = 1.0f / GFadeTime;
|
|
FadingState.FadeTimeScaleBias.Y = -CurrentRealTime / GFadeTime;
|
|
}
|
|
else
|
|
{
|
|
// Fading out
|
|
// 1 - (Time - StartTime) / FadeTime
|
|
FadingState.FadeTimeScaleBias.X = -1.0f / GFadeTime;
|
|
FadingState.FadeTimeScaleBias.Y = 1.0f + CurrentRealTime / GFadeTime;
|
|
}
|
|
|
|
FDistanceCullFadeUniformShaderParameters Uniforms;
|
|
Uniforms.FadeTimeScaleBias = FadingState.FadeTimeScaleBias;
|
|
FadingState.UniformBuffer = FDistanceCullFadeUniformBufferRef::CreateUniformBufferImmediate( Uniforms, UniformBuffer_MultiFrame );
|
|
}
|
|
else
|
|
{
|
|
// Reverse fading direction but maintain current opacity
|
|
// Solve for d: a*x+b = -a*x+d
|
|
FadingState.FadeTimeScaleBias.Y = 2.0f * CurrentRealTime * FadingState.FadeTimeScaleBias.X + FadingState.FadeTimeScaleBias.Y;
|
|
FadingState.FadeTimeScaleBias.X = -FadingState.FadeTimeScaleBias.X;
|
|
|
|
if( bVisible )
|
|
{
|
|
// Fading in
|
|
// Solve for x: a*x+b = 1
|
|
FadingState.EndTime = ( 1.0f - FadingState.FadeTimeScaleBias.Y ) / FadingState.FadeTimeScaleBias.X;
|
|
}
|
|
else
|
|
{
|
|
// Fading out
|
|
// Solve for x: a*x+b = 0
|
|
FadingState.EndTime = -FadingState.FadeTimeScaleBias.Y / FadingState.FadeTimeScaleBias.X;
|
|
}
|
|
|
|
FDistanceCullFadeUniformShaderParameters Uniforms;
|
|
Uniforms.FadeTimeScaleBias = FadingState.FadeTimeScaleBias;
|
|
FadingState.UniformBuffer = FDistanceCullFadeUniformBufferRef::CreateUniformBufferImmediate( Uniforms, UniformBuffer_MultiFrame );
|
|
}
|
|
}
|
|
}
|
|
|
|
FadingState.FrameNumber = View.Family->FrameNumber;
|
|
FadingState.bIsVisible = bVisible;
|
|
FadingState.bValid = true;
|
|
}
|
|
|
|
bool FViewInfo::IsDistanceCulled( float DistanceSquared, float MinDrawDistance, float InMaxDrawDistance, const FPrimitiveSceneInfo* PrimitiveSceneInfo)
|
|
{
|
|
float MaxDrawDistanceScale = GetCachedScalabilityCVars().ViewDistanceScale;
|
|
float FadeRadius = GDisableLODFade ? 0.0f : GDistanceFadeMaxTravel;
|
|
float MaxDrawDistance = InMaxDrawDistance * MaxDrawDistanceScale;
|
|
|
|
// If cull distance is disabled, always show (except foliage)
|
|
if (Family->EngineShowFlags.DistanceCulledPrimitives
|
|
&& !PrimitiveSceneInfo->Proxy->IsDetailMesh())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// The primitive is always culled if it exceeds the max fade distance.
|
|
if (DistanceSquared > FMath::Square(MaxDrawDistance + FadeRadius) ||
|
|
DistanceSquared < FMath::Square(MinDrawDistance))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
const bool bDistanceCulled = (DistanceSquared > FMath::Square(MaxDrawDistance));
|
|
const bool bMayBeFading = (DistanceSquared > FMath::Square(MaxDrawDistance - FadeRadius));
|
|
|
|
bool bStillFading = false;
|
|
if( !GDisableLODFade && bMayBeFading && State != NULL && !bDisableDistanceBasedFadeTransitions )
|
|
{
|
|
// Update distance-based visibility and fading state if it has not already been updated.
|
|
int32 PrimitiveIndex = PrimitiveSceneInfo->GetIndex();
|
|
FRelativeBitReference PrimitiveBit(PrimitiveIndex);
|
|
if (PotentiallyFadingPrimitiveMap.AccessCorrespondingBit(PrimitiveBit) == false)
|
|
{
|
|
FPrimitiveFadingState& FadingState = ((FSceneViewState*)State)->PrimitiveFadingStates.FindOrAdd(PrimitiveSceneInfo->PrimitiveComponentId);
|
|
UpdatePrimitiveFadingState(FadingState, *this, !bDistanceCulled);
|
|
FUniformBufferRHIParamRef UniformBuffer = FadingState.UniformBuffer;
|
|
bStillFading = (UniformBuffer != NULL);
|
|
PrimitiveFadeUniformBuffers[PrimitiveIndex] = UniformBuffer;
|
|
PotentiallyFadingPrimitiveMap.AccessCorrespondingBit(PrimitiveBit) = true;
|
|
}
|
|
}
|
|
|
|
// If we're still fading then make sure the object is still drawn, even if it's beyond the max draw distance
|
|
return ( bDistanceCulled && !bStillFading );
|
|
}
|
|
|
|
static int32 FrustumCullNumWordsPerTask = 128;
|
|
static FAutoConsoleVariableRef CVarFrustumCullNumWordsPerTask(
|
|
TEXT("r.FrustumCullNumWordsPerTask"),
|
|
FrustumCullNumWordsPerTask,
|
|
TEXT("Performance tweak. Controls the granularity for the ParallelFor for frustum culling."),
|
|
ECVF_Default
|
|
);
|
|
|
|
template<bool UseCustomCulling, bool bAlsoUseSphereTest>
|
|
static int32 FrustumCull(const FScene* Scene, FViewInfo& View)
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_FrustumCull);
|
|
|
|
FThreadSafeCounter NumCulledPrimitives;
|
|
float MaxDrawDistanceScale = GetCachedScalabilityCVars().ViewDistanceScale;
|
|
|
|
//Primitives per ParallelFor task
|
|
//Using async FrustumCull. Thanks Yager! See https://udn.unrealengine.com/questions/252385/performance-of-frustumcull.html
|
|
//Performance varies on total primitive count and tasks scheduled. Check the mentioned link above for some measurements.
|
|
//There have been some changes as compared to the code measured in the link
|
|
|
|
const int32 BitArrayNum = View.PrimitiveVisibilityMap.Num();
|
|
const int32 BitArrayWords = FMath::DivideAndRoundUp(View.PrimitiveVisibilityMap.Num(), (int32)NumBitsPerDWORD);
|
|
const int32 NumTasks = FMath::DivideAndRoundUp(BitArrayWords, FrustumCullNumWordsPerTask);
|
|
|
|
ParallelFor(NumTasks,
|
|
[&NumCulledPrimitives, Scene, &View, MaxDrawDistanceScale](int32 TaskIndex)
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_FrustumCull_Loop);
|
|
const int32 BitArrayNumInner = View.PrimitiveVisibilityMap.Num();
|
|
FVector ViewOriginForDistanceCulling = View.ViewMatrices.GetViewOrigin();
|
|
float FadeRadius = GDisableLODFade ? 0.0f : GDistanceFadeMaxTravel;
|
|
uint8 CustomVisibilityFlags = EOcclusionFlags::CanBeOccluded | EOcclusionFlags::HasPrecomputedVisibility;
|
|
|
|
// Primitives may be explicitly removed from stereo views when using mono
|
|
const bool UseMonoCulling = View.Family->IsMonoscopicFarFieldEnabled() && (View.StereoPass == eSSP_LEFT_EYE || View.StereoPass == eSSP_RIGHT_EYE);
|
|
|
|
const int32 TaskWordOffset = TaskIndex * FrustumCullNumWordsPerTask;
|
|
|
|
for (int32 WordIndex = TaskWordOffset; WordIndex < TaskWordOffset + FrustumCullNumWordsPerTask && WordIndex * NumBitsPerDWORD < BitArrayNumInner; WordIndex++)
|
|
{
|
|
uint32 Mask = 0x1;
|
|
uint32 VisBits = 0;
|
|
uint32 FadingBits = 0;
|
|
for (int32 BitSubIndex = 0; BitSubIndex < NumBitsPerDWORD && WordIndex * NumBitsPerDWORD + BitSubIndex < BitArrayNumInner; BitSubIndex++, Mask <<= 1)
|
|
{
|
|
int32 Index = WordIndex * NumBitsPerDWORD + BitSubIndex;
|
|
const FPrimitiveBounds& Bounds = Scene->PrimitiveBounds[Index];
|
|
float DistanceSquared = (Bounds.Origin - ViewOriginForDistanceCulling).SizeSquared();
|
|
float MaxDrawDistance = Bounds.MaxDrawDistance * MaxDrawDistanceScale;
|
|
int32 VisibilityId = INDEX_NONE;
|
|
|
|
if (UseCustomCulling &&
|
|
((Scene->PrimitiveOcclusionFlags[Index] & CustomVisibilityFlags) == CustomVisibilityFlags))
|
|
{
|
|
VisibilityId = Scene->PrimitiveVisibilityIds[Index].ByteIndex;
|
|
}
|
|
|
|
// If cull distance is disabled, always show (except foliage)
|
|
if (View.Family->EngineShowFlags.DistanceCulledPrimitives
|
|
&& !Scene->Primitives[Index]->Proxy->IsDetailMesh())
|
|
{
|
|
MaxDrawDistance = FLT_MAX;
|
|
}
|
|
|
|
if (DistanceSquared > FMath::Square(MaxDrawDistance + FadeRadius) ||
|
|
(DistanceSquared < Bounds.MinDrawDistanceSq) ||
|
|
(UseCustomCulling && !View.CustomVisibilityQuery->IsVisible(VisibilityId, FBoxSphereBounds(Bounds.Origin, Bounds.BoxExtent, Bounds.SphereRadius))) ||
|
|
(bAlsoUseSphereTest && View.ViewFrustum.IntersectSphere(Bounds.Origin, Bounds.SphereRadius) == false) ||
|
|
View.ViewFrustum.IntersectBox(Bounds.Origin, Bounds.BoxExtent) == false ||
|
|
(UseMonoCulling && Scene->Primitives[Index]->Proxy->RenderInMono()))
|
|
{
|
|
STAT(NumCulledPrimitives.Increment());
|
|
}
|
|
else
|
|
{
|
|
if (DistanceSquared > FMath::Square(MaxDrawDistance))
|
|
{
|
|
FadingBits |= Mask;
|
|
}
|
|
else
|
|
{
|
|
// The primitive is visible!
|
|
VisBits |= Mask;
|
|
if (DistanceSquared > FMath::Square(MaxDrawDistance - FadeRadius))
|
|
{
|
|
FadingBits |= Mask;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (FadingBits)
|
|
{
|
|
check(!View.PotentiallyFadingPrimitiveMap.GetData()[WordIndex]); // this should start at zero
|
|
View.PotentiallyFadingPrimitiveMap.GetData()[WordIndex] = FadingBits;
|
|
}
|
|
if (VisBits)
|
|
{
|
|
check(!View.PrimitiveVisibilityMap.GetData()[WordIndex]); // this should start at zero
|
|
View.PrimitiveVisibilityMap.GetData()[WordIndex] = VisBits;
|
|
}
|
|
}
|
|
},
|
|
!FApp::ShouldUseThreadingForPerformance() || (UseCustomCulling && !View.CustomVisibilityQuery->IsThreadsafe()) || CVarParallelInitViews.GetValueOnRenderThread() == 0
|
|
);
|
|
|
|
return NumCulledPrimitives.GetValue();
|
|
}
|
|
|
|
/**
|
|
* Updated primitive fading states for the view.
|
|
*/
|
|
static void UpdatePrimitiveFading(const FScene* Scene, FViewInfo& View)
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_UpdatePrimitiveFading);
|
|
|
|
FSceneViewState* ViewState = (FSceneViewState*)View.State;
|
|
|
|
if (ViewState)
|
|
{
|
|
uint32 PrevFrameNumber = ViewState->PrevFrameNumber;
|
|
float CurrentRealTime = View.Family->CurrentRealTime;
|
|
|
|
// First clear any stale fading states.
|
|
for (FPrimitiveFadingStateMap::TIterator It(ViewState->PrimitiveFadingStates); It; ++It)
|
|
{
|
|
FPrimitiveFadingState& FadingState = It.Value();
|
|
if (FadingState.FrameNumber != PrevFrameNumber ||
|
|
(IsValidRef(FadingState.UniformBuffer) && CurrentRealTime >= FadingState.EndTime))
|
|
{
|
|
It.RemoveCurrent();
|
|
}
|
|
}
|
|
|
|
// Should we allow fading transitions at all this frame? For frames where the camera moved
|
|
// a large distance or where we haven't rendered a view in awhile, it's best to disable
|
|
// fading so users don't see unexpected object transitions.
|
|
if (!GDisableLODFade && !View.bDisableDistanceBasedFadeTransitions)
|
|
{
|
|
// Do a pass over potentially fading primitives and update their states.
|
|
for (FSceneSetBitIterator BitIt(View.PotentiallyFadingPrimitiveMap); BitIt; ++BitIt)
|
|
{
|
|
bool bVisible = View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt);
|
|
FPrimitiveFadingState& FadingState = ViewState->PrimitiveFadingStates.FindOrAdd(Scene->PrimitiveComponentIds[BitIt.GetIndex()]);
|
|
UpdatePrimitiveFadingState(FadingState, View, bVisible);
|
|
FUniformBufferRHIParamRef UniformBuffer = FadingState.UniformBuffer;
|
|
if (UniformBuffer && !bVisible)
|
|
{
|
|
// If the primitive is fading out make sure it remains visible.
|
|
View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt) = true;
|
|
}
|
|
View.PrimitiveFadeUniformBuffers[BitIt.GetIndex()] = UniformBuffer;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct FOcclusionBounds
|
|
{
|
|
FOcclusionBounds(FPrimitiveOcclusionHistory* InPrimitiveOcclusionHistory, const FVector& InBoundsOrigin, const FVector& InBoundsExtent, bool bInGroupedQuery)
|
|
: PrimitiveOcclusionHistory(InPrimitiveOcclusionHistory)
|
|
, BoundsOrigin(InBoundsOrigin)
|
|
, BoundsExtent(InBoundsExtent)
|
|
, bGroupedQuery(bInGroupedQuery)
|
|
{}
|
|
FPrimitiveOcclusionHistory* PrimitiveOcclusionHistory;
|
|
FVector BoundsOrigin;
|
|
FVector BoundsExtent;
|
|
bool bGroupedQuery;
|
|
};
|
|
|
|
struct FHZBBound
|
|
{
|
|
FHZBBound(FPrimitiveOcclusionHistory* InTargetHistory, const FVector& InBoundsOrigin, const FVector& InBoundsExtent)
|
|
: TargetHistory(InTargetHistory)
|
|
, BoundsOrigin(InBoundsOrigin)
|
|
, BoundsExtent(InBoundsExtent)
|
|
{}
|
|
|
|
FPrimitiveOcclusionHistory* TargetHistory;
|
|
FVector BoundsOrigin;
|
|
FVector BoundsExtent;
|
|
};
|
|
|
|
#define BALANCE_LOAD 1
|
|
#define QUERY_SANITY_CHECK 0
|
|
|
|
struct FVisForPrimParams
|
|
{
|
|
FVisForPrimParams(){}
|
|
|
|
FVisForPrimParams(const FScene* InScene,
|
|
FViewInfo* InView,
|
|
FViewElementPDI* InOcclusionPDI,
|
|
const int32 InStartIndex,
|
|
const int32 InNumToProcess,
|
|
const bool bInSubmitQueries,
|
|
const bool bInHZBOcclusion,
|
|
TArray<FPrimitiveOcclusionHistory>* OutOcclusionHistory,
|
|
TArray<FPrimitiveOcclusionHistory*>* OutQueriesToRelease,
|
|
TArray<FHZBBound>* OutHZBBounds,
|
|
TArray<FOcclusionBounds>* OutQueriesToRun,
|
|
TArray<bool>* OutSubIsOccluded)
|
|
: Scene(InScene)
|
|
, View(InView)
|
|
, OcclusionPDI(InOcclusionPDI)
|
|
, StartIndex(InStartIndex)
|
|
, NumToProcess(InNumToProcess)
|
|
, bSubmitQueries(bInSubmitQueries)
|
|
, bHZBOcclusion(bInHZBOcclusion)
|
|
, InsertPrimitiveOcclusionHistory(OutOcclusionHistory)
|
|
, QueriesToRelease(OutQueriesToRelease)
|
|
, HZBBoundsToAdd(OutHZBBounds)
|
|
, QueriesToAdd(OutQueriesToRun)
|
|
, SubIsOccluded(OutSubIsOccluded)
|
|
{
|
|
|
|
}
|
|
|
|
void Init( const FScene* InScene,
|
|
FViewInfo* InView,
|
|
FViewElementPDI* InOcclusionPDI,
|
|
const int32 InStartIndex,
|
|
const int32 InNumToProcess,
|
|
const bool bInSubmitQueries,
|
|
const bool bInHZBOcclusion,
|
|
TArray<FPrimitiveOcclusionHistory>* OutOcclusionHistory,
|
|
TArray<FPrimitiveOcclusionHistory*>* OutQueriesToRelease,
|
|
TArray<FHZBBound>* OutHZBBounds,
|
|
TArray<FOcclusionBounds>* OutQueriesToRun,
|
|
TArray<bool>* OutSubIsOccluded)
|
|
|
|
{
|
|
Scene = InScene;
|
|
View = InView;
|
|
OcclusionPDI = InOcclusionPDI;
|
|
StartIndex = InStartIndex;
|
|
NumToProcess = InNumToProcess;
|
|
bSubmitQueries = bInSubmitQueries;
|
|
bHZBOcclusion = bInHZBOcclusion;
|
|
InsertPrimitiveOcclusionHistory = OutOcclusionHistory;
|
|
QueriesToRelease = OutQueriesToRelease;
|
|
HZBBoundsToAdd = OutHZBBounds;
|
|
QueriesToAdd = OutQueriesToRun;
|
|
SubIsOccluded = OutSubIsOccluded;
|
|
}
|
|
|
|
const FScene* Scene;
|
|
FViewInfo* View;
|
|
FViewElementPDI* OcclusionPDI;
|
|
int32 StartIndex;
|
|
int32 NumToProcess;
|
|
bool bSubmitQueries;
|
|
bool bHZBOcclusion;
|
|
|
|
//occlusion history to insert into. In parallel these will be all merged back into the view's history on the main thread.
|
|
//use TChunkedArray so pointers to the new FPrimitiveOcclusionHistory's won't change if the array grows.
|
|
TArray<FPrimitiveOcclusionHistory>* InsertPrimitiveOcclusionHistory;
|
|
TArray<FPrimitiveOcclusionHistory*>* QueriesToRelease;
|
|
TArray<FHZBBound>* HZBBoundsToAdd;
|
|
TArray<FOcclusionBounds>* QueriesToAdd;
|
|
int32 NumOccludedPrims;
|
|
TArray<bool>* SubIsOccluded;
|
|
};
|
|
|
|
//This function is shared between the single and multi-threaded versions. Modifications to any primitives indexed by BitIt should be ok
|
|
//since only one of the task threads will ever reference it. However, any modifications to shared state like the ViewState must be buffered
|
|
//to be recombined later.
|
|
template<bool bSingleThreaded>
|
|
static void FetchVisibilityForPrimitives_Range(FVisForPrimParams& Params)
|
|
{
|
|
int32 NumOccludedPrimitives = 0;
|
|
|
|
const FScene* Scene = Params.Scene;
|
|
FViewInfo& View = *Params.View;
|
|
FViewElementPDI* OcclusionPDI = Params.OcclusionPDI;
|
|
const int32 StartIndex = Params.StartIndex;
|
|
const int32 NumToProcess = Params.NumToProcess;
|
|
const bool bSubmitQueries = Params.bSubmitQueries;
|
|
const bool bHZBOcclusion = Params.bHZBOcclusion;
|
|
|
|
FSceneViewState* ViewState = (FSceneViewState*)View.State;
|
|
const int32 NumBufferedFrames = FOcclusionQueryHelpers::GetNumBufferedFrames();
|
|
const bool bClearQueries = !View.Family->EngineShowFlags.HitProxies;
|
|
const float CurrentRealTime = View.Family->CurrentRealTime;
|
|
uint32 OcclusionFrameCounter = ViewState->OcclusionFrameCounter;
|
|
FRenderQueryPool& OcclusionQueryPool = ViewState->OcclusionQueryPool;
|
|
FHZBOcclusionTester& HZBOcclusionTests = ViewState->HZBOcclusionTests;
|
|
|
|
|
|
TSet<FPrimitiveOcclusionHistory, FPrimitiveOcclusionHistoryKeyFuncs>& ViewPrimitiveOcclusionHistory = ViewState->PrimitiveOcclusionHistorySet;
|
|
TArray<FPrimitiveOcclusionHistory>* InsertPrimitiveOcclusionHistory = Params.InsertPrimitiveOcclusionHistory;
|
|
TArray<FPrimitiveOcclusionHistory*>* QueriesToRelease = Params.QueriesToRelease;
|
|
TArray<FHZBBound>* HZBBoundsToAdd = Params.HZBBoundsToAdd;
|
|
TArray<FOcclusionBounds>* QueriesToAdd = Params.QueriesToAdd;
|
|
|
|
const int32 ReserveAmount = NumToProcess;
|
|
if (!bSingleThreaded)
|
|
{
|
|
check(InsertPrimitiveOcclusionHistory);
|
|
check(QueriesToRelease);
|
|
check(HZBBoundsToAdd);
|
|
check(QueriesToAdd);
|
|
|
|
//avoid doing reallocs as much as possible. Unlikely to make an entry per processed element.
|
|
InsertPrimitiveOcclusionHistory->Reserve(ReserveAmount);
|
|
QueriesToRelease->Reserve(ReserveAmount);
|
|
HZBBoundsToAdd->Reserve(ReserveAmount);
|
|
QueriesToAdd->Reserve(ReserveAmount);
|
|
}
|
|
|
|
int32 NumProcessed = 0;
|
|
int32 NumTotalPrims = View.PrimitiveVisibilityMap.Num();
|
|
int32 NumTotalDefUnoccluded = View.PrimitiveDefinitelyUnoccludedMap.Num();
|
|
|
|
//if we are load balanced then we iterate only the set bits, and the ranges have been pre-selected to evenly distribute set bits among the tasks with no overlaps.
|
|
//if not, then the entire array is evenly divided by range.
|
|
#if BALANCE_LOAD
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap, StartIndex); BitIt && (NumProcessed < NumToProcess); ++BitIt, ++NumProcessed)
|
|
#else
|
|
for (TBitArray<SceneRenderingBitArrayAllocator>::FIterator BitIt(View.PrimitiveVisibilityMap, StartIndex); BitIt && (NumProcessed < NumToProcess); ++BitIt, ++NumProcessed)
|
|
#endif
|
|
{
|
|
uint8 OcclusionFlags = Scene->PrimitiveOcclusionFlags[BitIt.GetIndex()];
|
|
bool bCanBeOccluded = (OcclusionFlags & EOcclusionFlags::CanBeOccluded) != 0;
|
|
|
|
#if !BALANCE_LOAD
|
|
if (!View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt))
|
|
{
|
|
continue;
|
|
}
|
|
#endif
|
|
|
|
//we can't allow the prim history insertion array to realloc or it will invalidate pointers in the other output arrays.
|
|
const bool bCanAllocPrimHistory = bSingleThreaded || InsertPrimitiveOcclusionHistory->Num() < InsertPrimitiveOcclusionHistory->Max();
|
|
|
|
if (GIsEditor)
|
|
{
|
|
FPrimitiveSceneInfo* PrimitiveSceneInfo = Scene->Primitives[BitIt.GetIndex()];
|
|
|
|
if (PrimitiveSceneInfo->Proxy->IsSelected())
|
|
{
|
|
// to render occluded outline for selected objects
|
|
bCanBeOccluded = false;
|
|
}
|
|
}
|
|
int32 NumSubQueries = 1;
|
|
bool bSubQueries = false;
|
|
const TArray<FBoxSphereBounds>* SubBounds = nullptr;
|
|
|
|
check(Params.SubIsOccluded);
|
|
TArray<bool>& SubIsOccluded = *Params.SubIsOccluded;
|
|
int32 SubIsOccludedStart = SubIsOccluded.Num();
|
|
if ((OcclusionFlags & EOcclusionFlags::HasSubprimitiveQueries) && GAllowSubPrimitiveQueries)
|
|
{
|
|
FPrimitiveSceneProxy* Proxy = Scene->Primitives[BitIt.GetIndex()]->Proxy;
|
|
SubBounds = Proxy->GetOcclusionQueries(&View);
|
|
NumSubQueries = SubBounds->Num();
|
|
bSubQueries = true;
|
|
if (!NumSubQueries)
|
|
{
|
|
View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt) = false;
|
|
continue;
|
|
}
|
|
SubIsOccluded.Reserve(NumSubQueries);
|
|
}
|
|
|
|
bool bAllSubOcclusionStateIsDefinite = true;
|
|
bool bAllSubOccluded = true;
|
|
FPrimitiveComponentId PrimitiveId = Scene->PrimitiveComponentIds[BitIt.GetIndex()];
|
|
|
|
for (int32 SubQuery = 0; SubQuery < NumSubQueries; SubQuery++)
|
|
{
|
|
FPrimitiveOcclusionHistory* PrimitiveOcclusionHistory = ViewPrimitiveOcclusionHistory.Find(FPrimitiveOcclusionHistoryKey(PrimitiveId, SubQuery));
|
|
|
|
bool bIsOccluded = false;
|
|
bool bOcclusionStateIsDefinite = false;
|
|
|
|
if (!PrimitiveOcclusionHistory)
|
|
{
|
|
// If the primitive doesn't have an occlusion history yet, create it.
|
|
if (bSingleThreaded)
|
|
{
|
|
// In singlethreaded mode we can safely modify the view's history directly.
|
|
PrimitiveOcclusionHistory = &ViewPrimitiveOcclusionHistory[
|
|
ViewPrimitiveOcclusionHistory.Add(FPrimitiveOcclusionHistory(PrimitiveId, SubQuery))
|
|
];
|
|
}
|
|
else if (bCanAllocPrimHistory)
|
|
{
|
|
// In multithreaded mode we have to buffer the new histories and add them to the view during a post-combine
|
|
PrimitiveOcclusionHistory = &(*InsertPrimitiveOcclusionHistory)[
|
|
InsertPrimitiveOcclusionHistory->Add(FPrimitiveOcclusionHistory(PrimitiveId, SubQuery))
|
|
];
|
|
}
|
|
|
|
// If the primitive hasn't been visible recently enough to have a history, treat it as unoccluded this frame so it will be rendered as an occluder and its true occlusion state can be determined.
|
|
// already set bIsOccluded = false;
|
|
|
|
// Flag the primitive's occlusion state as indefinite, which will force it to be queried this frame.
|
|
// The exception is if the primitive isn't occludable, in which case we know that it's definitely unoccluded.
|
|
bOcclusionStateIsDefinite = bCanBeOccluded ? false : true;
|
|
}
|
|
else
|
|
{
|
|
if (View.bIgnoreExistingQueries)
|
|
{
|
|
// If the view is ignoring occlusion queries, the primitive is definitely unoccluded.
|
|
// already set bIsOccluded = false;
|
|
bOcclusionStateIsDefinite = View.bDisableQuerySubmissions;
|
|
}
|
|
else if (bCanBeOccluded)
|
|
{
|
|
if (bHZBOcclusion)
|
|
{
|
|
if (HZBOcclusionTests.IsValidFrame(PrimitiveOcclusionHistory->HZBTestFrameNumber))
|
|
{
|
|
bIsOccluded = !HZBOcclusionTests.IsVisible(PrimitiveOcclusionHistory->HZBTestIndex);
|
|
bOcclusionStateIsDefinite = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Read the occlusion query results.
|
|
uint64 NumSamples = 0;
|
|
FRenderQueryRHIRef& PastQuery = PrimitiveOcclusionHistory->GetPastQuery(OcclusionFrameCounter, NumBufferedFrames);
|
|
if (IsValidRef(PastQuery))
|
|
{
|
|
//int32 RefCount = PastQuery.GetReference()->GetRefCount();
|
|
// NOTE: RHIGetOcclusionQueryResult should never fail when using a blocking call, rendering artifacts may show up.
|
|
//if (RHICmdList.GetRenderQueryResult(PastQuery, NumSamples, true))
|
|
if (GDynamicRHI->RHIGetRenderQueryResult(PastQuery.GetReference(), NumSamples, true))
|
|
{
|
|
// we render occlusion without MSAA
|
|
uint32 NumPixels = (uint32)NumSamples;
|
|
|
|
// The primitive is occluded if none of its bounding box's pixels were visible in the previous frame's occlusion query.
|
|
bIsOccluded = (NumPixels == 0);
|
|
|
|
|
|
if (!bIsOccluded)
|
|
{
|
|
checkSlow(View.OneOverNumPossiblePixels > 0.0f);
|
|
PrimitiveOcclusionHistory->LastPixelsPercentage = NumPixels * View.OneOverNumPossiblePixels;
|
|
}
|
|
else
|
|
{
|
|
PrimitiveOcclusionHistory->LastPixelsPercentage = 0.0f;
|
|
}
|
|
|
|
|
|
// Flag the primitive's occlusion state as definite if it wasn't grouped.
|
|
bOcclusionStateIsDefinite = !PrimitiveOcclusionHistory->bGroupedQuery;
|
|
}
|
|
else
|
|
{
|
|
// If the occlusion query failed, treat the primitive as visible.
|
|
// already set bIsOccluded = false;
|
|
}
|
|
//checkf(RefCount == PastQuery.GetReference()->GetRefCount(), TEXT("Ref count on prim: %i, old: %i, new: %i"), PrimitiveOcclusionHistory->PrimitiveId.PrimIDValue, RefCount, PastQuery.GetReference()->GetRefCount());
|
|
}
|
|
else
|
|
{
|
|
// If there's no occlusion query for the primitive, set it's visibility state to whether it has been unoccluded recently.
|
|
bIsOccluded = (PrimitiveOcclusionHistory->LastVisibleTime + GEngine->PrimitiveProbablyVisibleTime < CurrentRealTime);
|
|
|
|
|
|
|
|
if (bIsOccluded)
|
|
{
|
|
PrimitiveOcclusionHistory->LastPixelsPercentage = 0.0f;
|
|
}
|
|
else
|
|
{
|
|
PrimitiveOcclusionHistory->LastPixelsPercentage = GEngine->MaxOcclusionPixelsFraction;
|
|
}
|
|
|
|
// the state was definite last frame, otherwise we would have ran a query
|
|
bOcclusionStateIsDefinite = true;
|
|
}
|
|
}
|
|
|
|
if (GVisualizeOccludedPrimitives && OcclusionPDI && bIsOccluded)
|
|
{
|
|
const FBoxSphereBounds& Bounds = bSubQueries ? (*SubBounds)[SubQuery] : Scene->PrimitiveOcclusionBounds[BitIt.GetIndex()];
|
|
DrawWireBox(OcclusionPDI, Bounds.GetBox(), FColor(50, 255, 50), SDPG_Foreground);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Primitives that aren't occludable are considered definitely unoccluded.
|
|
// already set bIsOccluded = false;
|
|
bOcclusionStateIsDefinite = true;
|
|
}
|
|
|
|
if (bClearQueries)
|
|
{
|
|
if (bSingleThreaded)
|
|
{
|
|
OcclusionQueryPool.ReleaseQuery(PrimitiveOcclusionHistory->GetPastQuery(OcclusionFrameCounter, NumBufferedFrames));
|
|
}
|
|
else
|
|
{
|
|
FRenderQueryRHIRef &Query = PrimitiveOcclusionHistory->GetPastQuery(OcclusionFrameCounter, NumBufferedFrames);
|
|
if (IsValidRef(Query))
|
|
{
|
|
check(Query.GetRefCount() > 0);
|
|
QueriesToRelease->Add(PrimitiveOcclusionHistory);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (PrimitiveOcclusionHistory)
|
|
{
|
|
|
|
// Set the primitive's considered time to keep its occlusion history from being trimmed.
|
|
PrimitiveOcclusionHistory->LastConsideredTime = CurrentRealTime;
|
|
|
|
if (bSubmitQueries && bCanBeOccluded)
|
|
{
|
|
bool bAllowBoundsTest;
|
|
const FBoxSphereBounds& OcclusionBounds = bSubQueries ? (*SubBounds)[SubQuery] : Scene->PrimitiveOcclusionBounds[BitIt.GetIndex()];
|
|
if (View.bHasNearClippingPlane)
|
|
{
|
|
bAllowBoundsTest = View.NearClippingPlane.PlaneDot(OcclusionBounds.Origin) <
|
|
-(FVector::BoxPushOut(View.NearClippingPlane, OcclusionBounds.BoxExtent));
|
|
|
|
}
|
|
else if (!View.IsPerspectiveProjection())
|
|
{
|
|
// Transform parallel near plane
|
|
static_assert((int32)ERHIZBuffer::IsInverted != 0, "Check equation for culling!");
|
|
bAllowBoundsTest = View.WorldToScreen(OcclusionBounds.Origin).Z - View.ViewMatrices.GetProjectionMatrix().M[2][2] * OcclusionBounds.SphereRadius < 1;
|
|
}
|
|
else
|
|
{
|
|
bAllowBoundsTest = OcclusionBounds.SphereRadius < HALF_WORLD_MAX;
|
|
}
|
|
|
|
if (bAllowBoundsTest)
|
|
{
|
|
if (bHZBOcclusion)
|
|
{
|
|
// Always run
|
|
if (bSingleThreaded)
|
|
{
|
|
PrimitiveOcclusionHistory->HZBTestIndex = HZBOcclusionTests.AddBounds(OcclusionBounds.Origin, OcclusionBounds.BoxExtent);
|
|
}
|
|
else
|
|
{
|
|
HZBBoundsToAdd->Emplace(PrimitiveOcclusionHistory, OcclusionBounds.Origin, OcclusionBounds.BoxExtent);
|
|
}
|
|
PrimitiveOcclusionHistory->HZBTestFrameNumber = OcclusionFrameCounter;
|
|
}
|
|
else
|
|
{
|
|
// decide if a query should be run this frame
|
|
bool bRunQuery, bGroupedQuery;
|
|
|
|
if (!bSubQueries && // sub queries are never grouped, we assume the custom code knows what it is doing and will group internally if it wants
|
|
(OcclusionFlags & EOcclusionFlags::AllowApproximateOcclusion))
|
|
{
|
|
if (bIsOccluded)
|
|
{
|
|
// Primitives that were occluded the previous frame use grouped queries.
|
|
bGroupedQuery = true;
|
|
bRunQuery = true;
|
|
}
|
|
else if (bOcclusionStateIsDefinite)
|
|
{
|
|
// If the primitive's is definitely unoccluded, only requery it occasionally.
|
|
float FractionMultiplier = FMath::Max(PrimitiveOcclusionHistory->LastPixelsPercentage / GEngine->MaxOcclusionPixelsFraction, 1.0f);
|
|
bRunQuery = (FractionMultiplier * GOcclusionRandomStream.GetFraction()) < GEngine->MaxOcclusionPixelsFraction;
|
|
bGroupedQuery = false;
|
|
}
|
|
else
|
|
{
|
|
bGroupedQuery = false;
|
|
bRunQuery = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Primitives that need precise occlusion results use individual queries.
|
|
bGroupedQuery = false;
|
|
bRunQuery = true;
|
|
}
|
|
|
|
if (bRunQuery)
|
|
{
|
|
const FVector BoundOrigin = OcclusionBounds.Origin + View.ViewMatrices.GetPreViewTranslation();
|
|
const FVector BoundExtent = OcclusionBounds.BoxExtent;
|
|
|
|
if (bSingleThreaded)
|
|
{
|
|
PrimitiveOcclusionHistory->SetCurrentQuery(OcclusionFrameCounter,
|
|
bGroupedQuery ?
|
|
View.GroupedOcclusionQueries.BatchPrimitive(BoundOrigin, BoundExtent) :
|
|
View.IndividualOcclusionQueries.BatchPrimitive(BoundOrigin, BoundExtent),
|
|
NumBufferedFrames
|
|
);
|
|
}
|
|
else
|
|
{
|
|
QueriesToAdd->Emplace(PrimitiveOcclusionHistory, BoundOrigin, BoundExtent, bGroupedQuery);
|
|
}
|
|
}
|
|
|
|
PrimitiveOcclusionHistory->bGroupedQuery = bGroupedQuery;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// If the primitive's bounding box intersects the near clipping plane, treat it as definitely unoccluded.
|
|
bIsOccluded = false;
|
|
bOcclusionStateIsDefinite = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (bSubQueries)
|
|
{
|
|
SubIsOccluded.Add(bIsOccluded);
|
|
if (!bIsOccluded)
|
|
{
|
|
bAllSubOccluded = false;
|
|
if (bOcclusionStateIsDefinite)
|
|
{
|
|
if (PrimitiveOcclusionHistory)
|
|
{
|
|
PrimitiveOcclusionHistory->LastVisibleTime = CurrentRealTime;
|
|
}
|
|
}
|
|
}
|
|
if (bIsOccluded || !bOcclusionStateIsDefinite)
|
|
{
|
|
bAllSubOcclusionStateIsDefinite = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
if (bIsOccluded)
|
|
{
|
|
View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt) = false;
|
|
STAT(NumOccludedPrimitives++);
|
|
}
|
|
else if (bOcclusionStateIsDefinite)
|
|
{
|
|
if (PrimitiveOcclusionHistory)
|
|
{
|
|
PrimitiveOcclusionHistory->LastVisibleTime = CurrentRealTime;
|
|
}
|
|
|
|
View.PrimitiveDefinitelyUnoccludedMap.AccessCorrespondingBit(BitIt) = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (bSubQueries)
|
|
{
|
|
FPrimitiveSceneProxy* Proxy = Scene->Primitives[BitIt.GetIndex()]->Proxy;
|
|
Proxy->AcceptOcclusionResults(&View, &SubIsOccluded, SubIsOccludedStart, SubIsOccluded.Num() - SubIsOccludedStart);
|
|
if (bAllSubOccluded)
|
|
{
|
|
View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt) = false;
|
|
STAT(NumOccludedPrimitives++);
|
|
}
|
|
else if (bAllSubOcclusionStateIsDefinite)
|
|
{
|
|
View.PrimitiveDefinitelyUnoccludedMap.AccessCorrespondingBit(BitIt) = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
check(NumTotalDefUnoccluded == View.PrimitiveDefinitelyUnoccludedMap.Num());
|
|
check(NumTotalPrims == View.PrimitiveVisibilityMap.Num());
|
|
check(!InsertPrimitiveOcclusionHistory || InsertPrimitiveOcclusionHistory->Num() <= ReserveAmount);
|
|
Params.NumOccludedPrims = NumOccludedPrimitives;
|
|
}
|
|
|
|
FAutoConsoleTaskPriority CPrio_FetchVisibilityForPrimitivesTask(
|
|
TEXT("TaskGraph.TaskPriorities.FetchVisibilityForPrimitivesTask"),
|
|
TEXT("Task and thread priority for FetchVisibilityForPrimitivesTask."),
|
|
ENamedThreads::HighThreadPriority, // if we have high priority task threads, then use them...
|
|
ENamedThreads::NormalTaskPriority, // .. at normal task priority
|
|
ENamedThreads::HighTaskPriority // if we don't have hi pri threads, then use normal priority threads at high task priority instead
|
|
);
|
|
|
|
class FetchVisibilityForPrimitivesTask
|
|
{
|
|
FVisForPrimParams& Params;
|
|
|
|
public:
|
|
|
|
FetchVisibilityForPrimitivesTask(FVisForPrimParams& InParams)
|
|
: Params(InParams)
|
|
{
|
|
}
|
|
|
|
FORCEINLINE TStatId GetStatId() const
|
|
{
|
|
RETURN_QUICK_DECLARE_CYCLE_STAT(FetchVisibilityForPrimitivesTask, STATGROUP_TaskGraphTasks);
|
|
}
|
|
|
|
ENamedThreads::Type GetDesiredThread()
|
|
{
|
|
return CPrio_FetchVisibilityForPrimitivesTask.Get();
|
|
}
|
|
|
|
static ESubsequentsMode::Type GetSubsequentsMode() { return ESubsequentsMode::TrackSubsequents; }
|
|
|
|
void DoTask(ENamedThreads::Type CurrentThread, const FGraphEventRef& MyCompletionGraphEvent)
|
|
{
|
|
FetchVisibilityForPrimitives_Range<false>(Params);
|
|
}
|
|
};
|
|
|
|
static int32 FetchVisibilityForPrimitives(const FScene* Scene, FViewInfo& View, const bool bSubmitQueries, const bool bHZBOcclusion)
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_FetchVisibilityForPrimitives);
|
|
FSceneViewState* ViewState = (FSceneViewState*)View.State;
|
|
|
|
const int32 NumBufferedSubIsOccludedArrays = 2;
|
|
static int32 SubIsOccludedArrayIndex = 0;
|
|
SubIsOccludedArrayIndex = 1 - SubIsOccludedArrayIndex;
|
|
|
|
if (GOcclusionCullParallelPrimFetch && GSupportsParallelOcclusionQueries)
|
|
{
|
|
static const int32 MaxNumCullTasks = 4;
|
|
static const int32 ActualNumCullTasks = 4;
|
|
static const int32 NumOutputArrays = MaxNumCullTasks;
|
|
|
|
FGraphEventRef TaskRefArray[NumOutputArrays];
|
|
|
|
//params for each task
|
|
FVisForPrimParams Params[NumOutputArrays];
|
|
|
|
//output arrays for each task
|
|
TArray<FPrimitiveOcclusionHistory> OutputOcclusionHistory[NumOutputArrays];
|
|
TArray<FPrimitiveOcclusionHistory*> OutQueriesToRelease[NumOutputArrays];
|
|
TArray<FHZBBound> OutHZBBounds[NumOutputArrays];
|
|
TArray<FOcclusionBounds> OutQueriesToRun[NumOutputArrays];
|
|
|
|
static TArray<bool> FrameSubIsOccluded[NumOutputArrays][NumBufferedSubIsOccludedArrays];
|
|
|
|
//optionally balance the tasks by how the visible primitives are distributed in the array rather than just breaking up the array by range.
|
|
//should make the tasks more equal length.
|
|
#if BALANCE_LOAD
|
|
int32 StartIndices[NumOutputArrays] = { 0 };
|
|
int32 ProcessRange[NumOutputArrays] = { 0 };
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_FetchVisibilityForPrimitivesPreProcess);
|
|
int32 NumBitsSet = 0;
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt, ++NumBitsSet)
|
|
{
|
|
}
|
|
|
|
int32 BitsPerTask = NumBitsSet / ActualNumCullTasks;
|
|
int32 NumBitsForRange = 0;
|
|
int32 CurrentStartIndex = 0;
|
|
int32 RangeToSet = 0;
|
|
|
|
//accumulate set bits for each task until we reach the target, then set the start/end and move on.
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap); BitIt && RangeToSet < (ActualNumCullTasks - 1); ++BitIt)
|
|
{
|
|
++NumBitsForRange;
|
|
if (NumBitsForRange == BitsPerTask)
|
|
{
|
|
StartIndices[RangeToSet] = CurrentStartIndex;
|
|
ProcessRange[RangeToSet] = NumBitsForRange;
|
|
|
|
++RangeToSet;
|
|
NumBitsForRange = 0;
|
|
CurrentStartIndex = BitIt.GetIndex() + 1;
|
|
}
|
|
}
|
|
|
|
//final range is the rest of the set bits, no matter how many there are.
|
|
StartIndices[ActualNumCullTasks - 1] = CurrentStartIndex;
|
|
ProcessRange[ActualNumCullTasks - 1] = NumBitsSet - (BitsPerTask * 3);
|
|
}
|
|
#endif
|
|
|
|
const int32 NumPrims = View.PrimitiveVisibilityMap.Num();
|
|
const int32 NumPerTask = NumPrims / ActualNumCullTasks;
|
|
int32 StartIndex = 0;
|
|
int32 NumToProcess = NumPerTask;
|
|
|
|
FGraphEventArray TaskWaitArray;
|
|
int32 NumTasks = 0;
|
|
for (int32 i = 0; i < ActualNumCullTasks && (StartIndex < NumPrims); ++i, ++NumTasks)
|
|
{
|
|
NumToProcess = (i == (ActualNumCullTasks - 1)) ? (NumPrims - StartIndex) : NumPerTask;
|
|
TArray<bool>& SubIsOccluded = FrameSubIsOccluded[i][SubIsOccludedArrayIndex];
|
|
SubIsOccluded.Reset();
|
|
|
|
Params[i].Init(
|
|
Scene,
|
|
&View,
|
|
nullptr,
|
|
#if BALANCE_LOAD
|
|
StartIndices[i],
|
|
ProcessRange[i],
|
|
#else
|
|
StartIndex,
|
|
NumToProcess,
|
|
#endif
|
|
bSubmitQueries,
|
|
bHZBOcclusion,
|
|
&OutputOcclusionHistory[i],
|
|
&OutQueriesToRelease[i],
|
|
&OutHZBBounds[i],
|
|
&OutQueriesToRun[i],
|
|
&SubIsOccluded
|
|
);
|
|
|
|
TaskRefArray[i] = TGraphTask<FetchVisibilityForPrimitivesTask>::CreateTask().ConstructAndDispatchWhenReady(Params[i]);
|
|
TaskWaitArray.Add(TaskRefArray[i]);
|
|
|
|
StartIndex += NumToProcess;
|
|
}
|
|
|
|
const int32 NumBufferedFrames = FOcclusionQueryHelpers::GetNumBufferedFrames();
|
|
uint32 OcclusionFrameCounter = ViewState->OcclusionFrameCounter;
|
|
TSet<FPrimitiveOcclusionHistory, FPrimitiveOcclusionHistoryKeyFuncs>& ViewPrimitiveOcclusionHistory = ViewState->PrimitiveOcclusionHistorySet;
|
|
FRenderQueryPool& OcclusionQueryPool = ViewState->OcclusionQueryPool;
|
|
FHZBOcclusionTester& HZBOcclusionTests = ViewState->HZBOcclusionTests;
|
|
|
|
int32 NumOccludedPrims = 0;
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_FetchVisibilityForPrimitivesCombine);
|
|
|
|
//wait for them all so we don't start modifying the prim histories while the gather is running
|
|
FTaskGraphInterface::Get().WaitUntilTasksComplete(TaskWaitArray, ENamedThreads::RenderThread_Local);
|
|
|
|
#if QUERY_SANITY_CHECK
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_FetchVisibilityForPrimitivesSanity);
|
|
TSet<int32> ReleaseQuerySet;
|
|
TSet<int32> RunQuerySet;
|
|
TSet<int32> MasterPrimsProcessed;
|
|
for (int32 i = 0; i < NumTasks; ++i)
|
|
{
|
|
bool bAlreadyIn = false;
|
|
for (auto ReleaseQueryIter = OutQueriesToRelease[i].CreateIterator(); ReleaseQueryIter; ++ReleaseQueryIter)
|
|
{
|
|
FPrimitiveOcclusionHistory* History = *ReleaseQueryIter;
|
|
ReleaseQuerySet.Add(History->PrimitiveId.PrimIDValue, &bAlreadyIn);
|
|
checkf(!bAlreadyIn, TEXT("Prim: %i double released query."), History->PrimitiveId.PrimIDValue);
|
|
}
|
|
|
|
for (auto RunQueriesIter = OutQueriesToRun[i].CreateIterator(); RunQueriesIter; ++RunQueriesIter)
|
|
{
|
|
FPrimitiveOcclusionHistory* History = RunQueriesIter->PrimitiveOcclusionHistory;
|
|
RunQuerySet.Add(History->PrimitiveId.PrimIDValue, &bAlreadyIn);
|
|
checkf(!bAlreadyIn, TEXT("Prim: %i double run query."), History->PrimitiveId.PrimIDValue);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
//Add/Release query ops use stored PrimitiveHistory pointers. We must do ALL of these from all tasks before adding any new PrimitiveHistories to the view.
|
|
//Adding new histories to the view could cause the array to resize which would invalidate all the stored output pointers for the other operations.
|
|
for (int32 i = 0; i < NumTasks; ++i)
|
|
{
|
|
//HZB output
|
|
for (auto HZBBoundIter = OutHZBBounds[i].CreateIterator(); HZBBoundIter; ++HZBBoundIter)
|
|
{
|
|
HZBBoundIter->TargetHistory->HZBTestIndex = HZBOcclusionTests.AddBounds(HZBBoundIter->BoundsOrigin, HZBBoundIter->BoundsExtent);
|
|
}
|
|
|
|
//Manual query release handling
|
|
for (auto ReleaseQueryIter = OutQueriesToRelease[i].CreateIterator(); ReleaseQueryIter; ++ReleaseQueryIter)
|
|
{
|
|
FPrimitiveOcclusionHistory* History = *ReleaseQueryIter;
|
|
OcclusionQueryPool.ReleaseQuery(History->GetPastQuery(OcclusionFrameCounter, NumBufferedFrames));
|
|
}
|
|
|
|
//New query batching
|
|
for (auto RunQueriesIter = OutQueriesToRun[i].CreateIterator(); RunQueriesIter; ++RunQueriesIter)
|
|
{
|
|
RunQueriesIter->PrimitiveOcclusionHistory->SetCurrentQuery(OcclusionFrameCounter,
|
|
RunQueriesIter->bGroupedQuery ?
|
|
View.GroupedOcclusionQueries.BatchPrimitive(RunQueriesIter->BoundsOrigin, RunQueriesIter->BoundsExtent) :
|
|
View.IndividualOcclusionQueries.BatchPrimitive(RunQueriesIter->BoundsOrigin, RunQueriesIter->BoundsExtent),
|
|
NumBufferedFrames
|
|
);
|
|
}
|
|
}
|
|
|
|
//now add new primitivie histories to the view. may resize the view's array.
|
|
for (int32 i = 0; i < NumTasks; ++i)
|
|
{
|
|
const TArray<FPrimitiveOcclusionHistory>& NewHistoryArray = OutputOcclusionHistory[i];
|
|
for (int32 HistoryIndex = 0; HistoryIndex < NewHistoryArray.Num(); ++HistoryIndex)
|
|
{
|
|
const FPrimitiveOcclusionHistory& CopySourceHistory = NewHistoryArray[HistoryIndex];
|
|
ViewPrimitiveOcclusionHistory.Add(CopySourceHistory);
|
|
}
|
|
|
|
//accumulate occluded prims across tasks
|
|
NumOccludedPrims += Params[i].NumOccludedPrims;
|
|
}
|
|
}
|
|
|
|
return NumOccludedPrims;
|
|
}
|
|
else
|
|
{
|
|
//SubIsOccluded stuff needs a frame's lifetime
|
|
static TArray<bool> FrameSubIsOccluded[NumBufferedSubIsOccludedArrays];
|
|
|
|
TArray<bool>& SubIsOccluded = FrameSubIsOccluded[SubIsOccludedArrayIndex];
|
|
SubIsOccluded.Reset();
|
|
|
|
FViewElementPDI OcclusionPDI(&View, NULL);
|
|
int32 StartIndex = 0;
|
|
int32 NumToProcess = View.PrimitiveVisibilityMap.Num();
|
|
FVisForPrimParams Params(
|
|
Scene,
|
|
&View,
|
|
&OcclusionPDI,
|
|
StartIndex,
|
|
NumToProcess,
|
|
bSubmitQueries,
|
|
bHZBOcclusion,
|
|
nullptr,
|
|
nullptr,
|
|
nullptr,
|
|
nullptr,
|
|
&FrameSubIsOccluded[SubIsOccludedArrayIndex]
|
|
);
|
|
|
|
FetchVisibilityForPrimitives_Range<true>(Params);
|
|
return Params.NumOccludedPrims;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Cull occluded primitives in the view.
|
|
*/
|
|
static int32 OcclusionCull(FRHICommandListImmediate& RHICmdList, const FScene* Scene, FViewInfo& View)
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_OcclusionCull);
|
|
|
|
// INITVIEWS_TODO: This could be more efficient if broken up in to separate concerns:
|
|
// - What is occluded?
|
|
// - For which primitives should we render occlusion queries?
|
|
// - Generate occlusion query geometry.
|
|
|
|
int32 NumOccludedPrimitives = 0;
|
|
FSceneViewState* ViewState = (FSceneViewState*)View.State;
|
|
|
|
// Disable HZB on OpenGL platforms to avoid rendering artefacts
|
|
// It can be forced on by setting HZBOcclusion to 2
|
|
bool bHZBOcclusion = (!IsOpenGLPlatform(GShaderPlatformForFeatureLevel[Scene->GetFeatureLevel()]) && GHZBOcclusion) || (GHZBOcclusion == 2);
|
|
|
|
// Use precomputed visibility data if it is available.
|
|
if (View.PrecomputedVisibilityData)
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_LookupPrecomputedVisibility);
|
|
|
|
FViewElementPDI OcclusionPDI(&View, NULL);
|
|
uint8 PrecomputedVisibilityFlags = EOcclusionFlags::CanBeOccluded | EOcclusionFlags::HasPrecomputedVisibility;
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt)
|
|
{
|
|
if ((Scene->PrimitiveOcclusionFlags[BitIt.GetIndex()] & PrecomputedVisibilityFlags) == PrecomputedVisibilityFlags)
|
|
{
|
|
FPrimitiveVisibilityId VisibilityId = Scene->PrimitiveVisibilityIds[BitIt.GetIndex()];
|
|
if ((View.PrecomputedVisibilityData[VisibilityId.ByteIndex] & VisibilityId.BitMask) == 0)
|
|
{
|
|
View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt) = false;
|
|
INC_DWORD_STAT_BY(STAT_StaticallyOccludedPrimitives,1);
|
|
STAT(NumOccludedPrimitives++);
|
|
|
|
if (GVisualizeOccludedPrimitives)
|
|
{
|
|
const FBoxSphereBounds& Bounds = Scene->PrimitiveOcclusionBounds[BitIt.GetIndex()];
|
|
DrawWireBox(&OcclusionPDI, Bounds.GetBox(), FColor(100, 50, 50), SDPG_Foreground);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
float CurrentRealTime = View.Family->CurrentRealTime;
|
|
if (ViewState)
|
|
{
|
|
if (Scene->GetFeatureLevel() >= ERHIFeatureLevel::SM4)
|
|
{
|
|
bool bSubmitQueries = !View.bDisableQuerySubmissions;
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
bSubmitQueries = bSubmitQueries && !ViewState->HasViewParent() && !ViewState->bIsFrozen;
|
|
#endif
|
|
|
|
if( bHZBOcclusion )
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_MapHZBResults);
|
|
check(!ViewState->HZBOcclusionTests.IsValidFrame(ViewState->OcclusionFrameCounter));
|
|
ViewState->HZBOcclusionTests.MapResults(RHICmdList);
|
|
}
|
|
|
|
NumOccludedPrimitives += FetchVisibilityForPrimitives(Scene, View, bSubmitQueries, bHZBOcclusion);
|
|
|
|
if( bHZBOcclusion )
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_HZBUnmapResults);
|
|
|
|
ViewState->HZBOcclusionTests.UnmapResults(RHICmdList);
|
|
|
|
if( bSubmitQueries )
|
|
{
|
|
ViewState->HZBOcclusionTests.SetValidFrameNumber(ViewState->OcclusionFrameCounter);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// No occlusion queries, so mark primitives as not occluded
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt)
|
|
{
|
|
View.PrimitiveDefinitelyUnoccludedMap.AccessCorrespondingBit(BitIt) = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return NumOccludedPrimitives;
|
|
}
|
|
|
|
template<class T, int TAmplifyFactor = 1>
|
|
struct FRelevancePrimSet
|
|
{
|
|
enum
|
|
{
|
|
MaxInputPrims = 127, //like 128, but we leave space for NumPrims
|
|
MaxOutputPrims = MaxInputPrims * TAmplifyFactor
|
|
};
|
|
int32 NumPrims;
|
|
|
|
T Prims[MaxOutputPrims];
|
|
|
|
FORCEINLINE FRelevancePrimSet()
|
|
: NumPrims(0)
|
|
{
|
|
//FMemory::Memzero(Prims, sizeof(T) * GetMaxOutputPrim());
|
|
}
|
|
FORCEINLINE void AddPrim(T Prim)
|
|
{
|
|
checkSlow(NumPrims < MaxOutputPrims);
|
|
Prims[NumPrims++] = Prim;
|
|
}
|
|
FORCEINLINE bool IsFull() const
|
|
{
|
|
return NumPrims >= MaxOutputPrims;
|
|
}
|
|
template<class TARRAY>
|
|
FORCEINLINE void AppendTo(TARRAY& DestArray)
|
|
{
|
|
DestArray.Append(Prims, NumPrims);
|
|
}
|
|
};
|
|
|
|
struct FMarkRelevantStaticMeshesForViewData
|
|
{
|
|
FVector ViewOrigin;
|
|
float MaxDrawDistanceScaleSquared;
|
|
int32 ForcedLODLevel;
|
|
float LODScale;
|
|
float InvLODScale;
|
|
float MinScreenRadiusForCSMDepthSquared;
|
|
float MinScreenRadiusForDepthPrepassSquared;
|
|
bool bFullEarlyZPass;
|
|
|
|
FMarkRelevantStaticMeshesForViewData(FViewInfo& View)
|
|
{
|
|
ViewOrigin = View.ViewMatrices.GetViewOrigin();
|
|
|
|
MaxDrawDistanceScaleSquared = GetCachedScalabilityCVars().ViewDistanceScaleSquared;
|
|
|
|
// outside of the loop to be more efficient
|
|
ForcedLODLevel = (View.Family->EngineShowFlags.LOD) ? GetCVarForceLOD() : 0;
|
|
|
|
LODScale = CVarStaticMeshLODDistanceScale.GetValueOnRenderThread() * View.LODDistanceFactor;
|
|
InvLODScale = 1.0f / LODScale;
|
|
|
|
MinScreenRadiusForCSMDepthSquared = GMinScreenRadiusForCSMDepth * GMinScreenRadiusForCSMDepth;
|
|
MinScreenRadiusForDepthPrepassSquared = GMinScreenRadiusForDepthPrepass * GMinScreenRadiusForDepthPrepass;
|
|
|
|
extern bool ShouldForceFullDepthPass(ERHIFeatureLevel::Type FeatureLevel);
|
|
bFullEarlyZPass = ShouldForceFullDepthPass(View.GetFeatureLevel());
|
|
}
|
|
};
|
|
|
|
namespace EMarkMaskBits
|
|
{
|
|
enum Type
|
|
{
|
|
StaticMeshShadowDepthMapMask = 0x1,
|
|
StaticMeshVisibilityMapMask = 0x2,
|
|
StaticMeshVelocityMapMask = 0x4,
|
|
StaticMeshOccluderMapMask = 0x8,
|
|
StaticMeshFadeOutDitheredLODMapMask = 0x10,
|
|
StaticMeshFadeInDitheredLODMapMask = 0x20,
|
|
StaticMeshEditorSelectedMask = 0x40,
|
|
};
|
|
}
|
|
|
|
struct FRelevancePacket
|
|
{
|
|
const float CurrentWorldTime;
|
|
const float DeltaWorldTime;
|
|
|
|
FRHICommandListImmediate& RHICmdList;
|
|
const FScene* Scene;
|
|
const FViewInfo& View;
|
|
const uint8 ViewBit;
|
|
const FMarkRelevantStaticMeshesForViewData& ViewData;
|
|
FPrimitiveViewMasks& OutHasDynamicMeshElementsMasks;
|
|
FPrimitiveViewMasks& OutHasDynamicEditorMeshElementsMasks;
|
|
uint8* RESTRICT MarkMasks;
|
|
|
|
FRelevancePrimSet<int32> Input;
|
|
FRelevancePrimSet<int32> RelevantStaticPrimitives;
|
|
FRelevancePrimSet<int32> NotDrawRelevant;
|
|
FRelevancePrimSet<FPrimitiveSceneInfo*> VisibleDynamicPrimitives;
|
|
FRelevancePrimSet<FTranslucentPrimSet::FTranslucentSortedPrim, ETranslucencyPass::TPT_MAX> TranslucencyPrims;
|
|
// belongs to TranslucencyPrims
|
|
FTranslucenyPrimCount TranslucencyPrimCount;
|
|
FRelevancePrimSet<FPrimitiveSceneProxy*> DistortionPrimSet;
|
|
FRelevancePrimSet<FMeshDecalPrimSet::KeyType> MeshDecalPrimSet;
|
|
FRelevancePrimSet<FPrimitiveSceneProxy*> CustomDepthSet;
|
|
FRelevancePrimSet<FPrimitiveSceneInfo*> LazyUpdatePrimitives;
|
|
FRelevancePrimSet<FPrimitiveSceneInfo*> DirtyPrecomputedLightingBufferPrimitives;
|
|
FRelevancePrimSet<FPrimitiveSceneInfo*> VisibleEditorPrimitives;
|
|
FRelevancePrimSet<FPrimitiveSceneProxy*> VolumetricPrimSet;
|
|
uint16 CombinedShadingModelMask;
|
|
bool bUsesGlobalDistanceField;
|
|
bool bUsesLightingChannels;
|
|
bool bTranslucentSurfaceLighting;
|
|
bool bUsesSceneDepth;
|
|
|
|
FRelevancePacket(
|
|
FRHICommandListImmediate& InRHICmdList,
|
|
const FScene* InScene,
|
|
const FViewInfo& InView,
|
|
uint8 InViewBit,
|
|
const FMarkRelevantStaticMeshesForViewData& InViewData,
|
|
FPrimitiveViewMasks& InOutHasDynamicMeshElementsMasks,
|
|
FPrimitiveViewMasks& InOutHasDynamicEditorMeshElementsMasks,
|
|
uint8* InMarkMasks)
|
|
|
|
: CurrentWorldTime(InView.Family->CurrentWorldTime)
|
|
, DeltaWorldTime(InView.Family->DeltaWorldTime)
|
|
, RHICmdList(InRHICmdList)
|
|
, Scene(InScene)
|
|
, View(InView)
|
|
, ViewBit(InViewBit)
|
|
, ViewData(InViewData)
|
|
, OutHasDynamicMeshElementsMasks(InOutHasDynamicMeshElementsMasks)
|
|
, OutHasDynamicEditorMeshElementsMasks(InOutHasDynamicEditorMeshElementsMasks)
|
|
, MarkMasks(InMarkMasks)
|
|
, CombinedShadingModelMask(0)
|
|
, bUsesGlobalDistanceField(false)
|
|
, bUsesLightingChannels(false)
|
|
, bTranslucentSurfaceLighting(false)
|
|
, bUsesSceneDepth(false)
|
|
{
|
|
}
|
|
|
|
void AnyThreadTask()
|
|
{
|
|
ComputeRelevance();
|
|
MarkRelevant();
|
|
}
|
|
|
|
void ComputeRelevance()
|
|
{
|
|
CombinedShadingModelMask = 0;
|
|
bUsesGlobalDistanceField = false;
|
|
bUsesLightingChannels = false;
|
|
bTranslucentSurfaceLighting = false;
|
|
|
|
SCOPE_CYCLE_COUNTER(STAT_ComputeViewRelevance);
|
|
for (int32 Index = 0; Index < Input.NumPrims; Index++)
|
|
{
|
|
int32 BitIndex = Input.Prims[Index];
|
|
FPrimitiveSceneInfo* PrimitiveSceneInfo = Scene->Primitives[BitIndex];
|
|
FPrimitiveViewRelevance& ViewRelevance = const_cast<FPrimitiveViewRelevance&>(View.PrimitiveViewRelevanceMap[BitIndex]);
|
|
ViewRelevance = PrimitiveSceneInfo->Proxy->GetViewRelevance(&View);
|
|
ViewRelevance.bInitializedThisFrame = true;
|
|
|
|
const bool bStaticRelevance = ViewRelevance.bStaticRelevance;
|
|
const bool bDrawRelevance = ViewRelevance.bDrawRelevance;
|
|
const bool bDynamicRelevance = ViewRelevance.bDynamicRelevance;
|
|
const bool bShadowRelevance = ViewRelevance.bShadowRelevance;
|
|
const bool bEditorRelevance = ViewRelevance.bEditorPrimitiveRelevance;
|
|
const bool bEditorSelectionRelevance = ViewRelevance.bEditorStaticSelectionRelevance;
|
|
const bool bTranslucentRelevance = ViewRelevance.HasTranslucency();
|
|
|
|
if (View.bIsReflectionCapture && !PrimitiveSceneInfo->Proxy->IsVisibleInReflectionCaptures())
|
|
{
|
|
NotDrawRelevant.AddPrim(BitIndex);
|
|
continue;
|
|
}
|
|
|
|
if (bStaticRelevance && (bDrawRelevance || bShadowRelevance))
|
|
{
|
|
RelevantStaticPrimitives.AddPrim(BitIndex);
|
|
}
|
|
|
|
if (!bDrawRelevance)
|
|
{
|
|
NotDrawRelevant.AddPrim(BitIndex);
|
|
continue;
|
|
}
|
|
|
|
if (ViewRelevance.bDecal)
|
|
{
|
|
MeshDecalPrimSet.AddPrim(FMeshDecalPrimSet::GenerateKey(PrimitiveSceneInfo));
|
|
}
|
|
|
|
if (bEditorRelevance)
|
|
{
|
|
// Editor primitives are rendered after post processing and composited onto the scene
|
|
VisibleEditorPrimitives.AddPrim(PrimitiveSceneInfo);
|
|
|
|
if (GIsEditor)
|
|
{
|
|
OutHasDynamicEditorMeshElementsMasks[BitIndex] |= ViewBit;
|
|
}
|
|
}
|
|
else if(bDynamicRelevance)
|
|
{
|
|
// Keep track of visible dynamic primitives.
|
|
VisibleDynamicPrimitives.AddPrim(PrimitiveSceneInfo);
|
|
OutHasDynamicMeshElementsMasks[BitIndex] |= ViewBit;
|
|
}
|
|
|
|
if (bTranslucentRelevance && !bEditorRelevance && ViewRelevance.bRenderInMainPass)
|
|
{
|
|
// Add to set of dynamic translucent primitives
|
|
FTranslucentPrimSet::PlaceScenePrimitive(PrimitiveSceneInfo, View,
|
|
ViewRelevance.bNormalTranslucencyRelevance, ViewRelevance.bSeparateTranslucencyRelevance, ViewRelevance.bMobileSeparateTranslucencyRelevance,
|
|
&TranslucencyPrims.Prims[0], TranslucencyPrims.NumPrims, TranslucencyPrimCount);
|
|
|
|
if (ViewRelevance.bDistortionRelevance)
|
|
{
|
|
// Add to set of dynamic distortion primitives
|
|
DistortionPrimSet.AddPrim(PrimitiveSceneInfo->Proxy);
|
|
}
|
|
}
|
|
|
|
if (ViewRelevance.bHasVolumeMaterialDomain)
|
|
{
|
|
VolumetricPrimSet.AddPrim(PrimitiveSceneInfo->Proxy);
|
|
}
|
|
|
|
CombinedShadingModelMask |= ViewRelevance.ShadingModelMaskRelevance;
|
|
bUsesGlobalDistanceField |= ViewRelevance.bUsesGlobalDistanceField;
|
|
bUsesLightingChannels |= ViewRelevance.bUsesLightingChannels;
|
|
bTranslucentSurfaceLighting |= ViewRelevance.bTranslucentSurfaceLighting;
|
|
bUsesSceneDepth |= ViewRelevance.bUsesSceneDepth;
|
|
|
|
if (ViewRelevance.bRenderCustomDepth)
|
|
{
|
|
// Add to set of dynamic distortion primitives
|
|
CustomDepthSet.AddPrim(PrimitiveSceneInfo->Proxy);
|
|
}
|
|
|
|
// INITVIEWS_TODO: Do this in a separate pass? There are no dependencies
|
|
// here except maybe ParentPrimitives. This could be done in a
|
|
// low-priority background task and forgotten about.
|
|
|
|
// If the primitive's last render time is older than last frame, consider
|
|
// it newly visible and update its visibility change time
|
|
if (PrimitiveSceneInfo->LastRenderTime < CurrentWorldTime - DeltaWorldTime - DELTA)
|
|
{
|
|
PrimitiveSceneInfo->LastVisibilityChangeTime = CurrentWorldTime;
|
|
}
|
|
PrimitiveSceneInfo->LastRenderTime = CurrentWorldTime;
|
|
|
|
// If the primitive is definitely unoccluded or if in Wireframe mode and the primitive is estimated
|
|
// to be unoccluded, then update the primitive components's LastRenderTime
|
|
// on the game thread. This signals that the primitive is visible.
|
|
if (View.PrimitiveDefinitelyUnoccludedMap[BitIndex] || (View.Family->EngineShowFlags.Wireframe && View.PrimitiveVisibilityMap[BitIndex]))
|
|
{
|
|
// Update the PrimitiveComponent's LastRenderTime.
|
|
*(PrimitiveSceneInfo->ComponentLastRenderTime) = CurrentWorldTime;
|
|
*(PrimitiveSceneInfo->ComponentLastRenderTimeOnScreen) = CurrentWorldTime;
|
|
}
|
|
|
|
// Cache the nearest reflection proxy if needed
|
|
if (PrimitiveSceneInfo->bNeedsCachedReflectionCaptureUpdate
|
|
// For mobile, the per-object reflection is used for everything
|
|
&& (Scene->GetShadingPath() == EShadingPath::Mobile || bTranslucentRelevance || IsForwardShadingEnabled(Scene->GetFeatureLevel())))
|
|
{
|
|
PrimitiveSceneInfo->CachedReflectionCaptureProxy = Scene->FindClosestReflectionCapture(Scene->PrimitiveBounds[BitIndex].Origin);
|
|
PrimitiveSceneInfo->CachedPlanarReflectionProxy = Scene->FindClosestPlanarReflection(Scene->PrimitiveBounds[BitIndex]);
|
|
|
|
if (Scene->GetShadingPath() == EShadingPath::Mobile)
|
|
{
|
|
// mobile HQ reflections
|
|
Scene->FindClosestReflectionCaptures(Scene->PrimitiveBounds[BitIndex].Origin, PrimitiveSceneInfo->CachedReflectionCaptureProxies);
|
|
}
|
|
|
|
PrimitiveSceneInfo->bNeedsCachedReflectionCaptureUpdate = false;
|
|
}
|
|
if (PrimitiveSceneInfo->NeedsLazyUpdateForRendering())
|
|
{
|
|
LazyUpdatePrimitives.AddPrim(PrimitiveSceneInfo);
|
|
}
|
|
if (PrimitiveSceneInfo->NeedsPrecomputedLightingBufferUpdate())
|
|
{
|
|
DirtyPrecomputedLightingBufferPrimitives.AddPrim(PrimitiveSceneInfo);
|
|
}
|
|
}
|
|
}
|
|
void MarkRelevant()
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_StaticRelevance);
|
|
|
|
// using a local counter to reduce memory traffic
|
|
int32 NumVisibleStaticMeshElements = 0;
|
|
FViewInfo& WriteView = const_cast<FViewInfo&>(View);
|
|
FFrozenSceneViewMatricesGuard FrozenMatricesGuard(WriteView);
|
|
const FSceneViewState* ViewState = (FSceneViewState*)View.State;
|
|
|
|
const bool bHLODActive = Scene->SceneLODHierarchy.IsActive();
|
|
|
|
for (int32 StaticPrimIndex = 0, Num = RelevantStaticPrimitives.NumPrims; StaticPrimIndex < Num; ++StaticPrimIndex)
|
|
{
|
|
int32 PrimitiveIndex = RelevantStaticPrimitives.Prims[StaticPrimIndex];
|
|
const FPrimitiveSceneInfo* RESTRICT PrimitiveSceneInfo = Scene->Primitives[PrimitiveIndex];
|
|
const FPrimitiveBounds& Bounds = Scene->PrimitiveBounds[PrimitiveIndex];
|
|
const FPrimitiveViewRelevance& ViewRelevance = View.PrimitiveViewRelevanceMap[PrimitiveIndex];
|
|
|
|
FLODMask LODToRender = ComputeLODForMeshes( PrimitiveSceneInfo->StaticMeshes, View, Bounds.Origin, Bounds.SphereRadius, ViewData.ForcedLODLevel, ViewData.LODScale);
|
|
const bool bIsHLODFading = bHLODActive && ViewState && ViewState->HLODVisibilityState.IsNodeFading(PrimitiveIndex);
|
|
const bool bIsHLODFadingOut = bHLODActive && ViewState && ViewState->HLODVisibilityState.IsNodeFadingOut(PrimitiveIndex);
|
|
const bool bIsLODDithered = LODToRender.IsDithered();
|
|
|
|
float DistanceSquared = (Bounds.Origin - ViewData.ViewOrigin).SizeSquared();
|
|
const float LODFactorDistanceSquared = DistanceSquared * FMath::Square(View.LODDistanceFactor * ViewData.InvLODScale);
|
|
const bool bDrawShadowDepth = FMath::Square(Bounds.SphereRadius) > ViewData.MinScreenRadiusForCSMDepthSquared * LODFactorDistanceSquared;
|
|
const bool bDrawDepthOnly = ViewData.bFullEarlyZPass || FMath::Square(Bounds.SphereRadius) > GMinScreenRadiusForDepthPrepass * GMinScreenRadiusForDepthPrepass * LODFactorDistanceSquared;
|
|
|
|
const int32 NumStaticMeshes = PrimitiveSceneInfo->StaticMeshes.Num();
|
|
for(int32 MeshIndex = 0;MeshIndex < NumStaticMeshes;MeshIndex++)
|
|
{
|
|
const FStaticMesh& StaticMesh = PrimitiveSceneInfo->StaticMeshes[MeshIndex];
|
|
if (LODToRender.ContainsLOD(StaticMesh.LODIndex))
|
|
{
|
|
uint8 MarkMask = 0;
|
|
bool bNeedsBatchVisibility = false;
|
|
bool bHiddenByHLODFade = false; // Hide mesh LOD levels that HLOD is substituting
|
|
|
|
if (bIsHLODFading)
|
|
{
|
|
if (bIsHLODFadingOut)
|
|
{
|
|
if (bIsLODDithered && LODToRender.DitheredLODIndices[1] == StaticMesh.LODIndex)
|
|
{
|
|
bHiddenByHLODFade = true;
|
|
}
|
|
else
|
|
{
|
|
MarkMask |= EMarkMaskBits::StaticMeshFadeOutDitheredLODMapMask;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (bIsLODDithered && LODToRender.DitheredLODIndices[0] == StaticMesh.LODIndex)
|
|
{
|
|
bHiddenByHLODFade = true;
|
|
}
|
|
else
|
|
{
|
|
MarkMask |= EMarkMaskBits::StaticMeshFadeInDitheredLODMapMask;
|
|
}
|
|
}
|
|
}
|
|
else if (bIsLODDithered)
|
|
{
|
|
if (LODToRender.DitheredLODIndices[0] == StaticMesh.LODIndex)
|
|
{
|
|
MarkMask |= EMarkMaskBits::StaticMeshFadeOutDitheredLODMapMask;
|
|
}
|
|
else
|
|
{
|
|
MarkMask |= EMarkMaskBits::StaticMeshFadeInDitheredLODMapMask;
|
|
}
|
|
}
|
|
|
|
if (ViewRelevance.bShadowRelevance && bDrawShadowDepth && StaticMesh.CastShadow)
|
|
{
|
|
// Mark static mesh as visible in shadows.
|
|
MarkMask |= EMarkMaskBits::StaticMeshShadowDepthMapMask;
|
|
bNeedsBatchVisibility = true;
|
|
}
|
|
|
|
if(ViewRelevance.bDrawRelevance && (StaticMesh.bUseForMaterial || StaticMesh.bUseAsOccluder) && (ViewRelevance.bRenderInMainPass || ViewRelevance.bRenderCustomDepth) && !bHiddenByHLODFade)
|
|
{
|
|
// Mark static mesh as visible for rendering
|
|
if (StaticMesh.bUseForMaterial)
|
|
{
|
|
MarkMask |= EMarkMaskBits::StaticMeshVisibilityMapMask;
|
|
if (PrimitiveSceneInfo->ShouldRenderVelocity(View, false))
|
|
{
|
|
MarkMask |= EMarkMaskBits::StaticMeshVelocityMapMask;
|
|
}
|
|
++NumVisibleStaticMeshElements;
|
|
}
|
|
|
|
// If the static mesh is an occluder, check whether it covers enough of the screen to be used as an occluder.
|
|
if( StaticMesh.bUseAsOccluder && bDrawDepthOnly )
|
|
{
|
|
MarkMask |= EMarkMaskBits::StaticMeshOccluderMapMask;
|
|
}
|
|
bNeedsBatchVisibility = true;
|
|
}
|
|
|
|
#if WITH_EDITOR
|
|
if(ViewRelevance.bDrawRelevance && ViewRelevance.bEditorStaticSelectionRelevance)
|
|
{
|
|
MarkMask |= EMarkMaskBits::StaticMeshEditorSelectedMask;
|
|
}
|
|
#endif
|
|
if (MarkMask)
|
|
{
|
|
MarkMasks[StaticMesh.Id] = MarkMask;
|
|
}
|
|
|
|
// Static meshes which don't need per-element visibility always draw all elements
|
|
if (bNeedsBatchVisibility && StaticMesh.bRequiresPerElementVisibility)
|
|
{
|
|
WriteView.StaticMeshBatchVisibility[StaticMesh.Id] = StaticMesh.VertexFactory->GetStaticBatchElementVisibility(View, &StaticMesh);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
static_assert(sizeof(WriteView.NumVisibleStaticMeshElements) == sizeof(int32), "Atomic is the wrong size");
|
|
FPlatformAtomics::InterlockedAdd((volatile int32*)&WriteView.NumVisibleStaticMeshElements, NumVisibleStaticMeshElements);
|
|
}
|
|
|
|
void RenderThreadFinalize()
|
|
{
|
|
FViewInfo& WriteView = const_cast<FViewInfo&>(View);
|
|
|
|
for (int32 Index = 0; Index < NotDrawRelevant.NumPrims; Index++)
|
|
{
|
|
WriteView.PrimitiveVisibilityMap[NotDrawRelevant.Prims[Index]] = false;
|
|
}
|
|
|
|
WriteView.ShadingModelMaskInView |= CombinedShadingModelMask;
|
|
WriteView.bUsesGlobalDistanceField |= bUsesGlobalDistanceField;
|
|
WriteView.bUsesLightingChannels |= bUsesLightingChannels;
|
|
WriteView.bTranslucentSurfaceLighting |= bTranslucentSurfaceLighting;
|
|
WriteView.bUsesSceneDepth |= bUsesSceneDepth;
|
|
VisibleEditorPrimitives.AppendTo(WriteView.VisibleEditorPrimitives);
|
|
VisibleDynamicPrimitives.AppendTo(WriteView.VisibleDynamicPrimitives);
|
|
WriteView.TranslucentPrimSet.AppendScenePrimitives(TranslucencyPrims.Prims, TranslucencyPrims.NumPrims, TranslucencyPrimCount);
|
|
DistortionPrimSet.AppendTo(WriteView.DistortionPrimSet);
|
|
MeshDecalPrimSet.AppendTo(WriteView.MeshDecalPrimSet.Prims);
|
|
CustomDepthSet.AppendTo(WriteView.CustomDepthSet);
|
|
DirtyPrecomputedLightingBufferPrimitives.AppendTo(WriteView.DirtyPrecomputedLightingBufferPrimitives);
|
|
VolumetricPrimSet.AppendTo(WriteView.VolumetricPrimSet);
|
|
for (int32 Index = 0; Index < LazyUpdatePrimitives.NumPrims; Index++)
|
|
{
|
|
LazyUpdatePrimitives.Prims[Index]->ConditionalLazyUpdateForRendering(RHICmdList);
|
|
}
|
|
}
|
|
};
|
|
|
|
static void ComputeAndMarkRelevanceForViewParallel(
|
|
FRHICommandListImmediate& RHICmdList,
|
|
const FScene* Scene,
|
|
FViewInfo& View,
|
|
uint8 ViewBit,
|
|
FPrimitiveViewMasks& OutHasDynamicMeshElementsMasks,
|
|
FPrimitiveViewMasks& OutHasDynamicEditorMeshElementsMasks
|
|
)
|
|
{
|
|
check(OutHasDynamicMeshElementsMasks.Num() == Scene->Primitives.Num());
|
|
|
|
const FMarkRelevantStaticMeshesForViewData ViewData(View);
|
|
|
|
int32 NumMesh = View.StaticMeshVisibilityMap.Num();
|
|
check(View.StaticMeshShadowDepthMap.Num() == NumMesh && View.StaticMeshVelocityMap.Num() == NumMesh && View.StaticMeshOccluderMap.Num() == NumMesh);
|
|
uint8* RESTRICT MarkMasks = (uint8*)FMemStack::Get().Alloc(NumMesh + 31 , 8); // some padding to simplify the high speed transpose
|
|
FMemory::Memzero(MarkMasks, NumMesh + 31);
|
|
|
|
int32 EstimateOfNumPackets = NumMesh / (FRelevancePrimSet<int32>::MaxInputPrims * 4);
|
|
|
|
TArray<FRelevancePacket*,SceneRenderingAllocator> Packets;
|
|
|
|
Packets.Reserve(EstimateOfNumPackets);
|
|
|
|
{
|
|
FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap);
|
|
if (BitIt)
|
|
{
|
|
|
|
FRelevancePacket* Packet = new(FMemStack::Get()) FRelevancePacket(
|
|
RHICmdList,
|
|
Scene,
|
|
View,
|
|
ViewBit,
|
|
ViewData,
|
|
OutHasDynamicMeshElementsMasks,
|
|
OutHasDynamicEditorMeshElementsMasks,
|
|
MarkMasks);
|
|
Packets.Add(Packet);
|
|
|
|
while (1)
|
|
{
|
|
Packet->Input.AddPrim(BitIt.GetIndex());
|
|
++BitIt;
|
|
if (Packet->Input.IsFull() || !BitIt)
|
|
{
|
|
if (!BitIt)
|
|
{
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
Packet = new(FMemStack::Get()) FRelevancePacket(
|
|
RHICmdList,
|
|
Scene,
|
|
View,
|
|
ViewBit,
|
|
ViewData,
|
|
OutHasDynamicMeshElementsMasks,
|
|
OutHasDynamicEditorMeshElementsMasks,
|
|
MarkMasks);
|
|
Packets.Add(Packet);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_ComputeAndMarkRelevanceForViewParallel_ParallelFor);
|
|
ParallelFor(Packets.Num(),
|
|
[&Packets](int32 Index)
|
|
{
|
|
Packets[Index]->AnyThreadTask();
|
|
},
|
|
!(FApp::ShouldUseThreadingForPerformance() && CVarParallelInitViews.GetValueOnRenderThread() > 0)
|
|
);
|
|
}
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_ComputeAndMarkRelevanceForViewParallel_RenderThreadFinalize);
|
|
for (auto Packet : Packets)
|
|
{
|
|
Packet->RenderThreadFinalize();
|
|
}
|
|
}
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_ComputeAndMarkRelevanceForViewParallel_TransposeMeshBits);
|
|
check(View.StaticMeshVelocityMap.Num() == NumMesh &&
|
|
View.StaticMeshShadowDepthMap.Num() == NumMesh &&
|
|
View.StaticMeshVisibilityMap.Num() == NumMesh &&
|
|
View.StaticMeshOccluderMap.Num() == NumMesh &&
|
|
View.StaticMeshFadeOutDitheredLODMap.Num() == NumMesh &&
|
|
View.StaticMeshFadeInDitheredLODMap.Num() == NumMesh
|
|
);
|
|
uint32* RESTRICT StaticMeshVisibilityMap_Words = View.StaticMeshVisibilityMap.GetData();
|
|
uint32* RESTRICT StaticMeshVelocityMap_Words = View.StaticMeshVelocityMap.GetData();
|
|
uint32* RESTRICT StaticMeshShadowDepthMap_Words = View.StaticMeshShadowDepthMap.GetData();
|
|
uint32* RESTRICT StaticMeshOccluderMap_Words = View.StaticMeshOccluderMap.GetData();
|
|
uint32* RESTRICT StaticMeshFadeOutDitheredLODMap_Words = View.StaticMeshFadeOutDitheredLODMap.GetData();
|
|
uint32* RESTRICT StaticMeshFadeInDitheredLODMap_Words = View.StaticMeshFadeInDitheredLODMap.GetData();
|
|
#if WITH_EDITOR
|
|
uint32* RESTRICT StaticMeshEditorSelectionMap_Words = View.StaticMeshEditorSelectionMap.GetData();
|
|
#endif
|
|
const uint64* RESTRICT MarkMasks64 = (const uint64* RESTRICT)MarkMasks;
|
|
const uint8* RESTRICT MarkMasks8 = MarkMasks;
|
|
for (int32 BaseIndex = 0; BaseIndex < NumMesh; BaseIndex += 32)
|
|
{
|
|
uint32 StaticMeshVisibilityMap_Word = 0;
|
|
uint32 StaticMeshVelocityMap_Word = 0;
|
|
uint32 StaticMeshShadowDepthMap_Word = 0;
|
|
uint32 StaticMeshOccluderMap_Word = 0;
|
|
uint32 StaticMeshFadeOutDitheredLODMap_Word = 0;
|
|
uint32 StaticMeshFadeInDitheredLODMap_Word = 0;
|
|
uint32 StaticMeshEditorSelectionMap_Word = 0;
|
|
uint32 Mask = 1;
|
|
bool bAny = false;
|
|
for (int32 QWordIndex = 0; QWordIndex < 4; QWordIndex++)
|
|
{
|
|
if (*MarkMasks64++)
|
|
{
|
|
for (int32 ByteIndex = 0; ByteIndex < 8; ByteIndex++, Mask <<= 1, MarkMasks8++)
|
|
{
|
|
uint8 MaskMask = *MarkMasks8;
|
|
StaticMeshVisibilityMap_Word |= (MaskMask & EMarkMaskBits::StaticMeshVisibilityMapMask) ? Mask : 0;
|
|
StaticMeshVelocityMap_Word |= (MaskMask & EMarkMaskBits::StaticMeshVelocityMapMask) ? Mask : 0;
|
|
StaticMeshShadowDepthMap_Word |= (MaskMask & EMarkMaskBits::StaticMeshShadowDepthMapMask) ? Mask : 0;
|
|
StaticMeshOccluderMap_Word |= (MaskMask & EMarkMaskBits::StaticMeshOccluderMapMask) ? Mask : 0;
|
|
StaticMeshFadeOutDitheredLODMap_Word |= (MaskMask & EMarkMaskBits::StaticMeshFadeOutDitheredLODMapMask) ? Mask : 0;
|
|
StaticMeshFadeInDitheredLODMap_Word |= (MaskMask & EMarkMaskBits::StaticMeshFadeInDitheredLODMapMask) ? Mask : 0;
|
|
#if WITH_EDITOR
|
|
StaticMeshEditorSelectionMap_Word |= (MaskMask & EMarkMaskBits::StaticMeshEditorSelectedMask) ? Mask : 0;
|
|
#endif
|
|
}
|
|
bAny = true;
|
|
}
|
|
else
|
|
{
|
|
MarkMasks8 += 8;
|
|
Mask <<= 8;
|
|
}
|
|
}
|
|
if (bAny)
|
|
{
|
|
checkSlow(!*StaticMeshVisibilityMap_Words && !*StaticMeshVelocityMap_Words && !*StaticMeshShadowDepthMap_Words && !*StaticMeshOccluderMap_Words && !*StaticMeshFadeOutDitheredLODMap_Words && !*StaticMeshFadeInDitheredLODMap_Words);
|
|
*StaticMeshVisibilityMap_Words = StaticMeshVisibilityMap_Word;
|
|
*StaticMeshVelocityMap_Words = StaticMeshVelocityMap_Word;
|
|
*StaticMeshShadowDepthMap_Words = StaticMeshShadowDepthMap_Word;
|
|
*StaticMeshOccluderMap_Words = StaticMeshOccluderMap_Word;
|
|
*StaticMeshFadeOutDitheredLODMap_Words = StaticMeshFadeOutDitheredLODMap_Word;
|
|
*StaticMeshFadeInDitheredLODMap_Words = StaticMeshFadeInDitheredLODMap_Word;
|
|
#if WITH_EDITOR
|
|
*StaticMeshEditorSelectionMap_Words = StaticMeshEditorSelectionMap_Word;
|
|
#endif
|
|
}
|
|
StaticMeshVisibilityMap_Words++;
|
|
StaticMeshVelocityMap_Words++;
|
|
StaticMeshShadowDepthMap_Words++;
|
|
StaticMeshOccluderMap_Words++;
|
|
StaticMeshFadeOutDitheredLODMap_Words++;
|
|
StaticMeshFadeInDitheredLODMap_Words++;
|
|
#if WITH_EDITOR
|
|
StaticMeshEditorSelectionMap_Words++;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void FSceneRenderer::GatherDynamicMeshElements(
|
|
TArray<FViewInfo>& InViews,
|
|
const FScene* InScene,
|
|
const FSceneViewFamily& InViewFamily,
|
|
const FPrimitiveViewMasks& HasDynamicMeshElementsMasks,
|
|
const FPrimitiveViewMasks& HasDynamicEditorMeshElementsMasks,
|
|
FMeshElementCollector& Collector)
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_GetDynamicMeshElements);
|
|
|
|
int32 NumPrimitives = InScene->Primitives.Num();
|
|
check(HasDynamicMeshElementsMasks.Num() == NumPrimitives);
|
|
|
|
int32 ViewCount = InViews.Num();
|
|
{
|
|
Collector.ClearViewMeshArrays();
|
|
|
|
for (int32 ViewIndex = 0; ViewIndex < ViewCount; ViewIndex++)
|
|
{
|
|
Collector.AddViewMeshArrays(&InViews[ViewIndex], &InViews[ViewIndex].DynamicMeshElements, &InViews[ViewIndex].SimpleElementCollector, InViewFamily.GetFeatureLevel());
|
|
}
|
|
|
|
const bool bIsInstancedStereo = (ViewCount > 0) ? (InViews[0].IsInstancedStereoPass() || InViews[0].bIsMobileMultiViewEnabled) : false;
|
|
|
|
for (int32 PrimitiveIndex = 0; PrimitiveIndex < NumPrimitives; ++PrimitiveIndex)
|
|
{
|
|
const uint8 ViewMask = HasDynamicMeshElementsMasks[PrimitiveIndex];
|
|
|
|
if (ViewMask != 0)
|
|
{
|
|
// Don't cull a single eye when drawing a stereo pair
|
|
const uint8 ViewMaskFinal = (bIsInstancedStereo) ? ViewMask | 0x3 : ViewMask;
|
|
|
|
FPrimitiveSceneInfo* PrimitiveSceneInfo = InScene->Primitives[PrimitiveIndex];
|
|
Collector.SetPrimitive(PrimitiveSceneInfo->Proxy, PrimitiveSceneInfo->DefaultDynamicHitProxyId);
|
|
PrimitiveSceneInfo->Proxy->GetDynamicMeshElements(InViewFamily.Views, InViewFamily, ViewMaskFinal, Collector);
|
|
}
|
|
|
|
// to support GetDynamicMeshElementRange()
|
|
for (int32 ViewIndex = 0; ViewIndex < ViewCount; ViewIndex++)
|
|
{
|
|
InViews[ViewIndex].DynamicMeshEndIndices[PrimitiveIndex] = Collector.GetMeshBatchCount(ViewIndex);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (GIsEditor)
|
|
{
|
|
Collector.ClearViewMeshArrays();
|
|
|
|
for (int32 ViewIndex = 0; ViewIndex < ViewCount; ViewIndex++)
|
|
{
|
|
Collector.AddViewMeshArrays(&InViews[ViewIndex], &InViews[ViewIndex].DynamicEditorMeshElements, &InViews[ViewIndex].EditorSimpleElementCollector, InViewFamily.GetFeatureLevel());
|
|
}
|
|
|
|
for (int32 PrimitiveIndex = 0; PrimitiveIndex < NumPrimitives; ++PrimitiveIndex)
|
|
{
|
|
const uint8 ViewMask = HasDynamicEditorMeshElementsMasks[PrimitiveIndex];
|
|
|
|
if (ViewMask != 0)
|
|
{
|
|
FPrimitiveSceneInfo* PrimitiveSceneInfo = InScene->Primitives[PrimitiveIndex];
|
|
Collector.SetPrimitive(PrimitiveSceneInfo->Proxy, PrimitiveSceneInfo->DefaultDynamicHitProxyId);
|
|
PrimitiveSceneInfo->Proxy->GetDynamicMeshElements(InViewFamily.Views, InViewFamily, ViewMask, Collector);
|
|
}
|
|
}
|
|
}
|
|
MeshCollector.ProcessTasks();
|
|
}
|
|
|
|
static void MarkAllPrimitivesForReflectionProxyUpdate(FScene* Scene)
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_MarkAllPrimitivesForReflectionProxyUpdate);
|
|
|
|
if (Scene->ReflectionSceneData.bRegisteredReflectionCapturesHasChanged)
|
|
{
|
|
// Mark all primitives as needing an update
|
|
// Note: Only visible primitives will actually update their reflection proxy
|
|
for (int32 PrimitiveIndex = 0; PrimitiveIndex < Scene->Primitives.Num(); PrimitiveIndex++)
|
|
{
|
|
Scene->Primitives[PrimitiveIndex]->bNeedsCachedReflectionCaptureUpdate = true;
|
|
}
|
|
|
|
Scene->ReflectionSceneData.bRegisteredReflectionCapturesHasChanged = false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Helper for InitViews to detect large camera movement, in both angle and position.
|
|
*/
|
|
static bool IsLargeCameraMovement(FSceneView& View, const FMatrix& PrevViewMatrix, const FVector& PrevViewOrigin, float CameraRotationThreshold, float CameraTranslationThreshold)
|
|
{
|
|
float RotationThreshold = FMath::Cos(CameraRotationThreshold * PI / 180.0f);
|
|
float ViewRightAngle = View.ViewMatrices.GetViewMatrix().GetColumn(0) | PrevViewMatrix.GetColumn(0);
|
|
float ViewUpAngle = View.ViewMatrices.GetViewMatrix().GetColumn(1) | PrevViewMatrix.GetColumn(1);
|
|
float ViewDirectionAngle = View.ViewMatrices.GetViewMatrix().GetColumn(2) | PrevViewMatrix.GetColumn(2);
|
|
|
|
FVector Distance = FVector(View.ViewMatrices.GetViewOrigin()) - PrevViewOrigin;
|
|
return
|
|
ViewRightAngle < RotationThreshold ||
|
|
ViewUpAngle < RotationThreshold ||
|
|
ViewDirectionAngle < RotationThreshold ||
|
|
Distance.SizeSquared() > CameraTranslationThreshold * CameraTranslationThreshold;
|
|
}
|
|
|
|
float Halton( int32 Index, int32 Base )
|
|
{
|
|
float Result = 0.0f;
|
|
float InvBase = 1.0f / Base;
|
|
float Fraction = InvBase;
|
|
while( Index > 0 )
|
|
{
|
|
Result += ( Index % Base ) * Fraction;
|
|
Index /= Base;
|
|
Fraction *= InvBase;
|
|
}
|
|
return Result;
|
|
}
|
|
|
|
void FSceneRenderer::PreVisibilityFrameSetup(FRHICommandListImmediate& RHICmdList)
|
|
{
|
|
// Notify the RHI we are beginning to render a scene.
|
|
RHICmdList.BeginScene();
|
|
|
|
// Notify the FX system that the scene is about to perform visibility checks.
|
|
if (Scene->FXSystem && !Views[0].bIsPlanarReflection)
|
|
{
|
|
Scene->FXSystem->PreInitViews();
|
|
}
|
|
|
|
// Draw lines to lights affecting this mesh if its selected.
|
|
if (ViewFamily.EngineShowFlags.LightInfluences)
|
|
{
|
|
for (TArray<FPrimitiveSceneInfo*>::TConstIterator It(Scene->Primitives); It; ++It)
|
|
{
|
|
const FPrimitiveSceneInfo* PrimitiveSceneInfo = *It;
|
|
if (PrimitiveSceneInfo->Proxy->IsSelected())
|
|
{
|
|
FLightPrimitiveInteraction *LightList = PrimitiveSceneInfo->LightList;
|
|
while (LightList)
|
|
{
|
|
const FLightSceneInfo* LightSceneInfo = LightList->GetLight();
|
|
|
|
bool bDynamic = true;
|
|
bool bRelevant = false;
|
|
bool bLightMapped = true;
|
|
bool bShadowMapped = false;
|
|
PrimitiveSceneInfo->Proxy->GetLightRelevance(LightSceneInfo->Proxy, bDynamic, bRelevant, bLightMapped, bShadowMapped);
|
|
|
|
if (bRelevant)
|
|
{
|
|
// Draw blue for light-mapped lights and orange for dynamic lights
|
|
const FColor LineColor = bLightMapped ? FColor(0,140,255) : FColor(255,140,0);
|
|
for (int32 ViewIndex = 0;ViewIndex < Views.Num();ViewIndex++)
|
|
{
|
|
FViewInfo& View = Views[ViewIndex];
|
|
FViewElementPDI LightInfluencesPDI(&View,NULL);
|
|
LightInfluencesPDI.DrawLine(PrimitiveSceneInfo->Proxy->GetBounds().Origin, LightSceneInfo->Proxy->GetLightToWorld().GetOrigin(), LineColor, SDPG_World);
|
|
}
|
|
}
|
|
LightList = LightList->GetNextLight();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Setup motion blur parameters (also check for camera movement thresholds)
|
|
for(int32 ViewIndex = 0;ViewIndex < Views.Num();ViewIndex++)
|
|
{
|
|
FViewInfo& View = Views[ViewIndex];
|
|
FSceneViewState* ViewState = View.ViewState;
|
|
|
|
// Once per render increment the occlusion frame counter.
|
|
if (ViewState)
|
|
{
|
|
ViewState->OcclusionFrameCounter++;
|
|
}
|
|
|
|
// HighResScreenshot should get best results so we don't do the occlusion optimization based on the former frame
|
|
extern bool GIsHighResScreenshot;
|
|
const bool bIsHitTesting = ViewFamily.EngineShowFlags.HitProxies;
|
|
if (GIsHighResScreenshot || !DoOcclusionQueries(FeatureLevel) || bIsHitTesting)
|
|
{
|
|
View.bDisableQuerySubmissions = true;
|
|
View.bIgnoreExistingQueries = true;
|
|
}
|
|
FSceneRenderTargets& SceneContext = FSceneRenderTargets::Get(RHICmdList);
|
|
|
|
// set up the screen area for occlusion
|
|
float NumPossiblePixels = SceneContext.UseDownsizedOcclusionQueries() && IsValidRef(SceneContext.GetSmallDepthSurface()) ?
|
|
(float)View.ViewRect.Width() / SceneContext.GetSmallColorDepthDownsampleFactor() * (float)View.ViewRect.Height() / SceneContext.GetSmallColorDepthDownsampleFactor() :
|
|
View.ViewRect.Width() * View.ViewRect.Height();
|
|
View.OneOverNumPossiblePixels = NumPossiblePixels > 0.0 ? 1.0f / NumPossiblePixels : 0.0f;
|
|
|
|
// Still need no jitter to be set for temporal feedback on SSR (it is enabled even when temporal AA is off).
|
|
View.TemporalJitterPixelsX = 0.0f;
|
|
View.TemporalJitterPixelsY = 0.0f;
|
|
|
|
if (ViewState)
|
|
{
|
|
ViewState->SetupDistanceFieldTemporalOffset(ViewFamily);
|
|
}
|
|
|
|
if( View.AntiAliasingMethod == AAM_TemporalAA && ViewState )
|
|
{
|
|
// Subpixel jitter for temporal AA
|
|
int32 TemporalAASamples = CVarTemporalAASamples.GetValueOnRenderThread();
|
|
|
|
if( TemporalAASamples > 1 && View.bAllowTemporalJitter )
|
|
{
|
|
float SampleX, SampleY;
|
|
|
|
if (Scene->GetFeatureLevel() < ERHIFeatureLevel::SM4)
|
|
{
|
|
// Only support 2 samples for mobile temporal AA.
|
|
TemporalAASamples = 2;
|
|
}
|
|
|
|
if( TemporalAASamples == 2 )
|
|
{
|
|
#if 0
|
|
// 2xMSAA
|
|
// Pattern docs: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476218(v=vs.85).aspx
|
|
// N.
|
|
// .S
|
|
float SamplesX[] = { -4.0f/16.0f, 4.0/16.0f };
|
|
float SamplesY[] = { -4.0f/16.0f, 4.0/16.0f };
|
|
#else
|
|
// This pattern is only used for mobile.
|
|
// Shift to reduce blur.
|
|
float SamplesX[] = { -8.0f/16.0f, 0.0/16.0f };
|
|
float SamplesY[] = { /* - */ 0.0f/16.0f, 8.0/16.0f };
|
|
#endif
|
|
ViewState->OnFrameRenderingSetup(ARRAY_COUNT(SamplesX), ViewFamily);
|
|
uint32 Index = ViewState->GetCurrentTemporalAASampleIndex();
|
|
SampleX = SamplesX[ Index ];
|
|
SampleY = SamplesY[ Index ];
|
|
}
|
|
else if( TemporalAASamples == 3 )
|
|
{
|
|
// 3xMSAA
|
|
// A..
|
|
// ..B
|
|
// .C.
|
|
// Rolling circle pattern (A,B,C).
|
|
float SamplesX[] = { -2.0f/3.0f, 2.0/3.0f, 0.0/3.0f };
|
|
float SamplesY[] = { -2.0f/3.0f, 0.0/3.0f, 2.0/3.0f };
|
|
ViewState->OnFrameRenderingSetup(ARRAY_COUNT(SamplesX), ViewFamily);
|
|
uint32 Index = ViewState->GetCurrentTemporalAASampleIndex();
|
|
SampleX = SamplesX[ Index ];
|
|
SampleY = SamplesY[ Index ];
|
|
}
|
|
else if( TemporalAASamples == 4 )
|
|
{
|
|
// 4xMSAA
|
|
// Pattern docs: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476218(v=vs.85).aspx
|
|
// .N..
|
|
// ...E
|
|
// W...
|
|
// ..S.
|
|
// Rolling circle pattern (N,E,S,W).
|
|
float SamplesX[] = { -2.0f/16.0f, 6.0/16.0f, 2.0/16.0f, -6.0/16.0f };
|
|
float SamplesY[] = { -6.0f/16.0f, -2.0/16.0f, 6.0/16.0f, 2.0/16.0f };
|
|
ViewState->OnFrameRenderingSetup(ARRAY_COUNT(SamplesX), ViewFamily);
|
|
uint32 Index = ViewState->GetCurrentTemporalAASampleIndex();
|
|
SampleX = SamplesX[ Index ];
|
|
SampleY = SamplesY[ Index ];
|
|
}
|
|
else if( TemporalAASamples == 5 )
|
|
{
|
|
// Compressed 4 sample pattern on same vertical and horizontal line (less temporal flicker).
|
|
// Compressed 1/2 works better than correct 2/3 (reduced temporal flicker).
|
|
// . N .
|
|
// W . E
|
|
// . S .
|
|
// Rolling circle pattern (N,E,S,W).
|
|
float SamplesX[] = { 0.0f/2.0f, 1.0/2.0f, 0.0/2.0f, -1.0/2.0f };
|
|
float SamplesY[] = { -1.0f/2.0f, 0.0/2.0f, 1.0/2.0f, 0.0/2.0f };
|
|
ViewState->OnFrameRenderingSetup(ARRAY_COUNT(SamplesX), ViewFamily);
|
|
uint32 Index = ViewState->GetCurrentTemporalAASampleIndex();
|
|
SampleX = SamplesX[ Index ];
|
|
SampleY = SamplesY[ Index ];
|
|
}
|
|
else
|
|
{
|
|
ViewState->OnFrameRenderingSetup(TemporalAASamples, ViewFamily);
|
|
uint32 Index = ViewState->GetCurrentTemporalAASampleIndex();
|
|
|
|
float u1 = Halton( Index + 1, 2 );
|
|
float u2 = Halton( Index + 1, 3 );
|
|
|
|
// Generates samples in normal distribution
|
|
// exp( x^2 / Sigma^2 )
|
|
|
|
static auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.TemporalAAFilterSize"));
|
|
float FilterSize = CVar->GetFloat();
|
|
|
|
// Scale distribution to set non-unit variance
|
|
// Variance = Sigma^2
|
|
float Sigma = 0.47f * FilterSize;
|
|
|
|
// Window to [-0.5, 0.5] output
|
|
// Without windowing we could generate samples far away on the infinite tails.
|
|
float OutWindow = 0.5f;
|
|
float InWindow = FMath::Exp( -0.5 * FMath::Square( OutWindow / Sigma ) );
|
|
|
|
// Box-Muller transform
|
|
float Theta = 2.0f * PI * u2;
|
|
float r = Sigma * FMath::Sqrt( -2.0f * FMath::Loge( (1.0f - u1) * InWindow + u1 ) );
|
|
|
|
SampleX = r * FMath::Cos( Theta );
|
|
SampleY = r * FMath::Sin( Theta );
|
|
}
|
|
|
|
View.TemporalJitterPixelsX = SampleX;
|
|
View.TemporalJitterPixelsY = SampleY;
|
|
|
|
View.ViewMatrices.HackAddTemporalAAProjectionJitter(FVector2D(SampleX * 2.0f / View.ViewRect.Width(), SampleY * -2.0f / View.ViewRect.Height()));
|
|
}
|
|
}
|
|
else if(ViewState)
|
|
{
|
|
// no TemporalAA
|
|
ViewState->OnFrameRenderingSetup(1, ViewFamily);
|
|
|
|
ViewState->TemporalAAHistoryRT.SafeRelease();
|
|
ViewState->PendingTemporalAAHistoryRT.SafeRelease();
|
|
}
|
|
|
|
if ( ViewState )
|
|
{
|
|
// update previous frame matrices in case world origin was rebased on this frame
|
|
if (!View.OriginOffsetThisFrame.IsZero())
|
|
{
|
|
ViewState->PrevViewMatrices.ApplyWorldOffset(View.OriginOffsetThisFrame);
|
|
ViewState->PendingPrevViewMatrices.ApplyWorldOffset(View.OriginOffsetThisFrame);
|
|
}
|
|
|
|
// determine if we are initializing or we should reset the persistent state
|
|
const float DeltaTime = View.Family->CurrentRealTime - ViewState->LastRenderTime;
|
|
const bool bFirstFrameOrTimeWasReset = DeltaTime < -0.0001f || ViewState->LastRenderTime < 0.0001f;
|
|
|
|
// detect conditions where we should reset occlusion queries
|
|
if (bFirstFrameOrTimeWasReset ||
|
|
ViewState->LastRenderTime + GEngine->PrimitiveProbablyVisibleTime < View.Family->CurrentRealTime ||
|
|
View.bCameraCut ||
|
|
IsLargeCameraMovement(
|
|
View,
|
|
ViewState->PrevViewMatrixForOcclusionQuery,
|
|
ViewState->PrevViewOriginForOcclusionQuery,
|
|
GEngine->CameraRotationThreshold, GEngine->CameraTranslationThreshold))
|
|
{
|
|
View.bIgnoreExistingQueries = true;
|
|
View.bDisableDistanceBasedFadeTransitions = true;
|
|
}
|
|
ViewState->PrevViewMatrixForOcclusionQuery = View.ViewMatrices.GetViewMatrix();
|
|
ViewState->PrevViewOriginForOcclusionQuery = View.ViewMatrices.GetViewOrigin();
|
|
|
|
// store old view matrix and detect conditions where we should reset motion blur
|
|
{
|
|
bool bResetCamera = bFirstFrameOrTimeWasReset
|
|
|| View.bCameraCut
|
|
|| IsLargeCameraMovement(View, ViewState->PrevViewMatrices.GetViewMatrix(), ViewState->PrevViewMatrices.GetViewOrigin(), 45.0f, 10000.0f);
|
|
|
|
if (bResetCamera)
|
|
{
|
|
ViewState->PrevViewMatrices = View.ViewMatrices;
|
|
|
|
ViewState->PendingPrevViewMatrices = ViewState->PrevViewMatrices;
|
|
|
|
// PT: If the motion blur shader is the last shader in the post-processing chain then it is the one that is
|
|
// adjusting for the viewport offset. So it is always required and we can't just disable the work the
|
|
// shader does. The correct fix would be to disable the effect when we don't need it and to properly mark
|
|
// the uber-postprocessing effect as the last effect in the chain.
|
|
|
|
View.bPrevTransformsReset = true;
|
|
}
|
|
else
|
|
{
|
|
// check for pause so we can keep motion blur in paused mode (doesn't work in editor)
|
|
if(!ViewFamily.bWorldIsPaused)
|
|
{
|
|
ViewState->PrevViewMatrices = ViewState->PendingPrevViewMatrices;
|
|
if( ViewState->PendingTemporalAAHistoryRT.GetRefCount() )
|
|
{
|
|
ViewState->TemporalAAHistoryRT = ViewState->PendingTemporalAAHistoryRT;
|
|
ViewState->PendingTemporalAAHistoryRT.SafeRelease();
|
|
}
|
|
|
|
// pending is needed as we are in init view and still need to render.
|
|
ViewState->PendingPrevViewMatrices = View.ViewMatrices;
|
|
}
|
|
}
|
|
// we don't use DeltaTime as it can be 0 (in editor) and is computed by subtracting floats (loses precision over time)
|
|
// Clamp DeltaWorldTime to reasonable values for the purposes of motion blur, things like TimeDilation can make it very small
|
|
if (!ViewFamily.bWorldIsPaused)
|
|
{
|
|
const bool bEnableTimeScale = !ViewState->bSequencerIsPaused;
|
|
const float FixedBlurTimeScale = 2.0f;// 1 / (30 * 1 / 60)
|
|
|
|
ViewState->MotionBlurTimeScale = bEnableTimeScale ? (1.0f / (FMath::Max(View.Family->DeltaWorldTime, .00833f) * 30.0f)) : FixedBlurTimeScale;
|
|
}
|
|
|
|
View.PrevViewMatrices = ViewState->PrevViewMatrices;
|
|
}
|
|
|
|
ViewState->PrevFrameNumber = ViewState->PendingPrevFrameNumber;
|
|
ViewState->PendingPrevFrameNumber = View.Family->FrameNumber;
|
|
|
|
// This finishes the update of view state
|
|
ViewState->UpdateLastRenderTime(*View.Family);
|
|
|
|
ViewState->UpdateTemporalLODTransition(View);
|
|
}
|
|
}
|
|
}
|
|
|
|
static TAutoConsoleVariable<int32> CVarAlsoUseSphereForFrustumCull(
|
|
TEXT("r.AlsoUseSphereForFrustumCull"),
|
|
0,
|
|
TEXT("Performance tweak. If > 0, then use a sphere cull before and in addition to a box for frustum culling."),
|
|
ECVF_RenderThreadSafe
|
|
);
|
|
|
|
void FSceneRenderer::ComputeViewVisibility(FRHICommandListImmediate& RHICmdList)
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_ViewVisibilityTime);
|
|
|
|
STAT(int32 NumProcessedPrimitives = 0);
|
|
STAT(int32 NumCulledPrimitives = 0);
|
|
STAT(int32 NumOccludedPrimitives = 0);
|
|
|
|
// Allocate the visible light info.
|
|
if (Scene->Lights.GetMaxIndex() > 0)
|
|
{
|
|
VisibleLightInfos.AddZeroed(Scene->Lights.GetMaxIndex());
|
|
}
|
|
|
|
int32 NumPrimitives = Scene->Primitives.Num();
|
|
float CurrentRealTime = ViewFamily.CurrentRealTime;
|
|
|
|
FPrimitiveViewMasks HasDynamicMeshElementsMasks;
|
|
HasDynamicMeshElementsMasks.AddZeroed(NumPrimitives);
|
|
|
|
FPrimitiveViewMasks HasDynamicEditorMeshElementsMasks;
|
|
|
|
if (GIsEditor)
|
|
{
|
|
HasDynamicEditorMeshElementsMasks.AddZeroed(NumPrimitives);
|
|
}
|
|
|
|
uint8 ViewBit = 0x1;
|
|
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ++ViewIndex, ViewBit <<= 1)
|
|
{
|
|
STAT(NumProcessedPrimitives += NumPrimitives);
|
|
|
|
FViewInfo& View = Views[ViewIndex];
|
|
FSceneViewState* ViewState = (FSceneViewState*)View.State;
|
|
|
|
// Allocate the view's visibility maps.
|
|
View.PrimitiveVisibilityMap.Init(false,Scene->Primitives.Num());
|
|
// we don't initialized as we overwrite the whole array (in GatherDynamicMeshElements)
|
|
View.DynamicMeshEndIndices.SetNumUninitialized(Scene->Primitives.Num());
|
|
View.PrimitiveDefinitelyUnoccludedMap.Init(false,Scene->Primitives.Num());
|
|
View.PotentiallyFadingPrimitiveMap.Init(false,Scene->Primitives.Num());
|
|
View.PrimitiveFadeUniformBuffers.AddZeroed(Scene->Primitives.Num());
|
|
View.StaticMeshVisibilityMap.Init(false,Scene->StaticMeshes.GetMaxIndex());
|
|
View.StaticMeshOccluderMap.Init(false,Scene->StaticMeshes.GetMaxIndex());
|
|
View.StaticMeshFadeOutDitheredLODMap.Init(false,Scene->StaticMeshes.GetMaxIndex());
|
|
View.StaticMeshFadeInDitheredLODMap.Init(false,Scene->StaticMeshes.GetMaxIndex());
|
|
View.StaticMeshVelocityMap.Init(false,Scene->StaticMeshes.GetMaxIndex());
|
|
View.StaticMeshShadowDepthMap.Init(false,Scene->StaticMeshes.GetMaxIndex());
|
|
View.StaticMeshBatchVisibility.AddZeroed(Scene->StaticMeshes.GetMaxIndex());
|
|
|
|
View.VisibleLightInfos.Empty(Scene->Lights.GetMaxIndex());
|
|
|
|
#if WITH_EDITOR
|
|
View.StaticMeshEditorSelectionMap.Init(false, Scene->StaticMeshes.GetMaxIndex());
|
|
#endif
|
|
|
|
// The dirty list allocation must take into account the max possible size because when GILCUpdatePrimTaskEnabled is true,
|
|
// the indirect lighting cache will be update on by threaded job, which can not do reallocs on the buffer (since it uses the SceneRenderingAllocator).
|
|
View.DirtyPrecomputedLightingBufferPrimitives.Reserve(Scene->Primitives.Num());
|
|
|
|
for(int32 LightIndex = 0;LightIndex < Scene->Lights.GetMaxIndex();LightIndex++)
|
|
{
|
|
if( LightIndex+2 < Scene->Lights.GetMaxIndex() )
|
|
{
|
|
if (LightIndex > 2)
|
|
{
|
|
FLUSH_CACHE_LINE(&View.VisibleLightInfos(LightIndex-2));
|
|
}
|
|
// @todo optimization These prefetches cause asserts since LightIndex > View.VisibleLightInfos.Num() - 1
|
|
//FPlatformMisc::Prefetch(&View.VisibleLightInfos[LightIndex+2]);
|
|
//FPlatformMisc::Prefetch(&View.VisibleLightInfos[LightIndex+1]);
|
|
}
|
|
new(View.VisibleLightInfos) FVisibleLightViewInfo();
|
|
}
|
|
|
|
View.PrimitiveViewRelevanceMap.Empty(Scene->Primitives.Num());
|
|
View.PrimitiveViewRelevanceMap.AddZeroed(Scene->Primitives.Num());
|
|
|
|
// If this is the visibility-parent of other views, reset its ParentPrimitives list.
|
|
const bool bIsParent = ViewState && ViewState->IsViewParent();
|
|
if ( bIsParent )
|
|
{
|
|
// PVS-Studio does not understand the validation of ViewState above, so we're disabling
|
|
// its warning that ViewState may be null:
|
|
ViewState->ParentPrimitives.Empty(); //-V595
|
|
}
|
|
|
|
if (ViewState)
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_DecompressPrecomputedOcclusion);
|
|
View.PrecomputedVisibilityData = ViewState->GetPrecomputedVisibilityData(View, Scene);
|
|
}
|
|
else
|
|
{
|
|
View.PrecomputedVisibilityData = NULL;
|
|
}
|
|
|
|
if (View.PrecomputedVisibilityData)
|
|
{
|
|
bUsedPrecomputedVisibility = true;
|
|
}
|
|
|
|
bool bNeedsFrustumCulling = true;
|
|
|
|
// Development builds sometimes override frustum culling, e.g. dependent views in the editor.
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
if( ViewState )
|
|
{
|
|
#if WITH_EDITOR
|
|
// For visibility child views, check if the primitive was visible in the parent view.
|
|
const FSceneViewState* const ViewParent = (FSceneViewState*)ViewState->GetViewParent();
|
|
if(ViewParent)
|
|
{
|
|
bNeedsFrustumCulling = false;
|
|
for (FSceneBitArray::FIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt)
|
|
{
|
|
if (ViewParent->ParentPrimitives.Contains(Scene->PrimitiveComponentIds[BitIt.GetIndex()]))
|
|
{
|
|
BitIt.GetValue() = true;
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
// For views with frozen visibility, check if the primitive is in the frozen visibility set.
|
|
if(ViewState->bIsFrozen)
|
|
{
|
|
bNeedsFrustumCulling = false;
|
|
for (FSceneBitArray::FIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt)
|
|
{
|
|
if (ViewState->FrozenPrimitives.Contains(Scene->PrimitiveComponentIds[BitIt.GetIndex()]))
|
|
{
|
|
BitIt.GetValue() = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// Most views use standard frustum culling.
|
|
if (bNeedsFrustumCulling)
|
|
{
|
|
int32 NumCulledPrimitivesForView;
|
|
if (View.CustomVisibilityQuery && View.CustomVisibilityQuery->Prepare())
|
|
{
|
|
if (CVarAlsoUseSphereForFrustumCull.GetValueOnRenderThread())
|
|
{
|
|
NumCulledPrimitivesForView = FrustumCull<true, true>(Scene, View);
|
|
}
|
|
else
|
|
{
|
|
NumCulledPrimitivesForView = FrustumCull<true, false>(Scene, View);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (CVarAlsoUseSphereForFrustumCull.GetValueOnRenderThread())
|
|
{
|
|
NumCulledPrimitivesForView = FrustumCull<false, true>(Scene, View);
|
|
}
|
|
else
|
|
{
|
|
NumCulledPrimitivesForView = FrustumCull<false, false>(Scene, View);
|
|
}
|
|
}
|
|
STAT(NumCulledPrimitives += NumCulledPrimitivesForView);
|
|
UpdatePrimitiveFading(Scene, View);
|
|
}
|
|
|
|
// If any primitives are explicitly hidden, remove them now.
|
|
if (View.HiddenPrimitives.Num())
|
|
{
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt)
|
|
{
|
|
if (View.HiddenPrimitives.Contains(Scene->PrimitiveComponentIds[BitIt.GetIndex()]))
|
|
{
|
|
View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt) = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// If the view has any show only primitives, hide everything else
|
|
if (View.ShowOnlyPrimitives.Num())
|
|
{
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt)
|
|
{
|
|
if (!View.ShowOnlyPrimitives.Contains(Scene->PrimitiveComponentIds[BitIt.GetIndex()]))
|
|
{
|
|
View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt) = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (View.bStaticSceneOnly)
|
|
{
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt)
|
|
{
|
|
// Reflection captures should only capture objects that won't move, since reflection captures won't update at runtime
|
|
if (!Scene->Primitives[BitIt.GetIndex()]->Proxy->HasStaticLighting())
|
|
{
|
|
View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt) = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Cull small objects in wireframe in ortho views
|
|
// This is important for performance in the editor because wireframe disables any kind of occlusion culling
|
|
if (View.Family->EngineShowFlags.Wireframe)
|
|
{
|
|
float ScreenSizeScale = FMath::Max(View.ViewMatrices.GetProjectionMatrix().M[0][0] * View.ViewRect.Width(), View.ViewMatrices.GetProjectionMatrix().M[1][1] * View.ViewRect.Height());
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt)
|
|
{
|
|
if (ScreenSizeScale * Scene->PrimitiveBounds[BitIt.GetIndex()].SphereRadius <= GWireframeCullThreshold)
|
|
{
|
|
View.PrimitiveVisibilityMap.AccessCorrespondingBit(BitIt) = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Occlusion cull for all primitives in the view frustum, but not in wireframe.
|
|
if (!View.Family->EngineShowFlags.Wireframe)
|
|
{
|
|
int32 NumOccludedPrimitivesInView = OcclusionCull(RHICmdList, Scene, View);
|
|
STAT(NumOccludedPrimitives += NumOccludedPrimitivesInView);
|
|
}
|
|
|
|
// visibility test is done, so now build the hidden flags based on visibility set up
|
|
FLODSceneTree& HLODTree = Scene->SceneLODHierarchy;
|
|
|
|
if (HLODTree.IsActive())
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_ViewVisibilityTime_HLOD);
|
|
HLODTree.UpdateAndApplyVisibilityStates(View);
|
|
}
|
|
|
|
MarkAllPrimitivesForReflectionProxyUpdate(Scene);
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_ViewVisibilityTime_ConditionalMarkStaticMeshElementsForUpdate);
|
|
Scene->ConditionalMarkStaticMeshElementsForUpdate();
|
|
}
|
|
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_ViewRelevance);
|
|
ComputeAndMarkRelevanceForViewParallel(RHICmdList, Scene, View, ViewBit, HasDynamicMeshElementsMasks, HasDynamicEditorMeshElementsMasks);
|
|
}
|
|
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
// Store the primitive for parent occlusion rendering.
|
|
if (FPlatformProperties::SupportsWindowedMode() && ViewState && ViewState->IsViewParent())
|
|
{
|
|
for (FSceneDualSetBitIterator BitIt(View.PrimitiveVisibilityMap, View.PrimitiveDefinitelyUnoccludedMap); BitIt; ++BitIt)
|
|
{
|
|
ViewState->ParentPrimitives.Add(Scene->PrimitiveComponentIds[BitIt.GetIndex()]);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
// if we are freezing the scene, then remember the primitives that are rendered.
|
|
if (ViewState && ViewState->bIsFreezing)
|
|
{
|
|
for (FSceneSetBitIterator BitIt(View.PrimitiveVisibilityMap); BitIt; ++BitIt)
|
|
{
|
|
ViewState->FrozenPrimitives.Add(Scene->PrimitiveComponentIds[BitIt.GetIndex()]);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// TODO: right now decals visibility computed right before rendering them, ideally it should be done in InitViews and this flag should be replaced with list of visible decals
|
|
// Currently used to disable stencil operations in forward base pass when scene has no any decals
|
|
View.bSceneHasDecals = (Scene->Decals.Num() > 0);
|
|
}
|
|
|
|
GatherDynamicMeshElements(Views, Scene, ViewFamily, HasDynamicMeshElementsMasks, HasDynamicEditorMeshElementsMasks, MeshCollector);
|
|
|
|
INC_DWORD_STAT_BY(STAT_ProcessedPrimitives,NumProcessedPrimitives);
|
|
INC_DWORD_STAT_BY(STAT_CulledPrimitives,NumCulledPrimitives);
|
|
INC_DWORD_STAT_BY(STAT_OccludedPrimitives,NumOccludedPrimitives);
|
|
}
|
|
|
|
void FSceneRenderer::PostVisibilityFrameSetup(FILCUpdatePrimTaskData& OutILCTaskData)
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_PostVisibilityFrameSetup);
|
|
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_PostVisibilityFrameSetup_Sort);
|
|
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
|
{
|
|
FViewInfo& View = Views[ViewIndex];
|
|
|
|
View.TranslucentPrimSet.SortPrimitives();
|
|
View.MeshDecalPrimSet.SortPrimitives();
|
|
|
|
if (View.State)
|
|
{
|
|
((FSceneViewState*)View.State)->TrimHistoryRenderTargets(Scene);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool bCheckLightShafts = false;
|
|
if (Scene->GetFeatureLevel() <= ERHIFeatureLevel::ES3_1)
|
|
{
|
|
// Clear the mobile light shaft data.
|
|
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
|
{
|
|
FViewInfo& View = Views[ViewIndex];
|
|
View.bLightShaftUse = false;
|
|
View.LightShaftCenter.X = 0.0f;
|
|
View.LightShaftCenter.Y = 0.0f;
|
|
View.LightShaftColorMask = FLinearColor(0.0f,0.0f,0.0f);
|
|
View.LightShaftColorApply = FLinearColor(0.0f,0.0f,0.0f);
|
|
}
|
|
|
|
extern int32 GLightShafts;
|
|
bCheckLightShafts = ViewFamily.EngineShowFlags.LightShafts && GLightShafts;
|
|
}
|
|
|
|
if (ViewFamily.EngineShowFlags.HitProxies == 0)
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_PostVisibilityFrameSetup_IndirectLightingCache_Update);
|
|
if (GILCUpdatePrimTaskEnabled)
|
|
{
|
|
Scene->IndirectLightingCache.StartUpdateCachePrimitivesTask(Scene, *this, true, OutILCTaskData);
|
|
}
|
|
else
|
|
{
|
|
Scene->IndirectLightingCache.UpdateCache(Scene, *this, true);
|
|
}
|
|
}
|
|
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_PostVisibilityFrameSetup_Light_Visibility);
|
|
// determine visibility of each light
|
|
for(TSparseArray<FLightSceneInfoCompact>::TConstIterator LightIt(Scene->Lights);LightIt;++LightIt)
|
|
{
|
|
const FLightSceneInfoCompact& LightSceneInfoCompact = *LightIt;
|
|
const FLightSceneInfo* LightSceneInfo = LightSceneInfoCompact.LightSceneInfo;
|
|
|
|
// view frustum cull lights in each view
|
|
for(int32 ViewIndex = 0;ViewIndex < Views.Num();ViewIndex++)
|
|
{
|
|
const FLightSceneProxy* Proxy = LightSceneInfo->Proxy;
|
|
FViewInfo& View = Views[ViewIndex];
|
|
FVisibleLightViewInfo& VisibleLightViewInfo = View.VisibleLightInfos[LightIt.GetIndex()];
|
|
// dir lights are always visible, and point/spot only if in the frustum
|
|
if (Proxy->GetLightType() == LightType_Point
|
|
|| Proxy->GetLightType() == LightType_Spot)
|
|
{
|
|
const float Radius = Proxy->GetRadius();
|
|
|
|
if (View.ViewFrustum.IntersectSphere(Proxy->GetOrigin(), Radius))
|
|
{
|
|
if (View.IsPerspectiveProjection())
|
|
{
|
|
FSphere Bounds = Proxy->GetBoundingSphere();
|
|
float DistanceSquared = (Bounds.Center - View.ViewMatrices.GetViewOrigin()).SizeSquared();
|
|
float MaxDistSquared = Proxy->GetMaxDrawDistance() * Proxy->GetMaxDrawDistance() * GLightMaxDrawDistanceScale * GLightMaxDrawDistanceScale;
|
|
const bool bDrawLight = (FMath::Square(FMath::Min(0.0002f, GMinScreenRadiusForLights / Bounds.W) * View.LODDistanceFactor) * DistanceSquared < 1.0f)
|
|
&& (MaxDistSquared == 0 || DistanceSquared < MaxDistSquared);
|
|
|
|
VisibleLightViewInfo.bInViewFrustum = bDrawLight;
|
|
}
|
|
else
|
|
{
|
|
VisibleLightViewInfo.bInViewFrustum = true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
VisibleLightViewInfo.bInViewFrustum = true;
|
|
|
|
static const auto CVarMobileMSAA = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MobileMSAA"));
|
|
bool bNotMobileMSAA = !(CVarMobileMSAA ? CVarMobileMSAA->GetValueOnRenderThread() > 1 : false);
|
|
|
|
// Setup single sun-shaft from direction lights for mobile.
|
|
if(bCheckLightShafts && LightSceneInfo->bEnableLightShaftBloom)
|
|
{
|
|
// Find directional light for sun shafts.
|
|
// Tweaked values from UE3 implementation.
|
|
const float PointLightFadeDistanceIncrease = 200.0f;
|
|
const float PointLightRadiusFadeFactor = 5.0f;
|
|
|
|
const FVector WorldSpaceBlurOrigin = LightSceneInfo->Proxy->GetPosition();
|
|
// Transform into post projection space
|
|
FVector4 ProjectedBlurOrigin = View.WorldToScreen(WorldSpaceBlurOrigin);
|
|
|
|
const float DistanceToBlurOrigin = (View.ViewMatrices.GetViewOrigin() - WorldSpaceBlurOrigin).Size() + PointLightFadeDistanceIncrease;
|
|
|
|
// Don't render if the light's origin is behind the view
|
|
if(ProjectedBlurOrigin.W >= 0.0f
|
|
// Don't render point lights that have completely faded out
|
|
&& (LightSceneInfo->Proxy->GetLightType() == LightType_Directional
|
|
|| DistanceToBlurOrigin < LightSceneInfo->Proxy->GetRadius() * PointLightRadiusFadeFactor))
|
|
{
|
|
View.bLightShaftUse = bNotMobileMSAA;
|
|
View.LightShaftCenter.X = ProjectedBlurOrigin.X / ProjectedBlurOrigin.W;
|
|
View.LightShaftCenter.Y = ProjectedBlurOrigin.Y / ProjectedBlurOrigin.W;
|
|
// TODO: Might want to hookup different colors for these.
|
|
View.LightShaftColorMask = LightSceneInfo->BloomTint;
|
|
View.LightShaftColorApply = LightSceneInfo->BloomTint;
|
|
|
|
// Apply bloom scale
|
|
View.LightShaftColorMask *= FLinearColor(LightSceneInfo->BloomScale, LightSceneInfo->BloomScale, LightSceneInfo->BloomScale, 1.0f);
|
|
View.LightShaftColorApply *= FLinearColor(LightSceneInfo->BloomScale, LightSceneInfo->BloomScale, LightSceneInfo->BloomScale, 1.0f);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Draw shapes for reflection captures
|
|
if( View.bIsReflectionCapture
|
|
&& VisibleLightViewInfo.bInViewFrustum
|
|
&& Proxy->HasStaticLighting()
|
|
&& Proxy->GetLightType() != LightType_Directional
|
|
// Min roughness is used to hide the specular response of virtual area lights, so skip drawing the source shape when Min Roughness is 1
|
|
&& Proxy->GetMinRoughness() < 1.0f)
|
|
{
|
|
FVector Origin = Proxy->GetOrigin();
|
|
FVector ToLight = Origin - View.ViewMatrices.GetViewOrigin();
|
|
float DistanceSqr = ToLight | ToLight;
|
|
float Radius = Proxy->GetRadius();
|
|
|
|
if( DistanceSqr < Radius * Radius )
|
|
{
|
|
FVector4 PositionAndInvRadius;
|
|
FVector4 ColorAndFalloffExponent;
|
|
FVector Direction;
|
|
FVector2D SpotAngles;
|
|
float SourceRadius;
|
|
float SourceLength;
|
|
float MinRoughness;
|
|
Proxy->GetParameters( PositionAndInvRadius, ColorAndFalloffExponent, Direction, SpotAngles, SourceRadius, SourceLength, MinRoughness );
|
|
|
|
// Force to be at least 0.75 pixels
|
|
float CubemapSize = 128.0f;
|
|
float Distance = FMath::Sqrt( DistanceSqr );
|
|
float MinRadius = Distance * 0.75f / CubemapSize;
|
|
SourceRadius = FMath::Max( MinRadius, SourceRadius );
|
|
|
|
// Snap to cubemap pixel center to reduce aliasing
|
|
FVector Scale = ToLight.GetAbs();
|
|
int32 MaxComponent = Scale.X > Scale.Y ? ( Scale.X > Scale.Z ? 0 : 2 ) : ( Scale.Y > Scale.Z ? 1 : 2 );
|
|
for( int32 k = 1; k < 3; k++ )
|
|
{
|
|
float Projected = ToLight[ (MaxComponent + k) % 3 ] / Scale[ MaxComponent ];
|
|
float Quantized = ( FMath::RoundToFloat( Projected * (0.5f * CubemapSize) - 0.5f ) + 0.5f ) / (0.5f * CubemapSize);
|
|
ToLight[ (MaxComponent + k) % 3 ] = Quantized * Scale[ MaxComponent ];
|
|
}
|
|
Origin = ToLight + View.ViewMatrices.GetViewOrigin();
|
|
|
|
FLinearColor Color( ColorAndFalloffExponent );
|
|
|
|
// Scale by visible area
|
|
Color /= PI * FMath::Square( SourceRadius );
|
|
|
|
if( Proxy->IsInverseSquared() )
|
|
{
|
|
// Correction for lumen units
|
|
Color *= 16.0f;
|
|
|
|
float LightRadiusMask = FMath::Square( 1.0f - FMath::Square( DistanceSqr * FMath::Square( PositionAndInvRadius.W ) ) );
|
|
Color.A = LightRadiusMask;
|
|
}
|
|
else
|
|
{
|
|
// Remove inverse square falloff
|
|
Color *= DistanceSqr + 1.0f;
|
|
|
|
// Apply falloff
|
|
Color.A = FMath::Pow( 1.0f - DistanceSqr * FMath::Square( PositionAndInvRadius.W ), ColorAndFalloffExponent.W );
|
|
}
|
|
|
|
// Spot falloff
|
|
FVector L = ToLight.GetSafeNormal();
|
|
Color.A *= FMath::Square( FMath::Clamp( ( (L | Direction) - SpotAngles.X ) * SpotAngles.Y, 0.0f, 1.0f ) );
|
|
|
|
FViewElementPDI LightPDI( &View, NULL );
|
|
FMaterialRenderProxy* const ColoredMeshInstance = new(FMemStack::Get()) FColoredMaterialRenderProxy( GEngine->DebugMeshMaterial->GetRenderProxy(false), Color );
|
|
DrawSphere( &LightPDI, Origin, FVector( SourceRadius, SourceRadius, SourceRadius ), 36, 24, ColoredMeshInstance, SDPG_World );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
{
|
|
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_PostVisibilityFrameSetup_InitFogConstants);
|
|
InitFogConstants();
|
|
}
|
|
}
|
|
|
|
uint32 GetShadowQuality();
|
|
|
|
/**
|
|
* Initialize scene's views.
|
|
* Check visibility, sort translucent items, etc.
|
|
*/
|
|
bool FDeferredShadingSceneRenderer::InitViews(FRHICommandListImmediate& RHICmdList, struct FILCUpdatePrimTaskData& ILCTaskData, FGraphEventArray& SortEvents)
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_InitViewsTime);
|
|
|
|
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
|
{
|
|
FViewInfo& View = Views[ViewIndex];
|
|
|
|
const bool bWillApplyTemporalAA = GPostProcessing.AllowFullPostProcessing(View, FeatureLevel) || (View.bIsPlanarReflection && FeatureLevel >= ERHIFeatureLevel::SM4);
|
|
|
|
if (!bWillApplyTemporalAA)
|
|
{
|
|
// Disable anti-aliasing if we are not going to be able to apply final post process effects
|
|
View.AntiAliasingMethod = AAM_None;
|
|
}
|
|
}
|
|
PreVisibilityFrameSetup(RHICmdList);
|
|
ComputeViewVisibility(RHICmdList);
|
|
|
|
// This has to happen before Scene->IndirectLightingCache.UpdateCache, since primitives in View.IndirectShadowPrimitives need ILC updates
|
|
CreateIndirectCapsuleShadows();
|
|
|
|
PostVisibilityFrameSetup(ILCTaskData);
|
|
|
|
FVector AverageViewPosition(0);
|
|
|
|
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
|
{
|
|
FViewInfo& View = Views[ViewIndex];
|
|
AverageViewPosition += View.ViewMatrices.GetViewOrigin() / Views.Num();
|
|
}
|
|
|
|
if (FApp::ShouldUseThreadingForPerformance() && CVarParallelInitViews.GetValueOnRenderThread() > 0)
|
|
{
|
|
AsyncSortBasePassStaticData(AverageViewPosition, SortEvents);
|
|
}
|
|
else
|
|
{
|
|
SortBasePassStaticData(AverageViewPosition);
|
|
}
|
|
|
|
bool bDoInitViewAftersPrepass = !!GDoInitViewsLightingAfterPrepass;
|
|
|
|
if (!bDoInitViewAftersPrepass)
|
|
{
|
|
InitViewsPossiblyAfterPrepass(RHICmdList, ILCTaskData, SortEvents);
|
|
}
|
|
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_InitViews_InitRHIResources);
|
|
// initialize per-view uniform buffer.
|
|
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
|
{
|
|
FViewInfo& View = Views[ViewIndex];
|
|
|
|
View.ForwardLightingResources = View.ViewState ? &View.ViewState->ForwardLightingResources : &View.ForwardLightingResourcesStorage;
|
|
|
|
// Possible stencil dither optimization approach
|
|
View.bAllowStencilDither = bDitheredLODTransitionsUseStencil;
|
|
|
|
// Initialize the view's RHI resources.
|
|
View.InitRHIResources();
|
|
}
|
|
}
|
|
|
|
SetupVolumetricFog();
|
|
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_InitViews_OnStartFrame);
|
|
OnStartFrame(RHICmdList);
|
|
}
|
|
|
|
return bDoInitViewAftersPrepass;
|
|
}
|
|
|
|
void FDeferredShadingSceneRenderer::InitViewsPossiblyAfterPrepass(FRHICommandListImmediate& RHICmdList, struct FILCUpdatePrimTaskData& ILCTaskData, FGraphEventArray& SortEvents)
|
|
{
|
|
SCOPE_CYCLE_COUNTER(STAT_InitViewsPossiblyAfterPrepass);
|
|
|
|
// this cannot be moved later because of static mesh updates for stuff that is only visible in shadows
|
|
if (SortEvents.Num())
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_FDeferredShadingSceneRenderer_AsyncSortBasePassStaticData_Wait);
|
|
FTaskGraphInterface::Get().WaitUntilTasksComplete(SortEvents, ENamedThreads::RenderThread);
|
|
}
|
|
|
|
if (ViewFamily.EngineShowFlags.DynamicShadows && !IsSimpleForwardShadingEnabled(GetFeatureLevelShaderPlatform(FeatureLevel)))
|
|
{
|
|
// Setup dynamic shadows.
|
|
InitDynamicShadows(RHICmdList);
|
|
}
|
|
|
|
// if we kicked off ILC update via task, wait and finalize.
|
|
if (ILCTaskData.TaskRef.IsValid())
|
|
{
|
|
Scene->IndirectLightingCache.FinalizeCacheUpdates(Scene, *this, ILCTaskData);
|
|
}
|
|
|
|
{
|
|
QUICK_SCOPE_CYCLE_COUNTER(STAT_InitViews_UpdatePrimitivePrecomputedLightingBuffers);
|
|
// Now that the indirect lighting cache is updated, we can update the primitive precomputed lighting buffers.
|
|
UpdatePrimitivePrecomputedLightingBuffers();
|
|
}
|
|
|
|
UpdateTranslucencyTimersAndSeparateTranslucencyBufferSize(RHICmdList);
|
|
|
|
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
|
{
|
|
FViewInfo& View = Views[ViewIndex];
|
|
SetupReflectionCaptureBuffers(View, RHICmdList);
|
|
}
|
|
}
|
|
|
|
/*------------------------------------------------------------------------------
|
|
FLODSceneTree Implementation
|
|
------------------------------------------------------------------------------*/
|
|
void FLODSceneTree::AddChildNode(const FPrimitiveComponentId NodeId, FPrimitiveSceneInfo* ChildSceneInfo)
|
|
{
|
|
if (NodeId.IsValid() && ChildSceneInfo)
|
|
{
|
|
FLODSceneNode* Node = SceneNodes.Find(NodeId);
|
|
|
|
if(!Node)
|
|
{
|
|
Node = &SceneNodes.Add(NodeId, FLODSceneNode());
|
|
|
|
// scene info can be added later depending on order of adding to the scene
|
|
// but at least add componentId, that way when parent is added, it will add its info properly
|
|
int32 ParentIndex = Scene->PrimitiveComponentIds.Find(NodeId);
|
|
if(Scene->Primitives.IsValidIndex(ParentIndex))
|
|
{
|
|
Node->SceneInfo = Scene->Primitives[ParentIndex];
|
|
}
|
|
//new nodes that will need distance scale, reset since we don't keep stateful data about this per node.
|
|
ResetHLODDistanceScaleApplication();
|
|
}
|
|
|
|
Node->AddChild(ChildSceneInfo);
|
|
}
|
|
}
|
|
|
|
void FLODSceneTree::RemoveChildNode(const FPrimitiveComponentId NodeId, FPrimitiveSceneInfo* ChildSceneInfo)
|
|
{
|
|
if(NodeId.IsValid() && ChildSceneInfo)
|
|
{
|
|
FLODSceneNode* Node = SceneNodes.Find(NodeId);
|
|
if (Node)
|
|
{
|
|
Node->RemoveChild(ChildSceneInfo);
|
|
|
|
// delete from scene if no children remains
|
|
if(Node->ChildrenSceneInfos.Num() == 0)
|
|
{
|
|
SceneNodes.Remove(NodeId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void FLODSceneTree::UpdateNodeSceneInfo(FPrimitiveComponentId NodeId, FPrimitiveSceneInfo* SceneInfo)
|
|
{
|
|
FLODSceneNode* Node = SceneNodes.Find(NodeId);
|
|
if(Node)
|
|
{
|
|
Node->SceneInfo = SceneInfo;
|
|
}
|
|
}
|
|
|
|
void FLODSceneTree::UpdateAndApplyVisibilityStates(FViewInfo& View)
|
|
{
|
|
if (FSceneViewState* ViewState = (FSceneViewState*)View.State)
|
|
{
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
// Skip update logic when frozen
|
|
if (ViewState->bIsFrozen)
|
|
{
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
const float HLODDistanceScale = FMath::Max(0.0f, CVarHLODDistanceScale.GetValueOnRenderThread());
|
|
|
|
// Per-frame initialization
|
|
FHLODVisibilityState& HLODState = ViewState->HLODVisibilityState;
|
|
TMap<FPrimitiveComponentId, FHLODSceneNodeVisibilityState>& VisibilityStates = ViewState->HLODSceneNodeVisibilityStates;
|
|
|
|
HLODState.PrimitiveFadingLODMap.Init(false, View.PrimitiveVisibilityMap.Num());
|
|
HLODState.PrimitiveFadingOutLODMap.Init(false, View.PrimitiveVisibilityMap.Num());
|
|
FSceneBitArray& VisibilityFlags = View.PrimitiveVisibilityMap;
|
|
TArray<FPrimitiveViewRelevance, SceneRenderingAllocator>& RelevanceMap = View.PrimitiveViewRelevanceMap;
|
|
|
|
int32 UpdateCount = ++HLODState.UpdateCount;
|
|
|
|
// Update persistent state on temporal dither sync frames
|
|
const FTemporalLODState& LODState = ViewState->GetTemporalLODState();
|
|
bool bSyncFrame = false;
|
|
|
|
if (HLODState.TemporalLODSyncTime != LODState.TemporalLODTime[0])
|
|
{
|
|
HLODState.TemporalLODSyncTime = LODState.TemporalLODTime[0];
|
|
bSyncFrame = true;
|
|
}
|
|
|
|
for (auto Iter = SceneNodes.CreateIterator(); Iter; ++Iter)
|
|
{
|
|
FLODSceneNode& Node = Iter.Value();
|
|
|
|
if (!Node.SceneInfo)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
FHLODSceneNodeVisibilityState& NodeVisibility = VisibilityStates.FindOrAdd(Node.SceneInfo->PrimitiveComponentId);
|
|
const TIndirectArray<FStaticMesh>& NodeMeshes = Node.SceneInfo->StaticMeshes;
|
|
|
|
// Ignore already updated nodes, or those that we can't work with
|
|
if (NodeVisibility.UpdateCount == UpdateCount || NodeMeshes.Num() == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
const int32 NodeIndex = Node.SceneInfo->GetIndex();
|
|
bool bIsVisible = VisibilityFlags[NodeIndex];
|
|
|
|
FPrimitiveBounds& Bounds = Scene->PrimitiveBounds[NodeIndex];
|
|
{
|
|
if (LastHLODDistanceScale != HLODDistanceScale)
|
|
{
|
|
// Determine desired HLOD state
|
|
const float MinDrawDistance = Scene->Primitives[NodeIndex]->Proxy->GetMinDrawDistance();
|
|
const float AdjustedMinDrawDist = MinDrawDistance * HLODDistanceScale;
|
|
Bounds.MinDrawDistanceSq = AdjustedMinDrawDist * AdjustedMinDrawDist;
|
|
}
|
|
}
|
|
|
|
const float DistanceSquared = (Bounds.Origin - View.ViewMatrices.GetViewOrigin()).SizeSquared();
|
|
const bool bIsInDrawRange = DistanceSquared >= Bounds.MinDrawDistanceSq;
|
|
|
|
const bool bWasFadingPreUpdate = !!NodeVisibility.bIsFading;
|
|
|
|
// Update fading state
|
|
if (NodeMeshes[0].bDitheredLODTransition)
|
|
{
|
|
// Fade when HLODs change threshold on-screen, else snap
|
|
// TODO: This logic can still be improved to clear state and
|
|
// transitions when off-screen, but needs better detection
|
|
const bool bChangedRange = bIsInDrawRange != !!NodeVisibility.bWasVisible;
|
|
const bool bIsOnScreen = bIsVisible || NodeVisibility.bWasVisible;
|
|
|
|
// Update with syncs
|
|
if (bSyncFrame)
|
|
{
|
|
if (NodeVisibility.bIsFading)
|
|
{
|
|
NodeVisibility.bIsFading = false;
|
|
}
|
|
else if (bChangedRange && bIsOnScreen)
|
|
{
|
|
NodeVisibility.bIsFading = true;
|
|
}
|
|
|
|
NodeVisibility.bWasVisible = NodeVisibility.bIsVisible;
|
|
NodeVisibility.bIsVisible = bIsInDrawRange;
|
|
}
|
|
|
|
// Flag as fading or freeze visibility if waiting for a fade
|
|
if (NodeVisibility.bIsFading)
|
|
{
|
|
HLODState.PrimitiveFadingLODMap[NodeIndex] = true;
|
|
HLODState.PrimitiveFadingOutLODMap[NodeIndex] = !NodeVisibility.bIsVisible;
|
|
}
|
|
else if (bChangedRange && bIsOnScreen)
|
|
{
|
|
VisibilityFlags[NodeIndex] = !!NodeVisibility.bWasVisible;
|
|
bIsVisible = !!NodeVisibility.bWasVisible;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Instant transitions without dithering
|
|
NodeVisibility.bWasVisible = NodeVisibility.bIsVisible;
|
|
NodeVisibility.bIsVisible = bIsInDrawRange;
|
|
NodeVisibility.bIsFading = false;
|
|
}
|
|
|
|
if (NodeVisibility.bIsFading)
|
|
{
|
|
// Fade until state back in sync
|
|
ApplyNodeFadingToChildren(ViewState, Node, VisibilityFlags, true, !!NodeVisibility.bIsVisible);
|
|
}
|
|
else if (bIsVisible)
|
|
{
|
|
// If stable and visible, override hierarchy visibility
|
|
HideNodeChildren(ViewState, Node, VisibilityFlags);
|
|
}
|
|
|
|
// Flush cached lighting data when changing visible contents
|
|
if (NodeVisibility.bIsVisible != NodeVisibility.bWasVisible || bWasFadingPreUpdate || NodeVisibility.bIsFading)
|
|
{
|
|
FLightPrimitiveInteraction* NodeLightList = Node.SceneInfo->LightList;
|
|
while (NodeLightList)
|
|
{
|
|
NodeLightList->FlushCachedShadowMapData();
|
|
NodeLightList = NodeLightList->GetNextLight();
|
|
}
|
|
}
|
|
|
|
// Force fully disabled view relevance so shadows don't attempt to recompute
|
|
if (!NodeVisibility.bIsVisible)
|
|
{
|
|
FPrimitiveViewRelevance& ViewRelevance = RelevanceMap[NodeIndex];
|
|
FMemory::Memzero(&ViewRelevance, sizeof(FPrimitiveViewRelevance));
|
|
ViewRelevance.bInitializedThisFrame = true;
|
|
}
|
|
}
|
|
LastHLODDistanceScale = HLODDistanceScale;
|
|
}
|
|
}
|
|
|
|
void FLODSceneTree::ApplyNodeFadingToChildren(FSceneViewState* ViewState, FLODSceneNode& Node, FSceneBitArray& VisibilityFlags, const bool bIsFading, const bool bIsFadingOut)
|
|
{
|
|
checkSlow(ViewState);
|
|
FHLODVisibilityState& HLODState = ViewState->HLODVisibilityState;
|
|
TMap<FPrimitiveComponentId, FHLODSceneNodeVisibilityState>& VisibilityStates = ViewState->HLODSceneNodeVisibilityStates;
|
|
FHLODSceneNodeVisibilityState& NodeVisibility = VisibilityStates.FindOrAdd(Node.SceneInfo->PrimitiveComponentId);
|
|
|
|
if (Node.SceneInfo)
|
|
{
|
|
NodeVisibility.UpdateCount = HLODState.UpdateCount;
|
|
|
|
// Force visibility during fades
|
|
const int32 NodeIndex = Node.SceneInfo->GetIndex();
|
|
VisibilityFlags[NodeIndex] = true;
|
|
|
|
for (const auto& Child : Node.ChildrenSceneInfos)
|
|
{
|
|
const int32 ChildIndex = Child->GetIndex();
|
|
|
|
HLODState.PrimitiveFadingLODMap[ChildIndex] = bIsFading;
|
|
HLODState.PrimitiveFadingOutLODMap[ChildIndex] = bIsFadingOut;
|
|
VisibilityFlags[ChildIndex] = true;
|
|
|
|
// Fading only occurs at the adjacent hierarchy level, below should be hidden
|
|
if (FLODSceneNode* ChildNode = SceneNodes.Find(Child->PrimitiveComponentId))
|
|
{
|
|
HideNodeChildren(ViewState, *ChildNode, VisibilityFlags);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void FLODSceneTree::HideNodeChildren(FSceneViewState* ViewState, FLODSceneNode& Node, FSceneBitArray& VisibilityFlags)
|
|
{
|
|
checkSlow(ViewState);
|
|
FHLODVisibilityState& HLODState = ViewState->HLODVisibilityState;
|
|
TMap<FPrimitiveComponentId, FHLODSceneNodeVisibilityState>& VisibilityStates = ViewState->HLODSceneNodeVisibilityStates;
|
|
FHLODSceneNodeVisibilityState& NodeVisibility = VisibilityStates.FindOrAdd(Node.SceneInfo->PrimitiveComponentId);
|
|
|
|
if (NodeVisibility.UpdateCount != HLODState.UpdateCount)
|
|
{
|
|
NodeVisibility.UpdateCount = HLODState.UpdateCount;
|
|
|
|
for (const auto& Child : Node.ChildrenSceneInfos)
|
|
{
|
|
const int32 ChildIndex = Child->GetIndex();
|
|
VisibilityFlags[ChildIndex] = false;
|
|
|
|
if (FLODSceneNode* ChildNode = SceneNodes.Find(Child->PrimitiveComponentId))
|
|
{
|
|
HideNodeChildren(ViewState, *ChildNode, VisibilityFlags);
|
|
}
|
|
}
|
|
}
|
|
}
|