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]
2409 lines
82 KiB
C++
2409 lines
82 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
ScenePrivate.h: Private scene manager definitions.
|
|
=============================================================================*/
|
|
|
|
#pragma once
|
|
|
|
// Dependencies.
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Misc/Guid.h"
|
|
#include "Math/RandomStream.h"
|
|
#include "Engine/EngineTypes.h"
|
|
#include "RHI.h"
|
|
#include "RenderResource.h"
|
|
#include "RenderingThread.h"
|
|
#include "SceneTypes.h"
|
|
#include "UniformBuffer.h"
|
|
#include "SceneInterface.h"
|
|
#include "SceneView.h"
|
|
#include "RendererInterface.h"
|
|
#include "SceneUtils.h"
|
|
#include "SceneManagement.h"
|
|
#include "Materials/MaterialInstanceDynamic.h"
|
|
#include "TextureLayout3d.h"
|
|
#include "ScenePrivateBase.h"
|
|
#include "PostProcess/RenderTargetPool.h"
|
|
#include "SceneCore.h"
|
|
#include "PrimitiveSceneInfo.h"
|
|
#include "LightSceneInfo.h"
|
|
#include "DepthRendering.h"
|
|
#include "SceneHitProxyRendering.h"
|
|
#include "ShadowRendering.h"
|
|
#include "TextureLayout.h"
|
|
#include "SceneRendering.h"
|
|
#include "StaticMeshDrawList.h"
|
|
#include "LightMapRendering.h"
|
|
#include "VelocityRendering.h"
|
|
#include "BasePassRendering.h"
|
|
#include "MobileBasePassRendering.h"
|
|
#include "VolumeRendering.h"
|
|
|
|
/** Factor by which to grow occlusion tests **/
|
|
#define OCCLUSION_SLOP (1.0f)
|
|
|
|
class AWorldSettings;
|
|
class FAtmosphericFogSceneInfo;
|
|
class FLightPropagationVolume;
|
|
class FMaterialParameterCollectionInstanceResource;
|
|
class FPrecomputedLightVolume;
|
|
class FScene;
|
|
class UAtmosphericFogComponent;
|
|
class UDecalComponent;
|
|
class UExponentialHeightFogComponent;
|
|
class ULightComponent;
|
|
class UPlanarReflectionComponent;
|
|
class UPrimitiveComponent;
|
|
class UReflectionCaptureComponent;
|
|
class USkyLightComponent;
|
|
class UStaticMesh;
|
|
class UStaticMeshComponent;
|
|
class UTextureCube;
|
|
class UWindDirectionalSourceComponent;
|
|
|
|
/** Holds information about a single primitive's occlusion. */
|
|
class FPrimitiveOcclusionHistory
|
|
{
|
|
public:
|
|
/** The primitive the occlusion information is about. */
|
|
FPrimitiveComponentId PrimitiveId;
|
|
|
|
/** The occlusion query which contains the primitive's pending occlusion results. */
|
|
TArray<FRenderQueryRHIRef, TInlineAllocator<FOcclusionQueryHelpers::MaxBufferedOcclusionFrames> > PendingOcclusionQuery;
|
|
|
|
uint32 HZBTestIndex;
|
|
uint32 HZBTestFrameNumber;
|
|
|
|
/** The last time the primitive was visible. */
|
|
float LastVisibleTime;
|
|
|
|
/** The last time the primitive was in the view frustum. */
|
|
float LastConsideredTime;
|
|
|
|
/**
|
|
* The pixels that were rendered the last time the primitive was drawn.
|
|
* It is the ratio of pixels unoccluded to the resolution of the scene.
|
|
*/
|
|
float LastPixelsPercentage;
|
|
|
|
/** whether or not this primitive was grouped the last time it was queried */
|
|
bool bGroupedQuery;
|
|
|
|
/**
|
|
* For things that have subqueries (folaige), this is the non-zero
|
|
*/
|
|
int32 CustomIndex;
|
|
|
|
/** Initialization constructor. */
|
|
FORCEINLINE FPrimitiveOcclusionHistory(FPrimitiveComponentId InPrimitiveId, int32 SubQuery)
|
|
: PrimitiveId(InPrimitiveId)
|
|
, HZBTestIndex(0)
|
|
, HZBTestFrameNumber(~0u)
|
|
, LastVisibleTime(0.0f)
|
|
, LastConsideredTime(0.0f)
|
|
, LastPixelsPercentage(0.0f)
|
|
, bGroupedQuery(false)
|
|
, CustomIndex(SubQuery)
|
|
{
|
|
PendingOcclusionQuery.Empty(FOcclusionQueryHelpers::MaxBufferedOcclusionFrames);
|
|
PendingOcclusionQuery.AddZeroed(FOcclusionQueryHelpers::MaxBufferedOcclusionFrames);
|
|
}
|
|
|
|
FORCEINLINE FPrimitiveOcclusionHistory()
|
|
: HZBTestIndex(0)
|
|
, HZBTestFrameNumber(~0u)
|
|
, LastVisibleTime(0.0f)
|
|
, LastConsideredTime(0.0f)
|
|
, LastPixelsPercentage(0.0f)
|
|
, bGroupedQuery(false)
|
|
, CustomIndex(0)
|
|
{
|
|
PendingOcclusionQuery.Empty(FOcclusionQueryHelpers::MaxBufferedOcclusionFrames);
|
|
PendingOcclusionQuery.AddZeroed(FOcclusionQueryHelpers::MaxBufferedOcclusionFrames);
|
|
}
|
|
|
|
|
|
/** Destructor. Note that the query should have been released already. */
|
|
~FPrimitiveOcclusionHistory()
|
|
{
|
|
// check( !IsValidRef(PendingOcclusionQuery) );
|
|
}
|
|
|
|
template<class TOcclusionQueryPool> // here we use a template just to allow this to be inlined without sorting out the header order
|
|
FORCEINLINE void ReleaseQueries(FRHICommandListImmediate& RHICmdList, TOcclusionQueryPool& Pool, int32 NumBufferedFrames)
|
|
{
|
|
for (int32 QueryIndex = 0; QueryIndex < NumBufferedFrames; QueryIndex++)
|
|
{
|
|
Pool.ReleaseQuery(PendingOcclusionQuery[QueryIndex]);
|
|
}
|
|
}
|
|
|
|
FORCEINLINE FRenderQueryRHIRef& GetPastQuery(uint32 FrameNumber, int32 NumBufferedFrames)
|
|
{
|
|
// Get the oldest occlusion query
|
|
const uint32 QueryIndex = FOcclusionQueryHelpers::GetQueryLookupIndex(FrameNumber, NumBufferedFrames);
|
|
return PendingOcclusionQuery[QueryIndex];
|
|
}
|
|
|
|
FORCEINLINE void SetCurrentQuery(uint32 FrameNumber, FRenderQueryRHIParamRef NewQuery, int32 NumBufferedFrames)
|
|
{
|
|
// Get the current occlusion query
|
|
const uint32 QueryIndex = FOcclusionQueryHelpers::GetQueryIssueIndex(FrameNumber, NumBufferedFrames);
|
|
PendingOcclusionQuery[QueryIndex] = NewQuery;
|
|
}
|
|
};
|
|
|
|
struct FPrimitiveOcclusionHistoryKey
|
|
{
|
|
FPrimitiveComponentId PrimitiveId;
|
|
int32 CustomIndex;
|
|
|
|
FPrimitiveOcclusionHistoryKey(const FPrimitiveOcclusionHistory& Element)
|
|
: PrimitiveId(Element.PrimitiveId)
|
|
, CustomIndex(Element.CustomIndex)
|
|
{
|
|
}
|
|
FPrimitiveOcclusionHistoryKey(FPrimitiveComponentId InPrimitiveId, int32 InCustomIndex)
|
|
: PrimitiveId(InPrimitiveId)
|
|
, CustomIndex(InCustomIndex)
|
|
{
|
|
}
|
|
};
|
|
|
|
/** Defines how the hash set indexes the FPrimitiveOcclusionHistory objects. */
|
|
struct FPrimitiveOcclusionHistoryKeyFuncs : BaseKeyFuncs<FPrimitiveOcclusionHistory,FPrimitiveOcclusionHistoryKey>
|
|
{
|
|
typedef FPrimitiveOcclusionHistoryKey KeyInitType;
|
|
|
|
static KeyInitType GetSetKey(const FPrimitiveOcclusionHistory& Element)
|
|
{
|
|
return FPrimitiveOcclusionHistoryKey(Element);
|
|
}
|
|
|
|
static bool Matches(KeyInitType A,KeyInitType B)
|
|
{
|
|
return A.PrimitiveId == B.PrimitiveId && A.CustomIndex == B.CustomIndex;
|
|
}
|
|
|
|
static uint32 GetKeyHash(KeyInitType Key)
|
|
{
|
|
return GetTypeHash(Key.PrimitiveId.PrimIDValue) ^ (GetTypeHash(Key.CustomIndex) >> 20);
|
|
}
|
|
};
|
|
|
|
|
|
class FIndividualOcclusionHistory
|
|
{
|
|
TArray<FRenderQueryRHIRef, TInlineAllocator<FOcclusionQueryHelpers::MaxBufferedOcclusionFrames> > PendingOcclusionQuery;
|
|
|
|
public:
|
|
|
|
FORCEINLINE FIndividualOcclusionHistory()
|
|
{
|
|
PendingOcclusionQuery.Empty(FOcclusionQueryHelpers::MaxBufferedOcclusionFrames);
|
|
PendingOcclusionQuery.AddZeroed(FOcclusionQueryHelpers::MaxBufferedOcclusionFrames);
|
|
}
|
|
|
|
|
|
template<class TOcclusionQueryPool> // here we use a template just to allow this to be inlined without sorting out the header order
|
|
FORCEINLINE void ReleaseQueries(FRHICommandListImmediate& RHICmdList, TOcclusionQueryPool& Pool, int32 NumBufferedFrames)
|
|
{
|
|
for (int32 QueryIndex = 0; QueryIndex < NumBufferedFrames; QueryIndex++)
|
|
{
|
|
Pool.ReleaseQuery(PendingOcclusionQuery[QueryIndex]);
|
|
}
|
|
}
|
|
|
|
FORCEINLINE FRenderQueryRHIRef& GetPastQuery(uint32 FrameNumber, int32 NumBufferedFrames)
|
|
{
|
|
// Get the oldest occlusion query
|
|
const uint32 QueryIndex = FOcclusionQueryHelpers::GetQueryLookupIndex(FrameNumber, NumBufferedFrames);
|
|
return PendingOcclusionQuery[QueryIndex];
|
|
}
|
|
|
|
FORCEINLINE void SetCurrentQuery(uint32 FrameNumber, FRenderQueryRHIParamRef NewQuery, int32 NumBufferedFrames)
|
|
{
|
|
// Get the current occlusion query
|
|
const uint32 QueryIndex = FOcclusionQueryHelpers::GetQueryIssueIndex(FrameNumber, NumBufferedFrames);
|
|
PendingOcclusionQuery[QueryIndex] = NewQuery;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Distance cull fading uniform buffer containing faded in
|
|
*/
|
|
class FGlobalDistanceCullFadeUniformBuffer : public TUniformBuffer< FDistanceCullFadeUniformShaderParameters >
|
|
{
|
|
public:
|
|
/** Default constructor. */
|
|
FGlobalDistanceCullFadeUniformBuffer()
|
|
{
|
|
FDistanceCullFadeUniformShaderParameters Uniforms;
|
|
Uniforms.FadeTimeScaleBias.X = 0.0f;
|
|
Uniforms.FadeTimeScaleBias.Y = 1.0f;
|
|
SetContents( Uniforms );
|
|
}
|
|
};
|
|
|
|
/** Global primitive uniform buffer resource containing faded in */
|
|
extern TGlobalResource< FGlobalDistanceCullFadeUniformBuffer > GDistanceCullFadedInUniformBuffer;
|
|
|
|
/**
|
|
* Stores fading state for a single primitive in a single view
|
|
*/
|
|
class FPrimitiveFadingState
|
|
{
|
|
public:
|
|
FPrimitiveFadingState()
|
|
: FadeTimeScaleBias(ForceInitToZero)
|
|
, FrameNumber(0)
|
|
, EndTime(0.0f)
|
|
, bIsVisible(false)
|
|
, bValid(false)
|
|
{
|
|
}
|
|
|
|
/** Scale and bias to use on time to calculate fade opacity */
|
|
FVector2D FadeTimeScaleBias;
|
|
|
|
/** The uniform buffer for the fade parameters */
|
|
FDistanceCullFadeUniformBufferRef UniformBuffer;
|
|
|
|
/** Frame number when last updated */
|
|
uint32 FrameNumber;
|
|
|
|
/** Time when fade will be finished. */
|
|
float EndTime;
|
|
|
|
/** Currently visible? */
|
|
bool bIsVisible;
|
|
|
|
/** Valid? */
|
|
bool bValid;
|
|
};
|
|
|
|
enum FGlobalDFCacheType
|
|
{
|
|
GDF_MostlyStatic,
|
|
GDF_Full,
|
|
GDF_Num
|
|
};
|
|
|
|
class FGlobalDistanceFieldCacheTypeState
|
|
{
|
|
public:
|
|
|
|
FGlobalDistanceFieldCacheTypeState()
|
|
{
|
|
}
|
|
|
|
TArray<FVector4> PrimitiveModifiedBounds;
|
|
TRefCountPtr<IPooledRenderTarget> VolumeTexture;
|
|
};
|
|
|
|
class FGlobalDistanceFieldClipmapState
|
|
{
|
|
public:
|
|
|
|
FGlobalDistanceFieldClipmapState()
|
|
{
|
|
FullUpdateOrigin = FIntVector::ZeroValue;
|
|
LastPartialUpdateOrigin = FIntVector::ZeroValue;
|
|
CachedMaxOcclusionDistance = 0;
|
|
CachedGlobalDistanceFieldViewDistance = 0;
|
|
CacheMostlyStaticSeparately = 1;
|
|
}
|
|
|
|
FIntVector FullUpdateOrigin;
|
|
FIntVector LastPartialUpdateOrigin;
|
|
float CachedMaxOcclusionDistance;
|
|
float CachedGlobalDistanceFieldViewDistance;
|
|
uint32 CacheMostlyStaticSeparately;
|
|
|
|
FGlobalDistanceFieldCacheTypeState Cache[GDF_Num];
|
|
};
|
|
|
|
/** Maps a single primitive to it's per-view fading state data */
|
|
typedef TMap<FPrimitiveComponentId, FPrimitiveFadingState> FPrimitiveFadingStateMap;
|
|
|
|
class FOcclusionRandomStream
|
|
{
|
|
enum {NumSamples = 3571};
|
|
public:
|
|
|
|
/** Default constructor - should set seed prior to use. */
|
|
FOcclusionRandomStream()
|
|
: CurrentSample(0)
|
|
{
|
|
FRandomStream RandomStream(0x83246);
|
|
for (int32 Index = 0; Index < NumSamples; Index++)
|
|
{
|
|
Samples[Index] = RandomStream.GetFraction();
|
|
}
|
|
Samples[0] = 0.0f; // we want to make sure we have at least a few zeros
|
|
Samples[NumSamples/3] = 0.0f; // we want to make sure we have at least a few zeros
|
|
Samples[(NumSamples*2)/3] = 0.0f; // we want to make sure we have at least a few zeros
|
|
}
|
|
|
|
/** @return A random number between 0 and 1. */
|
|
FORCEINLINE float GetFraction()
|
|
{
|
|
if (CurrentSample >= NumSamples)
|
|
{
|
|
CurrentSample = 0;
|
|
}
|
|
return Samples[CurrentSample++];
|
|
}
|
|
private:
|
|
|
|
/** Index of the last sample we produced **/
|
|
uint32 CurrentSample;
|
|
/** A list of float random samples **/
|
|
float Samples[NumSamples];
|
|
};
|
|
|
|
/** Random table for occlusion **/
|
|
extern FOcclusionRandomStream GOcclusionRandomStream;
|
|
|
|
|
|
/**
|
|
Helper class to time sections of the GPU work.
|
|
Buffers multiple frames to avoid waiting on the GPU so times are a little lagged.
|
|
*/
|
|
class FLatentGPUTimer
|
|
{
|
|
static const int32 NumBufferedFrames = FOcclusionQueryHelpers::MaxBufferedOcclusionFrames + 1;
|
|
|
|
public:
|
|
|
|
FLatentGPUTimer(int32 InAvgSamples = 30);
|
|
|
|
void Release();
|
|
|
|
/** Retrieves the most recently ready query results. */
|
|
bool Tick(FRHICommandListImmediate& RHICmdList);
|
|
/** Kicks off the query for the start of the rendering you're timing. */
|
|
void Begin(FRHICommandListImmediate& RHICmdList);
|
|
/** Kicks off the query for the end of the rendering you're timing. */
|
|
void End(FRHICommandListImmediate& RHICmdList);
|
|
|
|
/** Returns the most recent time in ms. */
|
|
float GetTimeMS();
|
|
/** Gets the average time in ms. Average is tracked over AvgSamples. */
|
|
float GetAverageTimeMS();
|
|
|
|
private:
|
|
|
|
int32 GetQueryIndex();
|
|
|
|
//Average Tracking;
|
|
int32 AvgSamples;
|
|
TArray<float> TimeSamples;
|
|
float TotalTime;
|
|
int32 SampleIndex;
|
|
|
|
int32 QueryIndex;
|
|
FRenderQueryRHIRef StartQueries[NumBufferedFrames];
|
|
FRenderQueryRHIRef EndQueries[NumBufferedFrames];
|
|
FGraphEventRef QuerySubmittedFences[NumBufferedFrames];
|
|
};
|
|
|
|
/** HLOD tree persistent fading and visibility state */
|
|
class FHLODVisibilityState
|
|
{
|
|
public:
|
|
FHLODVisibilityState()
|
|
: TemporalLODSyncTime(0.0f)
|
|
, UpdateCount(0)
|
|
{}
|
|
|
|
bool IsNodeFading(const int32 PrimIndex) const
|
|
{
|
|
checkSlow(PrimitiveFadingLODMap.IsValidIndex(PrimIndex));
|
|
return PrimitiveFadingLODMap[PrimIndex];
|
|
}
|
|
|
|
bool IsNodeFadingOut(const int32 PrimIndex) const
|
|
{
|
|
checkSlow(PrimitiveFadingOutLODMap.IsValidIndex(PrimIndex));
|
|
return PrimitiveFadingOutLODMap[PrimIndex];
|
|
}
|
|
|
|
TBitArray<> PrimitiveFadingLODMap;
|
|
TBitArray<> PrimitiveFadingOutLODMap;
|
|
float TemporalLODSyncTime;
|
|
uint16 UpdateCount;
|
|
};
|
|
|
|
/** HLOD scene node persistent fading and visibility state */
|
|
struct FHLODSceneNodeVisibilityState
|
|
{
|
|
FHLODSceneNodeVisibilityState()
|
|
: UpdateCount(0)
|
|
, bWasVisible(0)
|
|
, bIsVisible(0)
|
|
, bIsFading(0)
|
|
{}
|
|
|
|
/** Last updated FrameCount */
|
|
uint16 UpdateCount;
|
|
|
|
/** Persistent visibility states */
|
|
uint16 bWasVisible : 1;
|
|
uint16 bIsVisible : 1;
|
|
uint16 bIsFading : 1;
|
|
};
|
|
|
|
/**
|
|
* The scene manager's private implementation of persistent view state.
|
|
* This class is associated with a particular camera across multiple frames by the game thread.
|
|
* The game thread calls FRendererModule::AllocateViewState to create an instance of this private implementation.
|
|
*/
|
|
class FSceneViewState : public FSceneViewStateInterface, public FDeferredCleanupInterface, public FRenderResource
|
|
{
|
|
public:
|
|
|
|
class FProjectedShadowKey
|
|
{
|
|
public:
|
|
|
|
FORCEINLINE bool operator == (const FProjectedShadowKey &Other) const
|
|
{
|
|
return (PrimitiveId == Other.PrimitiveId && Light == Other.Light && ShadowSplitIndex == Other.ShadowSplitIndex && CacheMode == Other.CacheMode && bTranslucentShadow == Other.bTranslucentShadow);
|
|
}
|
|
|
|
FProjectedShadowKey(const FProjectedShadowInfo& ProjectedShadowInfo)
|
|
: PrimitiveId(ProjectedShadowInfo.GetParentSceneInfo() ? ProjectedShadowInfo.GetParentSceneInfo()->PrimitiveComponentId : FPrimitiveComponentId())
|
|
, Light(ProjectedShadowInfo.GetLightSceneInfo().Proxy->GetLightComponent())
|
|
, ShadowSplitIndex(ProjectedShadowInfo.CascadeSettings.ShadowSplitIndex)
|
|
, CacheMode(ProjectedShadowInfo.CacheMode)
|
|
, bTranslucentShadow(ProjectedShadowInfo.bTranslucentShadow)
|
|
{
|
|
}
|
|
|
|
FProjectedShadowKey(FPrimitiveComponentId InPrimitiveId, const ULightComponent* InLight, int32 InSplitIndex, bool bInTranslucentShadow)
|
|
: PrimitiveId(InPrimitiveId)
|
|
, Light(InLight)
|
|
, ShadowSplitIndex(InSplitIndex)
|
|
, CacheMode(SDCM_Uncached)
|
|
, bTranslucentShadow(bInTranslucentShadow)
|
|
{
|
|
}
|
|
|
|
friend FORCEINLINE uint32 GetTypeHash(const FSceneViewState::FProjectedShadowKey& Key)
|
|
{
|
|
return PointerHash(Key.Light,GetTypeHash(Key.PrimitiveId));
|
|
}
|
|
|
|
private:
|
|
FPrimitiveComponentId PrimitiveId;
|
|
const ULightComponent* Light;
|
|
int32 ShadowSplitIndex;
|
|
EShadowDepthCacheMode CacheMode;
|
|
bool bTranslucentShadow;
|
|
};
|
|
|
|
uint32 UniqueID;
|
|
typedef TMap<FSceneViewState::FProjectedShadowKey, FRenderQueryRHIRef> ShadowKeyOcclusionQueryMap;
|
|
TArray<ShadowKeyOcclusionQueryMap, TInlineAllocator<FOcclusionQueryHelpers::MaxBufferedOcclusionFrames> > ShadowOcclusionQueryMaps;
|
|
|
|
/** The view's occlusion query pool. */
|
|
FRenderQueryPool OcclusionQueryPool;
|
|
|
|
FHZBOcclusionTester HZBOcclusionTests;
|
|
|
|
/** Storage to which compressed visibility chunks are uncompressed at runtime. */
|
|
TArray<uint8> DecompressedVisibilityChunk;
|
|
|
|
/** Cached visibility data from the last call to GetPrecomputedVisibilityData. */
|
|
const TArray<uint8>* CachedVisibilityChunk;
|
|
int32 CachedVisibilityHandlerId;
|
|
int32 CachedVisibilityBucketIndex;
|
|
int32 CachedVisibilityChunkIndex;
|
|
|
|
/** Parameter to keep track of previous frame. Managed by the rendering thread. */
|
|
FViewMatrices PrevViewMatrices;
|
|
FViewMatrices PendingPrevViewMatrices;
|
|
|
|
uint32 PendingPrevFrameNumber;
|
|
uint32 PrevFrameNumber;
|
|
float LastRenderTime;
|
|
float LastRenderTimeDelta;
|
|
float MotionBlurTimeScale;
|
|
FMatrix PrevViewMatrixForOcclusionQuery;
|
|
FVector PrevViewOriginForOcclusionQuery;
|
|
|
|
// A counter incremented once each time this view is rendered.
|
|
uint32 OcclusionFrameCounter;
|
|
|
|
/** Used by states that have IsViewParent() == true to store primitives for child states. */
|
|
TSet<FPrimitiveComponentId> ParentPrimitives;
|
|
|
|
/** For this view, the set of primitives that are currently fading, either in or out. */
|
|
FPrimitiveFadingStateMap PrimitiveFadingStates;
|
|
|
|
FIndirectLightingCacheAllocation* TranslucencyLightingCacheAllocations[TVC_MAX];
|
|
|
|
TMap<int32, FIndividualOcclusionHistory> PlanarReflectionOcclusionHistories;
|
|
|
|
// Array of ClipmapIndex
|
|
TArray<int32> DeferredGlobalDistanceFieldUpdates[GDF_Num];
|
|
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
/** Are we currently in the state of freezing rendering? (1 frame where we gather what was rendered) */
|
|
uint32 bIsFreezing : 1;
|
|
|
|
/** Is rendering currently frozen? */
|
|
uint32 bIsFrozen : 1;
|
|
|
|
/** True if the CachedViewMatrices is holding frozen view matrices, otherwise false */
|
|
uint32 bIsFrozenViewMatricesCached : 1;
|
|
|
|
/** The set of primitives that were rendered the frame that we froze rendering */
|
|
TSet<FPrimitiveComponentId> FrozenPrimitives;
|
|
|
|
/** The cache view matrices at the time of freezing or the cached debug fly cam's view matrices. */
|
|
FViewMatrices CachedViewMatrices;
|
|
#endif
|
|
|
|
/** HLOD persistent fading and visibility state */
|
|
FHLODVisibilityState HLODVisibilityState;
|
|
TMap<FPrimitiveComponentId, FHLODSceneNodeVisibilityState> HLODSceneNodeVisibilityStates;
|
|
|
|
private:
|
|
|
|
// to implement eye adaptation / auto exposure changes over time
|
|
class FEyeAdaptationRTManager
|
|
{
|
|
public:
|
|
|
|
FEyeAdaptationRTManager() :
|
|
CurrentBuffer(0) {};
|
|
|
|
void SafeRelease()
|
|
{
|
|
PooledRenderTarget[0].SafeRelease();
|
|
PooledRenderTarget[1].SafeRelease();
|
|
}
|
|
|
|
/** Return current Render Target */
|
|
TRefCountPtr<IPooledRenderTarget>& GetCurrentRT(FRHICommandList& RHICmdList)
|
|
{
|
|
return GetRTRef(RHICmdList, CurrentBuffer);
|
|
}
|
|
|
|
/** Return old Render Target*/
|
|
TRefCountPtr<IPooledRenderTarget>& GetLastRT(FRHICommandList& RHICmdList)
|
|
{
|
|
return GetRTRef(RHICmdList, 1 - CurrentBuffer);
|
|
}
|
|
|
|
/** Reverse the current/last order of the targets */
|
|
void SwapRTs()
|
|
{
|
|
CurrentBuffer = 1 - CurrentBuffer;
|
|
}
|
|
|
|
private:
|
|
|
|
/** Return one of two two render targets */
|
|
TRefCountPtr<IPooledRenderTarget>& GetRTRef(FRHICommandList& RHICmdList, const int BufferNumber)
|
|
{
|
|
check(BufferNumber == 0 || BufferNumber == 1);
|
|
|
|
// Create textures if needed.
|
|
if (!PooledRenderTarget[BufferNumber].IsValid())
|
|
{
|
|
// Create the texture needed for EyeAdaptation
|
|
FPooledRenderTargetDesc Desc(FPooledRenderTargetDesc::Create2DDesc(FIntPoint(1, 1), PF_G32R32F, FClearValueBinding::None, TexCreate_None, TexCreate_RenderTargetable, false));
|
|
if (GMaxRHIFeatureLevel >= ERHIFeatureLevel::SM5)
|
|
{
|
|
Desc.TargetableFlags |= TexCreate_UAV;
|
|
}
|
|
GRenderTargetPool.FindFreeElement(RHICmdList, Desc, PooledRenderTarget[BufferNumber], TEXT("EyeAdaptation"));
|
|
}
|
|
|
|
return PooledRenderTarget[BufferNumber];
|
|
}
|
|
|
|
private:
|
|
|
|
int CurrentBuffer;
|
|
TRefCountPtr<IPooledRenderTarget> PooledRenderTarget[2];
|
|
} EyeAdaptationRTManager;
|
|
|
|
// eye adaptation is only valid after it has been computed, not on allocation of the RT
|
|
bool bValidEyeAdaptation;
|
|
|
|
// The LUT used by tonemapping. In stereo this is only computed and stored by the Left Eye.
|
|
TRefCountPtr<IPooledRenderTarget> CombinedLUTRenderTarget;
|
|
|
|
// LUT is only valid after it has been computed, not on allocation of the RT
|
|
bool bValidTonemappingLUT;
|
|
|
|
|
|
// used by the Postprocess Material Blending system to avoid recreation and garbage collection of MIDs
|
|
TArray<UMaterialInstanceDynamic*> MIDPool;
|
|
uint32 MIDUsedCount;
|
|
|
|
// if TemporalAA is on this cycles through 0..TemporalAASampleCount-1, ResetViewState() puts it back to 0
|
|
uint8 TemporalAASampleIndex;
|
|
// >= 1, 1 means there is no TemporalAA
|
|
uint8 TemporalAASampleCount;
|
|
|
|
// counts up by one each frame, warped in 0..7 range, ResetViewState() puts it back to 0
|
|
uint32 FrameIndexMod8;
|
|
|
|
// counts up by one each frame, warped in 0..3 range, ResetViewState() puts it back to 0
|
|
int32 DistanceFieldTemporalSampleIndex;
|
|
|
|
// light propagation volume used in this view
|
|
TRefCountPtr<FLightPropagationVolume> LightPropagationVolume;
|
|
|
|
// whether this view is a stereo counterpart to a primary view
|
|
bool bIsStereoView;
|
|
|
|
public:
|
|
|
|
FHeightfieldLightingAtlas* HeightfieldLightingAtlas;
|
|
|
|
// Temporal AA result of last frame
|
|
TRefCountPtr<IPooledRenderTarget> TemporalAAHistoryRT;
|
|
TRefCountPtr<IPooledRenderTarget> PendingTemporalAAHistoryRT;
|
|
// Temporal AA result for DOF of last frame
|
|
TRefCountPtr<IPooledRenderTarget> DOFHistoryRT;
|
|
TRefCountPtr<IPooledRenderTarget> DOFHistoryRT2;
|
|
// Temporal AA result for SSR
|
|
TRefCountPtr<IPooledRenderTarget> SSRHistoryRT;
|
|
// Temporal AA result for light shafts of last frame
|
|
TRefCountPtr<IPooledRenderTarget> LightShaftOcclusionHistoryRT;
|
|
// Temporal AA result for light shafts of last frame
|
|
TMap<const ULightComponent*, TRefCountPtr<IPooledRenderTarget> > LightShaftBloomHistoryRTs;
|
|
TRefCountPtr<IPooledRenderTarget> DistanceFieldAOHistoryRT;
|
|
TRefCountPtr<IPooledRenderTarget> DistanceFieldAOConfidenceHistoryRT;
|
|
TRefCountPtr<IPooledRenderTarget> DistanceFieldIrradianceHistoryRT;
|
|
// Mobile temporal AA surfaces.
|
|
TRefCountPtr<IPooledRenderTarget> MobileAaBloomSunVignette0;
|
|
TRefCountPtr<IPooledRenderTarget> MobileAaBloomSunVignette1;
|
|
TRefCountPtr<IPooledRenderTarget> MobileAaColor0;
|
|
TRefCountPtr<IPooledRenderTarget> MobileAaColor1;
|
|
|
|
// Pre-computed filter in spectral (i.e. FFT) domain along with data to determine if we need to up date it
|
|
struct {
|
|
void SafeRelease() { Spectral.SafeRelease(); CenterWeight.SafeRelease(); }
|
|
// The 2d fourier transform of the physical space texture.
|
|
TRefCountPtr<IPooledRenderTarget> Spectral;
|
|
TRefCountPtr<IPooledRenderTarget> CenterWeight; // a 1-pixel buffer that holds blend weights for half-resolution fft.
|
|
|
|
// The physical space source texture
|
|
UTexture2D* Physical = NULL;
|
|
|
|
// The Scale * 100 = percentage of the image space that the physical kernel represents.
|
|
// e.g. Scale = 1 indicates that the physical kernel image occupies the same size
|
|
// as the image to be processed with the FFT convolution.
|
|
float Scale = 0.f;
|
|
|
|
// The size of the viewport for which the spectral kernel was calculated.
|
|
FIntPoint ImageSize;
|
|
|
|
FVector2D CenterUV;
|
|
|
|
// Mip level of the physical space source texture used when caching the spectral space texture.
|
|
uint32 PhysicalMipLevel;
|
|
} BloomFFTKernel;
|
|
|
|
// cache for stencil reads to a avoid reallocations of the SRV, Key is to detect if the object has changed
|
|
FTextureRHIRef SelectionOutlineCacheKey;
|
|
TRefCountPtr<FRHIShaderResourceView> SelectionOutlineCacheValue;
|
|
|
|
FForwardLightingViewResources ForwardLightingResources;
|
|
|
|
TRefCountPtr<IPooledRenderTarget> LightScatteringHistory;
|
|
|
|
/** Distance field AO tile intersection GPU resources. Last frame's state is not used, but they must be sized exactly to the view so stored here. */
|
|
class FTileIntersectionResources* AOTileIntersectionResources;
|
|
|
|
class FAOScreenGridResources* AOScreenGridResources;
|
|
|
|
bool bInitializedGlobalDistanceFieldOrigins;
|
|
FGlobalDistanceFieldClipmapState GlobalDistanceFieldClipmapState[GMaxGlobalDistanceFieldClipmaps];
|
|
int32 GlobalDistanceFieldUpdateIndex;
|
|
|
|
FVertexBufferRHIRef IndirectShadowCapsuleShapesVertexBuffer;
|
|
FShaderResourceViewRHIRef IndirectShadowCapsuleShapesSRV;
|
|
FVertexBufferRHIRef IndirectShadowMeshDistanceFieldCasterIndicesVertexBuffer;
|
|
FShaderResourceViewRHIRef IndirectShadowMeshDistanceFieldCasterIndicesSRV;
|
|
FVertexBufferRHIRef IndirectShadowLightDirectionVertexBuffer;
|
|
FShaderResourceViewRHIRef IndirectShadowLightDirectionSRV;
|
|
FRWBuffer CapsuleTileIntersectionCountsBuffer;
|
|
|
|
/** Timestamp queries around separate translucency, used for auto-downsampling. */
|
|
FLatentGPUTimer TranslucencyTimer;
|
|
FLatentGPUTimer SeparateTranslucencyTimer;
|
|
|
|
/** This is float since it is derived off of UWorld::RealTimeSeconds, which is relative to BeginPlay time. */
|
|
float LastAutoDownsampleChangeTime;
|
|
float SmoothedHalfResTranslucencyGPUDuration;
|
|
float SmoothedFullResTranslucencyGPUDuration;
|
|
|
|
/** Current desired state of auto-downsampled separate translucency for this view. */
|
|
bool bShouldAutoDownsampleTranslucency;
|
|
|
|
// Is DOFHistoryRT set from DepthOfField?
|
|
bool bDOFHistory;
|
|
// Is DOFHistoryRT2 set from DepthOfField?
|
|
bool bDOFHistory2;
|
|
|
|
// True when Sequencer has paused
|
|
bool bSequencerIsPaused;
|
|
|
|
FTemporalLODState TemporalLODState;
|
|
|
|
// call after OnFrameRenderingSetup()
|
|
virtual uint32 GetCurrentTemporalAASampleIndex() const
|
|
{
|
|
return TemporalAASampleIndex;
|
|
}
|
|
|
|
// call after OnFrameRenderingSetup()
|
|
uint32 GetCurrentTemporalAASampleCount() const
|
|
{
|
|
return TemporalAASampleCount;
|
|
}
|
|
|
|
virtual uint32 GetFrameIndexMod8() const
|
|
{
|
|
return FrameIndexMod8;
|
|
}
|
|
|
|
// to make rendering more deterministic
|
|
virtual void ResetViewState()
|
|
{
|
|
TemporalAASampleIndex = 0;
|
|
FrameIndexMod8 = 0;
|
|
DistanceFieldTemporalSampleIndex = 0;
|
|
|
|
ReleaseDynamicRHI();
|
|
}
|
|
|
|
// @param SampleCount 0 or 1 for no TemporalAA
|
|
void OnFrameRenderingSetup(uint32 SampleCount, const FSceneViewFamily& Family)
|
|
{
|
|
if(!SampleCount)
|
|
{
|
|
SampleCount = 1;
|
|
}
|
|
|
|
TemporalAASampleCount = FMath::Min(SampleCount, (uint32)255);
|
|
|
|
if (!Family.bWorldIsPaused)
|
|
{
|
|
TemporalAASampleIndex++;
|
|
|
|
FrameIndexMod8 = (FrameIndexMod8 + 1) % 8;
|
|
}
|
|
|
|
if(TemporalAASampleIndex >= TemporalAASampleCount)
|
|
{
|
|
TemporalAASampleIndex = 0;
|
|
}
|
|
}
|
|
|
|
void SetupDistanceFieldTemporalOffset(const FSceneViewFamily& Family)
|
|
{
|
|
if (!Family.bWorldIsPaused)
|
|
{
|
|
DistanceFieldTemporalSampleIndex++;
|
|
}
|
|
|
|
if(DistanceFieldTemporalSampleIndex >= 4)
|
|
{
|
|
DistanceFieldTemporalSampleIndex = 0;
|
|
}
|
|
}
|
|
|
|
int32 GetDistanceFieldTemporalSampleIndex() const
|
|
{
|
|
return DistanceFieldTemporalSampleIndex;
|
|
}
|
|
|
|
|
|
// call only if not yet created
|
|
void SetupLightPropagationVolume(FSceneView& View, FSceneViewFamily& ViewFamily);
|
|
|
|
/**
|
|
* @return can return 0
|
|
* @param bIncludeStereo - specifies whether the getter should include stereo views in its returned value
|
|
*/
|
|
FLightPropagationVolume* GetLightPropagationVolume(ERHIFeatureLevel::Type InFeatureLevel, bool bIncludeStereo = false) const;
|
|
|
|
/** Default constructor. */
|
|
FSceneViewState();
|
|
|
|
void DestroyLightPropagationVolume();
|
|
|
|
virtual ~FSceneViewState();
|
|
|
|
// called every frame after the view state was updated
|
|
void UpdateLastRenderTime(const FSceneViewFamily& Family)
|
|
{
|
|
// The editor can trigger multiple update calls within a frame
|
|
if(Family.CurrentRealTime != LastRenderTime)
|
|
{
|
|
LastRenderTimeDelta = Family.CurrentRealTime - LastRenderTime;
|
|
LastRenderTime = Family.CurrentRealTime;
|
|
}
|
|
}
|
|
|
|
void TrimHistoryRenderTargets(const FScene* Scene);
|
|
|
|
/**
|
|
* Called every frame after UpdateLastRenderTime, sets up the information for the lagged temporal LOD transition
|
|
*/
|
|
void UpdateTemporalLODTransition(const FViewInfo& View)
|
|
{
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
if (bIsFrozen)
|
|
{
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
TemporalLODState.UpdateTemporalLODTransition(View, LastRenderTime);
|
|
}
|
|
|
|
/**
|
|
* Returns an array of visibility data for the given view, or NULL if none exists.
|
|
* The data bits are indexed by VisibilityId of each primitive in the scene.
|
|
* This method decompresses data if necessary and caches it based on the bucket and chunk index in the view state.
|
|
*/
|
|
const uint8* GetPrecomputedVisibilityData(FViewInfo& View, const FScene* Scene);
|
|
|
|
/**
|
|
* Cleans out old entries from the primitive occlusion history, and resets unused pending occlusion queries.
|
|
* @param MinHistoryTime - The occlusion history for any primitives which have been visible and unoccluded since
|
|
* this time will be kept. The occlusion history for any primitives which haven't been
|
|
* visible and unoccluded since this time will be discarded.
|
|
* @param MinQueryTime - The pending occlusion queries older than this will be discarded.
|
|
*/
|
|
void TrimOcclusionHistory(FRHICommandListImmediate& RHICmdList, float CurrentTime, float MinHistoryTime, float MinQueryTime, int32 FrameNumber);
|
|
|
|
/**
|
|
* Checks whether a shadow is occluded this frame.
|
|
* @param Primitive - The shadow subject.
|
|
* @param Light - The shadow source.
|
|
*/
|
|
bool IsShadowOccluded(FRHICommandListImmediate& RHICmdList, FPrimitiveComponentId PrimitiveId, const ULightComponent* Light, int32 SplitIndex, bool bTranslucentShadow, int32 NumBufferedFrames) const;
|
|
|
|
/**
|
|
* Retrieve a single-pixel render targets with intra-frame state for use in eye adaptation post processing.
|
|
*/
|
|
TRefCountPtr<IPooledRenderTarget>& GetEyeAdaptation(FRHICommandList& RHICmdList)
|
|
{
|
|
return EyeAdaptationRTManager.GetCurrentRT(RHICmdList);
|
|
}
|
|
|
|
/**
|
|
* Retrieve a single-pixel render targets with intra-frame state for use in eye adaptation post processing.
|
|
*/
|
|
IPooledRenderTarget* GetCurrentEyeAdaptationRT(FRHICommandList& RHICmdList)
|
|
{
|
|
return EyeAdaptationRTManager.GetCurrentRT(RHICmdList).GetReference();
|
|
}
|
|
IPooledRenderTarget* GetLastEyeAdaptationRT(FRHICommandList& RHICmdList)
|
|
{
|
|
return EyeAdaptationRTManager.GetLastRT(RHICmdList).GetReference();
|
|
}
|
|
|
|
/** Swaps the double-buffer targets used in eye adaptation */
|
|
void SwapEyeAdaptationRTs()
|
|
{
|
|
EyeAdaptationRTManager.SwapRTs();
|
|
}
|
|
|
|
bool HasValidEyeAdaptation() const
|
|
{
|
|
return bValidEyeAdaptation;
|
|
}
|
|
|
|
void SetValidEyeAdaptation()
|
|
{
|
|
bValidEyeAdaptation = true;
|
|
}
|
|
|
|
bool HasValidTonemappingLUT() const
|
|
{
|
|
return bValidTonemappingLUT;
|
|
}
|
|
|
|
void SetValidTonemappingLUT(bool bValid = true)
|
|
{
|
|
bValidTonemappingLUT = bValid;
|
|
}
|
|
|
|
|
|
// Returns a reference to the render target used for the LUT. Allocated on the first request.
|
|
FSceneRenderTargetItem& GetTonemappingLUTRenderTarget(FRHICommandList& RHICmdList, const int32 LUTSize, const bool bUseVolumeLUT, const bool bNeedUAV)
|
|
{
|
|
if (CombinedLUTRenderTarget.IsValid() == false ||
|
|
CombinedLUTRenderTarget->GetDesc().Extent.Y != LUTSize ||
|
|
((CombinedLUTRenderTarget->GetDesc().Depth != 0) != bUseVolumeLUT) ||
|
|
!!(CombinedLUTRenderTarget->GetDesc().TargetableFlags & TexCreate_UAV) != bNeedUAV)
|
|
{
|
|
// Create the texture needed for the tonemapping LUT
|
|
EPixelFormat LUTPixelFormat = PF_A2B10G10R10;
|
|
if (!GPixelFormats[LUTPixelFormat].Supported)
|
|
{
|
|
LUTPixelFormat = PF_R8G8B8A8;
|
|
}
|
|
|
|
FPooledRenderTargetDesc Desc = FPooledRenderTargetDesc::Create2DDesc(FIntPoint(LUTSize * LUTSize, LUTSize), LUTPixelFormat, FClearValueBinding::None, TexCreate_None, TexCreate_ShaderResource, false);
|
|
Desc.TargetableFlags |= bNeedUAV ? TexCreate_UAV : TexCreate_RenderTargetable;
|
|
|
|
if (bUseVolumeLUT)
|
|
{
|
|
Desc.Extent = FIntPoint(LUTSize, LUTSize);
|
|
Desc.Depth = LUTSize;
|
|
}
|
|
|
|
Desc.DebugName = TEXT("CombineLUTs");
|
|
|
|
GRenderTargetPool.FindFreeElement(RHICmdList, Desc, CombinedLUTRenderTarget, Desc.DebugName);
|
|
}
|
|
|
|
FSceneRenderTargetItem& RenderTarget = CombinedLUTRenderTarget.GetReference()->GetRenderTargetItem();
|
|
return RenderTarget;
|
|
}
|
|
|
|
const FTextureRHIRef* GetTonemappingLUTTexture() const {
|
|
const FTextureRHIRef* ShaderResourceTexture = NULL;
|
|
|
|
if (CombinedLUTRenderTarget.IsValid()) {
|
|
ShaderResourceTexture = &CombinedLUTRenderTarget->GetRenderTargetItem().ShaderResourceTexture;
|
|
}
|
|
return ShaderResourceTexture;
|
|
}
|
|
|
|
|
|
// FRenderResource interface.
|
|
virtual void InitDynamicRHI() override
|
|
{
|
|
HZBOcclusionTests.InitDynamicRHI();
|
|
}
|
|
|
|
virtual void ReleaseDynamicRHI() override
|
|
{
|
|
for (int i = 0; i < ShadowOcclusionQueryMaps.Num(); ++i)
|
|
{
|
|
ShadowOcclusionQueryMaps[i].Reset();
|
|
}
|
|
PrimitiveOcclusionHistorySet.Empty();
|
|
PrimitiveFadingStates.Empty();
|
|
OcclusionQueryPool.Release();
|
|
HZBOcclusionTests.ReleaseDynamicRHI();
|
|
EyeAdaptationRTManager.SafeRelease();
|
|
CombinedLUTRenderTarget.SafeRelease();
|
|
TemporalAAHistoryRT.SafeRelease();
|
|
PendingTemporalAAHistoryRT.SafeRelease();
|
|
DOFHistoryRT.SafeRelease();
|
|
DOFHistoryRT2.SafeRelease();
|
|
SSRHistoryRT.SafeRelease();
|
|
LightShaftOcclusionHistoryRT.SafeRelease();
|
|
LightShaftBloomHistoryRTs.Empty();
|
|
DistanceFieldAOHistoryRT.SafeRelease();
|
|
DistanceFieldAOConfidenceHistoryRT.SafeRelease();
|
|
DistanceFieldAOConfidenceHistoryRT.SafeRelease();
|
|
DistanceFieldIrradianceHistoryRT.SafeRelease();
|
|
MobileAaBloomSunVignette0.SafeRelease();
|
|
MobileAaBloomSunVignette1.SafeRelease();
|
|
MobileAaColor0.SafeRelease();
|
|
MobileAaColor1.SafeRelease();
|
|
BloomFFTKernel.SafeRelease();
|
|
SelectionOutlineCacheKey.SafeRelease();
|
|
SelectionOutlineCacheValue.SafeRelease();
|
|
|
|
for (int32 CascadeIndex = 0; CascadeIndex < ARRAY_COUNT(GlobalDistanceFieldClipmapState); CascadeIndex++)
|
|
{
|
|
for (int32 CacheType = 0; CacheType < ARRAY_COUNT(GlobalDistanceFieldClipmapState[CascadeIndex].Cache); CacheType++)
|
|
{
|
|
GlobalDistanceFieldClipmapState[CascadeIndex].Cache[CacheType].VolumeTexture.SafeRelease();
|
|
}
|
|
}
|
|
|
|
IndirectShadowCapsuleShapesVertexBuffer.SafeRelease();
|
|
IndirectShadowCapsuleShapesSRV.SafeRelease();
|
|
IndirectShadowMeshDistanceFieldCasterIndicesVertexBuffer.SafeRelease();
|
|
IndirectShadowMeshDistanceFieldCasterIndicesSRV.SafeRelease();
|
|
IndirectShadowLightDirectionVertexBuffer.SafeRelease();
|
|
IndirectShadowLightDirectionSRV.SafeRelease();
|
|
CapsuleTileIntersectionCountsBuffer.Release();
|
|
TranslucencyTimer.Release();
|
|
SeparateTranslucencyTimer.Release();
|
|
ForwardLightingResources.Release();
|
|
LightScatteringHistory.SafeRelease();
|
|
}
|
|
|
|
// FSceneViewStateInterface
|
|
RENDERER_API virtual void Destroy() override;
|
|
|
|
virtual FSceneViewState* GetConcreteViewState() override
|
|
{
|
|
return this;
|
|
}
|
|
|
|
virtual void AddReferencedObjects(FReferenceCollector& Collector) override
|
|
{
|
|
|
|
Collector.AddReferencedObjects(MIDPool);
|
|
|
|
if (BloomFFTKernel.Physical)
|
|
{
|
|
Collector.AddReferencedObject(BloomFFTKernel.Physical);
|
|
}
|
|
}
|
|
|
|
/** called in InitViews() */
|
|
virtual void OnStartFrame(FSceneView& View, FSceneViewFamily& ViewFamily) override
|
|
{
|
|
check(IsInRenderingThread());
|
|
|
|
if(!(View.FinalPostProcessSettings.IndirectLightingColor * View.FinalPostProcessSettings.IndirectLightingIntensity).IsAlmostBlack())
|
|
{
|
|
SetupLightPropagationVolume(View, ViewFamily);
|
|
}
|
|
}
|
|
|
|
// needed for GetReusableMID()
|
|
virtual void OnStartPostProcessing(FSceneView& CurrentView) override
|
|
{
|
|
check(IsInGameThread());
|
|
|
|
// Needs to be done once for all viewstates. If multiple FSceneViews are sharing the same ViewState, this will cause problems.
|
|
// Sharing should be illegal right now though.
|
|
MIDUsedCount = 0;
|
|
}
|
|
|
|
// Note: OnStartPostProcessing() needs to be called each frame for each view
|
|
virtual UMaterialInstanceDynamic* GetReusableMID(class UMaterialInterface* InSource) override
|
|
{
|
|
check(IsInGameThread());
|
|
check(InSource);
|
|
|
|
// 0 or MID (MaterialInstanceDynamic) pointer
|
|
auto InputAsMID = Cast<UMaterialInstanceDynamic>(InSource);
|
|
|
|
// fixup MID parents as this is not allowed, take the next MIC or Material.
|
|
UMaterialInterface* ParentOfTheNewMID = InputAsMID ? InputAsMID->Parent : InSource;
|
|
|
|
// this is not allowed and would cause an error later in the code
|
|
check(!ParentOfTheNewMID->IsA(UMaterialInstanceDynamic::StaticClass()));
|
|
|
|
UMaterialInstanceDynamic* NewMID = 0;
|
|
|
|
if(MIDUsedCount < (uint32)MIDPool.Num())
|
|
{
|
|
NewMID = MIDPool[MIDUsedCount];
|
|
|
|
if(NewMID->Parent != ParentOfTheNewMID)
|
|
{
|
|
// create a new one
|
|
// garbage collector will remove the old one
|
|
// this should not happen too often
|
|
NewMID = UMaterialInstanceDynamic::Create(ParentOfTheNewMID, 0);
|
|
MIDPool[MIDUsedCount] = NewMID;
|
|
}
|
|
|
|
// reusing an existing object means we need to clear out the Vector and Scalar parameters
|
|
NewMID->ClearParameterValues();
|
|
}
|
|
else
|
|
{
|
|
NewMID = UMaterialInstanceDynamic::Create(ParentOfTheNewMID, 0);
|
|
check(NewMID);
|
|
|
|
MIDPool.Add(NewMID);
|
|
}
|
|
|
|
if(InputAsMID)
|
|
{
|
|
// parent is an MID so we need to copy the MID Vector and Scalar parameters over
|
|
NewMID->CopyInterpParameters(InputAsMID);
|
|
}
|
|
|
|
check(NewMID->GetRenderProxy(false));
|
|
MIDUsedCount++;
|
|
return NewMID;
|
|
}
|
|
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
virtual void ActivateFrozenViewMatrices(FSceneView& SceneView) override
|
|
{
|
|
auto* ViewState = static_cast<FSceneViewState*>(SceneView.State);
|
|
if (ViewState->bIsFrozen)
|
|
{
|
|
check(ViewState->bIsFrozenViewMatricesCached);
|
|
|
|
Swap(SceneView.ViewMatrices, ViewState->CachedViewMatrices);
|
|
ViewState->bIsFrozenViewMatricesCached = false;
|
|
}
|
|
}
|
|
|
|
virtual void RestoreUnfrozenViewMatrices(FSceneView& SceneView) override
|
|
{
|
|
auto* ViewState = static_cast<FSceneViewState*>(SceneView.State);
|
|
if (ViewState->bIsFrozen)
|
|
{
|
|
check(!ViewState->bIsFrozenViewMatricesCached);
|
|
|
|
Swap(SceneView.ViewMatrices, ViewState->CachedViewMatrices);
|
|
ViewState->bIsFrozenViewMatricesCached = true;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
virtual FTemporalLODState& GetTemporalLODState() override
|
|
{
|
|
return TemporalLODState;
|
|
}
|
|
|
|
virtual const FTemporalLODState& GetTemporalLODState() const override
|
|
{
|
|
return TemporalLODState;
|
|
}
|
|
|
|
float GetTemporalLODTransition() const override
|
|
{
|
|
return TemporalLODState.GetTemporalLODTransition(LastRenderTime);
|
|
}
|
|
|
|
uint32 GetViewKey() const override
|
|
{
|
|
return UniqueID;
|
|
}
|
|
|
|
uint32 GetOcclusionFrameCounter() const
|
|
{
|
|
return OcclusionFrameCounter;
|
|
}
|
|
|
|
// FDeferredCleanupInterface
|
|
virtual void FinishCleanup() override
|
|
{
|
|
delete this;
|
|
}
|
|
|
|
virtual SIZE_T GetSizeBytes() const override;
|
|
|
|
virtual void SetSequencerState(const bool bIsPaused) override
|
|
{
|
|
bSequencerIsPaused = bIsPaused;
|
|
}
|
|
|
|
virtual bool GetSequencerState() override
|
|
{
|
|
return bSequencerIsPaused;
|
|
}
|
|
|
|
/** Information about visibility/occlusion states in past frames for individual primitives. */
|
|
TSet<FPrimitiveOcclusionHistory,FPrimitiveOcclusionHistoryKeyFuncs> PrimitiveOcclusionHistorySet;
|
|
};
|
|
|
|
/** Rendering resource class that manages a cubemap array for reflections. */
|
|
class FReflectionEnvironmentCubemapArray : public FRenderResource
|
|
{
|
|
public:
|
|
|
|
FReflectionEnvironmentCubemapArray(ERHIFeatureLevel::Type InFeatureLevel)
|
|
: FRenderResource(InFeatureLevel)
|
|
, MaxCubemaps(0)
|
|
, CubemapSize(0)
|
|
{}
|
|
|
|
virtual void InitDynamicRHI() override;
|
|
virtual void ReleaseDynamicRHI() override;
|
|
|
|
/**
|
|
* Updates the maximum number of cubemaps that this array is allocated for.
|
|
* This reallocates the resource but does not copy over the old contents.
|
|
*/
|
|
void UpdateMaxCubemaps(uint32 InMaxCubemaps, int32 CubemapSize);
|
|
|
|
/**
|
|
* Updates the maximum number of cubemaps that this array is allocated for.
|
|
* This reallocates the resource and copies over the old contents, preserving indices
|
|
*/
|
|
void ResizeCubemapArrayGPU(uint32 InMaxCubemaps, int32 CubemapSize, const TArray<int32>& IndexRemapping);
|
|
|
|
int32 GetMaxCubemaps() const { return MaxCubemaps; }
|
|
int32 GetCubemapSize() const { return CubemapSize; }
|
|
bool IsValid() const { return IsValidRef(ReflectionEnvs); }
|
|
FSceneRenderTargetItem& GetRenderTarget() const { return ReflectionEnvs->GetRenderTargetItem(); }
|
|
|
|
protected:
|
|
uint32 MaxCubemaps;
|
|
int32 CubemapSize;
|
|
TRefCountPtr<IPooledRenderTarget> ReflectionEnvs;
|
|
|
|
void ReleaseCubeArray();
|
|
};
|
|
|
|
/** Per-component reflection capture state that needs to persist through a re-register. */
|
|
class FCaptureComponentSceneState
|
|
{
|
|
public:
|
|
/** Index of the cubemap in the array for this capture component. */
|
|
int32 CaptureIndex;
|
|
|
|
FCaptureComponentSceneState(int32 InCaptureIndex) :
|
|
CaptureIndex(InCaptureIndex)
|
|
{}
|
|
|
|
bool operator==(const FCaptureComponentSceneState& Other) const
|
|
{
|
|
return CaptureIndex == Other.CaptureIndex;
|
|
}
|
|
};
|
|
|
|
/** Scene state used to manage the reflection environment feature. */
|
|
class FReflectionEnvironmentSceneData
|
|
{
|
|
public:
|
|
|
|
/**
|
|
* Set to true for one frame whenever RegisteredReflectionCaptures or the transforms of any registered reflection proxy has changed,
|
|
* Which allows one frame to update cached proxy associations.
|
|
*/
|
|
bool bRegisteredReflectionCapturesHasChanged;
|
|
|
|
/** The rendering thread's list of visible reflection captures in the scene. */
|
|
TArray<FReflectionCaptureProxy*> RegisteredReflectionCaptures;
|
|
TArray<FVector> RegisteredReflectionCapturePositions;
|
|
|
|
/**
|
|
* Cubemap array resource which contains the captured scene for each reflection capture.
|
|
* This is indexed by the value of AllocatedReflectionCaptureState.CaptureIndex.
|
|
*/
|
|
FReflectionEnvironmentCubemapArray CubemapArray;
|
|
|
|
/** Rendering thread map from component to scene state. This allows storage of RT state that needs to persist through a component re-register. */
|
|
TMap<const UReflectionCaptureComponent*, FCaptureComponentSceneState> AllocatedReflectionCaptureState;
|
|
|
|
/** Rendering bitfield to track cubemap slots used. Needs to kept in sync with AllocatedReflectionCaptureState */
|
|
TBitArray<> CubemapArraySlotsUsed;
|
|
|
|
|
|
/**
|
|
* Game thread list of reflection components that have been allocated in the cubemap array.
|
|
* These are not necessarily all visible or being rendered, but their scene state is stored in the cubemap array.
|
|
*/
|
|
TSparseArray<UReflectionCaptureComponent*> AllocatedReflectionCapturesGameThread;
|
|
|
|
/** Game thread tracking of what size this scene has allocated for the cubemap array. */
|
|
int32 MaxAllocatedReflectionCubemapsGameThread;
|
|
|
|
FReflectionEnvironmentSceneData(ERHIFeatureLevel::Type InFeatureLevel) :
|
|
bRegisteredReflectionCapturesHasChanged(true),
|
|
CubemapArray(InFeatureLevel),
|
|
MaxAllocatedReflectionCubemapsGameThread(0)
|
|
{}
|
|
|
|
|
|
void ResizeCubemapArrayGPU(uint32 InMaxCubemaps, int32 InCubemapSize);
|
|
};
|
|
|
|
class FPrimitiveAndInstance
|
|
{
|
|
public:
|
|
|
|
FPrimitiveAndInstance(const FVector4& InBoundingSphere, FPrimitiveSceneInfo* InPrimitive, int32 InInstanceIndex) :
|
|
BoundingSphere(InBoundingSphere),
|
|
Primitive(InPrimitive),
|
|
InstanceIndex(InInstanceIndex)
|
|
{}
|
|
|
|
FVector4 BoundingSphere;
|
|
FPrimitiveSceneInfo* Primitive;
|
|
int32 InstanceIndex;
|
|
};
|
|
|
|
class FPrimitiveSurfelFreeEntry
|
|
{
|
|
public:
|
|
FPrimitiveSurfelFreeEntry(int32 InOffset, int32 InNumSurfels) :
|
|
Offset(InOffset),
|
|
NumSurfels(InNumSurfels)
|
|
{}
|
|
|
|
FPrimitiveSurfelFreeEntry() :
|
|
Offset(0),
|
|
NumSurfels(0)
|
|
{}
|
|
|
|
int32 Offset;
|
|
int32 NumSurfels;
|
|
};
|
|
|
|
class FPrimitiveSurfelAllocation
|
|
{
|
|
public:
|
|
FPrimitiveSurfelAllocation(int32 InOffset, int32 InNumLOD0, int32 InNumSurfels, int32 InNumInstances) :
|
|
Offset(InOffset),
|
|
NumLOD0(InNumLOD0),
|
|
NumSurfels(InNumSurfels),
|
|
NumInstances(InNumInstances)
|
|
{}
|
|
|
|
FPrimitiveSurfelAllocation() :
|
|
Offset(0),
|
|
NumLOD0(0),
|
|
NumSurfels(0),
|
|
NumInstances(1)
|
|
{}
|
|
|
|
int32 GetTotalNumSurfels() const
|
|
{
|
|
return NumSurfels * NumInstances;
|
|
}
|
|
|
|
int32 Offset;
|
|
int32 NumLOD0;
|
|
int32 NumSurfels;
|
|
int32 NumInstances;
|
|
};
|
|
|
|
class FPrimitiveRemoveInfo
|
|
{
|
|
public:
|
|
FPrimitiveRemoveInfo(const FPrimitiveSceneInfo* InPrimitive) :
|
|
Primitive(InPrimitive),
|
|
bOftenMoving(InPrimitive->Proxy->IsOftenMoving()),
|
|
DistanceFieldInstanceIndices(Primitive->DistanceFieldInstanceIndices)
|
|
{}
|
|
|
|
/**
|
|
* Must not be dereferenced after creation, the primitive was removed from the scene and deleted
|
|
* Value of the pointer is still useful for map lookups
|
|
*/
|
|
const FPrimitiveSceneInfo* Primitive;
|
|
|
|
bool bOftenMoving;
|
|
|
|
TArray<int32, TInlineAllocator<1>> DistanceFieldInstanceIndices;
|
|
};
|
|
|
|
class FSurfelBufferAllocator
|
|
{
|
|
public:
|
|
|
|
FSurfelBufferAllocator() : NumSurfelsInBuffer(0) {}
|
|
|
|
int32 GetNumSurfelsInBuffer() const { return NumSurfelsInBuffer; }
|
|
void AddPrimitive(const FPrimitiveSceneInfo* PrimitiveSceneInfo, int32 PrimitiveLOD0Surfels, int32 PrimitiveNumSurfels, int32 NumInstances);
|
|
void RemovePrimitive(const FPrimitiveSceneInfo* Primitive);
|
|
|
|
const FPrimitiveSurfelAllocation* FindAllocation(const FPrimitiveSceneInfo* Primitive)
|
|
{
|
|
return Allocations.Find(Primitive);
|
|
}
|
|
|
|
private:
|
|
|
|
int32 NumSurfelsInBuffer;
|
|
TMap<const FPrimitiveSceneInfo*, FPrimitiveSurfelAllocation> Allocations;
|
|
TArray<FPrimitiveSurfelFreeEntry> FreeList;
|
|
};
|
|
|
|
/** Scene data used to manage distance field object buffers on the GPU. */
|
|
class FDistanceFieldSceneData
|
|
{
|
|
public:
|
|
|
|
FDistanceFieldSceneData(EShaderPlatform ShaderPlatform);
|
|
~FDistanceFieldSceneData();
|
|
|
|
void AddPrimitive(FPrimitiveSceneInfo* InPrimitive);
|
|
void UpdatePrimitive(FPrimitiveSceneInfo* InPrimitive);
|
|
void RemovePrimitive(FPrimitiveSceneInfo* InPrimitive);
|
|
void Release();
|
|
void VerifyIntegrity();
|
|
|
|
bool HasPendingOperations() const
|
|
{
|
|
return PendingAddOperations.Num() > 0 || PendingUpdateOperations.Num() > 0 || PendingRemoveOperations.Num() > 0;
|
|
}
|
|
|
|
bool HasPendingRemovePrimitive(const FPrimitiveSceneInfo* Primitive) const
|
|
{
|
|
for (int32 RemoveIndex = 0; RemoveIndex < PendingRemoveOperations.Num(); RemoveIndex++)
|
|
{
|
|
if (PendingRemoveOperations[RemoveIndex].Primitive == Primitive)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
inline bool CanUse16BitObjectIndices() const
|
|
{
|
|
return bCanUse16BitObjectIndices && (NumObjectsInBuffer < (1 << 16));
|
|
}
|
|
|
|
int32 NumObjectsInBuffer;
|
|
class FDistanceFieldObjectBuffers* ObjectBuffers;
|
|
|
|
/** Stores the primitive and instance index of every entry in the object buffer. */
|
|
TArray<FPrimitiveAndInstance> PrimitiveInstanceMapping;
|
|
TArray<const FPrimitiveSceneInfo*> HeightfieldPrimitives;
|
|
|
|
class FSurfelBuffers* SurfelBuffers;
|
|
FSurfelBufferAllocator SurfelAllocations;
|
|
|
|
class FInstancedSurfelBuffers* InstancedSurfelBuffers;
|
|
FSurfelBufferAllocator InstancedSurfelAllocations;
|
|
|
|
/** Pending operations on the object buffers to be processed next frame. */
|
|
TArray<FPrimitiveSceneInfo*> PendingAddOperations;
|
|
TSet<FPrimitiveSceneInfo*> PendingUpdateOperations;
|
|
TArray<FPrimitiveRemoveInfo> PendingRemoveOperations;
|
|
TArray<FVector4> PrimitiveModifiedBounds[GDF_Num];
|
|
|
|
/** Used to detect atlas reallocations, since objects store UVs into the atlas and need to be updated when it changes. */
|
|
int32 AtlasGeneration;
|
|
|
|
bool bTrackAllPrimitives;
|
|
bool bCanUse16BitObjectIndices;
|
|
};
|
|
|
|
/** Stores data for an allocation in the FIndirectLightingCache. */
|
|
class FIndirectLightingCacheBlock
|
|
{
|
|
public:
|
|
|
|
FIndirectLightingCacheBlock() :
|
|
MinTexel(FIntVector(0, 0, 0)),
|
|
TexelSize(0),
|
|
Min(FVector(0, 0, 0)),
|
|
Size(FVector(0, 0, 0)),
|
|
bHasEverBeenUpdated(false)
|
|
{}
|
|
|
|
FIntVector MinTexel;
|
|
int32 TexelSize;
|
|
FVector Min;
|
|
FVector Size;
|
|
bool bHasEverBeenUpdated;
|
|
};
|
|
|
|
/** Stores information about an indirect lighting cache block to be updated. */
|
|
class FBlockUpdateInfo
|
|
{
|
|
public:
|
|
|
|
FBlockUpdateInfo(const FIndirectLightingCacheBlock& InBlock, FIndirectLightingCacheAllocation* InAllocation) :
|
|
Block(InBlock),
|
|
Allocation(InAllocation)
|
|
{}
|
|
|
|
FIndirectLightingCacheBlock Block;
|
|
FIndirectLightingCacheAllocation* Allocation;
|
|
};
|
|
|
|
/** Information about the primitives that are attached together. */
|
|
class FAttachmentGroupSceneInfo
|
|
{
|
|
public:
|
|
|
|
/** The parent primitive, which is the root of the attachment tree. */
|
|
FPrimitiveSceneInfo* ParentSceneInfo;
|
|
|
|
/** The primitives in the attachment group. */
|
|
TArray<FPrimitiveSceneInfo*> Primitives;
|
|
|
|
FAttachmentGroupSceneInfo() :
|
|
ParentSceneInfo(nullptr)
|
|
{}
|
|
};
|
|
|
|
struct FILCUpdatePrimTaskData
|
|
{
|
|
FGraphEventRef TaskRef;
|
|
TMap<FIntVector, FBlockUpdateInfo> OutBlocksToUpdate;
|
|
TArray<FIndirectLightingCacheAllocation*> OutTransitionsOverTimeToUpdate;
|
|
};
|
|
|
|
/**
|
|
* Implements a volume texture atlas for caching indirect lighting on a per-object basis.
|
|
* The indirect lighting is interpolated from Lightmass SH volume lighting samples.
|
|
*/
|
|
class FIndirectLightingCache : public FRenderResource
|
|
{
|
|
public:
|
|
|
|
/** true for the editor case where we want a better preview for object that have no valid lightmaps */
|
|
FIndirectLightingCache(ERHIFeatureLevel::Type InFeatureLevel);
|
|
|
|
// FRenderResource interface
|
|
virtual void InitDynamicRHI();
|
|
virtual void ReleaseDynamicRHI();
|
|
|
|
/** Allocates a block in the volume texture atlas for a primitive. */
|
|
FIndirectLightingCacheAllocation* AllocatePrimitive(const FPrimitiveSceneInfo* PrimitiveSceneInfo, bool bUnbuiltPreview);
|
|
|
|
/** Releases the indirect lighting allocation for the given primitive. */
|
|
void ReleasePrimitive(FPrimitiveComponentId PrimitiveId);
|
|
|
|
FIndirectLightingCacheAllocation* FindPrimitiveAllocation(FPrimitiveComponentId PrimitiveId);
|
|
|
|
/** Updates indirect lighting in the cache based on visibility synchronously. */
|
|
void UpdateCache(FScene* Scene, FSceneRenderer& Renderer, bool bAllowUnbuiltPreview);
|
|
|
|
/** Starts a task to update the cache primitives. Results and task ref returned in the FILCUpdatePrimTaskData structure */
|
|
void StartUpdateCachePrimitivesTask(FScene* Scene, FSceneRenderer& Renderer, bool bAllowUnbuiltPreview, FILCUpdatePrimTaskData& OutTaskData);
|
|
|
|
/** Wait on a previously started task and complete any block updates and debug draw */
|
|
void FinalizeCacheUpdates(FScene* Scene, FSceneRenderer& Renderer, FILCUpdatePrimTaskData& TaskData);
|
|
|
|
/** Force all primitive allocations to be re-interpolated. */
|
|
void SetLightingCacheDirty(FScene* Scene, const FPrecomputedLightVolume* Volume);
|
|
|
|
// Accessors
|
|
FSceneRenderTargetItem& GetTexture0() { return Texture0->GetRenderTargetItem(); }
|
|
FSceneRenderTargetItem& GetTexture1() { return Texture1->GetRenderTargetItem(); }
|
|
FSceneRenderTargetItem& GetTexture2() { return Texture2->GetRenderTargetItem(); }
|
|
|
|
private:
|
|
/** Internal helper to determine if indirect lighting is enabled at all */
|
|
bool IndirectLightingAllowed(FScene* Scene, FSceneRenderer& Renderer) const;
|
|
|
|
void ProcessPrimitiveUpdate(FScene* Scene, FViewInfo& View, int32 PrimitiveIndex, bool bAllowUnbuiltPreview, TMap<FIntVector, FBlockUpdateInfo>& OutBlocksToUpdate, TArray<FIndirectLightingCacheAllocation*>& OutTransitionsOverTimeToUpdate);
|
|
|
|
/** Internal helper to perform the work of updating the cache primitives. Can be done on any thread as a task */
|
|
void UpdateCachePrimitivesInternal(FScene* Scene, FSceneRenderer& Renderer, bool bAllowUnbuiltPreview, TMap<FIntVector, FBlockUpdateInfo>& OutBlocksToUpdate, TArray<FIndirectLightingCacheAllocation*>& OutTransitionsOverTimeToUpdate);
|
|
|
|
/** Internal helper to perform blockupdates and transition updates on the results of UpdateCachePrimitivesInternal. Must be on render thread. */
|
|
void FinalizeUpdateInternal_RenderThread(FScene* Scene, FSceneRenderer& Renderer, TMap<FIntVector, FBlockUpdateInfo>& BlocksToUpdate, const TArray<FIndirectLightingCacheAllocation*>& TransitionsOverTimeToUpdate);
|
|
|
|
/** Internal helper which adds an entry to the update lists for this allocation, if needed (due to movement, etc). Returns true if the allocation was updated or will be udpated */
|
|
bool UpdateCacheAllocation(
|
|
const FBoxSphereBounds& Bounds,
|
|
int32 BlockSize,
|
|
bool bPointSample,
|
|
bool bUnbuiltPreview,
|
|
FIndirectLightingCacheAllocation*& Allocation,
|
|
TMap<FIntVector, FBlockUpdateInfo>& BlocksToUpdate,
|
|
TArray<FIndirectLightingCacheAllocation*>& TransitionsOverTimeToUpdate);
|
|
|
|
/**
|
|
* Creates a new allocation if needed, caches the result in PrimitiveSceneInfo->IndirectLightingCacheAllocation,
|
|
* And adds an entry to the update lists when an update is needed.
|
|
*/
|
|
void UpdateCachePrimitive(
|
|
const TMap<FPrimitiveComponentId, FAttachmentGroupSceneInfo>& AttachmentGroups,
|
|
FPrimitiveSceneInfo* PrimitiveSceneInfo,
|
|
bool bAllowUnbuiltPreview,
|
|
bool bOpaqueRelevance,
|
|
TMap<FIntVector, FBlockUpdateInfo>& BlocksToUpdate,
|
|
TArray<FIndirectLightingCacheAllocation*>& TransitionsOverTimeToUpdate);
|
|
|
|
/** Updates the contents of the volume texture blocks in BlocksToUpdate. */
|
|
void UpdateBlocks(FScene* Scene, FViewInfo* DebugDrawingView, TMap<FIntVector, FBlockUpdateInfo>& BlocksToUpdate);
|
|
|
|
/** Updates any outstanding transitions with a new delta time. */
|
|
void UpdateTransitionsOverTime(const TArray<FIndirectLightingCacheAllocation*>& TransitionsOverTimeToUpdate, float DeltaWorldTime) const;
|
|
|
|
/** Creates an allocation to be used outside the indirect lighting cache and a block to be used internally. */
|
|
FIndirectLightingCacheAllocation* CreateAllocation(int32 BlockSize, const FBoxSphereBounds& Bounds, bool bPointSample, bool bUnbuiltPreview);
|
|
|
|
/** Block accessors. */
|
|
FIndirectLightingCacheBlock& FindBlock(FIntVector TexelMin);
|
|
const FIndirectLightingCacheBlock& FindBlock(FIntVector TexelMin) const;
|
|
|
|
/** Block operations. */
|
|
void DeallocateBlock(FIntVector Min, int32 Size);
|
|
bool AllocateBlock(int32 Size, FIntVector& OutMin);
|
|
|
|
/**
|
|
* Updates an allocation block in the cache, by re-interpolating values and uploading to the cache volume texture.
|
|
* @param DebugDrawingView can be 0
|
|
*/
|
|
void UpdateBlock(FScene* Scene, FViewInfo* DebugDrawingView, FBlockUpdateInfo& Block);
|
|
|
|
/** Interpolates a single SH sample from all levels. */
|
|
void InterpolatePoint(
|
|
FScene* Scene,
|
|
const FIndirectLightingCacheBlock& Block,
|
|
float& OutDirectionalShadowing,
|
|
FSHVectorRGB3& OutIncidentRadiance,
|
|
FVector& OutSkyBentNormal);
|
|
|
|
/** Interpolates SH samples for a block from all levels. */
|
|
void InterpolateBlock(
|
|
FScene* Scene,
|
|
const FIndirectLightingCacheBlock& Block,
|
|
TArray<float>& AccumulatedWeight,
|
|
TArray<FSHVectorRGB2>& AccumulatedIncidentRadiance);
|
|
|
|
/**
|
|
* Normalizes, adjusts for SH ringing, and encodes SH samples into a texture format.
|
|
* @param DebugDrawingView can be 0
|
|
*/
|
|
void EncodeBlock(
|
|
FViewInfo* DebugDrawingView,
|
|
const FIndirectLightingCacheBlock& Block,
|
|
const TArray<float>& AccumulatedWeight,
|
|
const TArray<FSHVectorRGB2>& AccumulatedIncidentRadiance,
|
|
TArray<FFloat16Color>& Texture0Data,
|
|
TArray<FFloat16Color>& Texture1Data,
|
|
TArray<FFloat16Color>& Texture2Data
|
|
);
|
|
|
|
/** Helper that calculates an effective world position min and size given a bounds. */
|
|
void CalculateBlockPositionAndSize(const FBoxSphereBounds& Bounds, int32 TexelSize, FVector& OutMin, FVector& OutSize) const;
|
|
|
|
/** Helper that calculates a scale and add to convert world space position into volume texture UVs for a given block. */
|
|
void CalculateBlockScaleAndAdd(FIntVector InTexelMin, int32 AllocationTexelSize, FVector InMin, FVector InSize, FVector& OutScale, FVector& OutAdd, FVector& OutMinUV, FVector& OutMaxUV) const;
|
|
|
|
/** true: next rendering we update all entries no matter if they are visible to avoid further hitches */
|
|
bool bUpdateAllCacheEntries;
|
|
|
|
/** Size of the volume texture cache. */
|
|
int32 CacheSize;
|
|
|
|
/** Volume textures that store SH indirect lighting, interpolated from Lightmass volume samples. */
|
|
TRefCountPtr<IPooledRenderTarget> Texture0;
|
|
TRefCountPtr<IPooledRenderTarget> Texture1;
|
|
TRefCountPtr<IPooledRenderTarget> Texture2;
|
|
|
|
/** Tracks the allocation state of the atlas. */
|
|
TMap<FIntVector, FIndirectLightingCacheBlock> VolumeBlocks;
|
|
|
|
/** Tracks used sections of the volume texture atlas. */
|
|
FTextureLayout3d BlockAllocator;
|
|
|
|
int32 NextPointId;
|
|
|
|
/** Tracks primitive allocations by component, so that they persist across re-registers. */
|
|
TMap<FPrimitiveComponentId, FIndirectLightingCacheAllocation*> PrimitiveAllocations;
|
|
|
|
friend class FUpdateCachePrimitivesTask;
|
|
};
|
|
|
|
/**
|
|
* Bounding information used to cull primitives in the scene.
|
|
*/
|
|
struct FPrimitiveBounds
|
|
{
|
|
/** Origin of the primitive. */
|
|
FVector Origin;
|
|
/** Radius of the bounding sphere. */
|
|
float SphereRadius;
|
|
/** Extents of the axis-aligned bounding box. */
|
|
FVector BoxExtent;
|
|
/** Square of the minimum draw distance for the primitive. */
|
|
float MinDrawDistanceSq;
|
|
/** Maximum draw distance for the primitive. */
|
|
float MaxDrawDistance;
|
|
};
|
|
|
|
/**
|
|
* Precomputed primitive visibility ID.
|
|
*/
|
|
struct FPrimitiveVisibilityId
|
|
{
|
|
/** Index in to the byte where precomputed occlusion data is stored. */
|
|
int32 ByteIndex;
|
|
/** Mast of the bit where precomputed occlusion data is stored. */
|
|
uint8 BitMask;
|
|
};
|
|
|
|
/**
|
|
* Flags that affect how primitives are occlusion culled.
|
|
*/
|
|
namespace EOcclusionFlags
|
|
{
|
|
enum Type
|
|
{
|
|
/** No flags. */
|
|
None = 0x0,
|
|
/** Indicates the primitive can be occluded. */
|
|
CanBeOccluded = 0x1,
|
|
/** Allow the primitive to be batched with others to determine occlusion. */
|
|
AllowApproximateOcclusion = 0x4,
|
|
/** Indicates the primitive has a valid ID for precomputed visibility. */
|
|
HasPrecomputedVisibility = 0x8,
|
|
/** Indicates the primitive has a valid ID for precomputed visibility. */
|
|
HasSubprimitiveQueries = 0x10,
|
|
};
|
|
};
|
|
|
|
class FLODSceneTree
|
|
{
|
|
public:
|
|
FLODSceneTree(FScene* InScene)
|
|
: Scene(InScene)
|
|
, LastHLODDistanceScale(-1.0f)
|
|
{
|
|
}
|
|
|
|
/** Information about the primitives that are attached together. */
|
|
struct FLODSceneNode
|
|
{
|
|
/** Children scene infos. */
|
|
TArray<FPrimitiveSceneInfo*> ChildrenSceneInfos;
|
|
|
|
/** The primitive. */
|
|
FPrimitiveSceneInfo* SceneInfo;
|
|
|
|
FLODSceneNode()
|
|
: SceneInfo(nullptr)
|
|
{
|
|
}
|
|
|
|
void AddChild(FPrimitiveSceneInfo* NewChild)
|
|
{
|
|
if(NewChild && !ChildrenSceneInfos.Contains(NewChild))
|
|
{
|
|
ChildrenSceneInfos.Add(NewChild);
|
|
}
|
|
}
|
|
|
|
void RemoveChild(FPrimitiveSceneInfo* ChildToDelete)
|
|
{
|
|
if(ChildToDelete && ChildrenSceneInfos.Contains(ChildToDelete))
|
|
{
|
|
ChildrenSceneInfos.Remove(ChildToDelete);
|
|
}
|
|
}
|
|
};
|
|
|
|
void AddChildNode(FPrimitiveComponentId NodeId, FPrimitiveSceneInfo* ChildSceneInfo);
|
|
void RemoveChildNode(FPrimitiveComponentId NodeId, FPrimitiveSceneInfo* ChildSceneInfo);
|
|
|
|
void UpdateNodeSceneInfo(FPrimitiveComponentId NodeId, FPrimitiveSceneInfo* SceneInfo);
|
|
void UpdateAndApplyVisibilityStates(FViewInfo& View);
|
|
|
|
bool IsActive() const { return (SceneNodes.Num() > 0); }
|
|
|
|
private:
|
|
|
|
void ResetHLODDistanceScaleApplication()
|
|
{
|
|
LastHLODDistanceScale = -1.0f;
|
|
}
|
|
|
|
/** Scene this Tree belong to */
|
|
FScene* Scene;
|
|
|
|
/** The LOD groups in the scene. The map key is the current primitive who has children. */
|
|
TMap<FPrimitiveComponentId, FLODSceneNode> SceneNodes;
|
|
|
|
/** Transition distance scaling */
|
|
float LastHLODDistanceScale;
|
|
|
|
/** Recursive state updates */
|
|
void ApplyNodeFadingToChildren(FSceneViewState* ViewState, FLODSceneNode& Node, FSceneBitArray& VisibilityFlags, const bool bIsFading, const bool bIsFadingOut);
|
|
void HideNodeChildren(FSceneViewState* ViewState, FLODSceneNode& Node, FSceneBitArray& VisibilityFlags);
|
|
};
|
|
|
|
typedef TMap<FMaterial*, FMaterialShaderMap*> FMaterialsToUpdateMap;
|
|
|
|
class FCachedShadowMapData
|
|
{
|
|
public:
|
|
FWholeSceneProjectedShadowInitializer Initializer;
|
|
FShadowMapRenderTargetsRefCounted ShadowMap;
|
|
float LastUsedTime;
|
|
bool bCachedShadowMapHasPrimitives;
|
|
|
|
FCachedShadowMapData(const FWholeSceneProjectedShadowInitializer& InInitializer, float InLastUsedTime) :
|
|
Initializer(InInitializer),
|
|
LastUsedTime(InLastUsedTime),
|
|
bCachedShadowMapHasPrimitives(true)
|
|
{}
|
|
};
|
|
|
|
#if WITH_EDITOR
|
|
class FPixelInspectorData
|
|
{
|
|
public:
|
|
FPixelInspectorData();
|
|
|
|
void InitializeBuffers(FRenderTarget* BufferFinalColor, FRenderTarget* BufferSceneColor, FRenderTarget* BufferDepth, FRenderTarget* BufferHDR, FRenderTarget* BufferA, FRenderTarget* BufferBCDE, int32 bufferIndex);
|
|
|
|
bool AddPixelInspectorRequest(FPixelInspectorRequest *PixelInspectorRequest);
|
|
|
|
//Hold the buffer array
|
|
TMap<FIntPoint, FPixelInspectorRequest *> Requests;
|
|
|
|
FRenderTarget* RenderTargetBufferDepth[2];
|
|
FRenderTarget* RenderTargetBufferFinalColor[2];
|
|
FRenderTarget* RenderTargetBufferHDR[2];
|
|
FRenderTarget* RenderTargetBufferSceneColor[2];
|
|
FRenderTarget* RenderTargetBufferA[2];
|
|
FRenderTarget* RenderTargetBufferBCDE[2];
|
|
};
|
|
#endif //WITH_EDITOR
|
|
|
|
/**
|
|
* Renderer scene which is private to the renderer module.
|
|
* Ordinarily this is the renderer version of a UWorld, but an FScene can be created for previewing in editors which don't have a UWorld as well.
|
|
* The scene stores renderer state that is independent of any view or frame, with the primary actions being adding and removing of primitives and lights.
|
|
*/
|
|
class FScene : public FSceneInterface
|
|
{
|
|
public:
|
|
|
|
/** An optional world associated with the scene. */
|
|
UWorld* World;
|
|
|
|
/** An optional FX system associated with the scene. */
|
|
class FFXSystemInterface* FXSystem;
|
|
|
|
// various static draw lists for this DPG
|
|
|
|
/** position-only opaque depth draw list */
|
|
TStaticMeshDrawList<FPositionOnlyDepthDrawingPolicy> PositionOnlyDepthDrawList;
|
|
/** opaque depth draw list */
|
|
TStaticMeshDrawList<FDepthDrawingPolicy> DepthDrawList;
|
|
/** masked depth draw list */
|
|
TStaticMeshDrawList<FDepthDrawingPolicy> MaskedDepthDrawList;
|
|
/** Base pass draw list - no light map */
|
|
TStaticMeshDrawList<TBasePassDrawingPolicy<FUniformLightMapPolicy> > BasePassUniformLightMapPolicyDrawList[EBasePass_MAX];
|
|
/** Base pass draw list - self shadowed translucency*/
|
|
TStaticMeshDrawList<TBasePassDrawingPolicy<FSelfShadowedTranslucencyPolicy> > BasePassSelfShadowedTranslucencyDrawList[EBasePass_MAX];
|
|
TStaticMeshDrawList<TBasePassDrawingPolicy<FSelfShadowedCachedPointIndirectLightingPolicy> > BasePassSelfShadowedCachedPointIndirectTranslucencyDrawList[EBasePass_MAX];
|
|
|
|
/** hit proxy draw list (includes both opaque and translucent objects) */
|
|
TStaticMeshDrawList<FHitProxyDrawingPolicy> HitProxyDrawList;
|
|
|
|
/** hit proxy draw list, with only opaque objects */
|
|
TStaticMeshDrawList<FHitProxyDrawingPolicy> HitProxyDrawList_OpaqueOnly;
|
|
|
|
/** draw list for motion blur velocities */
|
|
TStaticMeshDrawList<FVelocityDrawingPolicy> VelocityDrawList;
|
|
|
|
/** Draw list used for rendering whole scene shadow depths. */
|
|
TStaticMeshDrawList<FShadowDepthDrawingPolicy<false> > WholeSceneShadowDepthDrawList;
|
|
|
|
/** Draw list used for rendering whole scene reflective shadow maps. */
|
|
TStaticMeshDrawList<FShadowDepthDrawingPolicy<true> > WholeSceneReflectiveShadowMapDrawList;
|
|
|
|
/** Maps a light-map type to the appropriate base pass draw list. */
|
|
template<typename LightMapPolicyType>
|
|
TStaticMeshDrawList<TBasePassDrawingPolicy<LightMapPolicyType> >& GetBasePassDrawList(EBasePassDrawListType DrawType);
|
|
|
|
/** Mobile base pass draw lists */
|
|
TStaticMeshDrawList<TMobileBasePassDrawingPolicy<FUniformLightMapPolicy, 0> > MobileBasePassUniformLightMapPolicyDrawList[EBasePass_MAX];
|
|
TStaticMeshDrawList<TMobileBasePassDrawingPolicy<FUniformLightMapPolicy, 0> > MobileBasePassUniformLightMapPolicyDrawListWithCSM[EBasePass_MAX];
|
|
|
|
|
|
/** Maps a light-map type to the appropriate base pass draw list. */
|
|
template<typename LightMapPolicyType>
|
|
TStaticMeshDrawList<TMobileBasePassDrawingPolicy<LightMapPolicyType,0> >& GetMobileBasePassDrawList(EBasePassDrawListType DrawType);
|
|
|
|
template<typename LightMapPolicyType>
|
|
TStaticMeshDrawList<TMobileBasePassDrawingPolicy<LightMapPolicyType, 0> >& GetMobileBasePassCSMDrawList(EBasePassDrawListType DrawType);
|
|
|
|
#if WITH_EDITOR
|
|
/** Draw list to use for selected static meshes in the editor only */
|
|
TStaticMeshDrawList<FEditorSelectionDrawingPolicy> EditorSelectionDrawList;
|
|
#endif
|
|
/**
|
|
* The following arrays are densely packed primitive data needed by various
|
|
* rendering passes. PrimitiveSceneInfo->PackedIndex maintains the index
|
|
* where data is stored in these arrays for a given primitive.
|
|
*/
|
|
|
|
/** Packed array of primitives in the scene. */
|
|
TArray<FPrimitiveSceneInfo*> Primitives;
|
|
/** Packed array of primitive bounds. */
|
|
TArray<FPrimitiveBounds> PrimitiveBounds;
|
|
/** Packed array of precomputed primitive visibility IDs. */
|
|
TArray<FPrimitiveVisibilityId> PrimitiveVisibilityIds;
|
|
/** Packed array of primitive occlusion flags. See EOcclusionFlags. */
|
|
TArray<uint8> PrimitiveOcclusionFlags;
|
|
/** Packed array of primitive occlusion bounds. */
|
|
TArray<FBoxSphereBounds> PrimitiveOcclusionBounds;
|
|
/** Packed array of primitive components associated with the primitive. */
|
|
TArray<FPrimitiveComponentId> PrimitiveComponentIds;
|
|
|
|
/** The lights in the scene. */
|
|
TSparseArray<FLightSceneInfoCompact> Lights;
|
|
|
|
/**
|
|
* Lights in the scene which are invisible, but still needed by the editor for previewing.
|
|
* Lights in this array cannot be in the Lights array. They also are not fully set up, as AddLightSceneInfo_RenderThread is not called for them.
|
|
*/
|
|
TSparseArray<FLightSceneInfoCompact> InvisibleLights;
|
|
|
|
/** Shadow casting lights that couldn't get a shadowmap channel assigned and therefore won't have valid dynamic shadows, forward renderer only. */
|
|
TArray<FName> OverflowingDynamicShadowedLights;
|
|
|
|
/** The mobile quality level for which static draw lists have been built. */
|
|
bool bStaticDrawListsMobileHDR;
|
|
bool bStaticDrawListsMobileHDR32bpp;
|
|
|
|
/** Whether the early Z pass was force enabled when static draw lists were built. */
|
|
int32 StaticDrawListsEarlyZPassMode;
|
|
|
|
/** Whether the ShaderPipelines were enabled when the static draw lists were built. */
|
|
int32 StaticDrawShaderPipelines;
|
|
|
|
/** True if a change to SkyLight / Lighting has occurred that requires static draw lists to be updated. */
|
|
bool bScenesPrimitivesNeedStaticMeshElementUpdate;
|
|
|
|
/** The scene's sky light, if any. */
|
|
FSkyLightSceneProxy* SkyLight;
|
|
|
|
/** Used to track the order that skylights were enabled in. */
|
|
TArray<FSkyLightSceneProxy*> SkyLightStack;
|
|
|
|
/** The directional light to use for simple dynamic lighting, if any. */
|
|
FLightSceneInfo* SimpleDirectionalLight;
|
|
|
|
/** For the mobile renderer, the first directional light in each lighting channel. */
|
|
FLightSceneInfo* MobileDirectionalLights[NUM_LIGHTING_CHANNELS];
|
|
|
|
/** The sun light for atmospheric effect, if any. */
|
|
FLightSceneInfo* SunLight;
|
|
|
|
/** The decals in the scene. */
|
|
TSparseArray<FDeferredDecalProxy*> Decals;
|
|
|
|
/** Potential capsule shadow casters registered to the scene. */
|
|
TArray<FPrimitiveSceneInfo*> DynamicIndirectCasterPrimitives;
|
|
|
|
TArray<class FPlanarReflectionSceneProxy*> PlanarReflections;
|
|
TArray<class UPlanarReflectionComponent*> PlanarReflections_GameThread;
|
|
|
|
/** State needed for the reflection environment feature. */
|
|
FReflectionEnvironmentSceneData ReflectionSceneData;
|
|
|
|
/**
|
|
* Precomputed lighting volumes in the scene, used for interpolating dynamic object lighting.
|
|
* These are typically one per streaming level and they store volume lighting samples computed by Lightmass.
|
|
*/
|
|
TArray<const FPrecomputedLightVolume*> PrecomputedLightVolumes;
|
|
|
|
/** Interpolates and caches indirect lighting for dynamic objects. */
|
|
FIndirectLightingCache IndirectLightingCache;
|
|
|
|
/** Distance field object scene data. */
|
|
FDistanceFieldSceneData DistanceFieldSceneData;
|
|
|
|
/** Map from light id to the cached shadowmap data for that light. */
|
|
TMap<int32, FCachedShadowMapData> CachedShadowMaps;
|
|
|
|
TRefCountPtr<IPooledRenderTarget> PreShadowCacheDepthZ;
|
|
|
|
/** Preshadows that are currently cached in the PreshadowCache render target. */
|
|
TArray<TRefCountPtr<FProjectedShadowInfo> > CachedPreshadows;
|
|
|
|
/** Texture layout that tracks current allocations in the PreshadowCache render target. */
|
|
FTextureLayout PreshadowCacheLayout;
|
|
|
|
/** The static meshes in the scene. */
|
|
TSparseArray<FStaticMesh*> StaticMeshes;
|
|
|
|
/** The exponential fog components in the scene. */
|
|
TArray<FExponentialHeightFogSceneInfo> ExponentialFogs;
|
|
|
|
/** The atmospheric fog components in the scene. */
|
|
FAtmosphericFogSceneInfo* AtmosphericFog;
|
|
|
|
/** The wind sources in the scene. */
|
|
TArray<class FWindSourceSceneProxy*> WindSources;
|
|
|
|
/** Wind source components, tracked so the game thread can also access wind parameters */
|
|
TArray<UWindDirectionalSourceComponent*> WindComponents_GameThread;
|
|
|
|
/** SpeedTree wind objects in the scene. FLocalVertexFactoryShaderParameters needs to lookup by FVertexFactory, but wind objects are per tree (i.e. per UStaticMesh)*/
|
|
TMap<const UStaticMesh*, struct FSpeedTreeWindComputation*> SpeedTreeWindComputationMap;
|
|
TMap<FVertexFactory*, const UStaticMesh*> SpeedTreeVertexFactoryMap;
|
|
|
|
/** The attachment groups in the scene. The map key is the attachment group's root primitive. */
|
|
TMap<FPrimitiveComponentId,FAttachmentGroupSceneInfo> AttachmentGroups;
|
|
|
|
/** Precomputed visibility data for the scene. */
|
|
const FPrecomputedVisibilityHandler* PrecomputedVisibilityHandler;
|
|
|
|
/** An octree containing the shadow casting lights in the scene. */
|
|
FSceneLightOctree LightOctree;
|
|
|
|
/** An octree containing the primitives in the scene. */
|
|
FScenePrimitiveOctree PrimitiveOctree;
|
|
|
|
/** Indicates whether this scene requires hit proxy rendering. */
|
|
bool bRequiresHitProxies;
|
|
|
|
/** Whether this is an editor scene. */
|
|
bool bIsEditorScene;
|
|
|
|
/** Set by the rendering thread to signal to the game thread that the scene needs a static lighting build. */
|
|
volatile mutable int32 NumUncachedStaticLightingInteractions;
|
|
|
|
/** Track numbers of various lights types on mobile, used to show warnings for disabled shader permutations. */
|
|
int32 NumMobileStaticAndCSMLights_RenderThread;
|
|
int32 NumMobileMovableDirectionalLights_RenderThread;
|
|
|
|
FMotionBlurInfoData MotionBlurInfoData;
|
|
|
|
/** GPU Skinning cache, if enabled */
|
|
class FGPUSkinCache* GPUSkinCache;
|
|
|
|
/** Uniform buffers for parameter collections with the corresponding Ids. */
|
|
TMap<FGuid, FUniformBufferRHIRef> ParameterCollections;
|
|
|
|
/** LOD Tree Holder for massive LOD system */
|
|
FLODSceneTree SceneLODHierarchy;
|
|
|
|
float DefaultMaxDistanceFieldOcclusionDistance;
|
|
|
|
float GlobalDistanceFieldViewDistance;
|
|
|
|
float DynamicIndirectShadowsSelfShadowingIntensity;
|
|
|
|
const FReadOnlyCVARCache& ReadOnlyCVARCache;
|
|
|
|
#if WITH_EDITOR
|
|
/** Editor Pixel inspector */
|
|
FPixelInspectorData PixelInspectorData;
|
|
#endif //WITH_EDITOR
|
|
|
|
/** Initialization constructor. */
|
|
FScene(UWorld* InWorld, bool bInRequiresHitProxies,bool bInIsEditorScene, bool bCreateFXSystem, ERHIFeatureLevel::Type InFeatureLevel);
|
|
|
|
virtual ~FScene();
|
|
|
|
// FSceneInterface interface.
|
|
virtual void AddPrimitive(UPrimitiveComponent* Primitive) override;
|
|
virtual void RemovePrimitive(UPrimitiveComponent* Primitive) override;
|
|
virtual void ReleasePrimitive(UPrimitiveComponent* Primitive) override;
|
|
virtual void UpdatePrimitiveTransform(UPrimitiveComponent* Primitive) override;
|
|
virtual void UpdatePrimitiveAttachment(UPrimitiveComponent* Primitive) override;
|
|
virtual FPrimitiveSceneInfo* GetPrimitiveSceneInfo(int32 PrimitiveIndex) override;
|
|
virtual void AddLight(ULightComponent* Light) override;
|
|
virtual void RemoveLight(ULightComponent* Light) override;
|
|
virtual void AddInvisibleLight(ULightComponent* Light) override;
|
|
virtual void SetSkyLight(FSkyLightSceneProxy* Light) override;
|
|
virtual void DisableSkyLight(FSkyLightSceneProxy* Light) override;
|
|
virtual void AddDecal(UDecalComponent* Component) override;
|
|
virtual void RemoveDecal(UDecalComponent* Component) override;
|
|
virtual void UpdateDecalTransform(UDecalComponent* Decal) override;
|
|
virtual void AddReflectionCapture(UReflectionCaptureComponent* Component) override;
|
|
virtual void RemoveReflectionCapture(UReflectionCaptureComponent* Component) override;
|
|
virtual void GetReflectionCaptureData(UReflectionCaptureComponent* Component, class FReflectionCaptureFullHDR& OutDerivedData) override;
|
|
virtual void UpdateReflectionCaptureTransform(UReflectionCaptureComponent* Component) override;
|
|
virtual void ReleaseReflectionCubemap(UReflectionCaptureComponent* CaptureComponent) override;
|
|
virtual void AddPlanarReflection(class UPlanarReflectionComponent* Component) override;
|
|
virtual void RemovePlanarReflection(UPlanarReflectionComponent* Component) override;
|
|
virtual void UpdatePlanarReflectionTransform(UPlanarReflectionComponent* Component) override;
|
|
virtual void UpdateSceneCaptureContents(class USceneCaptureComponent2D* CaptureComponent) override;
|
|
virtual void UpdateSceneCaptureContents(class USceneCaptureComponentCube* CaptureComponent) override;
|
|
virtual void UpdatePlanarReflectionContents(UPlanarReflectionComponent* CaptureComponent, FSceneRenderer& MainSceneRenderer) override;
|
|
virtual void AllocateReflectionCaptures(const TArray<UReflectionCaptureComponent*>& NewCaptures) override;
|
|
virtual void UpdateSkyCaptureContents(const USkyLightComponent* CaptureComponent, bool bCaptureEmissiveOnly, UTextureCube* SourceCubemap, FTexture* OutProcessedTexture, float& OutAverageBrightness, FSHVectorRGB3& OutIrradianceEnvironmentMap) override;
|
|
virtual void AddPrecomputedLightVolume(const class FPrecomputedLightVolume* Volume) override;
|
|
virtual void RemovePrecomputedLightVolume(const class FPrecomputedLightVolume* Volume) override;
|
|
virtual void UpdateLightTransform(ULightComponent* Light) override;
|
|
virtual void UpdateLightColorAndBrightness(ULightComponent* Light) override;
|
|
virtual void AddExponentialHeightFog(UExponentialHeightFogComponent* FogComponent) override;
|
|
virtual void RemoveExponentialHeightFog(UExponentialHeightFogComponent* FogComponent) override;
|
|
virtual void AddAtmosphericFog(UAtmosphericFogComponent* FogComponent) override;
|
|
virtual void RemoveAtmosphericFog(UAtmosphericFogComponent* FogComponent) override;
|
|
virtual void RemoveAtmosphericFogResource_RenderThread(FRenderResource* FogResource) override;
|
|
virtual FAtmosphericFogSceneInfo* GetAtmosphericFogSceneInfo() override { return AtmosphericFog; }
|
|
virtual void AddWindSource(UWindDirectionalSourceComponent* WindComponent) override;
|
|
virtual void RemoveWindSource(UWindDirectionalSourceComponent* WindComponent) override;
|
|
virtual const TArray<FWindSourceSceneProxy*>& GetWindSources_RenderThread() const override;
|
|
virtual void GetWindParameters(const FVector& Position, FVector& OutDirection, float& OutSpeed, float& OutMinGustAmt, float& OutMaxGustAmt) const override;
|
|
virtual void GetWindParameters_GameThread(const FVector& Position, FVector& OutDirection, float& OutSpeed, float& OutMinGustAmt, float& OutMaxGustAmt) const override;
|
|
virtual void GetDirectionalWindParameters(FVector& OutDirection, float& OutSpeed, float& OutMinGustAmt, float& OutMaxGustAmt) const override;
|
|
virtual void AddSpeedTreeWind(FVertexFactory* VertexFactory, const UStaticMesh* StaticMesh) override;
|
|
virtual void RemoveSpeedTreeWind(FVertexFactory* VertexFactory, const UStaticMesh* StaticMesh) override;
|
|
virtual void RemoveSpeedTreeWind_RenderThread(FVertexFactory* VertexFactory, const UStaticMesh* StaticMesh) override;
|
|
virtual void UpdateSpeedTreeWind(double CurrentTime) override;
|
|
virtual FUniformBufferRHIParamRef GetSpeedTreeUniformBuffer(const FVertexFactory* VertexFactory) override;
|
|
virtual void DumpUnbuiltLightIteractions( FOutputDevice& Ar ) const override;
|
|
virtual void DumpStaticMeshDrawListStats() const override;
|
|
virtual void SetClearMotionBlurInfoGameThread() override;
|
|
virtual void UpdateParameterCollections(const TArray<FMaterialParameterCollectionInstanceResource*>& InParameterCollections) override;
|
|
|
|
/** Determines whether the scene has atmospheric fog and sun light. */
|
|
bool HasAtmosphericFog() const
|
|
{
|
|
return (AtmosphericFog != NULL); // Use default value when Sun Light is not existing
|
|
}
|
|
|
|
/**
|
|
* Retrieves the lights interacting with the passed in primitive and adds them to the out array.
|
|
*
|
|
* @param Primitive Primitive to retrieve interacting lights for
|
|
* @param RelevantLights [out] Array of lights interacting with primitive
|
|
*/
|
|
virtual void GetRelevantLights( UPrimitiveComponent* Primitive, TArray<const ULightComponent*>* RelevantLights ) const override;
|
|
|
|
/** Sets the precomputed visibility handler for the scene, or NULL to clear the current one. */
|
|
virtual void SetPrecomputedVisibility(const FPrecomputedVisibilityHandler* InPrecomputedVisibilityHandler) override;
|
|
|
|
/** Sets shader maps on the specified materials without blocking. */
|
|
virtual void SetShaderMapsOnMaterialResources(const TMap<FMaterial*, class FMaterialShaderMap*>& MaterialsToUpdate) override;
|
|
|
|
/** Updates static draw lists for the given set of materials. */
|
|
virtual void UpdateStaticDrawListsForMaterials(const TArray<const FMaterial*>& Materials) override;
|
|
|
|
virtual void Release() override;
|
|
virtual UWorld* GetWorld() const override { return World; }
|
|
|
|
/** Finds the closest reflection capture to a point in space. */
|
|
const FReflectionCaptureProxy* FindClosestReflectionCapture(FVector Position) const;
|
|
|
|
const class FPlanarReflectionSceneProxy* FindClosestPlanarReflection(const FPrimitiveBounds& Bounds) const;
|
|
|
|
void FindClosestReflectionCaptures(FVector Position, const FReflectionCaptureProxy* (&SortedByDistanceOUT)[FPrimitiveSceneInfo::MaxCachedReflectionCaptureProxies]) const;
|
|
|
|
/**
|
|
* Gets the scene's cubemap array and index into that array for the given reflection proxy.
|
|
* If the proxy was not found in the scene's reflection state, the outputs are not written to.
|
|
*/
|
|
void GetCaptureParameters(const FReflectionCaptureProxy* ReflectionProxy, FTextureRHIParamRef& ReflectionCubemapArray, int32& ArrayIndex) const;
|
|
|
|
int64 GetCachedWholeSceneShadowMapsSize() const;
|
|
|
|
/**
|
|
* Marks static mesh elements as needing an update if necessary.
|
|
*/
|
|
void ConditionalMarkStaticMeshElementsForUpdate();
|
|
|
|
/**
|
|
* @return true if hit proxies should be rendered in this scene.
|
|
*/
|
|
virtual bool RequiresHitProxies() const override;
|
|
|
|
SIZE_T GetSizeBytes() const;
|
|
|
|
/**
|
|
* Return the scene to be used for rendering
|
|
*/
|
|
virtual class FScene* GetRenderScene() override
|
|
{
|
|
return this;
|
|
}
|
|
|
|
virtual void UpdateSceneSettings(AWorldSettings* WorldSettings) override;
|
|
|
|
virtual class FGPUSkinCache* GetGPUSkinCache() override
|
|
{
|
|
return GPUSkinCache;
|
|
}
|
|
|
|
/**
|
|
* Sets the FX system associated with the scene.
|
|
*/
|
|
virtual void SetFXSystem( class FFXSystemInterface* InFXSystem ) override;
|
|
|
|
/**
|
|
* Get the FX system associated with the scene.
|
|
*/
|
|
virtual class FFXSystemInterface* GetFXSystem() override;
|
|
|
|
/**
|
|
* Exports the scene.
|
|
*
|
|
* @param Ar The Archive used for exporting.
|
|
**/
|
|
virtual void Export( FArchive& Ar ) const override;
|
|
|
|
FUniformBufferRHIParamRef GetParameterCollectionBuffer(const FGuid& InId) const
|
|
{
|
|
const FUniformBufferRHIRef* ExistingUniformBuffer = ParameterCollections.Find(InId);
|
|
|
|
if (ExistingUniformBuffer)
|
|
{
|
|
return *ExistingUniformBuffer;
|
|
}
|
|
|
|
return FUniformBufferRHIParamRef();
|
|
}
|
|
|
|
virtual void ApplyWorldOffset(FVector InOffset) override;
|
|
|
|
virtual void OnLevelAddedToWorld(FName InLevelName, UWorld* InWorld, bool bIsLightingScenario) override;
|
|
virtual void OnLevelRemovedFromWorld(UWorld* InWorld, bool bIsLightingScenario) override;
|
|
|
|
virtual bool HasAnyLights() const override
|
|
{
|
|
check(IsInGameThread());
|
|
return NumVisibleLights_GameThread > 0 || NumEnabledSkylights_GameThread > 0;
|
|
}
|
|
|
|
virtual bool IsEditorScene() const override { return bIsEditorScene; }
|
|
|
|
virtual ERHIFeatureLevel::Type GetFeatureLevel() const override { return FeatureLevel; }
|
|
|
|
bool ShouldRenderSkylightInBasePass(EBlendMode BlendMode) const
|
|
{
|
|
const bool bStationarySkylight = SkyLight && SkyLight->bWantsStaticShadowing;
|
|
return ShouldRenderSkylightInBasePass_Internal(BlendMode) && (ReadOnlyCVARCache.bEnableStationarySkylight || !bStationarySkylight);
|
|
}
|
|
|
|
bool ShouldRenderSkylightInBasePass_Internal(EBlendMode BlendMode) const
|
|
{
|
|
if (IsTranslucentBlendMode(BlendMode))
|
|
{
|
|
//both stationary and movable skylights are applied during actual translucency render
|
|
return SkyLight && !SkyLight->bHasStaticLighting;
|
|
}
|
|
else
|
|
{
|
|
const bool bRenderSkylight = SkyLight
|
|
&& !SkyLight->bHasStaticLighting
|
|
// The deferred shading renderer does movable skylight diffuse in a later deferred pass, not in the base pass
|
|
// bWantsStaticShadowing means 'stationary skylight'
|
|
&& (SkyLight->bWantsStaticShadowing || IsAnyForwardShadingEnabled(GetShaderPlatform()));
|
|
|
|
return bRenderSkylight;
|
|
}
|
|
}
|
|
|
|
virtual TArray<FPrimitiveComponentId> GetScenePrimitiveComponentIds() const override
|
|
{
|
|
return PrimitiveComponentIds;
|
|
}
|
|
|
|
#if WITH_EDITOR
|
|
virtual bool InitializePixelInspector(FRenderTarget* BufferFinalColor, FRenderTarget* BufferSceneColor, FRenderTarget* BufferDepth, FRenderTarget* BufferHDR, FRenderTarget* BufferA, FRenderTarget* BufferBCDE, int32 BufferIndex) override;
|
|
|
|
virtual bool AddPixelInspectorRequest(FPixelInspectorRequest *PixelInspectorRequest) override;
|
|
#endif //WITH_EDITOR
|
|
|
|
virtual uint32 GetFrameNumber() const override
|
|
{
|
|
return SceneFrameNumber;
|
|
}
|
|
|
|
virtual void IncrementFrameNumber() override
|
|
{
|
|
++SceneFrameNumber;
|
|
}
|
|
|
|
private:
|
|
|
|
/**
|
|
* Ensures the packed primitive arrays contain the same number of elements.
|
|
*/
|
|
void CheckPrimitiveArrays();
|
|
|
|
/**
|
|
* Retrieves the lights interacting with the passed in primitive and adds them to the out array.
|
|
* Render thread version of function.
|
|
* @param Primitive Primitive to retrieve interacting lights for
|
|
* @param RelevantLights [out] Array of lights interacting with primitive
|
|
*/
|
|
void GetRelevantLights_RenderThread( UPrimitiveComponent* Primitive, TArray<const ULightComponent*>* RelevantLights ) const;
|
|
|
|
/**
|
|
* Adds a primitive to the scene. Called in the rendering thread by AddPrimitive.
|
|
* @param PrimitiveSceneInfo - The primitive being added.
|
|
*/
|
|
void AddPrimitiveSceneInfo_RenderThread(FRHICommandListImmediate& RHICmdList, FPrimitiveSceneInfo* PrimitiveSceneInfo);
|
|
|
|
/**
|
|
* Removes a primitive from the scene. Called in the rendering thread by RemovePrimitive.
|
|
* @param PrimitiveSceneInfo - The primitive being removed.
|
|
*/
|
|
void RemovePrimitiveSceneInfo_RenderThread(FPrimitiveSceneInfo* PrimitiveSceneInfo);
|
|
|
|
/** Updates a primitive's transform, called on the rendering thread. */
|
|
void UpdatePrimitiveTransform_RenderThread(FRHICommandListImmediate& RHICmdList, FPrimitiveSceneProxy* PrimitiveSceneProxy, const FBoxSphereBounds& WorldBounds, const FBoxSphereBounds& LocalBounds, const FMatrix& LocalToWorld, const FVector& OwnerPosition);
|
|
|
|
/** Updates a single primitive's lighting attachment root. */
|
|
void UpdatePrimitiveLightingAttachmentRoot(UPrimitiveComponent* Primitive);
|
|
|
|
void AssignAvailableShadowMapChannelForLight(FLightSceneInfo* LightSceneInfo);
|
|
|
|
/**
|
|
* Adds a light to the scene. Called in the rendering thread by AddLight.
|
|
* @param LightSceneInfo - The light being added.
|
|
*/
|
|
void AddLightSceneInfo_RenderThread(FLightSceneInfo* LightSceneInfo);
|
|
|
|
/**
|
|
* Adds a decal to the scene. Called in the rendering thread by AddDecal or RemoveDecal.
|
|
* @param Component - The object that should being added or removed.
|
|
* @param bAdd true:add, FASLE:remove
|
|
*/
|
|
void AddOrRemoveDecal_RenderThread(FDeferredDecalProxy* Component, bool bAdd);
|
|
|
|
/**
|
|
* Removes a light from the scene. Called in the rendering thread by RemoveLight.
|
|
* @param LightSceneInfo - The light being removed.
|
|
*/
|
|
void RemoveLightSceneInfo_RenderThread(FLightSceneInfo* LightSceneInfo);
|
|
|
|
void UpdateLightTransform_RenderThread(FLightSceneInfo* LightSceneInfo, const struct FUpdateLightTransformParameters& Parameters);
|
|
|
|
/**
|
|
* Updates the contents of the given reflection capture by rendering the scene.
|
|
* This must be called on the game thread.
|
|
*/
|
|
void UpdateReflectionCaptureContents(UReflectionCaptureComponent* CaptureComponent);
|
|
|
|
/** Updates the contents of all reflection captures in the scene. Must be called from the game thread. */
|
|
void UpdateAllReflectionCaptures();
|
|
|
|
/** Sets shader maps on the specified materials without blocking. */
|
|
void SetShaderMapsOnMaterialResources_RenderThread(FRHICommandListImmediate& RHICmdList, const FMaterialsToUpdateMap& MaterialsToUpdate);
|
|
|
|
/** Updates static draw lists for the given materials. */
|
|
void UpdateStaticDrawListsForMaterials_RenderThread(FRHICommandListImmediate& RHICmdList, const TArray<const FMaterial*>& Materials);
|
|
|
|
/**
|
|
* Shifts scene data by provided delta
|
|
* Called on world origin changes
|
|
*
|
|
* @param InOffset Delta to shift scene by
|
|
*/
|
|
void ApplyWorldOffset_RenderThread(FVector InOffset);
|
|
|
|
/**
|
|
* Notification from game thread that level was added to a world
|
|
*
|
|
* @param InLevelName Level name
|
|
*/
|
|
void OnLevelAddedToWorld_RenderThread(FName InLevelName);
|
|
|
|
private:
|
|
/**
|
|
* The number of visible lights in the scene
|
|
* Note: This is tracked on the game thread!
|
|
*/
|
|
int32 NumVisibleLights_GameThread;
|
|
|
|
/**
|
|
* Whether the scene has a valid sky light.
|
|
* Note: This is tracked on the game thread!
|
|
*/
|
|
int32 NumEnabledSkylights_GameThread;
|
|
|
|
/** This scene's feature level */
|
|
ERHIFeatureLevel::Type FeatureLevel;
|
|
|
|
/** Frame number incremented per-family viewing this scene. */
|
|
uint32 SceneFrameNumber;
|
|
};
|
|
|
|
inline bool ShouldIncludeDomainInMeshPass(EMaterialDomain Domain)
|
|
{
|
|
// Non-Surface domains can be applied to static meshes for thumbnails or material editor preview
|
|
// Volume domain materials however must only be rendered in the voxelization pass
|
|
return Domain != MD_Volume;
|
|
}
|
|
|
|
#include "BasePassRendering.inl"
|
|
|