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]
900 lines
31 KiB
Plaintext
900 lines
31 KiB
Plaintext
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
PostProcessCircleDOF.usf: PostProcessing Circle Depth of Field
|
|
=============================================================================*/
|
|
|
|
#include "Common.usf"
|
|
#include "PostProcessCommon.usf"
|
|
#include "DeferredShadingCommon.usf" // FGBufferData
|
|
#include "DepthOfFieldCommon.usf"
|
|
#include "CircleDOFCommon.usf"
|
|
|
|
// 0:off / 1:on (use with "vis CircleDOF0")
|
|
#define DEBUG_SAMPLE_PATTERN 0
|
|
|
|
// 0:old, 1:new(fixed high res screenshots), does not make a difference
|
|
#define DILATION_RESOLUTION_INDEPENDENT 0
|
|
|
|
// Note: View.CircleDOFParams.w = View.ViewSizeAndInvSize.x / 1920
|
|
|
|
// is wrapping the DepthToCoc() function in this file for faster iteration
|
|
// @return half res pixel radius
|
|
float DepthToCoc2(float SceneDepth)
|
|
{
|
|
// return ((SceneDepth > 8000) ? 5.0f : 2.6f) * 0.5f * View.CircleDOFParams.w;
|
|
return DepthToCoc(SceneDepth);
|
|
}
|
|
|
|
// pixel shader entry point
|
|
void CircleSetupPS(
|
|
noperspective float4 UVAndScreenPos : TEXCOORD0
|
|
, out float4 OutColor0 : SV_Target0
|
|
#if POST_PROCESS_ALPHA
|
|
, out float4 OutColor1 : SV_Target1
|
|
#endif
|
|
)
|
|
{
|
|
float2 UV = UVAndScreenPos.xy;
|
|
|
|
float4 DepthQuad = GatherSceneDepth(UV, PostprocessInput1Size.zw);
|
|
|
|
UV = UVAndScreenPos.xy - 0.5*PostprocessInput0Size.zw;
|
|
|
|
SceneColorLayout CW = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV.xy, 0));
|
|
SceneColorLayout CZ = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV.xy, 0, int2(1,0)));
|
|
SceneColorLayout CX = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV.xy, 0, int2(0,1)));
|
|
SceneColorLayout CY = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV.xy, 0, int2(1,1)));
|
|
|
|
// clamp to avoid artifacts from exceeding fp16 through framebuffer blending of multiple very bright lights
|
|
CW = min(256 * 256, CW);
|
|
CZ = min(256 * 256, CZ);
|
|
CX = min(256 * 256, CX);
|
|
CY = min(256 * 256, CY);
|
|
|
|
float4 CocQuad = float4(DepthToCoc2(DepthQuad.x), DepthToCoc2(DepthQuad.y), DepthToCoc2(DepthQuad.z), DepthToCoc2(DepthQuad.w));
|
|
|
|
#if ENABLE_FAR_BLUR == 0
|
|
CocQuad = min(CocQuad, 0);
|
|
#endif
|
|
|
|
// Doing a max depth reduction (erode the foreground). Less correct, but less artifacts.
|
|
// Perhaps need to re-open this in the future.
|
|
|
|
float mi = min(min(CocQuad.x,CocQuad.y),min(CocQuad.z,CocQuad.w));
|
|
float ma = max(max(CocQuad.x,CocQuad.y),max(CocQuad.z,CocQuad.w));
|
|
float ami = min(min(abs(CocQuad.x),abs(CocQuad.y)),min(abs(CocQuad.z),abs(CocQuad.w)));
|
|
float ama = max(max(abs(CocQuad.x),abs(CocQuad.y)),max(abs(CocQuad.z),abs(CocQuad.w)));
|
|
|
|
// 0:was an option before, causes erosion / 1:to reduce TemporalAA issues / 2:was used in KiteDemo
|
|
#define COC_METHOD 2
|
|
|
|
#if COC_METHOD == 0
|
|
// Stuff max radius in alpha.
|
|
// bad erosion on TemporalDitherAA
|
|
float PixelCoc = ma;
|
|
#elif COC_METHOD == 1
|
|
// acceptable TemporalDitherAA
|
|
// requires DefaultWeight > 1
|
|
float PixelCoc = (mi + ma) / 2;
|
|
#elif COC_METHOD == 2
|
|
// This in theory is better but causes bleeding artifacts with temporal AA..
|
|
// This is important otherwise near thin objects disappear (leaves clamping artifacts in recombined pass).
|
|
// bad on TemporalDitherAA, flat opacity where it should transition
|
|
float PixelCoc = CocQuad.x;
|
|
if(abs(PixelCoc) > CocQuad.y) PixelCoc = CocQuad.y;
|
|
if(abs(PixelCoc) > CocQuad.z) PixelCoc = CocQuad.z;
|
|
if(abs(PixelCoc) > CocQuad.w) PixelCoc = CocQuad.w;
|
|
#elif COC_METHOD == 3
|
|
// this should be better than the method before
|
|
// bad on TemporalDitherAA
|
|
float PixelCoc = CocQuad.x;
|
|
if(abs(PixelCoc) > abs(CocQuad.y)) PixelCoc = CocQuad.y;
|
|
if(abs(PixelCoc) > abs(CocQuad.z)) PixelCoc = CocQuad.z;
|
|
if(abs(PixelCoc) > abs(CocQuad.w)) PixelCoc = CocQuad.w;
|
|
#elif COC_METHOD == 4
|
|
// Stuff max radius in alpha.
|
|
float PixelCoc = mi;
|
|
#elif COC_METHOD == 5
|
|
// artifacts that look like negative colors (tb070) (with and without the 2nd line)
|
|
// bad erosion on TemporalDitherAA
|
|
float PixelCoc = (ami + ama) / 2;
|
|
// if((mi + ma) / 2 < 0) OutColor0.a = 0;
|
|
#elif COC_METHOD == 6
|
|
// like #3 but with inverted comparison, ok?
|
|
// bad erosion on TemporalDitherAA
|
|
float PixelCoc = CocQuad.x;
|
|
if(abs(PixelCoc) < abs(CocQuad.y)) PixelCoc = CocQuad.y;
|
|
if(abs(PixelCoc) < abs(CocQuad.z)) PixelCoc = CocQuad.z;
|
|
if(abs(PixelCoc) < abs(CocQuad.w)) PixelCoc = CocQuad.w;
|
|
#elif COC_METHOD == 7
|
|
// requires DefaultWeight > 1
|
|
float A = CocQuad.x;
|
|
if(abs(A) < abs(CocQuad.y)) A = CocQuad.y;
|
|
if(abs(A) < abs(CocQuad.z)) A = CocQuad.z;
|
|
if(abs(A) < abs(CocQuad.w)) A = CocQuad.w;
|
|
float B = CocQuad.x;
|
|
if(abs(B) > abs(CocQuad.y)) B = CocQuad.y;
|
|
if(abs(B) > abs(CocQuad.z)) B = CocQuad.z;
|
|
if(abs(B) > abs(CocQuad.w)) B = CocQuad.w;
|
|
float PixelCoc = (A + B) / 2;
|
|
#elif COC_METHOD == 8
|
|
// broken near dof
|
|
float PixelCoc = dot(0.25f, max(0, CocQuad));
|
|
#elif COC_METHOD == 9
|
|
// mix between 2 and 8, seems to be best in most cases
|
|
// requires DefaultWeight > 1
|
|
float PixelCoc = CocQuad.x;
|
|
if(abs(PixelCoc) > CocQuad.y) PixelCoc = CocQuad.y;
|
|
if(abs(PixelCoc) > CocQuad.z) PixelCoc = CocQuad.z;
|
|
if(abs(PixelCoc) > CocQuad.w) PixelCoc = CocQuad.w;
|
|
if(PixelCoc > 0) PixelCoc = dot(0.25f, max(0, CocQuad));
|
|
#else
|
|
error
|
|
#endif
|
|
|
|
// >1 to avoid /0 (resulting in dark outlines in level tb070)
|
|
// a bit laregr to avoid a specific leaking artifact in level tb080
|
|
const float DefaultWeight = 1.4f;
|
|
|
|
// Remove samples which are outside the size.
|
|
// TODO: Tune the ScaleFactor.
|
|
float ScaleFactor = 64.0;
|
|
float4 W = float4(
|
|
DefaultWeight - saturate(abs(PixelCoc - CocQuad.x) * ScaleFactor),
|
|
DefaultWeight - saturate(abs(PixelCoc - CocQuad.y) * ScaleFactor),
|
|
DefaultWeight - saturate(abs(PixelCoc - CocQuad.z) * ScaleFactor),
|
|
DefaultWeight - saturate(abs(PixelCoc - CocQuad.w) * ScaleFactor));
|
|
|
|
SceneColorLayout ColorDownSample = (1.0 / (W.x + W.y + W.z + W.w)) * (CX * W.x + CY * W.y + CZ * W.z + CW * W.w);
|
|
#if POST_PROCESS_ALPHA
|
|
OutColor0 = ColorDownSample;
|
|
OutColor1 = float4(PixelCoc, 0, 0, 0);
|
|
#else
|
|
OutColor0.rgb = ColorDownSample;
|
|
OutColor0.a = PixelCoc;
|
|
#endif
|
|
}
|
|
|
|
|
|
|
|
// {0 to 1} output.
|
|
float NoizNorm(float2 N, float X)
|
|
{
|
|
N+=X;
|
|
return frac(sin(dot(N.xy,float2(12.9898, 78.233)))*43758.5453);
|
|
}
|
|
|
|
// {-1 to 1} output.
|
|
float NoizSnorm(float2 N, float X)
|
|
{
|
|
return NoizNorm(N,X)*2.0-1.0;
|
|
}
|
|
|
|
float2 RotVec(float Radius, float Radians)
|
|
{
|
|
return Radius * float2(cos(Radians), sin(Radians));
|
|
}
|
|
|
|
float2 RandomOffset;
|
|
|
|
|
|
|
|
|
|
float Min4(float4 A)
|
|
{
|
|
return min(min(A.x,A.y),min(A.z,A.w));
|
|
}
|
|
|
|
float Min16(float4 A, float4 B, float4 C, float4 D)
|
|
{
|
|
return min(min(Min4(A),Min4(B)),min(Min4(C),Min4(D)));
|
|
}
|
|
|
|
#if COMPILER_GLSL || COMPILER_GLSL_ES2 || COMPILER_GLSL_ES3_1 || FEATURE_LEVEL < FEATURE_LEVEL_SM5
|
|
float ReadCoc(float2 UV, int2 PixelOffset)
|
|
{
|
|
#if POST_PROCESS_ALPHA
|
|
return PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV, 0, PixelOffset).r;
|
|
#else
|
|
return PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV, 0, PixelOffset).a;
|
|
#endif
|
|
}
|
|
#elif DILATION_RESOLUTION_INDEPENDENT
|
|
float4 GatherCoc(float2 UV)
|
|
{
|
|
#if POST_PROCESS_ALPHA
|
|
return PostprocessInput0.GatherRed(PostprocessInput0Sampler, UV);
|
|
#else
|
|
return PostprocessInput0.GatherAlpha(PostprocessInput0Sampler, UV);
|
|
#endif
|
|
}
|
|
#else
|
|
float4 GatherCoc(float2 UV, int2 PixelOffset)
|
|
{
|
|
#if POST_PROCESS_ALPHA
|
|
return PostprocessInput0.GatherRed(PostprocessInput0Sampler, UV, PixelOffset);
|
|
#else
|
|
return PostprocessInput0.GatherAlpha(PostprocessInput0Sampler, UV, PixelOffset);
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
// This does a 2x2:1 reduction with a 4x4:1 dilation.
|
|
// OutColor is float as we output to a single channel format (NVIDIA Windows driver has undefined result in the other channels if the RT has more than one)
|
|
void CircleDilatePS(noperspective float4 UVAndScreenPos : TEXCOORD0, out float OutColor : SV_Target0)
|
|
{
|
|
// Sampling pattern (each gather4)
|
|
// d g
|
|
// j M (M={0,0} point)
|
|
|
|
#if COMPILER_GLSL || COMPILER_GLSL_ES2 || COMPILER_GLSL_ES3_1 || FEATURE_LEVEL < FEATURE_LEVEL_SM5
|
|
float2 UV = UVAndScreenPos.xy + 0.5*PostprocessInput0Size.zw;
|
|
// This leverages nearest sampling (bilinear won't work).
|
|
// Probably not the best way to do this.
|
|
float4 Sd, Sg, Sj, Sm;
|
|
Sd.x = ReadCoc(UV, int2(-2,-2));
|
|
Sd.y = ReadCoc(UV, int2(-1,-2));
|
|
Sd.z = ReadCoc(UV, int2(-2,-1));
|
|
Sd.w = ReadCoc(UV, int2(-1,-1));
|
|
Sg.x = ReadCoc(UV, int2(0,-2));
|
|
Sg.y = ReadCoc(UV, int2(1,-2));
|
|
Sg.z = ReadCoc(UV, int2(0,-1));
|
|
Sg.w = ReadCoc(UV, int2(1,-1));
|
|
Sj.x = ReadCoc(UV, int2(-2,0));
|
|
Sj.y = ReadCoc(UV, int2(-1,0));
|
|
Sj.z = ReadCoc(UV, int2(-2,1));
|
|
Sj.w = ReadCoc(UV, int2(-1,1));
|
|
Sm.x = ReadCoc(UV, int2(0,0));
|
|
Sm.y = ReadCoc(UV, int2(1,0));
|
|
Sm.z = ReadCoc(UV, int2(0,1));
|
|
Sm.w = ReadCoc(UV, int2(1,1));
|
|
#else
|
|
#if DILATION_RESOLUTION_INDEPENDENT
|
|
float factor = View.ViewSizeAndInvSize.x / 1980.0f;
|
|
|
|
float2 A = 1 + float2(-2,-2);
|
|
float2 B = 1 + float2(0,-2);
|
|
float2 C = 1 + float2(-2,0);
|
|
float2 D = 1 + float2(0,0);
|
|
|
|
float4 Sd = GatherCoc(UVAndScreenPos.xy + A * factor * PostprocessInput0Size.zw);
|
|
float4 Sg = GatherCoc(UVAndScreenPos.xy + B * factor * PostprocessInput0Size.zw);
|
|
float4 Sj = GatherCoc(UVAndScreenPos.xy + C * factor * PostprocessInput0Size.zw);
|
|
float4 Sm = GatherCoc(UVAndScreenPos.xy + D * factor * PostprocessInput0Size.zw);
|
|
#else
|
|
float2 UV = UVAndScreenPos.xy + PostprocessInput0Size.zw;
|
|
float4 Sd = GatherCoc(UV, int2(-2,-2));
|
|
float4 Sg = GatherCoc(UV, int2(0,-2));
|
|
float4 Sj = GatherCoc(UV, int2(-2,0));
|
|
float4 Sm = GatherCoc(UV, int2(0,0));
|
|
#endif
|
|
#endif
|
|
|
|
// Make sure near is only near blur.
|
|
OutColor = min(0.0, Min16(Sd, Sg, Sj, Sm));
|
|
}
|
|
|
|
float4 TestFunc(float2 p)
|
|
{
|
|
return saturate(15 - length((p- 0.5f) * PostprocessInput0Size.xy));
|
|
}
|
|
|
|
void Circle4Samples(
|
|
noperspective float4 UVAndScreenPos
|
|
, float InRand
|
|
, out SceneColorLayout OutSceneColor
|
|
, out float OutColorCoc
|
|
)
|
|
{
|
|
float2 UV = UVAndScreenPos.xy;
|
|
|
|
//
|
|
// Pass 0
|
|
// Dilate near minimum CoC (near CoC is negative values).
|
|
//
|
|
|
|
// Fixed maximum search size (in terms of Circle of Confusion radius).
|
|
// Higher than 8 is too noizy for 4 samples. (actual radius is scaled by width/1920)
|
|
float Coc = 8.0 * View.CircleDOFParams.w;
|
|
|
|
float LocalRand = RandomOffset.x + InRand;
|
|
|
|
// Get base semi-random direction and dither along radius.
|
|
// Reused throughout the rest of the algorithm.
|
|
float TwoPi = 2.0 * 3.14159;
|
|
float RadianBase = NoizSnorm(UVAndScreenPos.xy, 0.010 * LocalRand) * TwoPi;
|
|
float RadiusBase = NoizNorm(UVAndScreenPos.xy, 0.013 * LocalRand);
|
|
|
|
#if DEBUG_SAMPLE_PATTERN
|
|
Coc = 100 * View.CircleDOFParams.w;
|
|
#endif
|
|
|
|
// Radius
|
|
float RadiusBase2 = RadiusBase * (1.0/4.0);
|
|
float R1 = sqrt(RadiusBase2 + 3.0/4.0) * Coc;
|
|
float R2 = sqrt(RadiusBase2 + 2.0/4.0) * Coc;
|
|
float R3 = sqrt(RadiusBase2 + 1.0/4.0) * Coc;
|
|
float R4 = sqrt(RadiusBase2 + 0.6/4.0) * Coc; // 0 gives a disk shape, 0.6 avoids some artifacts but results in a dark center
|
|
|
|
float2 UV1 = RotVec(R1, RadianBase + TwoPi * 0.0/4.0);
|
|
float2 UV2 = RotVec(R2, RadianBase + TwoPi * 2.0/4.0);
|
|
float2 UV3 = RotVec(R3, RadianBase + TwoPi * 1.0/4.0);
|
|
float2 UV4 = RotVec(R4, RadianBase + TwoPi * 3.0/4.0);
|
|
|
|
UV1 = UVAndScreenPos.xy + UV1 * PostprocessInput0Size.zw;
|
|
UV2 = UVAndScreenPos.xy + UV2 * PostprocessInput0Size.zw;
|
|
UV3 = UVAndScreenPos.xy + UV3 * PostprocessInput0Size.zw;
|
|
UV4 = UVAndScreenPos.xy + UV4 * PostprocessInput0Size.zw;
|
|
|
|
#if DEBUG_SAMPLE_PATTERN // TDOO
|
|
OutColor0 = TestFunc(UV1)*float4(1,0,0,0) +
|
|
TestFunc(UV2)*float4(0,1,0,0) +
|
|
TestFunc(UV3)*float4(0,0,1,0) +
|
|
TestFunc(UV4)*float4(1,1,1,0)/3.0f;
|
|
OutColor0.rgb=dot(1/3.0f, OutColor0.rgb);
|
|
OutColor0.a=1;
|
|
return;
|
|
#endif
|
|
|
|
float D1 = PostprocessInput1.SampleLevel(PostprocessInput1Sampler, UV1, 0).x;
|
|
float D2 = PostprocessInput1.SampleLevel(PostprocessInput1Sampler, UV2, 0).x;
|
|
float D3 = PostprocessInput1.SampleLevel(PostprocessInput1Sampler, UV3, 0).x;
|
|
float D4 = PostprocessInput1.SampleLevel(PostprocessInput1Sampler, UV4, 0).x;
|
|
|
|
float NearCoc = 65536.0;
|
|
// >0 causes DepthBlur to disappear in low resolutions, unclear why it was 2
|
|
float Feather = 0.0f;
|
|
if(abs(D1)+Feather > R1) NearCoc = min(NearCoc, D1);
|
|
if(abs(D2)+Feather > R2) NearCoc = min(NearCoc, D2);
|
|
if(abs(D3)+Feather > R3) NearCoc = min(NearCoc, D3);
|
|
if(abs(D4)+Feather > R4) NearCoc = min(NearCoc, D4);
|
|
|
|
|
|
//
|
|
// Pass 1
|
|
//
|
|
|
|
// Going to grab sets of 4 samples per pass.
|
|
// Each set of 4 samples can be a smaller circle of confusion
|
|
// (aka can be in-front of the larger background).
|
|
|
|
// Setup for 12 samples (3 passes of 4 samples).
|
|
RadiusBase *= (1.0/11.5);
|
|
|
|
// Grab circle of confusion for the pixel and pixel color.
|
|
|
|
#if POST_PROCESS_ALPHA
|
|
OutSceneColor = Texture2DSampleLevel(PostprocessInput0, PostprocessInput0Sampler, UV, 0);
|
|
float FarCoc = Texture2DSampleLevel(PostprocessInput2, PostprocessInput2Sampler, UV, 0).r;
|
|
#else
|
|
float4 OutSceneColorR = Texture2DSampleLevel(PostprocessInput0, PostprocessInput0Sampler, UV, 0);
|
|
OutSceneColor = OutSceneColorR.rgb;
|
|
float FarCoc = OutSceneColorR.a;
|
|
#endif
|
|
|
|
// Fix in case no near exists.
|
|
NearCoc = min(NearCoc, FarCoc);
|
|
|
|
// Used for sample pattern.
|
|
Coc = max(abs(FarCoc),abs(NearCoc));
|
|
|
|
// Bring out to the smaller radius of sample sets.
|
|
// This has the highest chance of seeing a smaller overlapping CoC.
|
|
R1 = (RadiusBase+9.0/11.5) * Coc;
|
|
R2 = (RadiusBase+3.0/11.5) * Coc;
|
|
R3 = (RadiusBase+6.0/11.5) * Coc;
|
|
R4 = (RadiusBase+0.0/11.5) * Coc;
|
|
|
|
// Ensure at least getting different sample than center pixel.
|
|
float R1a = max(1.0,R1);
|
|
float R2a = max(1.0,R2);
|
|
float R3a = max(1.0,R3);
|
|
float R4a = max(1.0,R4);
|
|
|
|
UV1 = RotVec(R1a, RadianBase + TwoPi * 0.0/12.0);
|
|
UV2 = RotVec(R2a, RadianBase + TwoPi * 3.0/12.0);
|
|
UV3 = RotVec(R3a, RadianBase + TwoPi * 6.0/12.0);
|
|
UV4 = RotVec(R4a, RadianBase + TwoPi * 9.0/12.0);
|
|
|
|
UV1 = UVAndScreenPos.xy + UV1 * PostprocessInput0Size.zw;
|
|
UV2 = UVAndScreenPos.xy + UV2 * PostprocessInput0Size.zw;
|
|
UV3 = UVAndScreenPos.xy + UV3 * PostprocessInput0Size.zw;
|
|
UV4 = UVAndScreenPos.xy + UV4 * PostprocessInput0Size.zw;
|
|
|
|
float4 C1R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV1, 0);
|
|
float4 C2R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV2, 0);
|
|
float4 C3R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV3, 0);
|
|
float4 C4R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV4, 0);
|
|
|
|
SceneColorLayout C1 = CastFloat4ToSceneColorLayout(C1R);
|
|
SceneColorLayout C2 = CastFloat4ToSceneColorLayout(C2R);
|
|
SceneColorLayout C3 = CastFloat4ToSceneColorLayout(C3R);
|
|
SceneColorLayout C4 = CastFloat4ToSceneColorLayout(C4R);
|
|
|
|
#if POST_PROCESS_ALPHA
|
|
float C1Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV1, 0).x;
|
|
float C2Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV2, 0).x;
|
|
float C3Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV3, 0).x;
|
|
float C4Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV4, 0).x;
|
|
#else
|
|
float C1Coc = C1R.a;
|
|
float C2Coc = C2R.a;
|
|
float C3Coc = C3R.a;
|
|
float C4Coc = C4R.a;
|
|
#endif
|
|
|
|
// Base weight works around the max(1.0,radius) constraint.
|
|
// Base weight also shapes to weight higher on the outside radius.
|
|
float W0 = 1.0 - saturate(Coc);
|
|
float W1 = R1;
|
|
float W2 = R2;
|
|
float W3 = R3;
|
|
float W4 = R4;
|
|
|
|
// Intersection weight: 0=sample does not intersect pixel, to 1=sample intersects.
|
|
// TODO: Tune feather factors.
|
|
float IFeather0 = 1.0/4.0;
|
|
float I1 = saturate((abs(C1Coc) - R1) * IFeather0);
|
|
float I2 = saturate((abs(C2Coc) - R2) * IFeather0);
|
|
float I3 = saturate((abs(C3Coc) - R3) * IFeather0);
|
|
float I4 = saturate((abs(C4Coc) - R4) * IFeather0);
|
|
|
|
// Check if have a more near intersecting Coc for next pass.
|
|
float FarCoc2 = FarCoc;
|
|
if(I1*W1 > 0.0) FarCoc2 = min(FarCoc2, C1Coc);
|
|
if(I2*W2 > 0.0) FarCoc2 = min(FarCoc2, C2Coc);
|
|
if(I3*W3 > 0.0) FarCoc2 = min(FarCoc2, C3Coc);
|
|
if(I4*W4 > 0.0) FarCoc2 = min(FarCoc2, C4Coc);
|
|
|
|
// Fully ignore intersection weight when in nearfield blur
|
|
// and sample average CoC is 50% between near and far CoC neighborhood.
|
|
float AvgCoc = (FarCoc + C1Coc + C2Coc + C3Coc + C4Coc) * (1.0/5.0);
|
|
// Get dilated far.
|
|
FarCoc = max(FarCoc, max(max(C1Coc, C2Coc),max(C3Coc, C4Coc)));
|
|
// Controls the transition between states.
|
|
float IFeather1 = 1.0;
|
|
float IFeather2 = 2.0;
|
|
float Ignore = saturate(-NearCoc * IFeather1) * saturate(((AvgCoc - FarCoc) / (NearCoc - FarCoc)) * IFeather2);
|
|
|
|
W1 *= lerp(I1, 1.0, Ignore);
|
|
W2 *= lerp(I2, 1.0, Ignore);
|
|
W3 *= lerp(I3, 1.0, Ignore);
|
|
W4 *= lerp(I4, 1.0, Ignore);
|
|
|
|
// Make sure at least something is not zero.
|
|
W0 += 1.0/65536.0;
|
|
|
|
// Start weighted accumulation.
|
|
OutSceneColor = OutSceneColor * W0 + C1 * W1 + C2 * W2 + C3 * W3 + C4 * W4;
|
|
float Weight = W0+W1+W2+W3+W4;
|
|
|
|
|
|
// Set current result as possible background.
|
|
SceneColorLayout Background = OutSceneColor * (1.0/Weight);
|
|
|
|
// former method
|
|
// #define FadeOutOutsideCoC(INDEX, COC) C##INDEX.rgb = lerp(C##INDEX.rgb, Background.rgb, saturate(abs(C##INDEX.a) - COC));
|
|
// new method avoids having the center leaking with large CoC
|
|
#define FadeOutOutsideCoC(INDEX, COC) W##INDEX = lerp(W##INDEX, 0, saturate(abs(C##INDEX##Coc) - COC));
|
|
|
|
// Uncomment to see intermediate debug output
|
|
// OutSceneColor *= (1.0/Weight);return;
|
|
|
|
//
|
|
// Pass 2
|
|
//
|
|
|
|
// Drop weight of existing pass if Coc changes too much.
|
|
float Coc2 = max(abs(FarCoc2),abs(NearCoc));
|
|
float Drop = (1.0/65536.0) + 1.0 - saturate(abs(Coc - Coc2));
|
|
OutSceneColor *= Drop;
|
|
Weight *= Drop;
|
|
|
|
R1 = (RadiusBase+10.0/11.5) * Coc2;
|
|
R2 = (RadiusBase+ 4.0/11.5) * Coc2;
|
|
R3 = (RadiusBase+ 7.0/11.5) * Coc2;
|
|
R4 = (RadiusBase+ 1.0/11.5) * Coc2;
|
|
|
|
R1a = max(1.0,R1);
|
|
R2a = max(1.0,R2);
|
|
R3a = max(1.0,R3);
|
|
R4a = max(1.0,R4);
|
|
|
|
UV1 = RotVec(R1a, RadianBase + TwoPi * 8.0/12.0);
|
|
UV2 = RotVec(R2a, RadianBase + TwoPi * 11.0/12.0);
|
|
UV3 = RotVec(R3a, RadianBase + TwoPi * 2.0/12.0);
|
|
UV4 = RotVec(R4a, RadianBase + TwoPi * 5.0/12.0);
|
|
|
|
UV1 = UVAndScreenPos.xy + UV1 * PostprocessInput0Size.zw;
|
|
UV2 = UVAndScreenPos.xy + UV2 * PostprocessInput0Size.zw;
|
|
UV3 = UVAndScreenPos.xy + UV3 * PostprocessInput0Size.zw;
|
|
UV4 = UVAndScreenPos.xy + UV4 * PostprocessInput0Size.zw;
|
|
|
|
C1R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV1, 0);
|
|
C2R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV2, 0);
|
|
C3R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV3, 0);
|
|
C4R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV4, 0);
|
|
|
|
C1 = CastFloat4ToSceneColorLayout(C1R);
|
|
C2 = CastFloat4ToSceneColorLayout(C2R);
|
|
C3 = CastFloat4ToSceneColorLayout(C3R);
|
|
C4 = CastFloat4ToSceneColorLayout(C4R);
|
|
|
|
#if POST_PROCESS_ALPHA
|
|
C1Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV1, 0).x;
|
|
C2Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV2, 0).x;
|
|
C3Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV3, 0).x;
|
|
C4Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV4, 0).x;
|
|
#else
|
|
C1Coc = C1R.a;
|
|
C2Coc = C2R.a;
|
|
C3Coc = C3R.a;
|
|
C4Coc = C4R.a;
|
|
#endif
|
|
|
|
// Lerp to background if outside possibly smaller CoC.
|
|
FadeOutOutsideCoC(1, Coc2)
|
|
FadeOutOutsideCoC(2, Coc2)
|
|
FadeOutOutsideCoC(3, Coc2)
|
|
FadeOutOutsideCoC(4, Coc2)
|
|
|
|
W1 = R1;
|
|
W2 = R2;
|
|
W3 = R3;
|
|
W4 = R4;
|
|
|
|
// Intersection weight: 0=sample does not intersect pixel, to 1=sample intersects.
|
|
I1 = saturate((abs(C1Coc) - R1) * IFeather0);
|
|
I2 = saturate((abs(C2Coc) - R2) * IFeather0);
|
|
I3 = saturate((abs(C3Coc) - R3) * IFeather0);
|
|
I4 = saturate((abs(C4Coc) - R4) * IFeather0);
|
|
|
|
// Check if have a more near intersecting Coc for next pass.
|
|
float FarCoc3 = FarCoc2;
|
|
if(I1*W1 > 0.0) FarCoc3 = min(FarCoc3, C1Coc);
|
|
if(I2*W2 > 0.0) FarCoc3 = min(FarCoc3, C2Coc);
|
|
if(I3*W3 > 0.0) FarCoc3 = min(FarCoc3, C3Coc);
|
|
if(I4*W4 > 0.0) FarCoc3 = min(FarCoc3, C4Coc);
|
|
|
|
W1 *= lerp(I1, 1.0, Ignore);
|
|
W2 *= lerp(I2, 1.0, Ignore);
|
|
W3 *= lerp(I3, 1.0, Ignore);
|
|
W4 *= lerp(I4, 1.0, Ignore);
|
|
|
|
OutSceneColor += C1 * W1 + C2 * W2 + C3 * W3 + C4 * W4;
|
|
Weight += W1+W2+W3+W4;
|
|
|
|
// Uncomment to see intermediate debug output
|
|
// OutSceneColor *= (1.0/Weight);return;
|
|
|
|
//
|
|
// Pass 3
|
|
//
|
|
|
|
// Drop weight of existing pass if Coc changes too much.
|
|
float Coc3 = max(abs(FarCoc3),abs(NearCoc));
|
|
Drop = (1.0/65536.0) + 1.0 - saturate(abs(Coc2 - Coc3));
|
|
OutSceneColor *= Drop;
|
|
Weight *= Drop;
|
|
|
|
// Send near most CoC back to recombine pass.
|
|
OutColorCoc = min(FarCoc3, NearCoc);
|
|
|
|
R1 = (RadiusBase+11.0/11.5) * Coc3;
|
|
R2 = (RadiusBase+ 5.0/11.5) * Coc3;
|
|
R3 = (RadiusBase+ 8.0/11.5) * Coc3;
|
|
R4 = (RadiusBase+ 2.0/11.5) * Coc3;
|
|
|
|
R1a = max(1.0,R1);
|
|
R2a = max(1.0,R2);
|
|
R3a = max(1.0,R3);
|
|
R4a = max(1.0,R4);
|
|
|
|
UV1 = RotVec(R1a, RadianBase + TwoPi * 4.0/12.0);
|
|
UV2 = RotVec(R2a, RadianBase + TwoPi * 7.0/12.0);
|
|
UV3 = RotVec(R3a, RadianBase + TwoPi * 10.0/12.0);
|
|
UV4 = RotVec(R4a, RadianBase + TwoPi * 1.0/12.0);
|
|
|
|
UV1 = UVAndScreenPos.xy + UV1 * PostprocessInput0Size.zw;
|
|
UV2 = UVAndScreenPos.xy + UV2 * PostprocessInput0Size.zw;
|
|
UV3 = UVAndScreenPos.xy + UV3 * PostprocessInput0Size.zw;
|
|
UV4 = UVAndScreenPos.xy + UV4 * PostprocessInput0Size.zw;
|
|
|
|
C1R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV1, 0);
|
|
C2R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV2, 0);
|
|
C3R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV3, 0);
|
|
C4R = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV4, 0);
|
|
|
|
C1 = CastFloat4ToSceneColorLayout(C1R);
|
|
C2 = CastFloat4ToSceneColorLayout(C2R);
|
|
C3 = CastFloat4ToSceneColorLayout(C3R);
|
|
C4 = CastFloat4ToSceneColorLayout(C4R);
|
|
|
|
#if POST_PROCESS_ALPHA
|
|
C1Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV1, 0).x;
|
|
C2Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV2, 0).x;
|
|
C3Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV3, 0).x;
|
|
C4Coc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UV4, 0).x;
|
|
#else
|
|
C1Coc = C1R.a;
|
|
C2Coc = C2R.a;
|
|
C3Coc = C3R.a;
|
|
C4Coc = C4R.a;
|
|
#endif
|
|
|
|
FadeOutOutsideCoC(1, Coc3)
|
|
FadeOutOutsideCoC(2, Coc3)
|
|
FadeOutOutsideCoC(3, Coc3)
|
|
FadeOutOutsideCoC(4, Coc3)
|
|
|
|
W1 = R1;
|
|
W2 = R2;
|
|
W3 = R3;
|
|
W4 = R4;
|
|
|
|
I1 = saturate((abs(C1Coc) - R1) * IFeather0);
|
|
I2 = saturate((abs(C2Coc) - R2) * IFeather0);
|
|
I3 = saturate((abs(C3Coc) - R3) * IFeather0);
|
|
I4 = saturate((abs(C4Coc) - R4) * IFeather0);
|
|
|
|
W1 *= lerp(I1, 1.0, Ignore);
|
|
W2 *= lerp(I2, 1.0, Ignore);
|
|
W3 *= lerp(I3, 1.0, Ignore);
|
|
W4 *= lerp(I4, 1.0, Ignore);
|
|
|
|
OutSceneColor += C1 * W1 + C2 * W2 + C3 * W3 + C4 * W4;
|
|
Weight += W1+W2+W3+W4;
|
|
|
|
OutSceneColor *= (1.0/Weight);
|
|
}
|
|
|
|
// pixel shader entry point
|
|
void CirclePS(
|
|
noperspective float4 UVAndScreenPos : TEXCOORD0
|
|
, out float4 OutColor0 : SV_Target0
|
|
#if POST_PROCESS_ALPHA
|
|
, out float OutColor1 : SV_Target1
|
|
#endif
|
|
)
|
|
{
|
|
// Count 2 or higher, gets slower but less noisy
|
|
#if ( QUALITY == 2 )
|
|
const uint Count = 32;
|
|
#elif ( QUALITY == 1 )
|
|
const uint Count = 12;
|
|
#else
|
|
const uint Count = 1;
|
|
#endif
|
|
|
|
OutColor0 = 0;
|
|
#if POST_PROCESS_ALPHA
|
|
OutColor1 = 0;
|
|
#endif
|
|
LOOP for(uint i = 0; i < Count; ++i)
|
|
{
|
|
SceneColorLayout Color;
|
|
float ColorCoc;
|
|
Circle4Samples(UVAndScreenPos, i, Color, ColorCoc);
|
|
|
|
#if POST_PROCESS_ALPHA
|
|
OutColor0 += Color;
|
|
OutColor1 += ColorCoc;
|
|
#else
|
|
OutColor0 += float4(Color, ColorCoc);
|
|
#endif
|
|
}
|
|
|
|
OutColor0 /= Count;
|
|
#if POST_PROCESS_ALPHA
|
|
OutColor1 /= Count;
|
|
#endif
|
|
}
|
|
|
|
// actual color is RGB/A
|
|
void Recombine2Samples(float4 UVAndScreenPos, float PixCoc, float InRand, out SceneColorLayout OutSampleColor, out float OutSampleWeight)
|
|
{
|
|
float LocalRand = RandomOffset.x + InRand;
|
|
|
|
#if 1
|
|
// Fetch 2 samples mirrored around the pixel
|
|
// which is stochastically distributed to fill out the circle of confusion.
|
|
// TODO: Fix the "random values".
|
|
float2 UV = UVAndScreenPos.xy * PostprocessInput0Size.xy;
|
|
|
|
float RadianBase = NoizNorm(UVAndScreenPos.xy, 0.010 * LocalRand) * PI; // 0..PI as we use sample pairs and don't need 0..2*PI
|
|
float RadiusJitter = NoizNorm(UVAndScreenPos.xy, 0.013 * LocalRand);
|
|
|
|
float ICoc = PixCoc*sqrt(RadiusJitter);
|
|
float2 VP = RotVec(ICoc, RadianBase) * PostprocessInput0Size.zw;
|
|
|
|
// These two samples will still have jitter induced artifacts (very limited utility).
|
|
// These two samples will also have bleeding artifacts.
|
|
SceneColorLayout CA = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UVAndScreenPos.xy + VP, 0));
|
|
SceneColorLayout CB = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UVAndScreenPos.xy - VP, 0));
|
|
|
|
// clamp to avoid artifacts from exceeding fp16 through framebuffer blending of multiple very bright lights
|
|
CA.rgb = min(float3(256 * 256, 256 * 256, 256 * 256), CA.rgb);
|
|
CB.rgb = min(float3(256 * 256, 256 * 256, 256 * 256), CB.rgb);
|
|
|
|
float I1 = 1.0/65536.0;
|
|
float I2 = 1.0/65536.0;
|
|
|
|
#if QUALITY
|
|
// we don't have depth in the alpha channel
|
|
float CACoc = DepthToCoc2(CalcSceneDepth(UVAndScreenPos.xy + VP));
|
|
float CBCoc = DepthToCoc2(CalcSceneDepth(UVAndScreenPos.xy - VP));
|
|
|
|
// Weight the two samples to avoid forground into background bleed.
|
|
float IFeather0 = 1.0/4.0;
|
|
ICoc *= 0.5; // Coc is half res units.
|
|
|
|
// todo: verify the value, was 0.0f at some point
|
|
float Tweak = 1.0f;
|
|
|
|
I1 += saturate((abs(CACoc) - ICoc) * IFeather0 + Tweak);
|
|
I2 += saturate((abs(CBCoc) - ICoc) * IFeather0 + Tweak);
|
|
#endif
|
|
|
|
OutSampleWeight = I1 + I2;
|
|
OutSampleColor = CA * I1 + CB * I2;
|
|
#else // do we need to maitain this dead code?
|
|
// Possibly higher quality option in the future.
|
|
|
|
// Fetch 4 samples in filled disc pattern
|
|
// which is stochastically distributed to fill out the circle of confusion.
|
|
float2 UV = UVAndScreenPos.xy * PostprocessInput0Size.xy;
|
|
float RadianBase = NoizNorm(UVAndScreenPos.xy, 0.010 * LocalRand) * 3.14159 * 2.0;
|
|
float RadiusBase = NoizNorm(UVAndScreenPos.xy, 0.013 * LocalRand);
|
|
|
|
float RadiusBase2 = RadiusBase * (1.0/4.0);
|
|
float R1 = sqrt(RadiusBase2 + 3.0/4.0) * PixCoc;
|
|
float R2 = sqrt(RadiusBase2 + 2.0/4.0) * PixCoc;
|
|
float R3 = sqrt(RadiusBase2 + 1.0/4.0) * PixCoc;
|
|
float R4 = sqrt(RadiusBase2 + 0.0/4.0) * PixCoc;
|
|
|
|
float TwoPi = 3.14159 * 2.0;
|
|
float2 UV1 = RotVec(R1, RadianBase + TwoPi * 0.0/4.0);
|
|
float2 UV2 = RotVec(R2, RadianBase + TwoPi * 2.0/4.0);
|
|
float2 UV3 = RotVec(R3, RadianBase + TwoPi * 1.0/4.0);
|
|
float2 UV4 = RotVec(R4, RadianBase + TwoPi * 3.0/4.0);
|
|
|
|
UV1 = UVAndScreenPos.xy + UV1 * PostprocessInput0Size.zw;
|
|
UV2 = UVAndScreenPos.xy + UV2 * PostprocessInput0Size.zw;
|
|
UV3 = UVAndScreenPos.xy + UV3 * PostprocessInput0Size.zw;
|
|
UV4 = UVAndScreenPos.xy + UV4 * PostprocessInput0Size.zw;
|
|
|
|
float4 CA = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV1, 0);
|
|
float4 CB = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV2, 0);
|
|
float4 CC = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV3, 0);
|
|
float4 CD = PostprocessInput0.SampleLevel(PostprocessInput0Sampler, UV4, 0);
|
|
|
|
// Weight the two samples to avoid forground into background bleed.
|
|
float IFeather0 = 1.0/4.0;
|
|
float ICoc = PixCoc * 0.5; // Coc is half res units.
|
|
float I1 = saturate((abs(CA.a) - ICoc) * IFeather0);
|
|
float I2 = saturate((abs(CB.a) - ICoc) * IFeather0);
|
|
float I3 = saturate((abs(CC.a) - ICoc) * IFeather0);
|
|
float I4 = saturate((abs(CD.a) - ICoc) * IFeather0);
|
|
|
|
// Make sure something is non-zero.
|
|
I1 += 1.0/65536.0;
|
|
I2 += 1.0/65536.0;
|
|
I3 += 1.0/65536.0;
|
|
I4 += 1.0/65536.0;
|
|
|
|
return float4(CA.rgb * I1 + CB.rgb * I2 + CC.rgb * I3 + CD.rgb * I4, I1+I2+I3+I4);
|
|
#endif
|
|
}
|
|
|
|
SceneColorLayout RecombineNSamples(float4 UVAndScreenPos, float PixCoc)
|
|
{
|
|
// Count 2 or higher, gets slower but less noisy
|
|
#if ( QUALITY == 2 )
|
|
const uint Count = 32;
|
|
#elif ( QUALITY == 1 )
|
|
const uint Count = 12;
|
|
#else
|
|
const uint Count = 1;
|
|
#endif
|
|
|
|
SceneColorLayout SceneColorSum = 0;
|
|
float SampleWeightSum = 0;
|
|
LOOP for(uint i = 0; i < Count; ++i)
|
|
{
|
|
SceneColorLayout SampleSceneColor;
|
|
float SampleWeight;
|
|
Recombine2Samples(UVAndScreenPos, PixCoc, i, SampleSceneColor, SampleWeight);
|
|
|
|
SceneColorSum += SampleSceneColor;
|
|
SampleWeightSum += SampleWeight;
|
|
}
|
|
|
|
return SceneColorSum / SampleWeightSum;
|
|
}
|
|
|
|
// pixel shader to combine the full res scene and the blurred images behind and in front of the the focal plane
|
|
void MainCircleRecombinePS(in noperspective float4 UVAndScreenPos : TEXCOORD0, out float4 OutColor : SV_Target0)
|
|
{
|
|
// Circle of confusion size for the pixel.
|
|
float PixDepth = CalcSceneDepth(UVAndScreenPos.xy);
|
|
float PixCoc = DepthToCoc2(PixDepth);
|
|
|
|
#if POST_PROCESS_ALPHA
|
|
float HalfResCoc = PostprocessInput2.SampleLevel(PostprocessInput2Sampler, UVAndScreenPos.xy, 0).r;
|
|
#else
|
|
float HalfResCoc = PostprocessInput1.SampleLevel(PostprocessInput1Sampler, UVAndScreenPos.xy, 0).a;
|
|
#endif
|
|
|
|
// Grab nearest Coc.
|
|
PixCoc = min(PixCoc, HalfResCoc);
|
|
|
|
// Transform into sample pattern.
|
|
PixCoc = abs(PixCoc) * 2.0; // 2x because full instead of half resolution.
|
|
|
|
SceneColorLayout RecombinedSceneColor = RecombineNSamples(UVAndScreenPos, PixCoc);
|
|
|
|
// Grab the half resolution neighborhood to remove the artifacts from the full resolution output.
|
|
// Nearest location.
|
|
#if 1
|
|
// This has higher in-focus contrast, but possibly lower noise reduction later.
|
|
float2 HUVBase = UVAndScreenPos.xy * PostprocessInput1Size.xy - 0.5;
|
|
float2 HUVFrac = frac(HUVBase);
|
|
float2 HUV = (trunc(HUVBase) + 0.5) * PostprocessInput1Size.zw;
|
|
#else
|
|
// This makes the mostly in-focus transition bad (too blurry).
|
|
float2 HUV = UVAndScreenPos.xy - 0.5 * PostprocessInput1Size.zw;
|
|
#endif
|
|
|
|
// Load four nearest samples.
|
|
SceneColorLayout H0 = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput1.SampleLevel(PostprocessInput1Sampler, HUV, 0));
|
|
SceneColorLayout H1 = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput1.SampleLevel(PostprocessInput1Sampler, HUV, 0, int2(1,0)));
|
|
SceneColorLayout H2 = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput1.SampleLevel(PostprocessInput1Sampler, HUV, 0, int2(0,1)));
|
|
SceneColorLayout H3 = CastFloat4ToSceneColorLayout(
|
|
PostprocessInput1.SampleLevel(PostprocessInput1Sampler, HUV, 0, int2(1,1)));
|
|
|
|
// to YCoCg (doesn't make much of a difference)
|
|
// H0.rgb = RGBToYCoCg(H0.rgb);
|
|
// H1.rgb = RGBToYCoCg(H1.rgb);
|
|
// H2.rgb = RGBToYCoCg(H2.rgb);
|
|
// H3.rgb = RGBToYCoCg(H3.rgb);
|
|
// OutColor.rgb = RGBToYCoCg(OutColor.rgb);
|
|
|
|
// TODO: This would work a lot better in YUV style colorspace?
|
|
// Limit the full resolution to remove jitter artifacts.
|
|
SceneColorLayout HMax = max(max(H0,H1),max(H2,H3));
|
|
SceneColorLayout HMin = min(min(H0,H1),min(H2,H3));
|
|
|
|
#if 1
|
|
// Increase constrast of limit a little to workaround to strong denoise at near-in-focus.
|
|
SceneColorLayout HD = HMin / 8.0;
|
|
float Small = 1.0 - saturate(PixCoc*PixCoc*(1.0/64.0));
|
|
HMax += HD * Small;
|
|
HMin -= HD * Small;
|
|
#endif
|
|
|
|
// debug unclamped color
|
|
// return;
|
|
|
|
// Blend in the limited version quickly to remove HDR jitter artifacts and noise.
|
|
SceneColorLayout OutLimited = min(max(RecombinedSceneColor,HMin),HMax);
|
|
SceneColorLayout FinalOutColor = lerp(RecombinedSceneColor, OutLimited, saturate(PixCoc*PixCoc*4.0));
|
|
|
|
#if POST_PROCESS_ALPHA
|
|
OutColor = FinalOutColor;
|
|
#else
|
|
OutColor = float4(FinalOutColor, 1);
|
|
#endif
|
|
|
|
// back to RGB
|
|
// OutColor.rgb = YCoCgToRGB(OutColor.rgb);
|
|
} |