├── .ignore ├── .github ├── .codespellignore ├── issue_template.md └── workflows │ ├── build-emscripten.yml │ ├── build-apple.yml │ ├── build-linux.yml │ └── msvc_analysis.yml ├── PBR ├── screenshots │ ├── mr_spheres.jpg │ ├── damaged_helmet.jpg │ ├── flight_helmet.jpg │ └── gltf_viewer_mr_spheres.jpg └── CMakeLists.txt ├── PostProcess ├── Bloom │ ├── media │ │ └── bloom.jpg │ └── CMakeLists.txt ├── DepthOfField │ ├── media │ │ └── depth_of_field.jpg │ └── CMakeLists.txt ├── ScreenSpaceReflection │ ├── media │ │ ├── ssr-logo.jpg │ │ ├── ssr-result.jpg │ │ ├── ssr-stencil-0.jpg │ │ ├── ssr-stencil-1.jpg │ │ ├── ssr-variance.jpg │ │ ├── ssr-blue-noise.jpg │ │ ├── ssr-confidence.jpg │ │ ├── ssr-intersection.jpg │ │ ├── ssr-unoccluded.jpg │ │ ├── ssr-visibility.jpg │ │ ├── ssr-bilateral-filter.jpg │ │ ├── ssr-hierachical-depth.jpg │ │ ├── ssr-hierarchical-traversal.gif │ │ ├── ssr-spatial-reconstruction.jpg │ │ └── ssr-temporal-accumulation.jpg │ └── CMakeLists.txt ├── EpipolarLightScattering │ ├── media │ │ ├── EpipolarSampling.png │ │ └── LightScattering.png │ └── CMakeLists.txt ├── ScreenSpaceAmbientOcclusion │ ├── media │ │ └── ssao-kitchen.jpg │ └── CMakeLists.txt ├── CMakeLists.txt ├── TemporalAntiAliasing │ └── CMakeLists.txt ├── SuperResolution │ └── CMakeLists.txt └── Common │ └── CMakeLists.txt ├── Components ├── media │ └── Powerplant-Shadows.jpg ├── CMakeLists.txt └── interface │ └── ToneMapping.hpp ├── Tests ├── CMakeLists.txt └── IncludeTest │ ├── CMakeLists.txt │ ├── PostProcess │ ├── Common │ │ ├── PostFXContextHpp_Test.cpp │ │ └── PostFXRenderTechniqueHpp_Test.cpp │ ├── ScreenSpaceReflection │ │ └── ScreenSpaceReflectionH_test.cpp │ ├── ScreenSpaceAmbientOcclusion │ │ └── ScreenSpaceAmbientOcclussionH_test.cpp │ └── EpipolarLightScattering │ │ └── EpipolarLightScatteringH_test.cpp │ ├── Components │ └── ShadowMapManagerH_test.cpp │ └── GLTF_PBR_Renderer │ └── GLTF_PBR_RendererH_test.cpp ├── Utilities ├── CMakeLists.txt ├── interface │ └── DiligentFXShaderSourceStreamFactory.hpp └── src │ └── DiligentFXShaderSourceStreamFactory.cpp ├── Hydrogent ├── shaders │ ├── HnAxesStructures.fxh │ ├── HnPostProcessStructures.fxh │ ├── HnInitClosestSelectedLocation.psh │ ├── HnClosestSelectedLocation.fxh │ ├── HnCopyFrame.psh │ └── HnUpdateClosestSelectedLocation.psh ├── src │ ├── HnBuffer.cpp │ ├── HnTokens.cpp │ ├── HnDrawItem.cpp │ ├── Computations │ │ └── HnExtComputationImpl.cpp │ ├── HnFrameRenderTargets.cpp │ ├── HnShaderSourceFactory.cpp │ ├── HnRenderParam.cpp │ └── HnExtComputation.cpp ├── include │ ├── HnShaderSourceFactory.hpp │ ├── HnTextureIdentifier.hpp │ ├── HnShadowMapManager.hpp │ ├── Computations │ │ └── HnExtComputationImpl.hpp │ └── HnTextureUtils.hpp └── interface │ ├── HnBuffer.hpp │ ├── Tasks │ ├── HnCopySelectionDepthTask.hpp │ ├── HnBeginMainPassTask.hpp │ ├── HnRenderEnvMapTask.hpp │ └── HnEndOITPassTask.hpp │ ├── HnCamera.hpp │ └── HnExtComputation.hpp ├── BuildTools └── FormatValidation │ ├── validate_format_linux.sh │ ├── validate_format_win.bat │ └── validate_format_mac.sh ├── Shaders ├── Common │ ├── private │ │ ├── FullScreenTriangleVSOutput.fxh │ │ ├── ComputeDepthRangeStructs.fxh │ │ ├── BoundBoxStructures.fxh │ │ ├── EnvMap.vsh │ │ ├── ClearDepthRange.csh │ │ ├── FullScreenTriangleVS.fx │ │ ├── ComputeReprojectedDepth.fx │ │ ├── CoordinateGridPS.psh │ │ ├── VectorField.vsh │ │ ├── BoundBox.psh │ │ ├── ComputeClosestMotion.fx │ │ ├── BoundBox.vsh │ │ └── EnvMap.psh │ └── public │ │ ├── OIT.fxh │ │ ├── ShaderDefinitions.fxh │ │ ├── SRGBUtilities.fxh │ │ └── CoordinateGridStructures.fxh ├── PostProcess │ ├── DepthOfField │ │ ├── private │ │ │ ├── DOF_ComputeSeparatedCircleOfConfusion.fx │ │ │ ├── DOF_Common.fx │ │ │ ├── DOF_ComputeBlurredCircleOfConfusion.fx │ │ │ ├── DOF_ComputeCircleOfConfusion.fx │ │ │ ├── DOF_ComputeCombinedTexture.fx │ │ │ ├── DOF_ComputePrefilteredTexture.fx │ │ │ ├── DOF_ComputePostfilteredTexture.fx │ │ │ ├── DOF_ComputeDilationCircleOfConfusion.fx │ │ │ └── DOF_ComputeTemporalCircleOfConfusion.fx │ │ └── public │ │ │ └── DepthOfFieldStructures.fxh │ ├── EpipolarLightScattering │ │ ├── private │ │ │ ├── precompute │ │ │ │ ├── PrecomputeCommon.fxh │ │ │ │ ├── InitHighOrderScattering.fx │ │ │ │ ├── CombineScatteringOrders.fx │ │ │ │ ├── UpdateHighOrderScattering.fx │ │ │ │ └── PrecomputeAmbientSkyLight.fx │ │ │ ├── ReconstructCameraSpaceZ.fx │ │ │ ├── MarkRayMarchingSamples.fx │ │ │ ├── UpdateAverageLuminance.fx │ │ │ ├── ComputeMinMaxShadowMapLevel.fx │ │ │ ├── InterpolateIrradiance.fx │ │ │ ├── Sun.fx │ │ │ ├── RenderSampling.fx │ │ │ ├── InitializeMinMaxShadowMap.fx │ │ │ └── RenderCoordinateTexture.fx │ │ └── public │ │ │ └── EpipolarLightScatteringFunctions.fxh │ ├── SuperResolution │ │ ├── public │ │ │ └── SuperResolutionStructures.fxh │ │ └── private │ │ │ ├── FSR_ContrastAdaptiveSharpening.fx │ │ │ └── fsr1 │ │ │ ├── ffx_core_portability.h │ │ │ └── ffx_core.h │ ├── ScreenSpaceAmbientOcclusion │ │ └── private │ │ │ ├── SSAO_Common.fxh │ │ │ └── SSAO_ComputeDownsampledDepth.fx │ ├── ScreenSpaceReflection │ │ └── private │ │ │ ├── SSR_ComputeStencilMaskAndExtractRoughness.fx │ │ │ ├── SSR_Common.fxh │ │ │ ├── SSR_ComputeDownsampledStencilMask.fx │ │ │ └── SSR_ComputeHierarchicalDepthBuffer.fx │ ├── Bloom │ │ ├── public │ │ │ └── BloomStructures.fxh │ │ └── private │ │ │ ├── Bloom_ComputeDownsampledTexture.fx │ │ │ ├── Bloom_ComputeUpsampledTexture.fx │ │ │ └── Bloom_ComputePrefilteredTexture.fx │ ├── ToneMapping │ │ └── public │ │ │ └── ToneMappingStructures.fxh │ └── TemporalAntiAliasing │ │ └── public │ │ └── TemporalAntiAliasingStructures.fxh ├── PBR │ ├── private │ │ ├── CubemapFace.vsh │ │ ├── RenderUnshaded.psh │ │ ├── OIT │ │ │ ├── ClearOITLayers.csh │ │ │ └── ApplyOITAttenuation.psh │ │ ├── RenderPBR_Structures.fxh │ │ ├── PBR_PrecomputeCommon.fxh │ │ └── PrecomputeBRDF.psh │ └── public │ │ └── VertexProcessing.fxh └── Shadows │ └── private │ └── ShadowConversions.fx ├── appveyor.yml └── BuildUtils.cmake /.ignore: -------------------------------------------------------------------------------- 1 | ThirdParty/ 2 | -------------------------------------------------------------------------------- /.github/.codespellignore: -------------------------------------------------------------------------------- 1 | inout 2 | lod 3 | complies 4 | thirdparty 5 | -------------------------------------------------------------------------------- /PBR/screenshots/mr_spheres.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PBR/screenshots/mr_spheres.jpg -------------------------------------------------------------------------------- /PBR/screenshots/damaged_helmet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PBR/screenshots/damaged_helmet.jpg -------------------------------------------------------------------------------- /PBR/screenshots/flight_helmet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PBR/screenshots/flight_helmet.jpg -------------------------------------------------------------------------------- /PostProcess/Bloom/media/bloom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/Bloom/media/bloom.jpg -------------------------------------------------------------------------------- /Components/media/Powerplant-Shadows.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/Components/media/Powerplant-Shadows.jpg -------------------------------------------------------------------------------- /PBR/screenshots/gltf_viewer_mr_spheres.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PBR/screenshots/gltf_viewer_mr_spheres.jpg -------------------------------------------------------------------------------- /PostProcess/DepthOfField/media/depth_of_field.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/DepthOfField/media/depth_of_field.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-logo.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-result.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-stencil-0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-stencil-0.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-stencil-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-stencil-1.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-variance.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-variance.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-blue-noise.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-blue-noise.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-confidence.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-confidence.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-intersection.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-intersection.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-unoccluded.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-unoccluded.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-visibility.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-visibility.jpg -------------------------------------------------------------------------------- /PostProcess/EpipolarLightScattering/media/EpipolarSampling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/EpipolarLightScattering/media/EpipolarSampling.png -------------------------------------------------------------------------------- /PostProcess/EpipolarLightScattering/media/LightScattering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/EpipolarLightScattering/media/LightScattering.png -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceAmbientOcclusion/media/ssao-kitchen.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceAmbientOcclusion/media/ssao-kitchen.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-bilateral-filter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-bilateral-filter.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-hierachical-depth.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-hierachical-depth.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-hierarchical-traversal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-hierarchical-traversal.gif -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-spatial-reconstruction.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-spatial-reconstruction.jpg -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/media/ssr-temporal-accumulation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DiligentGraphics/DiligentFX/HEAD/PostProcess/ScreenSpaceReflection/media/ssr-temporal-accumulation.jpg -------------------------------------------------------------------------------- /Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | if(TARGET gtest) 4 | if(DILIGENT_BUILD_FX_TESTS) 5 | 6 | endif() 7 | endif() 8 | 9 | if(DILIGENT_BUILD_FX_INCLUDE_TEST) 10 | add_subdirectory(IncludeTest) 11 | endif() 12 | -------------------------------------------------------------------------------- /Utilities/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | target_sources(DiligentFX PRIVATE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/DiligentFXShaderSourceStreamFactory.hpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/src/DiligentFXShaderSourceStreamFactory.cpp" 6 | ) 7 | -------------------------------------------------------------------------------- /Hydrogent/shaders/HnAxesStructures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _HN_AXES_STRUCTURES_FXH_ 2 | #define _HN_AXES_STRUCTURES_FXH_ 3 | 4 | struct AxesConstants 5 | { 6 | float4x4 Transform; 7 | float4 AxesColors[6]; // -X, +X, -Y, +Y, -Z, +Z 8 | }; 9 | 10 | #endif // _HN_AXES_STRUCTURES_FXH_ 11 | -------------------------------------------------------------------------------- /BuildTools/FormatValidation/validate_format_linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source ../../../DiligentCore/BuildTools/FormatValidation/validate_format_linux_implementation.sh 4 | 5 | validate_format ../../Components ../../PBR ../../PostProcess ../../Utilities ../../Hydrogent ../../Tests \ 6 | -e ../../Hydrogent/shaders_inc 7 | -------------------------------------------------------------------------------- /Shaders/Common/private/FullScreenTriangleVSOutput.fxh: -------------------------------------------------------------------------------- 1 | 2 | struct FullScreenTriangleVSOutput 3 | { 4 | float4 f4PixelPos : SV_Position; // Pixel position on the screen 5 | float2 f2NormalizedXY : NORMALIZED_XY; // Normalized device XY coordinates [-1,1]x[-1,1] 6 | uint uInstID : INSTANCE_ID; 7 | }; 8 | -------------------------------------------------------------------------------- /BuildTools/FormatValidation/validate_format_win.bat: -------------------------------------------------------------------------------- 1 | python ../../../DiligentCore/BuildTools/FormatValidation/clang-format-validate.py --color never ^ 2 | --clang-format-executable ../../../DiligentCore/BuildTools/FormatValidation/clang-format_10.0.0.exe ^ 3 | -r ../../Components ../../PBR ../../PostProcess ../../Utilities ../../Hydrogent ../../Tests ^ 4 | -e ../../Hydrogent/shaders_inc 5 | -------------------------------------------------------------------------------- /BuildTools/FormatValidation/validate_format_mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python3 ../../../DiligentCore/BuildTools/FormatValidation/clang-format-validate.py \ 3 | --clang-format-executable ../../../DiligentCore/BuildTools/FormatValidation/clang-format_mac_10.0.0 \ 4 | -r ../../Components ../../PBR ../../PostProcess ../../Utilities ../../Hydrogent ../../Tests \ 5 | -e ../../Hydrogent/shaders_inc 6 | -------------------------------------------------------------------------------- /PostProcess/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | add_subdirectory(Common) 4 | add_subdirectory(EpipolarLightScattering) 5 | add_subdirectory(TemporalAntiAliasing) 6 | add_subdirectory(ScreenSpaceReflection) 7 | add_subdirectory(ScreenSpaceAmbientOcclusion) 8 | add_subdirectory(Bloom) 9 | add_subdirectory(DepthOfField) 10 | add_subdirectory(SuperResolution) 11 | -------------------------------------------------------------------------------- /PostProcess/Bloom/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/Bloom.cpp" 5 | ) 6 | 7 | set(INCLUDE 8 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/Bloom.hpp" 9 | ) 10 | 11 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) 12 | 13 | target_include_directories(DiligentFX 14 | PUBLIC 15 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 16 | ) 17 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/private/DOF_ComputeSeparatedCircleOfConfusion.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | 3 | Texture2D g_TextureCoC; 4 | 5 | float ComputeSeparatedCoCPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 6 | { 7 | float2 Position = VSOut.f4PixelPos.xy; 8 | 9 | float CoC = g_TextureCoC.Load(int3(Position, 0)); 10 | return abs(CoC) * float(CoC < 0.0); 11 | } 12 | -------------------------------------------------------------------------------- /PostProcess/DepthOfField/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/DepthOfField.cpp" 5 | ) 6 | 7 | set(INCLUDE 8 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/DepthOfField.hpp" 9 | ) 10 | 11 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) 12 | 13 | target_include_directories(DiligentFX 14 | PUBLIC 15 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 16 | ) 17 | -------------------------------------------------------------------------------- /PostProcess/TemporalAntiAliasing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/TemporalAntiAliasing.cpp" 5 | ) 6 | 7 | set(INCLUDE 8 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/TemporalAntiAliasing.hpp" 9 | ) 10 | 11 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) 12 | 13 | target_include_directories(DiligentFX 14 | PUBLIC 15 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 16 | ) 17 | -------------------------------------------------------------------------------- /Shaders/Common/private/ComputeDepthRangeStructs.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _COMPUTE_DEPTH_RANGE_STRUCTS_FXH_ 2 | #define _COMPUTE_DEPTH_RANGE_STRUCTS_FXH_ 3 | 4 | // Store floats as ints as atomic operations only work with ints. 5 | // Note: members of this struct mirror the members of the CameraAttribs struct. 6 | struct DepthRangeI 7 | { 8 | int iSceneNearZ; 9 | int iSceneFarZ; 10 | int iSceneNearDepth; 11 | int iSceneFarDepth; 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/private/DOF_Common.fx: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _DOF_COMMON_FXH_ 3 | #define _DOF_COMMON_FXH_ 4 | 5 | int ComputeSampleCount(int RingCount, int RingDensity) 6 | { 7 | return 1 + RingDensity * ((RingCount - 1) * RingCount >> 1); 8 | } 9 | 10 | float ComputeHDRWeight(float3 Color) 11 | { 12 | return 1.0 + Luminance(Color); 13 | } 14 | 15 | float ComputeSDRWeight(float3 Color) 16 | { 17 | return 1.0 / (1.0 + Luminance(Color)); 18 | } 19 | 20 | #endif // _DOF_COMMON_FXH_ 21 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeCommon.fxh: -------------------------------------------------------------------------------- 1 | 2 | 3 | float4 LUTCoordsFromThreadID( uint3 ThreadId ) 4 | { 5 | float4 f4Corrds; 6 | f4Corrds.xy = (float2( ThreadId.xy ) + float2(0.5,0.5) ) / PRECOMPUTED_SCTR_LUT_DIM.xy; 7 | 8 | uint uiW = ThreadId.z % uint(PRECOMPUTED_SCTR_LUT_DIM.z); 9 | uint uiQ = ThreadId.z / uint(PRECOMPUTED_SCTR_LUT_DIM.z); 10 | f4Corrds.zw = ( float2(uiW, uiQ) + float2(0.5,0.5) ) / PRECOMPUTED_SCTR_LUT_DIM.zw; 11 | return f4Corrds; 12 | } 13 | -------------------------------------------------------------------------------- /PostProcess/SuperResolution/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/SuperResolution.cpp" 5 | ) 6 | 7 | set(INCLUDE 8 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/SuperResolution.hpp" 9 | ) 10 | 11 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) 12 | 13 | target_include_directories(DiligentFX 14 | PUBLIC 15 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 16 | "${CMAKE_CURRENT_SOURCE_DIR}/../../Shaders/PostProcess/SuperResolution/public" 17 | ) 18 | -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceReflection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/ScreenSpaceReflection.cpp" 5 | ) 6 | 7 | set(INCLUDE 8 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/ScreenSpaceReflection.hpp" 9 | ) 10 | 11 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) 12 | 13 | target_include_directories(DiligentFX 14 | PUBLIC 15 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 16 | "${CMAKE_CURRENT_SOURCE_DIR}/../../Shaders/PostProcess/ScreenSpaceReflection/public" 17 | ) 18 | -------------------------------------------------------------------------------- /PostProcess/EpipolarLightScattering/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/EpipolarLightScattering.cpp" 5 | ) 6 | 7 | set(INCLUDE 8 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/EpipolarLightScattering.hpp" 9 | ) 10 | 11 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) 12 | 13 | target_include_directories(DiligentFX 14 | PUBLIC 15 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 16 | "${CMAKE_CURRENT_SOURCE_DIR}/../../Shaders/PostProcess/EpipolarLightScattering/public" 17 | ) 18 | -------------------------------------------------------------------------------- /PostProcess/ScreenSpaceAmbientOcclusion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/ScreenSpaceAmbientOcclusion.cpp" 5 | ) 6 | 7 | set(INCLUDE 8 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/ScreenSpaceAmbientOcclusion.hpp" 9 | ) 10 | 11 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) 12 | 13 | target_include_directories(DiligentFX 14 | PUBLIC 15 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 16 | "${CMAKE_CURRENT_SOURCE_DIR}/../../Shaders/PostProcess/ScreenSpaceAmbientOcclusion/public" 17 | ) 18 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/precompute/InitHighOrderScattering.fx: -------------------------------------------------------------------------------- 1 | #ifndef THREAD_GROUP_SIZE 2 | # define THREAD_GROUP_SIZE 16 3 | #endif 4 | 5 | Texture3D g_tex3DCurrentOrderScattering; 6 | 7 | RWTexture3D g_rwtex3DHighOrderSctr; 8 | 9 | [numthreads(THREAD_GROUP_SIZE, THREAD_GROUP_SIZE, 1)] 10 | void InitHighOrderScatteringCS(uint3 ThreadId : SV_DispatchThreadID) 11 | { 12 | // Accumulate in-scattering using alpha-blending 13 | g_rwtex3DHighOrderSctr[ThreadId] = float4(g_tex3DCurrentOrderScattering.Load( int4(ThreadId, 0) ), 0.0); 14 | } 15 | -------------------------------------------------------------------------------- /Shaders/Common/private/BoundBoxStructures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _BOUND_BOX_STRUCTURES_FXH_ 2 | #define _BOUND_BOX_STRUCTURES_FXH_ 3 | 4 | struct BoundBoxAttribs 5 | { 6 | float4x4 Transform; 7 | float4 Color; 8 | 9 | float PatternLength; 10 | uint PatternMask; 11 | float Padding0; 12 | float Padding1; 13 | }; 14 | 15 | struct BoundBoxVSOutput 16 | { 17 | float4 Pos : SV_Position; 18 | float4 ClipPos : CLIP_POS; 19 | float4 PrevClipPos : PREV_CLIP_POS; 20 | float4 EdgeStartClipPos : EDGE_START_CLIP_POS; 21 | }; 22 | 23 | #endif // _BOUND_BOX_STRUCTURES_FXH_ 24 | -------------------------------------------------------------------------------- /Shaders/Common/private/EnvMap.vsh: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | 3 | cbuffer cbCameraAttribs 4 | { 5 | CameraAttribs g_Camera; 6 | CameraAttribs g_PrevCamera; 7 | } 8 | 9 | void main(in uint VertexId : SV_VertexID, 10 | out float4 Pos : SV_Position, 11 | out float4 ClipPos : CLIP_POS) 12 | { 13 | float2 PosXY[3]; 14 | PosXY[0] = float2(-1.0, -1.0); 15 | PosXY[1] = float2(-1.0, +3.0); 16 | PosXY[2] = float2(+3.0, -1.0); 17 | 18 | float2 f2XY = PosXY[VertexId]; 19 | Pos = float4(f2XY, DepthToNormalizedDeviceZ(g_Camera.fFarPlaneDepth), 1.0); 20 | ClipPos = Pos; 21 | } 22 | -------------------------------------------------------------------------------- /Hydrogent/shaders/HnPostProcessStructures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _HN_POST_PROCESS_STRUCTURES_FXH_ 2 | #define _HN_POST_PROCESS_STRUCTURES_FXH_ 3 | 4 | struct PostProcessAttribs 5 | { 6 | float4 SelectionOutlineColor; 7 | float4 OccludedSelectionOutlineColor; 8 | 9 | float NonselectionDesaturationFactor; 10 | float AverageLogLum; 11 | float ClearDepth; 12 | float SelectionOutlineWidth; 13 | 14 | float SSRScale; 15 | float SSAOScale; 16 | float Padding0; 17 | float Padding1; 18 | 19 | ToneMappingAttribs ToneMapping; 20 | CoordinateGridAttribs CoordinateGrid; 21 | }; 22 | 23 | #endif // _HN_POST_PROCESS_STRUCTURES_FXH_ 24 | -------------------------------------------------------------------------------- /PostProcess/Common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/PostFXRenderTechnique.cpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/src/PostFXContext.cpp" 6 | ) 7 | 8 | set(INTERFACE 9 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/PostFXRenderTechnique.hpp" 10 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/PostFXContext.hpp" 11 | ) 12 | 13 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INTERFACE} ${INCLUDE}) 14 | 15 | target_include_directories(DiligentFX 16 | PUBLIC 17 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 18 | "${CMAKE_CURRENT_SOURCE_DIR}/../../Shaders/PostProcess/Common/public" 19 | ) 20 | -------------------------------------------------------------------------------- /PBR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/PBR_Renderer.cpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/src/GLTF_PBR_Renderer.cpp" 6 | "${CMAKE_CURRENT_SOURCE_DIR}/src/USD_Renderer.cpp" 7 | ) 8 | 9 | set(INCLUDE 10 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/PBR_Renderer.hpp" 11 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/GLTF_PBR_Renderer.hpp" 12 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/USD_Renderer.hpp" 13 | ) 14 | 15 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) 16 | 17 | target_include_directories(DiligentFX 18 | PUBLIC 19 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 20 | ) 21 | -------------------------------------------------------------------------------- /Shaders/PBR/private/CubemapFace.vsh: -------------------------------------------------------------------------------- 1 | cbuffer cbTransform 2 | { 3 | float4x4 g_Rotation; 4 | } 5 | 6 | void main(in uint VertexId : SV_VertexID, 7 | out float4 Pos : SV_Position, 8 | out float3 WorldPos : WORLD_POS) 9 | { 10 | float2 PosXY[4]; 11 | PosXY[0] = float2(-1.0, -1.0); 12 | PosXY[1] = float2(-1.0, +1.0); 13 | PosXY[2] = float2(+1.0, -1.0); 14 | PosXY[3] = float2(+1.0, +1.0); 15 | Pos = float4(PosXY[VertexId], 1.0, 1.0); 16 | float4 f4WorldPos = mul(g_Rotation, Pos); 17 | WorldPos = f4WorldPos.xyz / f4WorldPos.w; 18 | #if (defined(GLSL) || defined(GL_ES)) && !defined(VULKAN) 19 | Pos.y *= -1.0; 20 | #endif 21 | } 22 | -------------------------------------------------------------------------------- /Shaders/PBR/private/RenderUnshaded.psh: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | #include "PBR_Structures.fxh" 3 | #include "RenderPBR_Structures.fxh" 4 | 5 | #include "VSOutputStruct.generated" 6 | 7 | cbuffer cbFrameAttribs 8 | { 9 | PBRFrameAttribs g_Frame; 10 | } 11 | 12 | #include "PSOutputStruct.generated" 13 | // struct PSOutput 14 | // { 15 | // float4 Color : SV_Target0; 16 | // }; 17 | 18 | PSOutput main(in VSOutput VSOut, 19 | in bool IsFrontFace : SV_IsFrontFace) 20 | { 21 | #include "PSMainFooter.generated" 22 | //PSOutput PSOut; 23 | //PSOut.Color = g_Frame.Renderer.UnshadedColor + g_Frame.Renderer.HighlightColor; 24 | //return PSOut; 25 | } 26 | -------------------------------------------------------------------------------- /Hydrogent/shaders/HnInitClosestSelectedLocation.psh: -------------------------------------------------------------------------------- 1 | #include "HnClosestSelectedLocation.fxh" 2 | #include "FullScreenTriangleVSOutput.fxh" 3 | 4 | cbuffer cbConstants 5 | { 6 | ClosestSelectedLocationConstants g_Constants; 7 | } 8 | 9 | Texture2D g_SelectionDepth; 10 | 11 | void main(in FullScreenTriangleVSOutput VSOut, 12 | out float2 Location : SV_Target0) 13 | { 14 | bool IsSelected = g_SelectionDepth.Load(int3(VSOut.f4PixelPos.xy, 0)).r != g_Constants.ClearDepth; 15 | float Width; 16 | float Height; 17 | g_SelectionDepth.GetDimensions(Width, Height); 18 | Location = EncodeClosestSelectedLocation(VSOut.f4PixelPos.xy / float2(Width, Height), IsSelected); 19 | } 20 | -------------------------------------------------------------------------------- /Tests/IncludeTest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | project(DiligentFX-IncludeTest) 4 | 5 | file(GLOB_RECURSE SOURCE LIST_DIRECTORIES false *.cpp) 6 | 7 | add_library(DiligentFX-IncludeTest ${SOURCE}) 8 | 9 | target_include_directories(DiligentFX-IncludeTest PRIVATE ../..) 10 | target_link_libraries(DiligentFX-IncludeTest PRIVATE Diligent-BuildSettings) 11 | set_common_target_properties(DiligentFX-IncludeTest) 12 | 13 | if(MSVC) 14 | set_target_properties(DiligentFX-IncludeTest PROPERTIES 15 | STATIC_LIBRARY_FLAGS "/IGNORE:4221" 16 | ) 17 | endif() 18 | 19 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE}) 20 | 21 | set_target_properties(DiligentFX-IncludeTest PROPERTIES 22 | FOLDER "DiligentFX/Tests" 23 | ) 24 | -------------------------------------------------------------------------------- /Shaders/PBR/private/OIT/ClearOITLayers.csh: -------------------------------------------------------------------------------- 1 | #include "OIT.fxh" 2 | #include "BasicStructures.fxh" 3 | 4 | cbuffer cbFrameAttribs 5 | { 6 | CameraAttribs g_Camera; 7 | } 8 | 9 | RWStructuredBuffer g_rwOITLayers; 10 | 11 | [numthreads(THREAD_GROUP_SIZE, THREAD_GROUP_SIZE, 1)] 12 | void main(uint3 ThreadID : SV_DispatchThreadID) 13 | { 14 | uint2 ScreenSize = uint2(g_Camera.f4ViewportSize.x, g_Camera.f4ViewportSize.y); 15 | if (ThreadID.x >= ScreenSize.x || 16 | ThreadID.y >= ScreenSize.y) 17 | return; 18 | 19 | uint Offset = GetOITLayerDataOffset(ThreadID.xy, ScreenSize, uint(NUM_OIT_LAYERS)); 20 | for (uint layer = 0; layer < uint(NUM_OIT_LAYERS); ++layer) 21 | { 22 | g_rwOITLayers[Offset + layer] = 0xFFFFFFFFu; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/precompute/CombineScatteringOrders.fx: -------------------------------------------------------------------------------- 1 | 2 | #ifndef THREAD_GROUP_SIZE 3 | # define THREAD_GROUP_SIZE 16 4 | #endif 5 | 6 | Texture3D g_tex3DSingleSctrLUT; 7 | Texture3D g_tex3DHighOrderSctrLUT; 8 | 9 | RWTexture3D g_rwtex3DMultipleSctr; 10 | 11 | [numthreads(THREAD_GROUP_SIZE, THREAD_GROUP_SIZE, 1)] 12 | void CombineScatteringOrdersCS(uint3 ThreadId : SV_DispatchThreadID) 13 | { 14 | // Combine single & higher order scattering into single look-up table 15 | float3 f3MultipleSctr = g_tex3DSingleSctrLUT.Load( int4(ThreadId, 0) ) + 16 | g_tex3DHighOrderSctrLUT.Load( int4(ThreadId, 0) ); 17 | g_rwtex3DMultipleSctr[ThreadId] = float4(f3MultipleSctr, 0.0); 18 | } 19 | -------------------------------------------------------------------------------- /Shaders/Common/private/ClearDepthRange.csh: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | #include "ComputeDepthRangeStructs.fxh" 3 | 4 | cbuffer cbCameraAttribs 5 | { 6 | CameraAttribs g_Camera; 7 | } 8 | 9 | RWStructuredBuffer g_DepthRange; 10 | 11 | [numthreads(1, 1, 1)] 12 | void main(uint3 ThreadID : SV_DispatchThreadID) 13 | { 14 | DepthRangeI Range; 15 | // fFarPlaneZ is always greater than fNearPlaneZ. 16 | Range.iSceneNearZ = asint(g_Camera.fFarPlaneZ); 17 | Range.iSceneFarZ = asint(g_Camera.fNearPlaneZ); 18 | 19 | // Note: when reverse depth is used, fFarPlaneDepth is 0.0 and fNearPlaneDepth is 1.0. 20 | Range.iSceneNearDepth = asint(g_Camera.fFarPlaneDepth); 21 | Range.iSceneFarDepth = asint(g_Camera.fNearPlaneDepth); 22 | 23 | g_DepthRange[0] = Range; 24 | } 25 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/precompute/UpdateHighOrderScattering.fx: -------------------------------------------------------------------------------- 1 | 2 | #ifndef THREAD_GROUP_SIZE 3 | # define THREAD_GROUP_SIZE 16 4 | #endif 5 | 6 | 7 | Texture3D g_tex3DCurrentOrderScattering; 8 | Texture3D g_tex3DHighOrderOrderScattering; 9 | 10 | RWTexture3D g_rwtex3DHighOrderSctr; 11 | 12 | [numthreads(THREAD_GROUP_SIZE, THREAD_GROUP_SIZE, 1)] 13 | void UpdateHighOrderScatteringCS(uint3 ThreadId : SV_DispatchThreadID) 14 | { 15 | // Accumulate in-scattering using alpha-blending 16 | float3 f3HighOrderSctr = g_tex3DHighOrderOrderScattering.Load( int4(ThreadId, 0) ) + 17 | g_tex3DCurrentOrderScattering.Load( int4(ThreadId, 0) ); 18 | g_rwtex3DHighOrderSctr[ThreadId] = float4(f3HighOrderSctr, 0.0); 19 | } 20 | -------------------------------------------------------------------------------- /Shaders/PostProcess/SuperResolution/public/SuperResolutionStructures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _SUPER_RESOLUTION_STRUCTURES_FXH_ 2 | #define _SUPER_RESOLUTION_STRUCTURES_FXH_ 3 | 4 | #ifndef __cplusplus 5 | # include "ShaderDefinitions.fxh" 6 | #elif !defined(_SHADER_DEFINITIONS_FXH_) 7 | # error "Include ShaderDefinitions.fxh before including this file" 8 | #endif 9 | 10 | struct SuperResolutionAttribs 11 | { 12 | float4 SourceSize; 13 | float4 OutputSize; 14 | float ResolutionScale DEFAULT_VALUE(1.0f); 15 | float Sharpening DEFAULT_VALUE(1.0f); 16 | float Padding0 DEFAULT_VALUE(0.0f); 17 | float Padding1 DEFAULT_VALUE(0.0f); 18 | }; 19 | 20 | #ifdef CHECK_STRUCT_ALIGNMENT 21 | CHECK_STRUCT_ALIGNMENT(SuperResolutionAttribs); 22 | #endif 23 | 24 | 25 | #endif //_SUPER_RESOLUTION_STRUCTURES_FXH_ 26 | -------------------------------------------------------------------------------- /Shaders/Common/public/OIT.fxh: -------------------------------------------------------------------------------- 1 | uint PackOITLayer(float Depth, float Transmittance) 2 | { 3 | // Pack depth into the high 24 bits so that packed values 4 | // can be sorted by depth. 5 | uint D = uint(clamp(Depth, 0.0, 1.0) * 16777215.0); 6 | uint T = uint(clamp(Transmittance, 0.0, 1.0) * 255.0); 7 | return (D << 8u) | T; 8 | } 9 | 10 | uint GetOITLayerDepth(uint Layer) 11 | { 12 | return Layer >> 8u; 13 | } 14 | 15 | float GetOITLayerTransmittance(uint Layer) 16 | { 17 | return float(Layer & 0xFFu) / 255.0; 18 | } 19 | 20 | uint GetOITLayerDataOffset(uint2 PixelCoord, uint2 ScreenSize, uint NumLayers) 21 | { 22 | return (PixelCoord.y * ScreenSize.x + PixelCoord.x) * NumLayers; 23 | } 24 | 25 | // Opacity is stored as 8-bit value. Any value less than 1/255 is flushed to 0. 26 | #define OIT_OPACITY_THRESHOLD (1.0/255.0) 27 | -------------------------------------------------------------------------------- /Shaders/PostProcess/ScreenSpaceAmbientOcclusion/private/SSAO_Common.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _SSAO_COMMON_FXH_ 2 | #define _SSAO_COMMON_FXH_ 3 | 4 | #include "PostFX_Common.fxh" 5 | 6 | #if SSAO_OPTION_INVERTED_DEPTH 7 | #define ClosestDepth max 8 | #define DepthFarPlane 0.0 9 | #define DepthNearPlane 1.0 10 | #else 11 | #define ClosestDepth min 12 | #define DepthFarPlane 1.0 13 | #define DepthNearPlane 0.0 14 | #endif // SSAO_OPTION_INVERTED_DEPTH 15 | 16 | bool IsBackground(float Depth) 17 | { 18 | #if SSAO_OPTION_INVERTED_DEPTH 19 | return Depth < 1e-6; 20 | #else 21 | return Depth >= (1.0 - 1e-6); 22 | #endif // SSAO_OPTION_INVERTED_DEPTH 23 | } 24 | 25 | float ComputeGeometryWeight(float3 CenterPos, float3 TapPos, float3 CenterNormal, float PlaneDistanceNorm) 26 | { 27 | return saturate(1.0 - abs(dot((TapPos - CenterPos), CenterNormal)) * PlaneDistanceNorm); 28 | } 29 | 30 | #endif // _SSAO_COMMON_FXH_ 31 | -------------------------------------------------------------------------------- /Shaders/Common/private/FullScreenTriangleVS.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | 3 | void FullScreenTriangleVS(in uint VertexId : SV_VertexID, 4 | in uint InstID : SV_InstanceID, 5 | out FullScreenTriangleVSOutput VSOut) 6 | { 7 | float2 PosXY[3]; 8 | PosXY[0] = float2(-1.0, -1.0); 9 | PosXY[1] = float2(-1.0, +3.0); 10 | PosXY[2] = float2(+3.0, -1.0); 11 | 12 | float2 f2XY = PosXY[VertexId % 3u]; 13 | VSOut.f2NormalizedXY = f2XY; 14 | 15 | // We use VertexId trick on old hardware that does not support BaseInstance. 16 | VSOut.uInstID = InstID != 0u ? InstID : VertexId / 3u; 17 | 18 | #ifdef TRIANGLE_DEPTH 19 | float z = DepthToNormalizedDeviceZ(TRIANGLE_DEPTH); 20 | #else 21 | // Write 0 to the depth buffer 22 | // NDC_MIN_Z == 0 in DX 23 | // NDC_MIN_Z == -1 in GL 24 | float z = NDC_MIN_Z; 25 | #endif 26 | 27 | VSOut.f4PixelPos = float4(f2XY, z, 1.0); 28 | } 29 | -------------------------------------------------------------------------------- /Shaders/Common/private/ComputeReprojectedDepth.fx: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | #include "FullScreenTriangleVSOutput.fxh" 3 | #include "PostFX_Common.fxh" 4 | 5 | cbuffer cbCameraAttribs 6 | { 7 | CameraAttribs g_CurrCamera; 8 | CameraAttribs g_PrevCamera; 9 | } 10 | 11 | Texture2D g_TextureDepth; 12 | 13 | float SampleDepth(int2 PixelCoord) 14 | { 15 | return g_TextureDepth.Load(int3(PixelCoord, 0)); 16 | } 17 | 18 | float ComputeReprojectedDepthPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 19 | { 20 | float4 Position = VSOut.f4PixelPos; 21 | float Depth = SampleDepth(int2(Position.xy)); 22 | 23 | float3 CurrScreenCoord = float3(Position.xy * g_CurrCamera.f4ViewportSize.zw, Depth); 24 | CurrScreenCoord.xy += F3NDC_XYZ_TO_UVD_SCALE.xy * g_CurrCamera.f2Jitter; 25 | 26 | float3 WorldPosition = InvProjectPosition(CurrScreenCoord, g_CurrCamera.mViewProjInv); 27 | float3 PrevScreenCoord = ProjectPosition(WorldPosition, g_PrevCamera.mViewProj); 28 | 29 | return PrevScreenCoord.z; 30 | } 31 | -------------------------------------------------------------------------------- /Hydrogent/shaders/HnClosestSelectedLocation.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _HN_CLOSEST_SELECTED_LOCATION_FXH_ 2 | #define _HN_CLOSEST_SELECTED_LOCATION_FXH_ 3 | 4 | struct ClosestSelectedLocationConstants 5 | { 6 | float ClearDepth; 7 | float SampleRange; 8 | float Padding1; 9 | float Padding2; 10 | }; 11 | 12 | #ifndef __cplusplus 13 | float2 EncodeClosestSelectedLocation(float2 Location, bool IsValid) 14 | { 15 | if (IsValid) 16 | { 17 | Location.y = Location.y * 0.5 + 0.5; 18 | return Location; 19 | } 20 | else 21 | { 22 | return float2(0.0, 0.0); 23 | } 24 | } 25 | 26 | bool DecodeClosestSelectedLocation(in float2 EncodedLocation, 27 | out float2 Location) 28 | { 29 | if (EncodedLocation.y <= 0.25) 30 | { 31 | Location = float2(0.0, 0.0); 32 | return false; 33 | } 34 | else 35 | { 36 | Location.x = EncodedLocation.x; 37 | Location.y = EncodedLocation.y * 2.0 - 1.0; 38 | return true; 39 | } 40 | } 41 | #endif 42 | 43 | #endif // _HN_CLOSEST_SELECTED_LOCATION_FXH_ 44 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/ReconstructCameraSpaceZ.fx: -------------------------------------------------------------------------------- 1 | // ReconstructCameraSpaceZ.fx 2 | // Reconstructs camera space z from depth 3 | 4 | #include "BasicStructures.fxh" 5 | #include "AtmosphereShadersCommon.fxh" 6 | #include "ShaderUtilities.fxh" 7 | 8 | Texture2D g_tex2DDepthBuffer; 9 | 10 | cbuffer cbCameraAttribs 11 | { 12 | CameraAttribs g_CameraAttribs; 13 | } 14 | 15 | void ReconstructCameraSpaceZPS(FullScreenTriangleVSOutput VSOut, 16 | // IMPORTANT: non-system generated pixel shader input 17 | // arguments must have the exact same name as vertex shader 18 | // outputs and must go in the same order. 19 | // Moreover, even if the shader is not using the argument, 20 | // it still must be declared. 21 | 22 | out float fCamSpaceZ : SV_Target) 23 | { 24 | float fDepth = g_tex2DDepthBuffer.Load( int3(VSOut.f4PixelPos.xy,0) ); 25 | fCamSpaceZ = DepthToCameraZ(fDepth, g_CameraAttribs.mProj); 26 | } 27 | -------------------------------------------------------------------------------- /Shaders/Common/private/CoordinateGridPS.psh: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | #include "FullScreenTriangleVSOutput.fxh" 3 | #include "SRGBUtilities.fxh" 4 | #include "CoordinateGrid.fxh" 5 | 6 | cbuffer cbCameraAttribs 7 | { 8 | CameraAttribs g_Camera; 9 | } 10 | 11 | cbuffer cbGridAxesAttribs 12 | { 13 | CoordinateGridAttribs g_GridAxesAttribs; 14 | } 15 | 16 | Texture2D g_TextureDepth; 17 | 18 | float SampleDepth(int2 PixelCoord) 19 | { 20 | return g_TextureDepth.Load(int3(PixelCoord, 0)); 21 | } 22 | 23 | 24 | float4 ComputeGridAxesPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 25 | { 26 | float GeometryDepth = SampleDepth(int2(VSOut.f4PixelPos.xy)); 27 | 28 | float4 Result = ComputeCoordinateGrid(VSOut.f2NormalizedXY + g_Camera.f2Jitter, 29 | g_Camera, 30 | GeometryDepth, GeometryDepth, 31 | g_GridAxesAttribs); 32 | 33 | #if COORDINATE_GRID_CONVERT_OUTPUT_TO_SRGB 34 | Result.rgb = LinearToSRGB(Result.rgb); 35 | #endif 36 | 37 | return Result; 38 | } 39 | -------------------------------------------------------------------------------- /Shaders/Common/public/ShaderDefinitions.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _SHADER_DEFINITIONS_FXH_ 2 | #define _SHADER_DEFINITIONS_FXH_ 3 | 4 | #ifdef __cplusplus 5 | 6 | # ifndef BOOL 7 | # define BOOL int32_t // Do not use bool, because sizeof(bool)==1 ! 8 | # endif 9 | 10 | # ifndef TRUE 11 | # define TRUE 1 12 | # endif 13 | 14 | # ifndef FALSE 15 | # define FALSE 0 16 | # endif 17 | 18 | # ifndef CHECK_STRUCT_ALIGNMENT 19 | // Note that defining empty macros causes GL shader compilation error on Mac, because 20 | // it does not allow standalone semicolons outside of main. 21 | // On the other hand, adding semicolon at the end of the macro definition causes gcc error. 22 | # define CHECK_STRUCT_ALIGNMENT(s) static_assert( sizeof(s) % 16 == 0, "sizeof(" #s ") is not multiple of 16" ) 23 | # endif 24 | 25 | # ifndef DEFAULT_VALUE 26 | # define DEFAULT_VALUE(x) =x 27 | # endif 28 | 29 | #else 30 | 31 | # ifndef BOOL 32 | # define BOOL bool 33 | # endif 34 | 35 | # ifndef DEFAULT_VALUE 36 | # define DEFAULT_VALUE(x) 37 | # endif 38 | 39 | #endif 40 | 41 | #endif //_SHADER_DEFINITIONS_FXH_ 42 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/MarkRayMarchingSamples.fx: -------------------------------------------------------------------------------- 1 | // MarkRayMarchingSamples.fx 2 | // Marks ray marching samples in the stencil by increasing stencil value and discarding all other samples 3 | 4 | #include "AtmosphereShadersCommon.fxh" 5 | 6 | Texture2D g_tex2DInterpolationSource; 7 | 8 | void MarkRayMarchingSamplesInStencilPS(FullScreenTriangleVSOutput VSOut 9 | // IMPORTANT: non-system generated pixel shader input 10 | // arguments must have the exact same name as vertex shader 11 | // outputs and must go in the same order. 12 | // Moreover, even if the shader is not using the argument, 13 | // it still must be declared. 14 | ) 15 | { 16 | uint2 ui2InterpolationSources = g_tex2DInterpolationSource.Load( int3(VSOut.f4PixelPos.xy,0) ); 17 | // Ray marching samples are interpolated from themselves, so it is easy to detect them: 18 | if( ui2InterpolationSources.x != ui2InterpolationSources.y ) 19 | discard; 20 | } 21 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/UpdateAverageLuminance.fx: -------------------------------------------------------------------------------- 1 | #include "AtmosphereShadersCommon.fxh" 2 | 3 | #if LIGHT_ADAPTATION 4 | cbuffer cbMiscDynamicParams 5 | { 6 | MiscDynamicParams g_MiscParams; 7 | } 8 | #endif 9 | 10 | Texture2D g_tex2DLowResLuminance; 11 | 12 | void UpdateAverageLuminancePS( FullScreenTriangleVSOutput VSOut, 13 | // We must declare vertex shader output even though we 14 | // do not use it, because otherwise the shader will not 15 | // run on NVidia GLES 16 | out float4 f4Luminance : SV_Target) 17 | { 18 | #if LIGHT_ADAPTATION 19 | const float fAdaptationRate = 1.0; 20 | float fNewLuminanceWeight = 1.0 - exp( - fAdaptationRate * g_MiscParams.fElapsedTime ); 21 | #else 22 | float fNewLuminanceWeight = 1.0; 23 | #endif 24 | float2 LogLum_W = g_tex2DLowResLuminance.Load( int3(0,0,LOW_RES_LUMINANCE_MIPS-1) ); 25 | float LogLum = LogLum_W.x / max(LogLum_W.y, 1e-6); 26 | fNewLuminanceWeight *= saturate(LogLum_W.y / 1e-3); 27 | 28 | f4Luminance = float4( exp(LogLum), 0.0, 0.0, fNewLuminanceWeight ); 29 | } 30 | -------------------------------------------------------------------------------- /Shaders/PostProcess/ScreenSpaceAmbientOcclusion/private/SSAO_ComputeDownsampledDepth.fx: -------------------------------------------------------------------------------- 1 | #include "SSAO_Common.fxh" 2 | #include "PostFX_Common.fxh" 3 | #include "BasicStructures.fxh" 4 | #include "FullScreenTriangleVSOutput.fxh" 5 | 6 | Texture2D g_TextureDepth; 7 | 8 | int ComputeCheckerboardPattern(int2 Position) 9 | { 10 | return (Position.x + Position.y & 1) & 1; 11 | } 12 | 13 | float ComputeDepthCheckerboard(Texture2D SampledTexture, int2 Position) 14 | { 15 | float Depth0 = SampledTexture.Load(int3(2 * Position + int2(0, 0), 0)).x; 16 | float Depth1 = SampledTexture.Load(int3(2 * Position + int2(0, 1), 0)).x; 17 | float Depth2 = SampledTexture.Load(int3(2 * Position + int2(1, 0), 0)).x; 18 | float Depth3 = SampledTexture.Load(int3(2 * Position + int2(1, 1), 0)).x; 19 | float MinDepth = min(min(Depth0, Depth1), min(Depth2, Depth3)); 20 | float MaxDepth = max(max(Depth0, Depth1), max(Depth2, Depth3)); 21 | return lerp(MinDepth, MaxDepth, float(ComputeCheckerboardPattern(Position))); 22 | } 23 | 24 | float ComputeDownsampledDepthPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 25 | { 26 | float2 Position = VSOut.f4PixelPos.xy; 27 | return ComputeDepthCheckerboard(g_TextureDepth, int2(Position)); 28 | } 29 | -------------------------------------------------------------------------------- /Shaders/PBR/private/RenderPBR_Structures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _RENDER_PBR_STRUCTURES_FXH_ 2 | #define _RENDER_PBR_STRUCTURES_FXH_ 3 | 4 | // #include "BasicStructures.fxh" 5 | // #include "PBR_Structures.fxh" 6 | 7 | #ifndef COMPUTE_MOTION_VECTORS 8 | # define COMPUTE_MOTION_VECTORS 0 9 | #endif 10 | 11 | struct PBRFrameAttribs 12 | { 13 | CameraAttribs Camera; 14 | CameraAttribs PrevCamera; // Previous frame camera used to compute motion vectors 15 | PBRRendererShaderParameters Renderer; 16 | 17 | #if defined(PBR_MAX_LIGHTS) && PBR_MAX_LIGHTS > 0 18 | PBRLightAttribs Lights[PBR_MAX_LIGHTS]; 19 | #endif 20 | 21 | #if defined(ENABLE_SHADOWS) && ENABLE_SHADOWS && defined(PBR_MAX_SHADOW_MAPS) && PBR_MAX_SHADOW_MAPS > 0 22 | PBRShadowMapInfo ShadowMaps[PBR_MAX_SHADOW_MAPS]; 23 | #endif 24 | }; 25 | #ifdef CHECK_STRUCT_ALIGNMENT 26 | CHECK_STRUCT_ALIGNMENT(PBRFrameAttribs); 27 | #endif 28 | 29 | 30 | struct PBRPrimitiveAttribs 31 | { 32 | GLTFNodeShaderTransforms Transforms; 33 | 34 | float4 FallbackColor; 35 | float4 CustomData; 36 | }; 37 | #ifdef CHECK_STRUCT_ALIGNMENT 38 | CHECK_STRUCT_ALIGNMENT(PBRPrimitiveAttribs); 39 | #endif 40 | 41 | 42 | #endif // _RENDER_PBR_STRUCTURES_FXH_ 43 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | (Click "Preview" to turn any URL into a clickable link) 2 | 3 | If you have build or run problems, please read [troubleshooting](https://github.com/DiligentGraphics/DiligentEngine/blob/master/Troubleshooting.md) first. 4 | 5 | Please double-check that your [code is up-to-date, including all submodules](https://github.com/DiligentGraphics/DiligentEngine#cloning-the-repository). 6 | 7 | If you have a question that does not require creating an issue, you may ask it on [discord](https://discord.gg/t7HGBK7). 8 | 9 | For performance issues, please make sure you are running release builds. Debug builds may be significantly slower, especially on Windows. 10 | 11 | For GPU-related problems, please make sure you have up-to-date drivers. 12 | 13 | Please provide the following information: 14 | 15 | - OS and version you are running (e.g. Windows 10.0.18362, MacOS Catalina 10.15, etc.) 16 | - Build tools and configuration you used to build the engine (e.g. Visual Studio 2017 Debug x64 + CMake 3.15.4) 17 | - GPU and driver version you have installed on your system 18 | - Debug output, especially messages from Diligent 19 | - Call stack (if available) 20 | - If you experience a problem with one back-end, please try running other back-ends and see if the same issue arises 21 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/private/DOF_ComputeBlurredCircleOfConfusion.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "DepthOfFieldStructures.fxh" 3 | #include "PostFX_Common.fxh" 4 | 5 | Texture2D g_TextureCoC; 6 | Texture2D g_TextureGaussKernel; 7 | 8 | float ComputeBlurredCoCPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 9 | { 10 | int2 TextureDimension; 11 | g_TextureCoC.GetDimensions(TextureDimension.x, TextureDimension.y); 12 | 13 | int2 Position = int2(VSOut.f4PixelPos.xy); 14 | 15 | float ResultSum = 0.0; 16 | for (int SampleIdx = -DOF_GAUSS_KERNEL_RADIUS; SampleIdx <= DOF_GAUSS_KERNEL_RADIUS; SampleIdx++) 17 | { 18 | #if DOF_CIRCLE_OF_CONFUSION_BLUR_TYPE == DOF_CIRCLE_OF_CONFUSION_BLUR_X 19 | float CoC = g_TextureCoC.Load(int3(ClampScreenCoord(Position + int2(SampleIdx, 0), TextureDimension), 0)); 20 | #elif DOF_CIRCLE_OF_CONFUSION_BLUR_TYPE == DOF_CIRCLE_OF_CONFUSION_BLUR_Y 21 | float CoC = g_TextureCoC.Load(int3(ClampScreenCoord(Position + int2(0, SampleIdx), TextureDimension), 0)); 22 | #endif 23 | float Weight = g_TextureGaussKernel.Load(int3(SampleIdx + DOF_GAUSS_KERNEL_RADIUS, 0, 0)); 24 | ResultSum += CoC * Weight; 25 | } 26 | 27 | return ResultSum; 28 | } 29 | -------------------------------------------------------------------------------- /Shaders/Common/private/VectorField.vsh: -------------------------------------------------------------------------------- 1 | struct VectorFieldRenderAttribs 2 | { 3 | float4 ScaleAndBias; 4 | 5 | float fGridWidth; 6 | float fGridHeight; 7 | uint uGridWidth; 8 | uint uGridHeight; 9 | 10 | float4 Colors[2]; 11 | }; 12 | 13 | cbuffer cbAttribs 14 | { 15 | VectorFieldRenderAttribs g_Attribs; 16 | } 17 | 18 | Texture2D g_tex2DVectorField; 19 | SamplerState g_tex2DVectorField_sampler; 20 | 21 | void main(in uint VertexId : SV_VertexID, 22 | out float4 Pos : SV_Position, 23 | out float4 Color : COLOR) 24 | { 25 | uint Col = (VertexId / 2u) % g_Attribs.uGridWidth; 26 | uint Row = (VertexId / 2u) / g_Attribs.uGridWidth; 27 | 28 | float2 UV = float2( 29 | (float(Col) + 0.5) / g_Attribs.fGridWidth, 30 | (float(Row) + 0.5) / g_Attribs.fGridHeight); 31 | 32 | float2 MotionVec = g_tex2DVectorField.SampleLevel(g_tex2DVectorField_sampler, UV, 0.0).xy; 33 | MotionVec = (MotionVec + g_Attribs.ScaleAndBias.zw) * g_Attribs.ScaleAndBias.xy; 34 | 35 | float2 PosXY = TexUVToNormalizedDeviceXY(UV); 36 | if ((VertexId & 0x01u) != 0u) 37 | { 38 | PosXY += MotionVec; 39 | } 40 | 41 | Pos = float4(PosXY, 0.0, 1.0); 42 | Color = g_Attribs.Colors[VertexId & 0x01u]; 43 | } 44 | -------------------------------------------------------------------------------- /Components/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(SOURCE 4 | "${CMAKE_CURRENT_SOURCE_DIR}/src/BoundBoxRenderer.cpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/src/ShadowMapManager.cpp" 6 | "${CMAKE_CURRENT_SOURCE_DIR}/src/EnvMapRenderer.cpp" 7 | "${CMAKE_CURRENT_SOURCE_DIR}/src/GBuffer.cpp" 8 | "${CMAKE_CURRENT_SOURCE_DIR}/src/VectorFieldRenderer.cpp" 9 | "${CMAKE_CURRENT_SOURCE_DIR}/src/ToneMapping.cpp" 10 | "${CMAKE_CURRENT_SOURCE_DIR}/src/CoordinateGridRenderer.cpp" 11 | "${CMAKE_CURRENT_SOURCE_DIR}/src/DepthRangeCalculator.cpp" 12 | ) 13 | 14 | set(INCLUDE 15 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/BoundBoxRenderer.hpp" 16 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/ShadowMapManager.hpp" 17 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/EnvMapRenderer.hpp" 18 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/GBuffer.hpp" 19 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/VectorFieldRenderer.hpp" 20 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/ToneMapping.hpp" 21 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/CoordinateGridRenderer.hpp" 22 | "${CMAKE_CURRENT_SOURCE_DIR}/interface/DepthRangeCalculator.hpp" 23 | ) 24 | 25 | target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) 26 | 27 | target_include_directories(DiligentFX 28 | PUBLIC 29 | "${CMAKE_CURRENT_SOURCE_DIR}/interface" 30 | ) 31 | -------------------------------------------------------------------------------- /Shaders/PostProcess/SuperResolution/private/FSR_ContrastAdaptiveSharpening.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "SuperResolutionStructures.fxh" 3 | #include "SRGBUtilities.fxh" 4 | 5 | cbuffer cbFSRAttribs 6 | { 7 | SuperResolutionAttribs g_FSRAttribs; 8 | } 9 | 10 | Texture2D g_TextureSource; 11 | 12 | #define FFX_GPU 13 | #define FFX_HLSL 14 | #define FFX_HALF 0 15 | #define FFX_HLSL_SM 50 16 | #include "ffx_core.h" 17 | 18 | #define FSR_RCAS_F 1 19 | #define FSR_RCAS_DENOISE 1 20 | 21 | FfxFloat32x4 FsrRcasLoadF(FfxInt32x2 Position) 22 | { 23 | return g_TextureSource.Load(FfxInt32x3(Position, 0)); 24 | } 25 | 26 | void FsrRcasInputF(FFX_PARAMETER_INOUT FfxFloat32 R, FFX_PARAMETER_INOUT FfxFloat32 G, FFX_PARAMETER_INOUT FfxFloat32 B) 27 | { 28 | 29 | } 30 | 31 | #include "ffx_fsr1.h" 32 | 33 | FfxFloat32x4 ComputeContrastAdaptiveSharpeningPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 34 | { 35 | FfxUInt32x2 Location = FfxUInt32x2(VSOut.f4PixelPos.xy); 36 | 37 | FfxUInt32x4 Constants = FfxUInt32x4(0, 0, 0, 0); 38 | FsrRcasCon(Constants, g_FSRAttribs.Sharpening); 39 | 40 | FfxFloat32x3 ResultColor = FfxFloat32x3(0.0, 0.0, 0.0); 41 | FsrRcasF(ResultColor.r, ResultColor.g, ResultColor.b, Location, Constants); 42 | return FfxFloat32x4(ResultColor, 1.0); 43 | } 44 | -------------------------------------------------------------------------------- /Shaders/Common/public/SRGBUtilities.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _SRGB_UTILITIES_FXH_ 2 | #define _SRGB_UTILITIES_FXH_ 3 | 4 | float3 SRGBToLinear(float3 sRGB) 5 | { 6 | float3 bLess = step(float3(0.04045, 0.04045, 0.04045), sRGB); 7 | return lerp(sRGB / 12.92, 8 | pow(saturate((sRGB + float3(0.055, 0.055, 0.055)) / 1.055), float3(2.4, 2.4, 2.4)), 9 | bLess); 10 | } 11 | 12 | float4 SRGBAToLinear(float4 sRGBA) 13 | { 14 | return float4(SRGBToLinear(sRGBA.rgb), sRGBA.a); 15 | } 16 | 17 | float3 FastSRGBToLinear(float3 sRGB) 18 | { 19 | return pow(sRGB, float3(2.2, 2.2, 2.2)); 20 | } 21 | 22 | float4 FastSRGBAToLinear(float4 sRGBA) 23 | { 24 | return float4(FastSRGBToLinear(sRGBA.rgb), sRGBA.a); 25 | } 26 | 27 | float3 LinearToSRGB(float3 RGB) 28 | { 29 | float3 bGreater = step(float3(0.0031308, 0.0031308, 0.0031308), RGB); 30 | return lerp(RGB * 12.92, 31 | (pow(RGB, float3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4)) * 1.055) - float3(0.055, 0.055, 0.055), 32 | bGreater); 33 | } 34 | 35 | float4 LinearToSRGBA(float4 RGBA) 36 | { 37 | return float4(LinearToSRGB(RGBA.rgb), RGBA.a); 38 | } 39 | 40 | float3 FastLinearToSRGB(float3 RGB) 41 | { 42 | return pow(RGB, float3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2)); 43 | } 44 | 45 | float4 FastLinearToSRGBA(float4 RGBA) 46 | { 47 | return float4(FastLinearToSRGB(RGBA.rgb), RGBA.a); 48 | } 49 | 50 | #endif // _SRGB_UTILITIES_FXH_ 51 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/private/DOF_ComputeCircleOfConfusion.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "DepthOfFieldStructures.fxh" 3 | #include "BasicStructures.fxh" 4 | #include "PostFX_Common.fxh" 5 | 6 | cbuffer cbCameraAttribs 7 | { 8 | CameraAttribs g_Camera; 9 | } 10 | 11 | cbuffer cbDepthOfFieldAttribs 12 | { 13 | DepthOfFieldAttribs g_DOFAttribs; 14 | } 15 | 16 | Texture2D g_TextureDepth; 17 | 18 | float SampleDepth(int2 PixelCoord) 19 | { 20 | return g_TextureDepth.Load(int3(PixelCoord, 0)); 21 | } 22 | 23 | float ComputeCircleOfConfusionPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 24 | { 25 | // Linear Depth in camera space in meters 26 | float LinearDepth = DepthToCameraZ(SampleDepth(int2(VSOut.f4PixelPos.xy)), g_Camera.mProj); 27 | 28 | // Focal Length converts from millimeters to meters 29 | float f = g_Camera.fFocalLength / 1000.0f; 30 | 31 | // Lens Coefficient f * f / (N * (F - f)) 32 | float K = f * f / (g_Camera.fFStop * (g_Camera.fFocusDistance - f)); 33 | 34 | // Circle of Confusion K * (x - F) / x in millimeters 35 | float CoC = K * (LinearDepth - g_Camera.fFocusDistance) / max(LinearDepth, 1e-4); 36 | 37 | // The blur disc size for the pixel at relative texture coordinate. Near Plane: < 0.0; Focus Plane: 0; Far Plane: > 0.0; Range: [-1.0, 1,0] 38 | return clamp(1000.0 * CoC / (g_Camera.fSensorWidth * g_DOFAttribs.MaxCircleOfConfusion), -1.0, 1.0); 39 | } 40 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '2.6.{build}' 2 | 3 | # branches to build 4 | branches: 5 | # whitelist 6 | only: 7 | - master 8 | 9 | image: 10 | - Visual Studio 2019 11 | 12 | environment: 13 | matrix: 14 | - platform: x64 15 | configuration: Debug 16 | 17 | - platform: x64 18 | configuration: Release 19 | 20 | # clone directory 21 | clone_folder: c:\projects\DiligentFX 22 | 23 | install: 24 | # clone submodules 25 | - git clone https://github.com/DiligentGraphics/DiligentCore.git ../DiligentCore --recursive 26 | - git clone https://github.com/DiligentGraphics/DiligentTools.git ../DiligentTools --recursive 27 | - ps: ..\DiligentCore\BuildTools\Scripts\appveyor\install.ps1 28 | 29 | before_build: 30 | - cd c:\projects\DiligentFX\BuildTools\FormatValidation 31 | - validate_format_win.bat 32 | - cd c:\projects 33 | - echo cmake_minimum_required(VERSION 3.10) > CMakeLists.txt 34 | - echo Project(DiligentFX_Test) >> CMakeLists.txt 35 | - echo add_subdirectory(DiligentCore) >> CMakeLists.txt 36 | - echo add_subdirectory(DiligentTools) >> CMakeLists.txt 37 | - echo add_subdirectory(DiligentFX) >> CMakeLists.txt 38 | - echo %PLATFORM% 39 | - cmake -S . -B ./build -D DILIGENT_MSVC_COMPILE_OPTIONS="/WX" -D DILIGENT_MSVC_RELEASE_COMPILE_OPTIONS="/arch:AVX2" -D CMAKE_SYSTEM_VERSION=10.0.19041.0 -G "Visual Studio 16 2019" -A %PLATFORM% 40 | 41 | build: 42 | project: c:\projects\build\DiligentFX_Test.sln 43 | verbosity: minimal 44 | parallel: true 45 | -------------------------------------------------------------------------------- /Shaders/PBR/public/VertexProcessing.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _VERTEX_PROCESSING_FXH_ 2 | #define _VERTEX_PROCESSING_FXH_ 3 | 4 | struct GLTF_TransformedVertex 5 | { 6 | float3 WorldPos; 7 | float3 Normal; 8 | }; 9 | 10 | float3x3 InverseTranspose3x3(float3x3 M) 11 | { 12 | // Note that in HLSL, M_t[0] is the first row, while in GLSL, it is the 13 | // first column. Luckily, determinant and inverse matrix can be equally 14 | // defined through both rows and columns. 15 | float det = dot(cross(M[0], M[1]), M[2]); 16 | float3x3 adjugate = float3x3(cross(M[1], M[2]), 17 | cross(M[2], M[0]), 18 | cross(M[0], M[1])); 19 | return adjugate / det; 20 | } 21 | 22 | GLTF_TransformedVertex GLTF_TransformVertex(in float3 Pos, 23 | in float3 Normal, 24 | in float4x4 Transform) 25 | { 26 | GLTF_TransformedVertex TransformedVert; 27 | 28 | float4 locPos = mul(float4(Pos, 1.0), Transform); 29 | float3x3 NormalTransform = float3x3(Transform[0].xyz, Transform[1].xyz, Transform[2].xyz); 30 | NormalTransform = InverseTranspose3x3(NormalTransform); 31 | Normal = mul(Normal, NormalTransform); 32 | float NormalLen = length(Normal); 33 | TransformedVert.Normal = Normal / max(NormalLen, 1e-5); 34 | 35 | TransformedVert.WorldPos = locPos.xyz / locPos.w; 36 | 37 | return TransformedVert; 38 | } 39 | 40 | #endif // _VERTEX_PROCESSING_FXH_ 41 | -------------------------------------------------------------------------------- /Shaders/PostProcess/ScreenSpaceReflection/private/SSR_ComputeStencilMaskAndExtractRoughness.fx: -------------------------------------------------------------------------------- 1 | #include "ScreenSpaceReflectionStructures.fxh" 2 | #include "SSR_Common.fxh" 3 | #include "FullScreenTriangleVSOutput.fxh" 4 | 5 | cbuffer cbScreenSpaceReflectionAttribs 6 | { 7 | ScreenSpaceReflectionAttribs g_SSRAttribs; 8 | } 9 | 10 | Texture2D g_TextureMaterialParameters; 11 | Texture2D g_TextureDepth; 12 | 13 | float LoadRoughness(int2 PixelCoord) 14 | { 15 | float4 MaterialParams = g_TextureMaterialParameters.Load(int3(PixelCoord, 0)); 16 | float4 RoughnessSelector = float4( 17 | g_SSRAttribs.RoughnessChannel == 0u ? 1.0 : 0.0, 18 | g_SSRAttribs.RoughnessChannel == 1u ? 1.0 : 0.0, 19 | g_SSRAttribs.RoughnessChannel == 2u ? 1.0 : 0.0, 20 | g_SSRAttribs.RoughnessChannel == 3u ? 1.0 : 0.0); 21 | float Roughness = dot(MaterialParams, RoughnessSelector); 22 | if (!g_SSRAttribs.IsRoughnessPerceptual) 23 | Roughness = sqrt(Roughness); 24 | return Roughness; 25 | } 26 | 27 | float LoadDepth(int2 PixelCoord) 28 | { 29 | return g_TextureDepth.Load(int3(PixelCoord, 0)); 30 | } 31 | 32 | float ComputeStencilMaskAndExtractRoughnessPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 33 | { 34 | float Roughness = LoadRoughness(int2(VSOut.f4PixelPos.xy)); 35 | float Depth = LoadDepth(int2(VSOut.f4PixelPos.xy)); 36 | if (!IsReflectionSample(Roughness, Depth, g_SSRAttribs.RoughnessThreshold)) 37 | discard; 38 | 39 | return Roughness; 40 | } 41 | -------------------------------------------------------------------------------- /Tests/IncludeTest/PostProcess/Common/PostFXContextHpp_Test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "PostProcess/Common/interface/PostFXContext.hpp" 28 | -------------------------------------------------------------------------------- /Tests/IncludeTest/PostProcess/Common/PostFXRenderTechniqueHpp_Test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "PostProcess/Common/interface/PostFXRenderTechnique.hpp" 28 | -------------------------------------------------------------------------------- /Shaders/PostProcess/Bloom/public/BloomStructures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _BLOOM_STRUCTURES_FXH_ 2 | #define _BLOOM_STRUCTURES_FXH_ 3 | 4 | #ifndef __cplusplus 5 | # include "ShaderDefinitions.fxh" 6 | #elif !defined(_SHADER_DEFINITIONS_FXH_) 7 | # error "Include ShaderDefinitions.fxh before including this file" 8 | #endif 9 | 10 | // Implemented based on this article 11 | // https://www.froyok.fr/blog/2021-12-ue4-custom-bloom/ 12 | struct BloomAttribs 13 | { 14 | // The intensity of the bloom effect. 15 | float Intensity DEFAULT_VALUE(0.15f); 16 | 17 | // This value determines the minimum brightness required for a pixel to contribute to the bloom effect. 18 | float Threshold DEFAULT_VALUE(1.0); 19 | 20 | // This value determines the softness of the threshold. A higher value will result in a softer threshold. 21 | float SoftTreshold DEFAULT_VALUE(0.125); 22 | 23 | // This variable controls the size of the bloom effect. A larger radius will result in a larger area of the image being affected by the bloom effect. 24 | float Radius DEFAULT_VALUE(0.75); 25 | 26 | // The parameter is responsible for adjusting the intensity of Bloom with time 27 | float AlphaInterpolation DEFAULT_VALUE(1.0); 28 | 29 | float Padding0 DEFAULT_VALUE(0.0); 30 | 31 | float Padding1 DEFAULT_VALUE(0.0); 32 | 33 | float Padding2 DEFAULT_VALUE(0.0); 34 | }; 35 | #ifdef CHECK_STRUCT_ALIGNMENT 36 | CHECK_STRUCT_ALIGNMENT(BloomAttribs); 37 | #endif 38 | 39 | #endif //_BLOOM_STRUCTURES_FXH_ 40 | -------------------------------------------------------------------------------- /Tests/IncludeTest/Components/ShadowMapManagerH_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Diligent Graphics LLC 3 | * Copyright 2015-2019 Egor Yusov 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * In no event and under no legal theory, whether in tort (including negligence), 18 | * contract, or otherwise, unless required by applicable law (such as deliberate 19 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 20 | * liable for any damages, including any direct, indirect, special, incidental, 21 | * or consequential damages of any character arising as a result of this License or 22 | * out of the use or inability to use the software (including but not limited to damages 23 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 24 | * all other commercial damages or losses), even if such Contributor has been advised 25 | * of the possibility of such damages. 26 | */ 27 | 28 | #include "Components/interface/ShadowMapManager.hpp" 29 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/ComputeMinMaxShadowMapLevel.fx: -------------------------------------------------------------------------------- 1 | #include "AtmosphereShadersCommon.fxh" 2 | 3 | Texture2D g_tex2DMinMaxLightSpaceDepth; 4 | 5 | cbuffer cbMiscDynamicParams 6 | { 7 | MiscDynamicParams g_MiscParams; 8 | } 9 | 10 | // 1D min max mip map is arranged as follows: 11 | // 12 | // g_MiscParams.ui4SrcDstMinMaxLevelOffset.x 13 | // | 14 | // | g_MiscParams.ui4SrcDstMinMaxLevelOffset.z 15 | // |_______|____ __ 16 | // | | | | 17 | // | | | | 18 | // | | | | 19 | // | | | | 20 | // |_______|____|__| 21 | // |<----->|<-->| 22 | // | | 23 | // | uiMinMaxShadowMapResolution/ 24 | // uiMinMaxShadowMapResolution/2 25 | // 26 | void ComputeMinMaxShadowMapLevelPS(in FullScreenTriangleVSOutput VSOut, 27 | out float2 f2MinMaxDepth : SV_Target) 28 | { 29 | uint2 uiDstSampleInd = uint2(VSOut.f4PixelPos.xy); 30 | uint2 uiSrcSample0Ind = uint2(g_MiscParams.ui4SrcDstMinMaxLevelOffset.x + (uiDstSampleInd.x - g_MiscParams.ui4SrcDstMinMaxLevelOffset.z)*2u, uiDstSampleInd.y); 31 | uint2 uiSrcSample1Ind = uiSrcSample0Ind + uint2(1,0); 32 | float2 f2MinMaxDepth0 = g_tex2DMinMaxLightSpaceDepth.Load( int3(uiSrcSample0Ind,0) ).xy; 33 | float2 f2MinMaxDepth1 = g_tex2DMinMaxLightSpaceDepth.Load( int3(uiSrcSample1Ind,0) ).xy; 34 | 35 | f2MinMaxDepth.x = min(f2MinMaxDepth0.x, f2MinMaxDepth1.x); 36 | f2MinMaxDepth.y = max(f2MinMaxDepth0.y, f2MinMaxDepth1.y); 37 | } 38 | -------------------------------------------------------------------------------- /Tests/IncludeTest/GLTF_PBR_Renderer/GLTF_PBR_RendererH_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Diligent Graphics LLC 3 | * Copyright 2015-2019 Egor Yusov 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * In no event and under no legal theory, whether in tort (including negligence), 18 | * contract, or otherwise, unless required by applicable law (such as deliberate 19 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 20 | * liable for any damages, including any direct, indirect, special, incidental, 21 | * or consequential damages of any character arising as a result of this License or 22 | * out of the use or inability to use the software (including but not limited to damages 23 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 24 | * all other commercial damages or losses), even if such Contributor has been advised 25 | * of the possibility of such damages. 26 | */ 27 | 28 | #include "PBR/interface/GLTF_PBR_Renderer.hpp" 29 | -------------------------------------------------------------------------------- /Tests/IncludeTest/PostProcess/ScreenSpaceReflection/ScreenSpaceReflectionH_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023-2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "PostProcess/ScreenSpaceReflection/interface/ScreenSpaceReflection.hpp" 28 | -------------------------------------------------------------------------------- /Shaders/Common/private/BoundBox.psh: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | #include "BoundBoxStructures.fxh" 3 | 4 | #if COMPUTE_MOTION_VECTORS 5 | #include "ShaderUtilities.fxh" 6 | #endif 7 | 8 | cbuffer cbCameraAttribs 9 | { 10 | CameraAttribs g_Camera; 11 | CameraAttribs g_PrevCamera; 12 | } 13 | 14 | cbuffer cbBoundBoxAttribs 15 | { 16 | BoundBoxAttribs g_Attribs; 17 | } 18 | 19 | struct BoundBoxOutput 20 | { 21 | float4 Color; 22 | #if COMPUTE_MOTION_VECTORS 23 | float2 MotionVector; 24 | #endif 25 | }; 26 | 27 | BoundBoxOutput GetBoundBoxOutput(BoundBoxVSOutput VSOut) 28 | { 29 | BoundBoxOutput Output; 30 | Output.Color = g_Attribs.Color; 31 | 32 | float DistToEdgeStart = length((VSOut.ClipPos.xy / VSOut.ClipPos.w - VSOut.EdgeStartClipPos.xy / VSOut.EdgeStartClipPos.w) * g_Camera.f4ViewportSize.xy); 33 | float PatternPos = frac(DistToEdgeStart / g_Attribs.PatternLength); 34 | uint PatternBit = min(uint(PatternPos * g_Attribs.PatternLength), 31u); 35 | if ((g_Attribs.PatternMask & (1u << PatternBit)) == 0u) 36 | discard; 37 | 38 | #if COMPUTE_MOTION_VECTORS 39 | Output.MotionVector = GetMotionVector( 40 | VSOut.ClipPos.xy / VSOut.ClipPos.w, 41 | VSOut.PrevClipPos.xy / VSOut.PrevClipPos.w, 42 | g_Camera.f2Jitter, 43 | g_PrevCamera.f2Jitter 44 | ); 45 | #endif 46 | 47 | return Output; 48 | } 49 | 50 | #include "PSMainGenerated.generated" 51 | //void main(in BoundBoxVSOutput VSOut, 52 | // out float4 Color : SV_Target) 53 | //{ 54 | // Color = GetBoundBoxOutput(VSOut).Color; 55 | //} 56 | -------------------------------------------------------------------------------- /.github/workflows/build-emscripten.yml: -------------------------------------------------------------------------------- 1 | name: Emscripten build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | strategy: 8 | matrix: 9 | os: ["windows-latest", "ubuntu-24.04", "macos-15"] 10 | build_type: ["Debug", "Release"] 11 | 12 | exclude: 13 | # Exclude MacOS-Release 14 | - os: "macos-15" 15 | build_type: "Release" 16 | 17 | include: 18 | - os: "windows-latest" 19 | host_name: "Win10" 20 | cmake_args: "-DDILIGENT_NO_WEBGPU=ON" 21 | 22 | - os: "ubuntu-24.04" 23 | host_name: "Linux" 24 | cmake_args: "-DDILIGENT_NO_WEBGPU=ON" 25 | 26 | - os: "macos-15" 27 | host_name: "MacOS" 28 | cmake_args: "-DDILIGENT_NO_WEBGPU=ON" 29 | 30 | runs-on: ${{ matrix.os }} 31 | name: ${{ matrix.host_name }} -> Emscripten, ${{ matrix.build_type }} 32 | 33 | steps: 34 | - name: Checkout 35 | uses: DiligentGraphics/github-action/checkout@v9 36 | 37 | - name: Set up build environment 38 | if: success() 39 | uses: DiligentGraphics/github-action/setup-build-env@v9 40 | with: 41 | platform: Web 42 | 43 | - name: Configure CMake 44 | if: success() 45 | uses: DiligentGraphics/github-action/configure-cmake@v9 46 | with: 47 | build-type: ${{ matrix.build_type }} 48 | cmake-args: ${{ matrix.cmake_args }} 49 | 50 | - name: Build 51 | if: success() 52 | uses: DiligentGraphics/github-action/build@v9 53 | -------------------------------------------------------------------------------- /Tests/IncludeTest/PostProcess/ScreenSpaceAmbientOcclusion/ScreenSpaceAmbientOcclussionH_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "PostProcess/ScreenSpaceAmbientOcclusion/interface/ScreenSpaceAmbientOcclusion.hpp" 28 | -------------------------------------------------------------------------------- /Shaders/Common/public/CoordinateGridStructures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _COORDINATE_GRID_STRUCTURES_FXH_ 2 | #define _COORDINATE_GRID_STRUCTURES_FXH_ 3 | 4 | #include "ShaderDefinitions.fxh" 5 | 6 | struct CoordinateGridAttribs 7 | { 8 | float4 PositiveXAxisColor DEFAULT_VALUE(float4(1, 0, 0, 1)); 9 | float4 PositiveYAxisColor DEFAULT_VALUE(float4(0, 1, 0, 1)); 10 | float4 PositiveZAxisColor DEFAULT_VALUE(float4(0, 0, 1, 1)); 11 | float4 NegativeXAxisColor DEFAULT_VALUE(float4(0.40f, 0.15f, 0.15f, 1)); 12 | float4 NegativeYAxisColor DEFAULT_VALUE(float4(0.15f, 0.40f, 0.15f, 1)); 13 | float4 NegativeZAxisColor DEFAULT_VALUE(float4(0.15f, 0.15f, 0.40f, 1)); 14 | 15 | float XAxisWidth DEFAULT_VALUE(3); // in pixels 16 | float YAxisWidth DEFAULT_VALUE(3); // in pixels 17 | float ZAxisWidth DEFAULT_VALUE(3); // in pixels 18 | float Padding0 DEFAULT_VALUE(0); 19 | 20 | float4 GridMajorColor DEFAULT_VALUE(float4(0.4f, 0.4f, 0.4f, 1)); 21 | float4 GridMinorColor DEFAULT_VALUE(float4(0.1f, 0.1f, 0.1f, 1)); 22 | float4 GridScale DEFAULT_VALUE(float4(1, 1, 1, 0)); // YZ, XZ, XY 23 | float4 GridSubdivision DEFAULT_VALUE(float4(10, 10, 10, 0)); // YZ, XZ, XY 24 | 25 | float GridLineWidth DEFAULT_VALUE(2); // in pixels 26 | float GridMinCellWidth DEFAULT_VALUE(4); // in pixels 27 | float GridMinCellSize DEFAULT_VALUE(0.0001f); 28 | float Padding1 DEFAULT_VALUE(0); 29 | }; 30 | #ifdef CHECK_STRUCT_ALIGNMENT 31 | CHECK_STRUCT_ALIGNMENT(CoordinateGridAttribs); 32 | #endif 33 | 34 | #endif //_COORDINATE_GRID_STRUCTURES_FXH_ 35 | -------------------------------------------------------------------------------- /Tests/IncludeTest/PostProcess/EpipolarLightScattering/EpipolarLightScatteringH_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Diligent Graphics LLC 3 | * Copyright 2015-2019 Egor Yusov 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * In no event and under no legal theory, whether in tort (including negligence), 18 | * contract, or otherwise, unless required by applicable law (such as deliberate 19 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 20 | * liable for any damages, including any direct, indirect, special, incidental, 21 | * or consequential damages of any character arising as a result of this License or 22 | * out of the use or inability to use the software (including but not limited to damages 23 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 24 | * all other commercial damages or losses), even if such Contributor has been advised 25 | * of the possibility of such damages. 26 | */ 27 | 28 | #include "PostProcess/EpipolarLightScattering/interface/EpipolarLightScattering.hpp" 29 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/private/DOF_ComputeCombinedTexture.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "DepthOfFieldStructures.fxh" 3 | #include "BasicStructures.fxh" 4 | #include "PostFX_Common.fxh" 5 | 6 | cbuffer cbCameraAttribs 7 | { 8 | CameraAttribs g_Camera; 9 | } 10 | 11 | cbuffer cbDepthOfFieldAttribs 12 | { 13 | DepthOfFieldAttribs g_DOFAttribs; 14 | } 15 | 16 | Texture2D g_TextureColor; 17 | Texture2D g_TextureCoC; 18 | Texture2D g_TextureDoFNearPlane; 19 | Texture2D g_TextureDoFFarPlane; 20 | 21 | SamplerState g_TextureDoFNearPlane_sampler; 22 | SamplerState g_TextureDoFFarPlane_sampler; 23 | 24 | float4 SampleDoFNearPlane(float2 Texcoord) 25 | { 26 | return g_TextureDoFNearPlane.SampleLevel(g_TextureDoFNearPlane_sampler, Texcoord, 0.0); 27 | } 28 | 29 | float4 SampleDoFFarPlane(float2 Texcoord) 30 | { 31 | return g_TextureDoFFarPlane.SampleLevel(g_TextureDoFFarPlane_sampler, Texcoord, 0.0); 32 | } 33 | 34 | float3 ComputeCombinedTexturePS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 35 | { 36 | float2 Texcoord = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY.xy); 37 | float3 SourceFullRes = g_TextureColor.Load(int3(VSOut.f4PixelPos.xy, 0)); 38 | 39 | float4 DoFNear = SampleDoFNearPlane(Texcoord); 40 | float4 DoFFar = SampleDoFFarPlane(Texcoord); 41 | 42 | float3 Result = SourceFullRes; 43 | Result.rgb = lerp(Result, DoFFar.rgb, smoothstep(0.1, 1.0, DoFFar.a)); 44 | Result.rgb = lerp(Result.rgb, DoFNear.rgb, smoothstep(0.1, 1.0, DoFNear.a)); 45 | return lerp(SourceFullRes, Result, g_DOFAttribs.AlphaInterpolation); 46 | } 47 | -------------------------------------------------------------------------------- /Shaders/Common/private/ComputeClosestMotion.fx: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | #include "FullScreenTriangleVSOutput.fxh" 3 | #include "PostFX_Common.fxh" 4 | 5 | #if POSTFX_OPTION_INVERTED_DEPTH 6 | #define DepthFarPlane 0.0 7 | #else 8 | #define DepthFarPlane 1.0 9 | #endif // POSTFX_OPTION_INVERTED_DEPTH 10 | 11 | Texture2D g_TextureDepth; 12 | Texture2D g_TextureMotion; 13 | 14 | float SampleDepth(int2 PixelCoord) 15 | { 16 | return g_TextureDepth.Load(int3(PixelCoord, 0)); 17 | } 18 | 19 | float2 SampleMotion(int2 PixelCoord) 20 | { 21 | return g_TextureMotion.Load(int3(PixelCoord, 0)); 22 | } 23 | 24 | float2 SampleClosestMotion(int2 PixelCoord) 25 | { 26 | float ClosestDepth = DepthFarPlane; 27 | int2 ClosestOffset = int2(0, 0); 28 | 29 | const int SearchRadius = 1; 30 | for (int x = -SearchRadius; x <= SearchRadius; x++) 31 | { 32 | for (int y = -SearchRadius; y <= SearchRadius; y++) 33 | { 34 | int2 Coord = int2(PixelCoord) + int2(x, y); 35 | float NeighborDepth = SampleDepth(Coord); 36 | #if POSTFX_OPTION_INVERTED_DEPTH 37 | if (NeighborDepth > ClosestDepth) 38 | #else 39 | if (NeighborDepth < ClosestDepth) 40 | #endif 41 | { 42 | ClosestOffset = int2(x, y); 43 | ClosestDepth = NeighborDepth; 44 | } 45 | } 46 | } 47 | 48 | return SampleMotion(PixelCoord + ClosestOffset); 49 | } 50 | 51 | float2 ComputeClosestMotionPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 52 | { 53 | float4 Position = VSOut.f4PixelPos; 54 | return SampleClosestMotion(int2(Position.xy)); 55 | } 56 | -------------------------------------------------------------------------------- /Shaders/PBR/private/OIT/ApplyOITAttenuation.psh: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "BasicStructures.fxh" 3 | #include "OIT.fxh" 4 | 5 | cbuffer cbFrameAttribs 6 | { 7 | CameraAttribs g_Camera; 8 | } 9 | 10 | StructuredBuffer g_OITLayers; 11 | Texture2D g_OITTail; 12 | 13 | #include "PSOutputStruct.generated" 14 | //struct PSOutput 15 | //{ 16 | // float4 Color0 : SV_Target0; 17 | // float4 Color1 : SV_Target1; 18 | // float4 Color2 : SV_Target2; 19 | //}; 20 | 21 | void main(FullScreenTriangleVSOutput VSOut, 22 | out PSOutput PSOut) 23 | { 24 | uint2 Pos = uint2(VSOut.f4PixelPos.xy); 25 | 26 | uint Offset = GetOITLayerDataOffset(Pos.xy, uint2(g_Camera.f4ViewportSize.xy), uint(NUM_OIT_LAYERS)); 27 | float T = 1.0; 28 | 29 | // Apply attenuation of each layer 30 | uint layer = 0u; 31 | while (layer < uint(NUM_OIT_LAYERS)) 32 | { 33 | uint LayerDT = g_OITLayers[Offset + layer]; 34 | if (LayerDT == 0xFFFFFFFFu) 35 | break; 36 | T *= GetOITLayerTransmittance(LayerDT); 37 | ++layer; 38 | } 39 | 40 | // If we reached the last layer, apply the tail attenuation 41 | if (layer == uint(NUM_OIT_LAYERS)) 42 | { 43 | float4 Tail = g_OITTail.Load(int3(Pos.xy, 0)); 44 | T *= Tail.a; 45 | } 46 | 47 | if (T == 1.0) 48 | { 49 | // Discard fully transparent pixels 50 | discard; 51 | } 52 | 53 | // RGB blend: Src * 0 + Dst * SrcA 54 | float4 OutColor = float4(0.0, 0.0, 0.0, T); 55 | 56 | #include "PSMainFooter.generated" 57 | //PSOut.Color0 = OutColor; 58 | //PSOut.Color1 = OutColor; 59 | //PSOut.Color2 = OutColor; 60 | } 61 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/InterpolateIrradiance.fx: -------------------------------------------------------------------------------- 1 | // InterpolateIrradiance.fx 2 | // Interpolates irradiance from ray marching samples to all epipolar samples 3 | 4 | #include "AtmosphereShadersCommon.fxh" 5 | 6 | Texture2D g_tex2DInterpolationSource; 7 | Texture2D g_tex2DInitialInsctrIrradiance; 8 | 9 | void InterpolateIrradiancePS(FullScreenTriangleVSOutput VSOut, 10 | // IMPORTANT: non-system generated pixel shader input 11 | // arguments must have the exact same name as vertex shader 12 | // outputs and must go in the same order. 13 | // Moreover, even if the shader is not using the argument, 14 | // it still must be declared. 15 | 16 | out float4 f4InterpolatedIrradiance : SV_Target) 17 | { 18 | int iSampleInd = int(VSOut.f4PixelPos.x); 19 | int iSliceInd = int(VSOut.f4PixelPos.y); 20 | // Get interpolation sources 21 | uint2 ui2InterpolationSources = g_tex2DInterpolationSource.Load( int3(iSampleInd, iSliceInd, 0) ); 22 | float fInterpolationPos = float(iSampleInd - int(ui2InterpolationSources.x)) / float( max(ui2InterpolationSources.y - ui2InterpolationSources.x, 1u) ); 23 | 24 | float3 f3SrcInsctr0 = g_tex2DInitialInsctrIrradiance.Load( int3(ui2InterpolationSources.x, iSliceInd, 0) ); 25 | float3 f3SrcInsctr1 = g_tex2DInitialInsctrIrradiance.Load( int3(ui2InterpolationSources.y, iSliceInd, 0)); 26 | 27 | // Ray marching samples are interpolated from themselves 28 | f4InterpolatedIrradiance.rgb = lerp(f3SrcInsctr0, f3SrcInsctr1, fInterpolationPos); 29 | f4InterpolatedIrradiance.a = 1.0; 30 | } 31 | -------------------------------------------------------------------------------- /Hydrogent/src/HnBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "HnBuffer.hpp" 28 | 29 | namespace Diligent 30 | { 31 | 32 | namespace USD 33 | { 34 | 35 | HnBuffer::HnBuffer(const pxr::SdfPath& Id, IBuffer* pBuffer) : 36 | pxr::HdBprim{Id}, 37 | m_pBuffer{pBuffer} 38 | { 39 | } 40 | 41 | HnBuffer::~HnBuffer() 42 | { 43 | } 44 | 45 | } // namespace USD 46 | 47 | } // namespace Diligent 48 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/private/DOF_ComputePrefilteredTexture.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "DepthOfFieldStructures.fxh" 3 | #include "PostFX_Common.fxh" 4 | #include "DOF_Common.fx" 5 | 6 | cbuffer cbDepthOfFieldAttribs 7 | { 8 | DepthOfFieldAttribs g_DOFAttribs; 9 | } 10 | 11 | Texture2D g_TextureColor; 12 | Texture2D g_TextureCoC; 13 | Texture2D g_TextureDilationCoC; 14 | 15 | SamplerState g_TextureDilationCoC_sampler; 16 | 17 | struct PSOutput 18 | { 19 | float4 ForegroundColor : SV_Target0; 20 | float4 BackgroundColor : SV_Target1; 21 | }; 22 | 23 | PSOutput ComputePrefilteredTexturePS(in FullScreenTriangleVSOutput VSOut) 24 | { 25 | int2 Position = int2(VSOut.f4PixelPos.xy); 26 | float2 Texcoord = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY.xy); 27 | 28 | float CoCMin = +FLT_MAX; 29 | float CoCMax = -FLT_MAX; 30 | 31 | float4 ColorSum = float4(0.0, 0.0, 0.0, 0.0); 32 | 33 | for (int SampleIdx = 0; SampleIdx < 4; ++SampleIdx) 34 | { 35 | int2 Location = 2 * Position + int2(SampleIdx & 0x01, SampleIdx >> 1); 36 | float3 Color = g_TextureColor.Load(int3(Location, 0)); 37 | float CoC = g_TextureCoC.Load(int3(Location, 0)); 38 | float Weight = ComputeSDRWeight(Color); 39 | 40 | CoCMin = min(CoCMin, CoC); 41 | CoCMax = max(CoCMax, CoC); 42 | ColorSum += float4(Color, 1.0) * Weight; 43 | } 44 | 45 | float ForegroundAlpha = g_TextureDilationCoC.SampleLevel(g_TextureDilationCoC_sampler, Texcoord, 0.0); 46 | float BackgroundAlpha = abs(CoCMax) * float(CoCMax > 0.0); 47 | 48 | PSOutput Output; 49 | Output.ForegroundColor = float4(ColorSum.xyz / max(ColorSum.w, 1.e-5), ForegroundAlpha); 50 | Output.BackgroundColor = float4(ColorSum.xyz / max(ColorSum.w, 1.e-5), BackgroundAlpha); 51 | return Output; 52 | } 53 | -------------------------------------------------------------------------------- /Shaders/PostProcess/ScreenSpaceReflection/private/SSR_Common.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _SSR_COMMON_FXH_ 2 | #define _SSR_COMMON_FXH_ 3 | 4 | #include "PostFX_Common.fxh" 5 | 6 | #if SSR_OPTION_INVERTED_DEPTH 7 | #define ClosestDepth max 8 | #define DepthFarPlane 0.0 9 | #else 10 | #define ClosestDepth min 11 | #define DepthFarPlane 1.0 12 | #endif // SSR_OPTION_INVERTED_DEPTH 13 | 14 | #if !defined(DESKTOP_GL) && !defined(GL_ES) 15 | #define SSR_ATTRIBUTE_EARLY_DEPTH_STENCIL [earlydepthstencil] 16 | #else 17 | #define SSR_ATTRIBUTE_EARLY_DEPTH_STENCIL 18 | #endif 19 | 20 | float VanDerCorputSequenceBase2(uint SampleIdx) 21 | { 22 | return float(reversebits(SampleIdx)) / exp2(32.0); 23 | } 24 | 25 | float2 HammersleySequence(uint SampleIdx, uint N) 26 | { 27 | return float2(float(SampleIdx) / float(N), VanDerCorputSequenceBase2(SampleIdx)); 28 | } 29 | 30 | float2 VogelDiskSample(uint SampleIdx, uint N, float Phi) 31 | { 32 | float GoldenAngle = 2.4; 33 | float R = sqrt(float(SampleIdx) + 0.5) / sqrt(float(N)); 34 | float Theta = float(SampleIdx) * GoldenAngle + Phi; 35 | 36 | float Sine, Cosine; 37 | sincos(Theta, Sine, Cosine); 38 | return float2(R * Cosine, R * Sine); 39 | } 40 | 41 | float2 MapSquareToDisk(float2 Point) 42 | { 43 | float Lam = sqrt(Point.x); 44 | float Phi = 2.0 * M_PI * Point.y; 45 | return float2(cos(Phi) * Lam, sin(Phi) * Lam); 46 | } 47 | 48 | bool IsBackground(float Depth) 49 | { 50 | #if SSR_OPTION_INVERTED_DEPTH 51 | return Depth < 1e-6; 52 | #else 53 | return Depth >= (1.0 - 1e-6); 54 | #endif // SSR_OPTION_INVERTED_DEPTH 55 | } 56 | 57 | bool IsReflectionSample(float Roughness, float Depth, float RoughnessThreshold) 58 | { 59 | return Roughness <= RoughnessThreshold && !IsBackground(Depth); 60 | } 61 | 62 | bool IsMirrorReflection(float Roughness) 63 | { 64 | return Roughness < 0.01; 65 | } 66 | 67 | #endif // _SSR_COMMON_FXH_ 68 | -------------------------------------------------------------------------------- /Shaders/PBR/private/PBR_PrecomputeCommon.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _PBR_PRECOMPUTE_COMMON_FXH_ 2 | #define _PBR_PRECOMPUTE_COMMON_FXH_ 3 | 4 | #include "PBR_Common.fxh" 5 | 6 | #ifndef PI 7 | # define PI 3.1415926536 8 | #endif 9 | 10 | float2 Hammersley2D(uint i, uint N) 11 | { 12 | // Radical inverse based on http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html 13 | uint bits = reversebits(i); 14 | float rdi = float(bits) * 2.3283064365386963e-10; 15 | return float2(float(i) / float(N), rdi); 16 | } 17 | 18 | // Based on http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf 19 | float3 ImportanceSampleGGX(float2 Xi, float PerceptualRoughness, float3 N) 20 | { 21 | float AlphaRoughness = PerceptualRoughness * PerceptualRoughness; 22 | float a2 = AlphaRoughness * AlphaRoughness; 23 | 24 | float Phi = 2.0 * PI * Xi.x; 25 | float CosTheta = sqrt( saturate((1.0 - Xi.y) / (1.0 + (a2 - 1.0) * Xi.y)) ); 26 | float SinTheta = sqrt( saturate(1.0 - CosTheta * CosTheta) ); 27 | float3 H; 28 | H.x = SinTheta * cos( Phi ); 29 | H.y = SinTheta * sin( Phi ); 30 | H.z = CosTheta; 31 | float3 UpVector = abs(N.z) < 0.999 ? float3(0.0, 0.0, 1.0) : float3(1.0, 0.0, 0.0); 32 | float3 TangentX = normalize( cross( UpVector, N ) ); 33 | float3 TangentY = cross( N, TangentX ); 34 | // Tangent to world space 35 | return TangentX * H.x + TangentY * H.y + N * H.z; 36 | } 37 | 38 | float ComputeCubeMapPixelSolidAngle(float Width, float Height) 39 | { 40 | return 4.0 * PI / (6.0 * Width * Height); 41 | } 42 | 43 | float ComputeSphereMapPixelSolidAngle(float Width, float Height, float Theta, float Gamma) 44 | { 45 | float dTheta = PI / Width; 46 | float dPhi = 2.0 * PI / Height; 47 | return dPhi * (cos(Theta - 0.5 * dTheta * Gamma) - cos(Theta + 0.5 * dTheta * Gamma)); 48 | } 49 | 50 | #endif // _PBR_PRECOMPUTE_COMMON_FXH_ 51 | -------------------------------------------------------------------------------- /Hydrogent/src/HnTokens.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "HnTokens.hpp" 28 | 29 | namespace Diligent 30 | { 31 | 32 | namespace USD 33 | { 34 | 35 | TF_DEFINE_PUBLIC_TOKENS(HnMaterialTagTokens, HN_MATERIAL_TAG_TOKENS); 36 | TF_DEFINE_PUBLIC_TOKENS(HnSdrMetadataTokens, HN_SDR_METADATA_TOKENS); 37 | TF_DEFINE_PUBLIC_TOKENS(HnTextureTokens, HN_TEXTURE_TOKENS); 38 | TF_DEFINE_PUBLIC_TOKENS(HnTokens, HN_TOKENS); 39 | TF_DEFINE_PUBLIC_TOKENS(HnRenderResourceTokens, HN_RENDER_RESOURCE_TOKENS); 40 | 41 | } // namespace USD 42 | 43 | } // namespace Diligent 44 | -------------------------------------------------------------------------------- /Utilities/interface/DiligentFXShaderSourceStreamFactory.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2023 Diligent Graphics LLC 3 | * Copyright 2015-2019 Egor Yusov 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * In no event and under no legal theory, whether in tort (including negligence), 18 | * contract, or otherwise, unless required by applicable law (such as deliberate 19 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 20 | * liable for any damages, including any direct, indirect, special, incidental, 21 | * or consequential damages of any character arising as a result of this License or 22 | * out of the use or inability to use the software (including but not limited to damages 23 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 24 | * all other commercial damages or losses), even if such Contributor has been advised 25 | * of the possibility of such damages. 26 | */ 27 | 28 | #pragma once 29 | 30 | #include "Shader.h" 31 | #include "RefCntAutoPtr.hpp" 32 | 33 | namespace Diligent 34 | { 35 | 36 | class DiligentFXShaderSourceStreamFactory final 37 | { 38 | public: 39 | static IShaderSourceInputStreamFactory& GetInstance(); 40 | 41 | private: 42 | DiligentFXShaderSourceStreamFactory(); 43 | 44 | RefCntAutoPtr m_pFactory; 45 | }; 46 | 47 | } // namespace Diligent 48 | -------------------------------------------------------------------------------- /Shaders/PostProcess/SuperResolution/private/fsr1/ffx_core_portability.h: -------------------------------------------------------------------------------- 1 | // This file is part of the FidelityFX SDK. 2 | // 3 | // Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | 23 | FfxFloat32x3 opAAddOneF3(FfxFloat32x3 d, FfxFloat32x3 a, FfxFloat32 b) 24 | { 25 | d = a + ffxBroadcast3(b); 26 | return d; 27 | } 28 | 29 | FfxFloat32x3 opACpyF3(FfxFloat32x3 d, FfxFloat32x3 a) 30 | { 31 | d = a; 32 | return d; 33 | } 34 | 35 | FfxFloat32x3 opAMulF3(FfxFloat32x3 d, FfxFloat32x3 a, FfxFloat32x3 b) 36 | { 37 | d = a * b; 38 | return d; 39 | } 40 | 41 | FfxFloat32x3 opAMulOneF3(FfxFloat32x3 d, FfxFloat32x3 a, FfxFloat32 b) 42 | { 43 | d = a * ffxBroadcast3(b); 44 | return d; 45 | } 46 | 47 | FfxFloat32x3 opARcpF3(FfxFloat32x3 d, FfxFloat32x3 a) 48 | { 49 | d = rcp(a); 50 | return d; 51 | } 52 | -------------------------------------------------------------------------------- /.github/workflows/build-apple.yml: -------------------------------------------------------------------------------- 1 | name: MacOS/iOS/tvOS build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | precheks: 7 | name: MacOS -> Pre-Checks 8 | runs-on: macos-15 9 | 10 | steps: 11 | - name: Clone DiligentCore 12 | uses: actions/checkout@v4 13 | with: 14 | repository: DiligentGraphics/DiligentCore 15 | path: DiligentCore 16 | 17 | - name: Clone DiligentFX 18 | uses: actions/checkout@v4 19 | with: 20 | path: DiligentFX 21 | 22 | - name: Format validation 23 | shell: bash 24 | working-directory: ${{github.workspace}}/DiligentFX/BuildTools/FormatValidation 25 | run: ./validate_format_mac.sh 26 | 27 | 28 | build: 29 | needs: precheks 30 | runs-on: macos-15 31 | 32 | strategy: 33 | matrix: 34 | platform: ["MacOS", "iOS", "tvOS"] 35 | build_type: ["Debug", "Release"] 36 | # Do not build GLSLang and friends to save time as it is built by Core and Engine CI. 37 | cmake_args: ["-DDILIGENT_NO_GLSLANG=ON -DDILIGENT_NO_HLSL=ON -DDILIGENT_BUILD_FX_INCLUDE_TEST=ON"] 38 | exclude: 39 | # Exclude tvOS-Release 40 | - platform: "tvOS" 41 | build_type: "Release" 42 | 43 | name: MacOS -> ${{ matrix.platform }}-${{ matrix.build_type }} 44 | 45 | steps: 46 | - name: Checkout 47 | uses: DiligentGraphics/github-action/checkout@v9 48 | 49 | - name: Set up build environment 50 | if: success() 51 | uses: DiligentGraphics/github-action/setup-build-env@v9 52 | with: 53 | platform: ${{ matrix.platform }} 54 | 55 | - name: Configure CMake 56 | if: success() 57 | uses: DiligentGraphics/github-action/configure-cmake@v9 58 | with: 59 | build-type: ${{ matrix.build_type }} 60 | cmake-args: ${{ matrix.cmake_args }} 61 | 62 | - name: Build 63 | if: success() 64 | uses: DiligentGraphics/github-action/build@v9 65 | -------------------------------------------------------------------------------- /Shaders/PostProcess/Bloom/private/Bloom_ComputeDownsampledTexture.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | 3 | Texture2D g_TextureInput; 4 | SamplerState g_TextureInput_sampler; 5 | 6 | float3 SampleColor(float2 Texcoord, float2 Offset) 7 | { 8 | return g_TextureInput.SampleLevel(g_TextureInput_sampler, Texcoord + Offset, 0.0); 9 | } 10 | 11 | float3 ComputeDownsampledTexturePS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 12 | { 13 | float2 TextureResolution; 14 | g_TextureInput.GetDimensions(TextureResolution.x, TextureResolution.y); 15 | 16 | float2 TexelSize = rcp(TextureResolution); 17 | float2 CenterTexcoord = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY.xy); 18 | 19 | float3 A = SampleColor(CenterTexcoord, TexelSize * float2(-2.0, +2.0)); 20 | float3 B = SampleColor(CenterTexcoord, TexelSize * float2(+0.0, +2.0)); 21 | float3 C = SampleColor(CenterTexcoord, TexelSize * float2(+2.0, +2.0)); 22 | 23 | float3 D = SampleColor(CenterTexcoord, TexelSize * float2(-2.0, +0.0)); 24 | float3 E = SampleColor(CenterTexcoord, TexelSize * float2(+0.0, +0.0)); 25 | float3 F = SampleColor(CenterTexcoord, TexelSize * float2(+2.0, +0.0)); 26 | 27 | float3 G = SampleColor(CenterTexcoord, TexelSize * float2(-2.0, -2.0)); 28 | float3 H = SampleColor(CenterTexcoord, TexelSize * float2(+0.0, -2.0)); 29 | float3 I = SampleColor(CenterTexcoord, TexelSize * float2(+2.0, -2.0)); 30 | 31 | float3 J = SampleColor(CenterTexcoord, TexelSize * float2(-1.0, +1.0)); 32 | float3 K = SampleColor(CenterTexcoord, TexelSize * float2(+1.0, +1.0)); 33 | float3 L = SampleColor(CenterTexcoord, TexelSize * float2(-1.0, -1.0)); 34 | float3 M = SampleColor(CenterTexcoord, TexelSize * float2(+1.0, -1.0)); 35 | 36 | float3 OutColor = float3(0.0f, 0.0f, 0.0f); 37 | OutColor += (A + C + G + I) * 0.03125; 38 | OutColor += (B + D + F + H) * 0.0625; 39 | OutColor += (E + J + K + L + M) * 0.125; 40 | return OutColor; 41 | } 42 | -------------------------------------------------------------------------------- /BuildUtils.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Converts shaders to headers and generates master header with the list of all files 3 | function(convert_shaders_to_headers _SHADERS _SHADER_OUTPUT_DIR _SHADERS_LIST_FILE _SHADERS_INC_LIST) 4 | if(NOT FILE2STRING_PATH STREQUAL "") 5 | find_package(Python3 REQUIRED) 6 | 7 | file(MAKE_DIRECTORY ${_SHADER_OUTPUT_DIR}) 8 | 9 | file(WRITE ${_SHADERS_LIST_FILE} 10 | "static const MemoryShaderSourceFileInfo g_Shaders[] =\n" 11 | "{" 12 | ) 13 | 14 | foreach(FILE ${_SHADERS}) 15 | get_filename_component(FILE_NAME ${FILE} NAME) 16 | set(CONVERTED_FILE ${_SHADER_OUTPUT_DIR}/${FILE_NAME}.h) 17 | add_custom_command(OUTPUT ${CONVERTED_FILE} 18 | COMMAND ${Python3_EXECUTABLE} ${FILE2STRING_PATH} ${FILE} ${CONVERTED_FILE} 19 | MAIN_DEPENDENCY ${FILE} # the primary input source file to the command 20 | COMMENT "Processing shader ${FILE}" 21 | VERBATIM) 22 | 23 | string(REPLACE "." "_" VAR_NAME "${FILE_NAME}") 24 | file(APPEND ${_SHADERS_LIST_FILE} 25 | "\n {" 26 | "\n \"${FILE_NAME}\"," 27 | "\n #include \"${FILE_NAME}.h\"" 28 | "\n }," 29 | ) 30 | 31 | list(APPEND SHADERS_INC_LIST ${CONVERTED_FILE}) 32 | endforeach() 33 | 34 | file(APPEND ${_SHADERS_LIST_FILE} 35 | "\n};\n" 36 | ) 37 | 38 | set_source_files_properties( 39 | ${SHADERS_INC_LIST} 40 | PROPERTIES GENERATED TRUE 41 | ) 42 | 43 | set(${_SHADERS_INC_LIST} ${SHADERS_INC_LIST} PARENT_SCOPE) 44 | else() 45 | message(WARNING "File2String utility is currently unavailable on this host system. This is not an issues unless you modify shaders") 46 | endif() 47 | endfunction() 48 | -------------------------------------------------------------------------------- /Hydrogent/shaders/HnCopyFrame.psh: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "SRGBUtilities.fxh" 3 | #include "ToneMapping.fxh" 4 | #include "CoordinateGridStructures.fxh" 5 | #include "HnPostProcessStructures.fxh" 6 | #include "BasicStructures.fxh" 7 | #include "PBR_Structures.fxh" 8 | #include "RenderPBR_Structures.fxh" 9 | 10 | #ifdef ENABLE_GRID 11 | # include "CoordinateGrid.fxh" 12 | #endif 13 | 14 | cbuffer cbPostProcessAttribs 15 | { 16 | PostProcessAttribs g_Attribs; 17 | } 18 | 19 | cbuffer cbFrameAttribs 20 | { 21 | PBRFrameAttribs g_Frame; 22 | } 23 | 24 | Texture2D g_ColorBuffer; 25 | Texture2D g_Depth; 26 | 27 | void main(in FullScreenTriangleVSOutput VSOut, 28 | out float4 Color : SV_Target0) 29 | { 30 | float4 Pos = VSOut.f4PixelPos; 31 | 32 | Color = g_ColorBuffer.Load(int3(Pos.xy, 0)); 33 | 34 | #if TONE_MAPPING_MODE > TONE_MAPPING_MODE_NONE 35 | Color.rgb = ToneMap(Color.rgb, g_Attribs.ToneMapping, g_Attribs.AverageLogLum * exp2(-g_Frame.Camera.fExposure)); 36 | #endif 37 | 38 | #ifdef ENABLE_GRID 39 | // Compute depth range in the 3x3 neighborhood to avoid grid flickering 40 | // caused by temporal jittering. 41 | float MinDepth = 1.0; 42 | float MaxDepth = 0.0; 43 | for (int i = -1; i <= +1; ++i) 44 | { 45 | for (int j = -1; j <= +1; ++j) 46 | { 47 | float Depth = g_Depth.Load(int3(int2(Pos.xy) + int2(i, j), 0)).r; 48 | MinDepth = min(MinDepth, Depth); 49 | MaxDepth = max(MaxDepth, Depth); 50 | } 51 | } 52 | 53 | float4 GridColor = ComputeCoordinateGrid(VSOut.f2NormalizedXY + g_Frame.Camera.f2Jitter, 54 | g_Frame.Camera, 55 | MinDepth, MaxDepth, 56 | g_Attribs.CoordinateGrid); 57 | Color.rgb = lerp(Color.rgb, GridColor.rgb, GridColor.a); 58 | #endif 59 | 60 | #if CONVERT_OUTPUT_TO_SRGB 61 | Color.rgb = LinearToSRGB(Color.rgb); 62 | #endif 63 | } 64 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/private/DOF_ComputePostfilteredTexture.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "DepthOfFieldStructures.fxh" 3 | 4 | Texture2D g_TextureColorCoCNear; 5 | Texture2D g_TextureColorCoCFar; 6 | 7 | SamplerState g_TextureColorCoCNear_sampler; 8 | SamplerState g_TextureColorCoCFar_sampler; 9 | 10 | struct PSOutput 11 | { 12 | float4 ForegroundColor : SV_Target0; 13 | float4 BackgroundColor : SV_Target1; 14 | }; 15 | 16 | float4 SampleColorCoCNear(float2 Texcoord, float2 Offset) 17 | { 18 | return g_TextureColorCoCNear.SampleLevel(g_TextureColorCoCNear_sampler, Texcoord + Offset, 0.0); 19 | } 20 | 21 | float4 SampleColorCoCFar(float2 Texcoord, float2 Offset) 22 | { 23 | return g_TextureColorCoCFar.SampleLevel(g_TextureColorCoCFar_sampler, Texcoord + Offset, 0.0); 24 | } 25 | 26 | PSOutput ComputePostfilteredTexturePS(in FullScreenTriangleVSOutput VSOut) 27 | { 28 | float2 TextureResolution; 29 | g_TextureColorCoCNear.GetDimensions(TextureResolution.x, TextureResolution.y); 30 | 31 | float2 TexelSize = rcp(TextureResolution); 32 | float2 CenterTexcoord = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY.xy); 33 | 34 | float4 A = SampleColorCoCNear(CenterTexcoord, TexelSize * float2(-0.5, -0.5)); 35 | float4 B = SampleColorCoCNear(CenterTexcoord, TexelSize * float2(-0.5, +0.5)); 36 | float4 C = SampleColorCoCNear(CenterTexcoord, TexelSize * float2(+0.5, -0.5)); 37 | float4 D = SampleColorCoCNear(CenterTexcoord, TexelSize * float2(+0.5, +0.5)); 38 | 39 | float4 E = SampleColorCoCFar(CenterTexcoord, TexelSize * float2(-0.5, -0.5)); 40 | float4 F = SampleColorCoCFar(CenterTexcoord, TexelSize * float2(-0.5, +0.5)); 41 | float4 G = SampleColorCoCFar(CenterTexcoord, TexelSize * float2(+0.5, -0.5)); 42 | float4 H = SampleColorCoCFar(CenterTexcoord, TexelSize * float2(+0.5, +0.5)); 43 | 44 | PSOutput Output; 45 | Output.ForegroundColor = 0.25 * (A + B + C + D); 46 | Output.BackgroundColor = 0.25 * (E + F + G + H); 47 | return Output; 48 | } 49 | -------------------------------------------------------------------------------- /Shaders/PBR/private/PrecomputeBRDF.psh: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "PBR_PrecomputeCommon.fxh" 3 | 4 | #ifndef NUM_SAMPLES 5 | # define NUM_SAMPLES 512u 6 | #endif 7 | 8 | float2 IntegrateBRDF( float PerceptualRoughness, float NoV, uint NumSamples ) 9 | { 10 | float3 V; 11 | V.x = sqrt( 1.0 - NoV * NoV ); // sin 12 | V.y = 0.0; 13 | V.z = NoV; // cos 14 | const float3 N = float3(0.0, 0.0, 1.0); 15 | float A = 0.0; 16 | float B = 0.0; 17 | for( uint i = 0u; i < NumSamples; i++ ) 18 | { 19 | float2 Xi = Hammersley2D( i, NumSamples ); 20 | float3 H = ImportanceSampleGGX( Xi, PerceptualRoughness, N ); 21 | float3 L = 2.0 * dot( V, H ) * H - V; 22 | float NoL = saturate( L.z ); 23 | float NoH = saturate( H.z ); 24 | float VoH = saturate( dot( V, H ) ); 25 | if( NoL > 0.0 ) 26 | { 27 | // https://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf 28 | // Also see eq. 92 in https://google.github.io/filament/Filament.md.html#lighting/imagebasedlights 29 | // Also https://www.shadertoy.com/view/3lXXDB 30 | // Note that VoH / (NormalDistribution_GGX(H,Roughness) * NoH) term comes from importance sampling 31 | float AlphaRoughness = PerceptualRoughness * PerceptualRoughness; 32 | float G_Vis = 4.0 * SmithGGXVisibilityCorrelated( NoL, NoV, AlphaRoughness ) * VoH * NoL / NoH; 33 | float Fc = pow( 1.0 - VoH, 5.0 ); 34 | A += (1.0 - Fc) * G_Vis; 35 | B += Fc * G_Vis; 36 | } 37 | } 38 | return float2( A, B ) / float(NumSamples); 39 | } 40 | 41 | void PrecomputeBRDF_PS(FullScreenTriangleVSOutput VSOut, 42 | out float2 f2BRDF_LUT : SV_Target) 43 | { 44 | float2 UV = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY); 45 | float NdotV = UV.x; 46 | float PerceptualRoughness = UV.y; 47 | f2BRDF_LUT = IntegrateBRDF(PerceptualRoughness, NdotV, NUM_SAMPLES); 48 | } 49 | -------------------------------------------------------------------------------- /Hydrogent/include/HnShaderSourceFactory.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/Shader.h" 30 | #include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp" 31 | 32 | namespace Diligent 33 | { 34 | 35 | namespace USD 36 | { 37 | 38 | class HnShaderSourceFactory final 39 | { 40 | public: 41 | static IShaderSourceInputStreamFactory& GetInstance(); 42 | 43 | static RefCntAutoPtr CreateHnFxCompoundFactory(); 44 | 45 | private: 46 | HnShaderSourceFactory(); 47 | 48 | RefCntAutoPtr m_pFactory; 49 | }; 50 | 51 | } // namespace USD 52 | 53 | } // namespace Diligent 54 | -------------------------------------------------------------------------------- /Hydrogent/interface/HnBuffer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "pxr/imaging/hd/bprim.h" 30 | 31 | #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/Buffer.h" 32 | #include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp" 33 | 34 | namespace Diligent 35 | { 36 | 37 | namespace USD 38 | { 39 | 40 | /// Buffer implementation in Hydrogent. 41 | class HnBuffer final : public pxr::HdBprim 42 | { 43 | public: 44 | HnBuffer(const pxr::SdfPath& Id, IBuffer* pBuffer); 45 | ~HnBuffer(); 46 | 47 | IBuffer* GetResource() const 48 | { 49 | return m_pBuffer; 50 | } 51 | 52 | private: 53 | RefCntAutoPtr m_pBuffer; 54 | }; 55 | 56 | } // namespace USD 57 | 58 | } // namespace Diligent 59 | -------------------------------------------------------------------------------- /Shaders/Common/private/BoundBox.vsh: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | #include "BoundBoxStructures.fxh" 3 | 4 | cbuffer cbCameraAttribs 5 | { 6 | CameraAttribs g_Camera; 7 | CameraAttribs g_PrevCamera; 8 | } 9 | 10 | cbuffer cbBoundBoxAttribs 11 | { 12 | BoundBoxAttribs g_Attribs; 13 | } 14 | 15 | float4 GetBoxCorner(uint id) 16 | { 17 | // 5________________6 18 | // /| /| 19 | // / | / | 20 | // / | / | 21 | // / | / | 22 | // 4/____|__________/7 | 23 | // | |__________|____| 24 | // | /1 | /2 25 | // | / | / 26 | // | / | / 27 | // |/ | / 28 | // /_______________|/ 29 | // 0 3 30 | // 31 | 32 | if (id < 8u) 33 | { 34 | // 0,1, 1,2, 2,3, 3,0 35 | id = ((id + 1u) >> 1u) & 0x03u; 36 | } 37 | else if (id < 16u) 38 | { 39 | // 4,5, 5,6, 6,7, 7,4 40 | id = 4u + (((id + 1u) >> 1u) & 0x03u); 41 | } 42 | else 43 | { 44 | // 0,4, 1,5, 2,6, 3,7 45 | id = ((id - 16u) >> 1u) + (id & 0x01u) * 4u; 46 | } 47 | 48 | float4 BoxCorner; 49 | BoxCorner.x = (id & 0x02u) == 0u ? 0.0 : 1.0; 50 | BoxCorner.y = ((id + 1u) & 0x02u) == 0u ? 0.0 : 1.0; 51 | BoxCorner.z = (id & 0x04u) == 0u ? 0.0 : 1.0; 52 | BoxCorner.w = 1.0; 53 | 54 | BoxCorner = mul(BoxCorner, g_Attribs.Transform); 55 | 56 | return BoxCorner; 57 | } 58 | 59 | void BoundBoxVS(uint id : SV_VertexID, 60 | out BoundBoxVSOutput VSOut) 61 | { 62 | float4 BoxCorner = GetBoxCorner(id); 63 | float4 EdgeStart = GetBoxCorner(id & ~0x01u); 64 | 65 | VSOut.Pos = mul(BoxCorner, g_Camera.mViewProj); 66 | 67 | VSOut.ClipPos = VSOut.Pos; 68 | VSOut.EdgeStartClipPos = mul(EdgeStart, g_Camera.mViewProj); 69 | #if COMPUTE_MOTION_VECTORS 70 | VSOut.PrevClipPos = mul(BoxCorner, g_PrevCamera.mViewProj); 71 | #else 72 | VSOut.PrevClipPos = VSOut.ClipPos; 73 | #endif 74 | } 75 | -------------------------------------------------------------------------------- /Utilities/src/DiligentFXShaderSourceStreamFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2024 Diligent Graphics LLC 3 | * Copyright 2015-2019 Egor Yusov 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * In no event and under no legal theory, whether in tort (including negligence), 18 | * contract, or otherwise, unless required by applicable law (such as deliberate 19 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 20 | * liable for any damages, including any direct, indirect, special, incidental, 21 | * or consequential damages of any character arising as a result of this License or 22 | * out of the use or inability to use the software (including but not limited to damages 23 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 24 | * all other commercial damages or losses), even if such Contributor has been advised 25 | * of the possibility of such damages. 26 | */ 27 | 28 | #include "../interface/DiligentFXShaderSourceStreamFactory.hpp" 29 | #include "ShaderSourceFactoryUtils.h" 30 | 31 | namespace Diligent 32 | { 33 | 34 | #include "shaders_list.h" 35 | 36 | DiligentFXShaderSourceStreamFactory::DiligentFXShaderSourceStreamFactory() 37 | { 38 | MemoryShaderSourceFactoryCreateInfo CI{g_Shaders, _countof(g_Shaders), false}; 39 | 40 | CreateMemoryShaderSourceFactory(CI, &m_pFactory); 41 | } 42 | 43 | IShaderSourceInputStreamFactory& DiligentFXShaderSourceStreamFactory::GetInstance() 44 | { 45 | static DiligentFXShaderSourceStreamFactory TheFactory; 46 | return *TheFactory.m_pFactory; 47 | } 48 | 49 | } // namespace Diligent 50 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/private/DOF_ComputeDilationCircleOfConfusion.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "PostFX_Common.fxh" 3 | 4 | #define MipConvFunc max 5 | 6 | Texture2D g_TextureLastMip; 7 | 8 | float SampleCoC(int2 Location, int2 Offset, int3 Dimension) 9 | { 10 | int2 Position = ClampScreenCoord(Location + Offset, Dimension.xy); 11 | return g_TextureLastMip.Load(int3(Position, 0)); 12 | } 13 | 14 | float ComputeDilationCoCPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 15 | { 16 | int3 LastMipDimension; 17 | g_TextureLastMip.GetDimensions(LastMipDimension.x, LastMipDimension.y); 18 | 19 | int2 RemappedPosition = int2(2.0 * floor(VSOut.f4PixelPos.xy)); 20 | 21 | float4 SampledPixels; 22 | SampledPixels.x = SampleCoC(RemappedPosition, int2(0, 0), LastMipDimension); 23 | SampledPixels.y = SampleCoC(RemappedPosition, int2(0, 1), LastMipDimension); 24 | SampledPixels.z = SampleCoC(RemappedPosition, int2(1, 0), LastMipDimension); 25 | SampledPixels.w = SampleCoC(RemappedPosition, int2(1, 1), LastMipDimension); 26 | 27 | float MaxCoC = MipConvFunc(MipConvFunc(SampledPixels.x, SampledPixels.y), MipConvFunc(SampledPixels.z, SampledPixels.w)); 28 | 29 | bool IsWidthOdd = (LastMipDimension.x & 1) != 0; 30 | bool IsHeightOdd = (LastMipDimension.y & 1) != 0; 31 | 32 | if (IsWidthOdd) 33 | { 34 | SampledPixels.x = SampleCoC(RemappedPosition, int2(2, 0), LastMipDimension); 35 | SampledPixels.y = SampleCoC(RemappedPosition, int2(2, 1), LastMipDimension); 36 | MaxCoC = MipConvFunc(MaxCoC, MipConvFunc(SampledPixels.x, SampledPixels.y)); 37 | } 38 | 39 | if (IsHeightOdd) 40 | { 41 | SampledPixels.x = SampleCoC(RemappedPosition, int2(0, 2), LastMipDimension); 42 | SampledPixels.y = SampleCoC(RemappedPosition, int2(1, 2), LastMipDimension); 43 | MaxCoC = MipConvFunc(MaxCoC, MipConvFunc(SampledPixels.x, SampledPixels.y)); 44 | } 45 | 46 | if (IsWidthOdd && IsHeightOdd) 47 | { 48 | MaxCoC = MipConvFunc(MaxCoC, SampleCoC(RemappedPosition, int2(2, 2), LastMipDimension)); 49 | } 50 | 51 | return MaxCoC; 52 | } 53 | -------------------------------------------------------------------------------- /Hydrogent/src/HnDrawItem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "HnDrawItem.hpp" 28 | #include "HnMaterial.hpp" 29 | #include "HnTokens.hpp" 30 | 31 | namespace Diligent 32 | { 33 | 34 | namespace USD 35 | { 36 | 37 | HnDrawItem::HnDrawItem(const pxr::HdRprimSharedData& SharedData, 38 | const HnMesh& Mesh) noexcept : 39 | pxr::HdDrawItem{&SharedData}, 40 | m_Mesh{Mesh} 41 | { 42 | } 43 | 44 | HnDrawItem::~HnDrawItem() 45 | { 46 | } 47 | 48 | void HnDrawItem::SetMaterial(const HnMaterial& Material) 49 | { 50 | m_pMaterial = &Material; 51 | bool IsFallbackMaterial = Material.GetId().IsEmpty(); 52 | SetMaterialTag(!IsFallbackMaterial ? Material.GetTag() : HnMaterialTagTokens->defaultTag); 53 | } 54 | 55 | } // namespace USD 56 | 57 | } // namespace Diligent 58 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/public/EpipolarLightScatteringFunctions.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _EPIPOLAR_LIGHT_SCATTERING_FUNCTIONS_FXH_ 2 | #define _EPIPOLAR_LIGHT_SCATTERING_FUNCTIONS_FXH_ 3 | 4 | void GetSunLightExtinctionAndSkyLight(in float3 f3PosWS, 5 | in float3 f3EarthCentre, 6 | in float3 f3LightDirection, 7 | in AirScatteringAttribs MediaAttribs, 8 | 9 | in Texture2D tex2DOccludedNetDensityToAtmTop, 10 | in SamplerState tex2DOccludedNetDensityToAtmTop_sampler, 11 | in Texture2D< float3 > tex2DAmbientSkylight, 12 | in SamplerState tex2DAmbientSkylight_sampler, 13 | 14 | out float3 f3Extinction, 15 | out float3 f3AmbientSkyLight) 16 | { 17 | float3 f3DirFromEarthCentre = f3PosWS - f3EarthCentre; 18 | float fDistToCentre = length(f3DirFromEarthCentre); 19 | f3DirFromEarthCentre /= fDistToCentre; 20 | float fAltitude = fDistToCentre - MediaAttribs.fEarthRadius; 21 | float fCosZenithAngle = dot(f3DirFromEarthCentre, -f3LightDirection); 22 | 23 | float fNormalizedAltitude = (fAltitude - MediaAttribs.fAtmBottomAltitude) * MediaAttribs.fAtmAltitudeRangeInv; 24 | float2 f2ParticleDensityToAtmTop = tex2DOccludedNetDensityToAtmTop.SampleLevel( tex2DOccludedNetDensityToAtmTop_sampler, float2(fNormalizedAltitude, fCosZenithAngle*0.5 + 0.5), 0 ); 25 | 26 | float3 f3RlghOpticalDepth = MediaAttribs.f4RayleighExtinctionCoeff.rgb * f2ParticleDensityToAtmTop.x; 27 | float3 f3MieOpticalDepth = MediaAttribs.f4MieExtinctionCoeff.rgb * f2ParticleDensityToAtmTop.y; 28 | 29 | f3Extinction = exp( -(f3RlghOpticalDepth + f3MieOpticalDepth) ); 30 | 31 | f3AmbientSkyLight = tex2DAmbientSkylight.SampleLevel( tex2DAmbientSkylight_sampler, float2(fCosZenithAngle*0.5 + 0.5, 0.5), 0 ); 32 | } 33 | 34 | #endif //_EPIPOLAR_LIGHT_SCATTERING_FUNCTIONS_FXH_ 35 | -------------------------------------------------------------------------------- /Hydrogent/include/HnTextureIdentifier.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "pxr/pxr.h" 30 | #include "pxr/base/tf/token.h" 31 | #include "pxr/imaging/hd/enums.h" 32 | 33 | #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/TextureView.h" 34 | 35 | 36 | namespace Diligent 37 | { 38 | 39 | namespace USD 40 | { 41 | 42 | struct HnSubTextureIdentifier 43 | { 44 | pxr::HdTextureType Type; 45 | 46 | bool IsSRGB = false; 47 | bool FlipVertically = false; 48 | bool PremultiplyAlpha = false; 49 | 50 | TextureComponentMapping Swizzle = TextureComponentMapping::Identity(); 51 | }; 52 | 53 | struct HnTextureIdentifier 54 | { 55 | pxr::TfToken FilePath; 56 | HnSubTextureIdentifier SubtextureId; 57 | }; 58 | 59 | } // namespace USD 60 | 61 | } // namespace Diligent 62 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/Sun.fx: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | #include "AtmosphereShadersCommon.fxh" 3 | 4 | cbuffer cbCameraAttribs 5 | { 6 | CameraAttribs g_CameraAttribs; 7 | } 8 | 9 | cbuffer cbPostProcessingAttribs 10 | { 11 | EpipolarLightScatteringAttribs g_PPAttribs; 12 | } 13 | 14 | #define fSunAngularRadius (32.0/2.0 / 60.0 * ((2.0 * PI)/180.0)) // Sun angular DIAMETER is 32 arc minutes 15 | #define fTanSunAngularRadius tan(fSunAngularRadius) 16 | 17 | struct SunVSOutput 18 | { 19 | float2 f2NormalizedXY : NORMALIZED_XY; // Normalized device XY coordinates [-1,1]x[-1,1] 20 | }; 21 | 22 | void SunVS(in uint VertexId : SV_VertexID, 23 | out SunVSOutput VSOut, 24 | // IMPORTANT: non-system generated pixel shader input 25 | // arguments must have the exact same name as vertex shader 26 | // outputs and must go in the same order. 27 | // Moreover, even if the shader is not using the argument, 28 | // it still must be declared. 29 | 30 | out float4 f4Pos : SV_Position) 31 | { 32 | float2 fCotanHalfFOV = float2( MATRIX_ELEMENT(g_CameraAttribs.mProj, 0, 0), MATRIX_ELEMENT(g_CameraAttribs.mProj, 1, 1) ); 33 | float2 f2SunScreenPos = g_PPAttribs.f4LightScreenPos.xy; 34 | float2 f2SunScreenSize = fTanSunAngularRadius * fCotanHalfFOV; 35 | float4 MinMaxUV = f2SunScreenPos.xyxy + float4(-1.0, -1.0, 1.0, 1.0) * f2SunScreenSize.xyxy; 36 | 37 | float2 Verts[4]; 38 | Verts[0] = MinMaxUV.xy; 39 | Verts[1] = MinMaxUV.xw; 40 | Verts[2] = MinMaxUV.zy; 41 | Verts[3] = MinMaxUV.zw; 42 | 43 | VSOut.f2NormalizedXY = Verts[VertexId]; 44 | f4Pos = float4(Verts[VertexId], 1.0, 1.0); 45 | } 46 | 47 | void SunPS(SunVSOutput VSOut, 48 | out float4 f4Color : SV_Target) 49 | { 50 | float2 fCotanHalfFOV = float2( MATRIX_ELEMENT(g_CameraAttribs.mProj, 0, 0), MATRIX_ELEMENT(g_CameraAttribs.mProj, 1, 1) ); 51 | float2 f2SunScreenSize = fTanSunAngularRadius * fCotanHalfFOV; 52 | float2 f2dXY = (VSOut.f2NormalizedXY - g_PPAttribs.f4LightScreenPos.xy) / f2SunScreenSize; 53 | f4Color.rgb = sqrt(saturate(1.0 - dot(f2dXY, f2dXY))) * float3(1.0, 1.0, 1.0); 54 | f4Color.a = 1.0; 55 | } 56 | -------------------------------------------------------------------------------- /Shaders/PostProcess/Bloom/private/Bloom_ComputeUpsampledTexture.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "BloomStructures.fxh" 3 | 4 | cbuffer cbBloomAttribs 5 | { 6 | BloomAttribs g_BloomAttribs; 7 | } 8 | 9 | Texture2D g_TextureInput; 10 | SamplerState g_TextureInput_sampler; 11 | 12 | Texture2D g_TextureDownsampled; 13 | SamplerState g_TextureDownsampled_sampler; 14 | 15 | float3 SampleColor(float2 Texcoord, float2 Offset) 16 | { 17 | return g_TextureDownsampled.SampleLevel(g_TextureDownsampled_sampler, Texcoord + Offset, 0.0); 18 | } 19 | 20 | float3 ComputeUpsampledTexturePS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 21 | { 22 | float2 TextureResolution; 23 | g_TextureInput.GetDimensions(TextureResolution.x, TextureResolution.y); 24 | 25 | float2 TexelSize = rcp(TextureResolution); 26 | float2 CenterTexcoord = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY); 27 | 28 | float3 A = SampleColor(CenterTexcoord, TexelSize * float2(-1.0, +1.0)); 29 | float3 B = SampleColor(CenterTexcoord, TexelSize * float2(+0.0, +1.0)); 30 | float3 C = SampleColor(CenterTexcoord, TexelSize * float2(+1.0, +1.0)); 31 | 32 | float3 D = SampleColor(CenterTexcoord, TexelSize * float2(-1.0, +0.0)); 33 | float3 E = SampleColor(CenterTexcoord, TexelSize * float2(+0.0, +0.0)); 34 | float3 F = SampleColor(CenterTexcoord, TexelSize * float2(+1.0, +0.0)); 35 | 36 | float3 G = SampleColor(CenterTexcoord, TexelSize * float2(-1.0, -1.0)); 37 | float3 H = SampleColor(CenterTexcoord, TexelSize * float2(+0.0, -1.0)); 38 | float3 I = SampleColor(CenterTexcoord, TexelSize * float2(+1.0, -1.0)); 39 | 40 | float3 ColorSum = E * 0.25; 41 | ColorSum += (B + D + F + H) * 0.125; 42 | ColorSum += (A + C + G + I) * 0.0625; 43 | 44 | if (VSOut.uInstID != 0u) 45 | { 46 | float3 SourceColor = g_TextureInput.SampleLevel(g_TextureInput_sampler, CenterTexcoord, 0.0); 47 | return lerp(SourceColor, SourceColor + g_BloomAttribs.Intensity * ColorSum, g_BloomAttribs.AlphaInterpolation); 48 | } 49 | else 50 | { 51 | float3 SourceColor = g_TextureInput.SampleLevel(g_TextureInput_sampler, CenterTexcoord, 0.0); 52 | return SourceColor + ColorSum; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Shaders/PostProcess/ToneMapping/public/ToneMappingStructures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _TONE_MAPPING_STRUCTURES_FXH_ 2 | #define _TONE_MAPPING_STRUCTURES_FXH_ 3 | 4 | #ifndef __cplusplus 5 | # include "ShaderDefinitions.fxh" 6 | #elif !defined(_SHADER_DEFINITIONS_FXH_) 7 | # error "Include ShaderDefinitions.fxh before including this file" 8 | #endif 9 | 10 | // Tone mapping mode 11 | #define TONE_MAPPING_MODE_NONE 0 12 | #define TONE_MAPPING_MODE_EXP 1 13 | #define TONE_MAPPING_MODE_REINHARD 2 14 | #define TONE_MAPPING_MODE_REINHARD_MOD 3 15 | #define TONE_MAPPING_MODE_UNCHARTED2 4 16 | #define TONE_MAPPING_MODE_FILMIC_ALU 5 17 | #define TONE_MAPPING_MODE_LOGARITHMIC 6 18 | #define TONE_MAPPING_MODE_ADAPTIVE_LOG 7 19 | #define TONE_MAPPING_MODE_AGX 8 20 | #define TONE_MAPPING_MODE_AGX_CUSTOM 9 21 | #define TONE_MAPPING_MODE_PBR_NEUTRAL 10 22 | #define TONE_MAPPING_MODE_COMMERCE 11 23 | 24 | struct AgXAttribs 25 | { 26 | float Saturation DEFAULT_VALUE(1.f); 27 | float Slope DEFAULT_VALUE(1.f); 28 | float Power DEFAULT_VALUE(1.f); 29 | float Offset DEFAULT_VALUE(0.f); 30 | }; 31 | 32 | struct ToneMappingAttribs 33 | { 34 | // Tone mapping mode. 35 | int iToneMappingMode DEFAULT_VALUE(TONE_MAPPING_MODE_UNCHARTED2); 36 | // Automatically compute exposure to use in tone mapping. 37 | BOOL bAutoExposure DEFAULT_VALUE(TRUE); 38 | // Middle gray value used by tone mapping operators. 39 | float fMiddleGray DEFAULT_VALUE(0.18f); 40 | // Simulate eye adaptation to light changes. 41 | BOOL bLightAdaptation DEFAULT_VALUE(TRUE); 42 | 43 | // White point to use in tone mapping. 44 | float fWhitePoint DEFAULT_VALUE(3.f); 45 | // Luminance point to use in tone mapping. 46 | float fLuminanceSaturation DEFAULT_VALUE(1.f); 47 | uint Padding0 DEFAULT_VALUE(0); 48 | uint Padding1 DEFAULT_VALUE(0); 49 | 50 | // Settings for AGX custom tone mapping operator. 51 | AgXAttribs AgX DEFAULT_VALUE({}); 52 | }; 53 | #ifdef CHECK_STRUCT_ALIGNMENT 54 | CHECK_STRUCT_ALIGNMENT(ToneMappingAttribs); 55 | #endif 56 | 57 | #endif // _TONE_MAPPING_STRUCTURES_FXH_ 58 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/public/DepthOfFieldStructures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _DEPTH_OF_FIELD_STRUCTURES_FXH_ 2 | #define _DEPTH_OF_FIELD_STRUCTURES_FXH_ 3 | 4 | #ifndef __cplusplus 5 | # include "ShaderDefinitions.fxh" 6 | #elif !defined(_SHADER_DEFINITIONS_FXH_) 7 | # error "Include ShaderDefinitions.fxh before including this file" 8 | #endif 9 | 10 | #define DOF_TEMPORAL_VARIANCE_GAMMA 2.5 11 | 12 | // Number of rings in the bokeh kernel for flood-filling. 13 | #define DOF_BOKEH_KERNEL_SMALL_RING_COUNT 3 14 | 15 | // Number of samples within each ring of the bokeh kernel for flood-filling. 16 | #define DOF_BOKEH_KERNEL_SMALL_RING_DENSITY 5 17 | 18 | // Gaussian kernel radius for blurring the dilated CoC texture 19 | #define DOF_GAUSS_KERNEL_RADIUS 6 20 | 21 | // Gaussian kernel sigma for blurring the dilated CoC texture 22 | #define DOF_GAUSS_KERNEL_SIGMA 5.0 23 | 24 | // Macro for selecting the direction of CoC blur 25 | #define DOF_CIRCLE_OF_CONFUSION_BLUR_X 0 26 | 27 | // Macro for selecting the direction of CoC blur 28 | #define DOF_CIRCLE_OF_CONFUSION_BLUR_Y 1 29 | 30 | 31 | struct DepthOfFieldAttribs 32 | { 33 | // This is the maximum size of CoC in texture coordinates for a pixel. 34 | // This parameter affects the strength of the bokeh effect. 35 | // In reality, such a parameter does not exist, but unfortunately, we have to use it for performance reasons. 36 | float MaxCircleOfConfusion DEFAULT_VALUE(0.01f); 37 | 38 | // This parameter is used to control the stability of the temporal accumulation of the CoC. 39 | float TemporalStabilityFactor DEFAULT_VALUE(0.9375f); 40 | 41 | // The number of rings in the Octaweb kernel 42 | int BokehKernelRingCount DEFAULT_VALUE(5); 43 | 44 | // The number of samples within each ring of the Octaweb kernel. 45 | int BokehKernelRingDensity DEFAULT_VALUE(7); 46 | 47 | // The parameter is responsible for adjusting the intensity of DoF with time 48 | float AlphaInterpolation DEFAULT_VALUE(1.0); 49 | 50 | float Padding0 DEFAULT_VALUE(0.0); 51 | 52 | float Padding1 DEFAULT_VALUE(0.0); 53 | 54 | float Padding2 DEFAULT_VALUE(0.0); 55 | 56 | }; 57 | #ifdef CHECK_STRUCT_ALIGNMENT 58 | CHECK_STRUCT_ALIGNMENT(DepthOfFieldAttribs); 59 | #endif 60 | 61 | #endif // _DEPTH_OF_FIELD_STRUCTURES_FXH_ 62 | -------------------------------------------------------------------------------- /Hydrogent/src/Computations/HnExtComputationImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "Computations/HnExtComputationImpl.hpp" 28 | #include "Computations/HnSkinningComputation.hpp" 29 | 30 | namespace Diligent 31 | { 32 | 33 | namespace USD 34 | { 35 | 36 | HnExtComputationImpl::HnExtComputationImpl(HnExtComputation& Owner, ImplType Type) : 37 | m_Owner{Owner}, 38 | m_Type{Type} 39 | {} 40 | 41 | HnExtComputationImpl::~HnExtComputationImpl() 42 | { 43 | } 44 | 45 | HnExtComputationImpl::ImplType HnExtComputationImpl::GetType(const HnExtComputation& Owner) 46 | { 47 | if (HnSkinningComputation::IsCompatible(Owner)) 48 | { 49 | return ImplType::Skinning; 50 | } 51 | 52 | return ImplType::Unknown; 53 | } 54 | 55 | std::unique_ptr HnExtComputationImpl::Create(HnExtComputation& Owner) 56 | { 57 | if (HnSkinningComputation::IsCompatible(Owner)) 58 | { 59 | return std::make_unique(Owner); 60 | } 61 | 62 | return {}; 63 | } 64 | 65 | } // namespace USD 66 | 67 | } // namespace Diligent 68 | -------------------------------------------------------------------------------- /Hydrogent/src/HnFrameRenderTargets.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "HnFrameRenderTargets.hpp" 28 | 29 | #include "DebugUtilities.hpp" 30 | 31 | namespace Diligent 32 | { 33 | 34 | namespace USD 35 | { 36 | 37 | const char* HnFrameRenderTargets::GetGBufferTargetName(GBUFFER_TARGET Id) 38 | { 39 | static_assert(GBUFFER_TARGET_COUNT == 7, "Please handle all GBuffer target names."); 40 | switch (Id) 41 | { 42 | // clang-format off 43 | case GBUFFER_TARGET_SCENE_COLOR: return "Scene color"; 44 | case GBUFFER_TARGET_MESH_ID: return "Mesh ID"; 45 | case GBUFFER_TARGET_MOTION_VECTOR: return "Motion vectors"; 46 | case GBUFFER_TARGET_NORMAL: return "Normal"; 47 | case GBUFFER_TARGET_BASE_COLOR: return "Base color"; 48 | case GBUFFER_TARGET_MATERIAL: return "Material"; 49 | case GBUFFER_TARGET_IBL: return "IBL"; 50 | // clang-format on 51 | default: 52 | UNEXPECTED("Unexpected GBuffer target"); 53 | return "Unknown"; 54 | }; 55 | } 56 | 57 | } // namespace USD 58 | 59 | } // namespace Diligent 60 | -------------------------------------------------------------------------------- /Hydrogent/src/HnShaderSourceFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023-2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "HnShaderSourceFactory.hpp" 28 | #include "ShaderSourceFactoryUtils.h" 29 | 30 | #include "Utilities/interface/DiligentFXShaderSourceStreamFactory.hpp" 31 | #include "ShaderSourceFactoryUtils.hpp" 32 | 33 | namespace Diligent 34 | { 35 | 36 | namespace USD 37 | { 38 | 39 | #include "shaders_list.h" 40 | 41 | HnShaderSourceFactory::HnShaderSourceFactory() 42 | { 43 | MemoryShaderSourceFactoryCreateInfo CI{g_Shaders, _countof(g_Shaders), false}; 44 | 45 | CreateMemoryShaderSourceFactory(CI, &m_pFactory); 46 | } 47 | 48 | IShaderSourceInputStreamFactory& HnShaderSourceFactory::GetInstance() 49 | { 50 | static HnShaderSourceFactory TheFactory; 51 | return *TheFactory.m_pFactory; 52 | } 53 | 54 | RefCntAutoPtr HnShaderSourceFactory::CreateHnFxCompoundFactory() 55 | { 56 | return CreateCompoundShaderSourceFactory({ 57 | &HnShaderSourceFactory::GetInstance(), 58 | &DiligentFXShaderSourceStreamFactory::GetInstance(), 59 | }); 60 | } 61 | 62 | } // namespace USD 63 | 64 | } // namespace Diligent 65 | -------------------------------------------------------------------------------- /Shaders/Common/private/EnvMap.psh: -------------------------------------------------------------------------------- 1 | #include "BasicStructures.fxh" 2 | #include "ToneMapping.fxh" 3 | #include "ShaderUtilities.fxh" 4 | 5 | cbuffer cbCameraAttribs 6 | { 7 | CameraAttribs g_Camera; 8 | CameraAttribs g_PrevCamera; 9 | } 10 | 11 | cbuffer cbEnvMapRenderAttribs 12 | { 13 | ToneMappingAttribs g_ToneMappingAttribs; 14 | 15 | float g_AverageLogLum; 16 | float g_MipLevel; 17 | float g_Alpha; 18 | float Unusued2; 19 | 20 | float4 g_Scale; 21 | } 22 | 23 | #if ENV_MAP_TYPE == ENV_MAP_TYPE_CUBE 24 | TextureCube EnvMap; 25 | #elif ENV_MAP_TYPE == ENV_MAP_TYPE_SPHERE 26 | Texture2D EnvMap; 27 | #endif 28 | SamplerState EnvMap_sampler; 29 | 30 | float3 SampleEnvrionmentMap(float3 R, float g_MipLevel) 31 | { 32 | #if ENV_MAP_TYPE == ENV_MAP_TYPE_CUBE 33 | return EnvMap.SampleLevel(EnvMap_sampler, R, g_MipLevel).rgb; 34 | #elif ENV_MAP_TYPE == ENV_MAP_TYPE_SPHERE 35 | return EnvMap.SampleLevel(EnvMap_sampler, TransformDirectionToSphereMapUV(R), g_MipLevel).rgb; 36 | #endif 37 | } 38 | 39 | struct SampleEnvMapOutput 40 | { 41 | float4 Color; 42 | float2 MotionVector; 43 | }; 44 | 45 | SampleEnvMapOutput SampleEnvMap(in float4 ClipPos) 46 | { 47 | float4 WorldPos = mul(ClipPos, g_Camera.mViewProjInv); 48 | float3 Direction = WorldPos.xyz / WorldPos.w - g_Camera.f4Position.xyz; 49 | float3 Color = SampleEnvrionmentMap(normalize(Direction), g_MipLevel) * g_Scale.rgb; 50 | 51 | #if TONE_MAPPING_MODE > TONE_MAPPING_MODE_NONE 52 | Color.rgb = ToneMap(Color.rgb, g_ToneMappingAttribs, g_AverageLogLum); 53 | #endif 54 | 55 | #if CONVERT_OUTPUT_TO_SRGB 56 | Color.rgb = pow(Color.rgb, float3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2)); 57 | #endif 58 | 59 | float2 MotionVector = float2(0.0, 0.0); 60 | #if COMPUTE_MOTION_VECTORS 61 | float3 PrevWorldPos = g_PrevCamera.f4Position.xyz + Direction; 62 | float4 PrevClipPos = mul(float4(PrevWorldPos, 1.0), g_PrevCamera.mViewProj); 63 | PrevClipPos.xy /= PrevClipPos.w; 64 | MotionVector = GetMotionVector(ClipPos.xy, PrevClipPos.xy, g_Camera.f2Jitter, g_PrevCamera.f2Jitter); 65 | #endif 66 | 67 | SampleEnvMapOutput Output; 68 | Output.Color = float4(Color.rgb, g_Alpha); 69 | Output.MotionVector = MotionVector; 70 | return Output; 71 | } 72 | 73 | #include "PSMainGenerated.generated" 74 | // void main(in float4 Pos : SV_Position, 75 | // in float4 ClipPos : CLIP_POS, 76 | // out float4 Color : SV_Target) 77 | // { 78 | // Color = SampleEnvMap(ClipPos).Color; 79 | // } 80 | -------------------------------------------------------------------------------- /Components/interface/ToneMapping.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | /// \file 30 | /// Defines tone mapping functions 31 | 32 | #include "../../../DiligentCore/Common/interface/BasicMath.hpp" 33 | 34 | namespace Diligent 35 | { 36 | 37 | namespace HLSL 38 | { 39 | struct ToneMappingAttribs; 40 | } // namespace HLSL 41 | 42 | 43 | /// Computes approximate reverse tone mapping for the given tone-mapped color. 44 | /// \param Color - Tone-mapped color. 45 | /// \param MiddleGray - Middle gray value used by the tone mapping operator. 46 | /// \param AverageLogLum - Average log luminance of the original image. 47 | /// \return Approximate reverse tone-mapped color. 48 | /// 49 | /// The function computes approximate reverse tone mapping assuming the 50 | /// exponential tone mapping operator. The value is not exact, but 51 | /// works well for practical purposes. 52 | float3 ReverseExpToneMap(const float3& Color, float MiddleGray, float AverageLogLum); 53 | 54 | /// Adds tone mapping UI elements 55 | bool ToneMappingUpdateUI(HLSL::ToneMappingAttribs& Attribs, float* AverageLogLum = nullptr); 56 | 57 | } // namespace Diligent 58 | -------------------------------------------------------------------------------- /Hydrogent/interface/Tasks/HnCopySelectionDepthTask.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "HnTask.hpp" 30 | 31 | namespace Diligent 32 | { 33 | 34 | namespace USD 35 | { 36 | 37 | struct HnCopySelectionDepthTaskParams 38 | { 39 | constexpr operator bool() const 40 | { 41 | return true; 42 | } 43 | }; 44 | 45 | /// Copies depth buffer to the selection depth buffer. 46 | class HnCopySelectionDepthTask final : public HnTask 47 | { 48 | public: 49 | HnCopySelectionDepthTask(pxr::HdSceneDelegate* ParamsDelegate, const pxr::SdfPath& Id); 50 | ~HnCopySelectionDepthTask(); 51 | 52 | virtual void Sync(pxr::HdSceneDelegate* Delegate, 53 | pxr::HdTaskContext* TaskCtx, 54 | pxr::HdDirtyBits* DirtyBits) override final; 55 | 56 | virtual void Prepare(pxr::HdTaskContext* TaskCtx, 57 | pxr::HdRenderIndex* RenderIndex) override final; 58 | 59 | 60 | virtual void Execute(pxr::HdTaskContext* TaskCtx) override final; 61 | 62 | private: 63 | pxr::HdRenderIndex* m_RenderIndex = nullptr; 64 | }; 65 | 66 | } // namespace USD 67 | 68 | } // namespace Diligent 69 | -------------------------------------------------------------------------------- /Hydrogent/shaders/HnUpdateClosestSelectedLocation.psh: -------------------------------------------------------------------------------- 1 | #include "HnClosestSelectedLocation.fxh" 2 | #include "FullScreenTriangleVSOutput.fxh" 3 | 4 | cbuffer cbConstants 5 | { 6 | ClosestSelectedLocationConstants g_Constants; 7 | } 8 | 9 | Texture2D g_SrcClosestLocation; 10 | 11 | void UpdateClosestLocation(in float2 CurrentLocation, 12 | in float2 Offset, 13 | inout float2 ClosestLocation, 14 | inout bool IsLocationValid, 15 | inout float ClosestDistance) 16 | { 17 | float2 TestSelectedLocation; 18 | if (!DecodeClosestSelectedLocation(g_SrcClosestLocation.Load(int3(CurrentLocation + Offset * g_Constants.SampleRange, 0)).xy, TestSelectedLocation)) 19 | return; 20 | 21 | float Width; 22 | float Height; 23 | g_SrcClosestLocation.GetDimensions(Width, Height); 24 | float2 Dir = TestSelectedLocation * float2(Width, Height) - CurrentLocation; 25 | float DistSqr = dot(Dir, Dir); 26 | if (DistSqr < ClosestDistance) 27 | { 28 | ClosestDistance = DistSqr; 29 | ClosestLocation = TestSelectedLocation; 30 | IsLocationValid = true; 31 | } 32 | } 33 | 34 | void main(in FullScreenTriangleVSOutput VSOut, 35 | out float2 Location : SV_Target0) 36 | { 37 | float2 ClosestLocation = float2(0.0, 0.0); 38 | bool IsLocationValid = false; 39 | float ClosestDistance = 1e+10; 40 | 41 | float2 Pos = VSOut.f4PixelPos.xy; 42 | 43 | UpdateClosestLocation(Pos, float2(-1.0, -1.0), ClosestLocation, IsLocationValid, ClosestDistance); 44 | UpdateClosestLocation(Pos, float2( 0.0, -1.0), ClosestLocation, IsLocationValid, ClosestDistance); 45 | UpdateClosestLocation(Pos, float2(+1.0, -1.0), ClosestLocation, IsLocationValid, ClosestDistance); 46 | 47 | UpdateClosestLocation(Pos, float2(-1.0, 0.0), ClosestLocation, IsLocationValid, ClosestDistance); 48 | UpdateClosestLocation(Pos, float2( 0.0, 0.0), ClosestLocation, IsLocationValid, ClosestDistance); 49 | UpdateClosestLocation(Pos, float2(+1.0, 0.0), ClosestLocation, IsLocationValid, ClosestDistance); 50 | 51 | UpdateClosestLocation(Pos, float2(-1.0, +1.0), ClosestLocation, IsLocationValid, ClosestDistance); 52 | UpdateClosestLocation(Pos, float2( 0.0, +1.0), ClosestLocation, IsLocationValid, ClosestDistance); 53 | UpdateClosestLocation(Pos, float2(+1.0, +1.0), ClosestLocation, IsLocationValid, ClosestDistance); 54 | 55 | Location = EncodeClosestSelectedLocation(ClosestLocation, IsLocationValid); 56 | } 57 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/RenderSampling.fx: -------------------------------------------------------------------------------- 1 | #include "AtmosphereShadersCommon.fxh" 2 | 3 | cbuffer cbPostProcessingAttribs 4 | { 5 | EpipolarLightScatteringAttribs g_PPAttribs; 6 | }; 7 | 8 | Texture2D g_tex2DCoordinates; 9 | Texture2D g_tex2DInterpolationSource; 10 | 11 | struct VSOutput 12 | { 13 | float3 f3Color : COLOR; 14 | float2 f2PosXY : XY; 15 | float4 f4QuadCenterAndSize : QUAD_CENTER_SIZE; 16 | }; 17 | 18 | void RenderSampleLocationsVS(in uint VertexID : SV_VertexID, 19 | in uint InstID : SV_InstanceID, 20 | out VSOutput VSOut, 21 | // IMPORTANT: non-system generated pixel shader input 22 | // arguments must have the exact same name as vertex shader 23 | // outputs and must go in the same order. 24 | // Moreover, even if the shader is not using the argument, 25 | // it still must be declared. 26 | 27 | out float4 f4PosPS : SV_Position) 28 | { 29 | uint2 CoordTexDim; 30 | g_tex2DCoordinates.GetDimensions(CoordTexDim.x, CoordTexDim.y); 31 | uint2 TexelIJ = uint2( InstID%CoordTexDim.x, InstID/CoordTexDim.x ); 32 | float2 f2QuadCenterPos = g_tex2DCoordinates.Load(int3(TexelIJ,0)); 33 | 34 | uint2 ui2InterpolationSources = g_tex2DInterpolationSource.Load( int3(TexelIJ,0) ); 35 | bool bIsInterpolation = ui2InterpolationSources.x != ui2InterpolationSources.y; 36 | 37 | float2 f2QuadSize = (bIsInterpolation ? 2.0 : 4.0) * g_PPAttribs.f4ScreenResolution.zw; 38 | float4 MinMaxUV = float4(f2QuadCenterPos.x-f2QuadSize.x, f2QuadCenterPos.y - f2QuadSize.y, f2QuadCenterPos.x+f2QuadSize.x, f2QuadCenterPos.y + f2QuadSize.y); 39 | 40 | float3 f3Color = bIsInterpolation ? float3(0.5,0.0,0.0) : float3(1.0,0.0,0.0); 41 | float4 Verts[4]; 42 | Verts[0] = float4(MinMaxUV.xy, 1.0, 1.0); 43 | Verts[1] = float4(MinMaxUV.xw, 1.0, 1.0); 44 | Verts[2] = float4(MinMaxUV.zy, 1.0, 1.0); 45 | Verts[3] = float4(MinMaxUV.zw, 1.0, 1.0); 46 | 47 | f4PosPS = Verts[VertexID]; 48 | VSOut.f2PosXY = Verts[VertexID].xy; 49 | VSOut.f3Color = f3Color; 50 | VSOut.f4QuadCenterAndSize = float4(f2QuadCenterPos, f2QuadSize); 51 | } 52 | 53 | 54 | void RenderSampleLocationsPS(in VSOutput VSOut, 55 | out float4 f4Color : SV_Target) 56 | { 57 | f4Color = float4(VSOut.f3Color, 1.0 - pow( length( (VSOut.f2PosXY - VSOut.f4QuadCenterAndSize.xy) / VSOut.f4QuadCenterAndSize.zw),4.0) ); 58 | } 59 | -------------------------------------------------------------------------------- /Hydrogent/interface/HnCamera.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023-2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "pxr/imaging/hd/camera.h" 30 | 31 | #include "../../../../DiligentCore/Common/interface/BasicMath.hpp" 32 | 33 | namespace Diligent 34 | { 35 | 36 | namespace USD 37 | { 38 | 39 | /// Camera implementation in Hydrogent. 40 | class HnCamera final : public pxr::HdCamera 41 | { 42 | public: 43 | static HnCamera* Create(const pxr::SdfPath& Id); 44 | 45 | ~HnCamera(); 46 | 47 | void Sync(pxr::HdSceneDelegate* SceneDelegate, 48 | pxr::HdRenderParam* RenderParam, 49 | pxr::HdDirtyBits* DirtyBits) override final; 50 | 51 | const float4x4& GetViewMatrix() const { return m_ViewMatrix; } 52 | const float4x4& GetWorldMatrix() const { return m_WorldMatrix; } 53 | float4x4 GetProjectionMatrix(bool UseReverseDepth, const float2& Jitter) const; 54 | 55 | private: 56 | HnCamera(const pxr::SdfPath& Id); 57 | 58 | private: 59 | float4x4 m_ViewMatrix; 60 | float4x4 m_WorldMatrix; 61 | float4x4 m_ProjectionMatrix; 62 | 63 | bool m_NegativeOneToOneNDCZ = false; 64 | pxr::GfRange1f m_ClippingRangeMeters{}; 65 | }; 66 | 67 | } // namespace USD 68 | 69 | } // namespace Diligent 70 | -------------------------------------------------------------------------------- /Shaders/PostProcess/ScreenSpaceReflection/private/SSR_ComputeDownsampledStencilMask.fx: -------------------------------------------------------------------------------- 1 | #include "ScreenSpaceReflectionStructures.fxh" 2 | #include "SSR_Common.fxh" 3 | #include "FullScreenTriangleVSOutput.fxh" 4 | 5 | cbuffer cbScreenSpaceReflectionAttribs 6 | { 7 | ScreenSpaceReflectionAttribs g_SSRAttribs; 8 | } 9 | 10 | Texture2D g_TextureRoughness; 11 | Texture2D g_TextureDepth; 12 | 13 | void UpdateClosestDepthAndMaxRoughness(int2 Location, int2 Dimension, inout float MinDepth, inout float MaxRoughness) 14 | { 15 | Location = ClampScreenCoord(Location, Dimension); 16 | 17 | float Depth = g_TextureDepth.Load(int3(Location, 0)); 18 | float Roughness = g_TextureRoughness.Load(int3(Location, 0)); 19 | 20 | MinDepth = ClosestDepth(MinDepth, Depth); 21 | MaxRoughness = max(MaxRoughness, Roughness); 22 | } 23 | 24 | void ComputeDownsampledStencilMaskPS(in FullScreenTriangleVSOutput VSOut) 25 | { 26 | int2 RemappedPosition = int2(2.0 * floor(VSOut.f4PixelPos.xy)); 27 | 28 | int2 TextureDimension; 29 | g_TextureDepth.GetDimensions(TextureDimension.x, TextureDimension.y); 30 | 31 | float MinDepth = DepthFarPlane; 32 | float MaxRoughness = 0.0f; 33 | 34 | UpdateClosestDepthAndMaxRoughness(RemappedPosition + int2(0, 0), TextureDimension, MinDepth, MaxRoughness); 35 | UpdateClosestDepthAndMaxRoughness(RemappedPosition + int2(1, 0), TextureDimension, MinDepth, MaxRoughness); 36 | UpdateClosestDepthAndMaxRoughness(RemappedPosition + int2(0, 1), TextureDimension, MinDepth, MaxRoughness); 37 | UpdateClosestDepthAndMaxRoughness(RemappedPosition + int2(1, 1), TextureDimension, MinDepth, MaxRoughness); 38 | 39 | bool IsWidthOdd = (TextureDimension.x & 1) != 0; 40 | bool IsHeightOdd = (TextureDimension.y & 1) != 0; 41 | 42 | if (IsWidthOdd) 43 | { 44 | UpdateClosestDepthAndMaxRoughness(RemappedPosition + int2(2, 0), TextureDimension, MinDepth, MaxRoughness); 45 | UpdateClosestDepthAndMaxRoughness(RemappedPosition + int2(2, 1), TextureDimension, MinDepth, MaxRoughness); 46 | } 47 | 48 | if (IsHeightOdd) 49 | { 50 | UpdateClosestDepthAndMaxRoughness(RemappedPosition + int2(0, 2), TextureDimension, MinDepth, MaxRoughness); 51 | UpdateClosestDepthAndMaxRoughness(RemappedPosition + int2(1, 2), TextureDimension, MinDepth, MaxRoughness); 52 | } 53 | 54 | if (IsWidthOdd && IsHeightOdd) 55 | { 56 | UpdateClosestDepthAndMaxRoughness(RemappedPosition + int2(2, 2), TextureDimension, MinDepth, MaxRoughness); 57 | } 58 | 59 | if (!IsReflectionSample(MaxRoughness, MinDepth, g_SSRAttribs.RoughnessThreshold)) 60 | discard; 61 | } 62 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/precompute/PrecomputeAmbientSkyLight.fx: -------------------------------------------------------------------------------- 1 | #include "AtmosphereShadersCommon.fxh" 2 | 3 | cbuffer cbParticipatingMediaScatteringParams 4 | { 5 | AirScatteringAttribs g_MediaParams; 6 | } 7 | 8 | #include "LookUpTables.fxh" 9 | 10 | Texture2D g_tex2DSphereRandomSampling; 11 | 12 | Texture3D g_tex3DMultipleSctrLUT; 13 | SamplerState g_tex3DMultipleSctrLUT_sampler; 14 | 15 | 16 | void PrecomputeAmbientSkyLightPS(FullScreenTriangleVSOutput VSOut, 17 | // IMPORTANT: non-system generated pixel shader input 18 | // arguments must have the exact same name as vertex shader 19 | // outputs and must go in the same order. 20 | 21 | out float4 f4SkyLight : SV_Target) 22 | { 23 | float fU = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY).x; 24 | float3 f3RayStart = float3(0.0, 20.0, 0.0); 25 | float3 f3EarthCentre = float3(0.0, -g_MediaParams.fEarthRadius, 0.0); 26 | float fCosZenithAngle = clamp(fU * 2.0 - 1.0, -1.0, +1.0); 27 | float3 f3DirOnLight = float3(sqrt(saturate(1.0 - fCosZenithAngle*fCosZenithAngle)), fCosZenithAngle, 0.0); 28 | f4SkyLight = float4(0.0, 0.0, 0.0, 0.0); 29 | // Go through a number of random directions on the sphere 30 | for(int iSample = 0; iSample < NUM_RANDOM_SPHERE_SAMPLES; ++iSample) 31 | { 32 | // Get random direction 33 | float3 f3RandomDir = normalize( g_tex2DSphereRandomSampling.Load(int3(iSample,0,0)) ); 34 | // Reflect directions from the lower hemisphere 35 | f3RandomDir.y = abs(f3RandomDir.y); 36 | // Get multiple scattered light radiance when looking in direction f3RandomDir (the light thus goes in direction -f3RandomDir) 37 | float4 f4UVWQ = float4(-1.0, -1.0, -1.0, -1.0); 38 | float3 f3Sctr = LookUpPrecomputedScattering( 39 | f3RayStart, 40 | f3RandomDir, 41 | f3EarthCentre, 42 | g_MediaParams.fEarthRadius, 43 | f3DirOnLight.xyz, 44 | g_MediaParams.fAtmBottomAltitude, 45 | g_MediaParams.fAtmTopAltitude, 46 | g_tex3DMultipleSctrLUT, 47 | g_tex3DMultipleSctrLUT_sampler, 48 | f4UVWQ); 49 | // Accumulate ambient irradiance through the horizontal plane 50 | f4SkyLight.rgb += f3Sctr * dot(f3RandomDir, float3(0.0, 1.0, 0.0)); 51 | } 52 | // Each sample covers 2 * PI / NUM_RANDOM_SPHERE_SAMPLES solid angle (integration is performed over 53 | // upper hemisphere) 54 | f4SkyLight.rgb *= 2.0 * PI / float(NUM_RANDOM_SPHERE_SAMPLES); 55 | } 56 | -------------------------------------------------------------------------------- /.github/workflows/build-linux.yml: -------------------------------------------------------------------------------- 1 | name: Linux build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | precheks: 7 | name: Linux -> Pre-checks 8 | runs-on: ubuntu-24.04 9 | 10 | steps: 11 | - name: Clone DiligentCore 12 | uses: actions/checkout@v4 13 | with: 14 | repository: DiligentGraphics/DiligentCore 15 | path: DiligentCore 16 | 17 | - name: Clone DiligentFX 18 | uses: actions/checkout@v4 19 | with: 20 | path: DiligentFX 21 | 22 | - name: Format validation 23 | shell: bash 24 | working-directory: ${{github.workspace}}/DiligentFX/BuildTools/FormatValidation 25 | run: ./validate_format_linux.sh 26 | 27 | - name: Codespell 28 | uses: codespell-project/actions-codespell@master 29 | with: 30 | check_filenames: true 31 | ignore_words_file: ./DiligentFX/.github/.codespellignore 32 | skip: ./DiligentFX/.git,./DiligentFX/ThirdParty 33 | path: ./DiligentFX 34 | 35 | 36 | build: 37 | needs: precheks 38 | runs-on: ubuntu-24.04 39 | 40 | strategy: 41 | matrix: 42 | name: ["GCC", "Clang"] 43 | build_type: ["Debug", "Release"] 44 | # Do not build GLSLang and friends to save time as it is built by Core and Engine CI. 45 | cmake_args: ["-DDILIGENT_NO_GLSLANG=ON -DDILIGENT_NO_HLSL=ON -DDILIGENT_BUILD_FX_INCLUDE_TEST=ON"] 46 | include: 47 | - name: "GCC" 48 | cmake_generator: "Unix Makefiles" 49 | cc: "gcc-14" 50 | cxx: "g++-14" 51 | 52 | - name: "Clang" 53 | cmake_generator: "Ninja" 54 | cc: "clang-18" 55 | cxx: "clang++-18" 56 | 57 | name: Linux -> ${{ matrix.name }}-x64, ${{ matrix.build_type }} 58 | 59 | steps: 60 | - name: Checkout 61 | uses: DiligentGraphics/github-action/checkout@v9 62 | 63 | - name: Set up build environment 64 | if: success() 65 | uses: DiligentGraphics/github-action/setup-build-env@v9 66 | with: 67 | platform: Linux 68 | cmake-generator: ${{ matrix.cmake_generator }} 69 | 70 | - name: Configure CMake 71 | if: success() 72 | uses: DiligentGraphics/github-action/configure-cmake@v9 73 | with: 74 | cc: ${{ matrix.cc }} 75 | cxx: ${{ matrix.cxx }} 76 | generator: ${{ matrix.cmake_generator }} 77 | build-type: ${{ matrix.build_type }} 78 | cmake-args: ${{ matrix.cmake_args }} 79 | 80 | - name: Build 81 | if: success() 82 | uses: DiligentGraphics/github-action/build@v9 83 | -------------------------------------------------------------------------------- /Hydrogent/interface/Tasks/HnBeginMainPassTask.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "HnTask.hpp" 30 | 31 | namespace Diligent 32 | { 33 | 34 | namespace USD 35 | { 36 | 37 | struct HnBeginMainPassTaskParams 38 | { 39 | constexpr bool operator==(const HnBeginMainPassTaskParams& rhs) const 40 | { 41 | return true; 42 | } 43 | constexpr bool operator!=(const HnBeginMainPassTaskParams& rhs) const 44 | { 45 | return !(*this == rhs); 46 | } 47 | }; 48 | 49 | /// Prepares rendering state for the main render pass: 50 | /// - Binds and clears render targets and the depth buffer 51 | class HnBeginMainPassTask final : public HnTask 52 | { 53 | public: 54 | HnBeginMainPassTask(pxr::HdSceneDelegate* ParamsDelegate, const pxr::SdfPath& Id); 55 | ~HnBeginMainPassTask(); 56 | 57 | virtual void Sync(pxr::HdSceneDelegate* Delegate, 58 | pxr::HdTaskContext* TaskCtx, 59 | pxr::HdDirtyBits* DirtyBits) override final; 60 | 61 | virtual void Prepare(pxr::HdTaskContext* TaskCtx, 62 | pxr::HdRenderIndex* RenderIndex) override final; 63 | 64 | virtual void Execute(pxr::HdTaskContext* TaskCtx) override final; 65 | 66 | private: 67 | pxr::HdRenderIndex* m_RenderIndex = nullptr; 68 | }; 69 | 70 | } // namespace USD 71 | 72 | } // namespace Diligent 73 | -------------------------------------------------------------------------------- /Hydrogent/include/HnShadowMapManager.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include "RenderDevice.h" 32 | #include "DeviceContext.h" 33 | #include "RefCntAutoPtr.hpp" 34 | 35 | namespace Diligent 36 | { 37 | 38 | struct IDynamicTextureAtlas; 39 | struct ITextureAtlasSuballocation; 40 | 41 | namespace USD 42 | { 43 | 44 | class HnShadowMapManager final 45 | { 46 | public: 47 | struct CreateInfo 48 | { 49 | Uint32 AtlasDim = 2048; 50 | TEXTURE_FORMAT Format = TEX_FORMAT_D32_FLOAT; 51 | }; 52 | HnShadowMapManager(const CreateInfo& CI); 53 | 54 | RefCntAutoPtr Allocate(Uint32 Width, Uint32 Height); 55 | 56 | /// Commit the shadow map atlas and returns the atlas version. 57 | void Commit(IRenderDevice* pDevice, IDeviceContext* pCtx); 58 | 59 | Uint32 GetAtlasVersion() const; 60 | 61 | const TextureDesc& GetAtlasDesc() const; 62 | 63 | ITexture* GetShadowTexture() const; 64 | ITextureView* GetShadowDSV(Uint32 Slice) const { return m_DSVs[Slice]; } 65 | ITextureView* GetShadowSRV() const; 66 | 67 | private: 68 | RefCntAutoPtr m_ShadowMapAtlas; 69 | 70 | Uint32 m_AtlasVersion = ~0u; 71 | 72 | std::vector> m_DSVs; 73 | }; 74 | 75 | } // namespace USD 76 | 77 | } // namespace Diligent 78 | -------------------------------------------------------------------------------- /Shaders/PostProcess/SuperResolution/private/fsr1/ffx_core.h: -------------------------------------------------------------------------------- 1 | // This file is part of the FidelityFX SDK. 2 | // 3 | // Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | 23 | /// @defgroup FfxGPU GPU 24 | /// The FidelityFX SDK GPU References 25 | /// 26 | /// @ingroup ffxSDK 27 | 28 | /// @defgroup FfxHLSL HLSL References 29 | /// FidelityFX SDK HLSL GPU References 30 | /// 31 | /// @ingroup FfxGPU 32 | 33 | /// @defgroup FfxGLSL GLSL References 34 | /// FidelityFX SDK GLSL GPU References 35 | /// 36 | /// @ingroup FfxGPU 37 | 38 | /// @defgroup FfxGPUEffects FidelityFX GPU References 39 | /// FidelityFX Effect GPU Reference Documentation 40 | /// 41 | /// @ingroup FfxGPU 42 | 43 | /// @defgroup GPUCore GPU Core 44 | /// GPU defines and functions 45 | /// 46 | /// @ingroup FfxGPU 47 | 48 | #if !defined(FFX_CORE_H) 49 | #define FFX_CORE_H 50 | 51 | #ifdef __hlsl_dx_compiler 52 | #pragma dxc diagnostic push 53 | #pragma dxc diagnostic ignored "-Wambig-lit-shift" 54 | #endif //__hlsl_dx_compiler 55 | 56 | #include "ffx_common_types.h" 57 | 58 | #if defined(FFX_GLSL) && defined(FFX_GPU) 59 | #include "ffx_core_glsl.h" 60 | #endif // #if defined(FFX_GLSL) && defined(FFX_GPU) 61 | 62 | #if defined(FFX_HLSL) && defined(FFX_GPU) 63 | #include "ffx_core_hlsl.h" 64 | #endif // #if defined(FFX_HLSL) && defined(FFX_GPU) 65 | 66 | #if defined(FFX_GPU) 67 | #include "ffx_core_gpu_common.h" 68 | #include "ffx_core_gpu_common_half.h" 69 | #include "ffx_core_portability.h" 70 | #endif // #if defined(FFX_GPU) 71 | 72 | #ifdef __hlsl_dx_compiler 73 | #pragma dxc diagnostic pop 74 | #endif //__hlsl_dx_compiler 75 | 76 | #endif // #if !defined(FFX_CORE_H) 77 | -------------------------------------------------------------------------------- /Shaders/PostProcess/ScreenSpaceReflection/private/SSR_ComputeHierarchicalDepthBuffer.fx: -------------------------------------------------------------------------------- 1 | #include "SSR_Common.fxh" 2 | #include "FullScreenTriangleVSOutput.fxh" 3 | 4 | #if SUPPORTED_SHADER_SRV 5 | Texture2D g_TextureLastMip; 6 | #else 7 | Texture2D g_TextureMips; 8 | #endif 9 | 10 | #if SUPPORTED_SHADER_SRV 11 | float LoadDepth(int2 Location, int3 Dimension) 12 | { 13 | int2 Position = ClampScreenCoord(Location, Dimension.xy); 14 | return g_TextureLastMip.Load(int3(Position, 0)); 15 | } 16 | #else 17 | float LoadDepth(int2 Location, int3 Dimension) 18 | { 19 | int2 Position = ClampScreenCoord(Location, Dimension.xy); 20 | return g_TextureMips.Load(int3(Position, Dimension.z)); 21 | } 22 | #endif 23 | 24 | void UpdateClosestDepth(int2 Location, int3 LastMipDimension, inout float MinDepth) 25 | { 26 | float Depth = LoadDepth(Location, LastMipDimension); 27 | MinDepth = ClosestDepth(MinDepth, Depth); 28 | } 29 | 30 | float ComputeHierarchicalDepthBufferPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 31 | { 32 | int3 LastMipDimension; 33 | #if SUPPORTED_SHADER_SRV 34 | g_TextureLastMip.GetDimensions(LastMipDimension.x, LastMipDimension.y); 35 | LastMipDimension.z = 0; // Unused 36 | #else 37 | int Dummy; 38 | g_TextureMips.GetDimensions(0, LastMipDimension.x, LastMipDimension.y, Dummy); 39 | LastMipDimension.x = int(floor(float(LastMipDimension.x) / exp2(float(VSOut.uInstID)))); 40 | LastMipDimension.y = int(floor(float(LastMipDimension.y) / exp2(float(VSOut.uInstID)))); 41 | LastMipDimension.z = int(VSOut.uInstID); 42 | #endif 43 | 44 | int2 RemappedPosition = int2(2.0 * floor(VSOut.f4PixelPos.xy)); 45 | 46 | float MinDepth = DepthFarPlane; 47 | UpdateClosestDepth(RemappedPosition + int2(0, 0), LastMipDimension, MinDepth); 48 | UpdateClosestDepth(RemappedPosition + int2(0, 1), LastMipDimension, MinDepth); 49 | UpdateClosestDepth(RemappedPosition + int2(1, 0), LastMipDimension, MinDepth); 50 | UpdateClosestDepth(RemappedPosition + int2(1, 1), LastMipDimension, MinDepth); 51 | 52 | bool IsWidthOdd = (LastMipDimension.x & 1) != 0; 53 | bool IsHeightOdd = (LastMipDimension.y & 1) != 0; 54 | 55 | if (IsWidthOdd) 56 | { 57 | UpdateClosestDepth(RemappedPosition + int2(2, 0), LastMipDimension, MinDepth); 58 | UpdateClosestDepth(RemappedPosition + int2(2, 1), LastMipDimension, MinDepth); 59 | } 60 | 61 | if (IsHeightOdd) 62 | { 63 | UpdateClosestDepth(RemappedPosition + int2(0, 2), LastMipDimension, MinDepth); 64 | UpdateClosestDepth(RemappedPosition + int2(1, 2), LastMipDimension, MinDepth); 65 | } 66 | 67 | if (IsWidthOdd && IsHeightOdd) 68 | { 69 | UpdateClosestDepth(RemappedPosition + int2(2, 2), LastMipDimension, MinDepth); 70 | } 71 | 72 | return MinDepth; 73 | } 74 | -------------------------------------------------------------------------------- /Hydrogent/interface/HnExtComputation.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include 31 | 32 | #include "pxr/imaging/hd/extComputation.h" 33 | #include "Computations/HnExtComputationImpl.hpp" 34 | #include "BasicTypes.h" 35 | 36 | namespace Diligent 37 | { 38 | 39 | namespace USD 40 | { 41 | 42 | /// External computation implementation in Hydrogent. 43 | class HnExtComputation final : public pxr::HdExtComputation 44 | { 45 | public: 46 | static HnExtComputation* Create(const pxr::SdfPath& Id); 47 | 48 | HnExtComputation(const pxr::SdfPath& Id); 49 | ~HnExtComputation(); 50 | 51 | // Synchronizes state from the delegate to this object. 52 | virtual void Sync(pxr::HdSceneDelegate* SceneDelegate, 53 | pxr::HdRenderParam* RenderParam, 54 | pxr::HdDirtyBits* DirtyBits) override final; 55 | 56 | Uint32 GetSceneInputsVersion() const 57 | { 58 | return m_SceneInputsVersion.load(); 59 | } 60 | 61 | template 62 | T* GetImpl() 63 | { 64 | return m_Impl ? m_Impl->As() : nullptr; 65 | } 66 | 67 | template 68 | const T* GetImpl() const 69 | { 70 | return m_Impl ? m_Impl->As() : nullptr; 71 | } 72 | 73 | private: 74 | std::unique_ptr m_Impl; 75 | 76 | std::atomic m_SceneInputsVersion{0}; 77 | }; 78 | 79 | } // namespace USD 80 | 81 | } // namespace Diligent 82 | -------------------------------------------------------------------------------- /Hydrogent/include/Computations/HnExtComputationImpl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include "pxr/imaging/hd/sceneDelegate.h" 32 | 33 | namespace Diligent 34 | { 35 | 36 | namespace USD 37 | { 38 | 39 | class HnExtComputation; 40 | 41 | class HnExtComputationImpl 42 | { 43 | public: 44 | enum class ImplType 45 | { 46 | Unknown, 47 | Skinning 48 | }; 49 | 50 | HnExtComputationImpl(HnExtComputation& Owner, ImplType Type); 51 | virtual ~HnExtComputationImpl(); 52 | 53 | ImplType GetType() const { return m_Type; } 54 | 55 | static ImplType GetType(const HnExtComputation& Owner); 56 | static std::unique_ptr Create(HnExtComputation& Owner); 57 | 58 | // Synchronizes state from the delegate to this object. 59 | virtual void Sync(pxr::HdSceneDelegate* SceneDelegate, 60 | pxr::HdRenderParam* RenderParam, 61 | pxr::HdDirtyBits* DirtyBits) = 0; 62 | 63 | template 64 | T* As() 65 | { 66 | return m_Type == T::Type ? static_cast(this) : nullptr; 67 | } 68 | 69 | template 70 | const T* As() const 71 | { 72 | return m_Type == T::Type ? static_cast(this) : nullptr; 73 | } 74 | 75 | protected: 76 | HnExtComputation& m_Owner; 77 | const ImplType m_Type; 78 | }; 79 | 80 | } // namespace USD 81 | 82 | } // namespace Diligent 83 | -------------------------------------------------------------------------------- /Hydrogent/interface/Tasks/HnRenderEnvMapTask.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023-2025 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include "HnTask.hpp" 32 | 33 | namespace Diligent 34 | { 35 | 36 | class EnvMapRenderer; 37 | 38 | namespace USD 39 | { 40 | 41 | struct HnRenderEnvMapTaskParams 42 | { 43 | constexpr bool operator==(const HnRenderEnvMapTaskParams& rhs) const 44 | { 45 | return true; 46 | } 47 | constexpr bool operator!=(const HnRenderEnvMapTaskParams& rhs) const 48 | { 49 | return !(*this == rhs); 50 | } 51 | }; 52 | 53 | /// Renders the environment map. 54 | class HnRenderEnvMapTask final : public HnTask 55 | { 56 | public: 57 | HnRenderEnvMapTask(pxr::HdSceneDelegate* ParamsDelegate, const pxr::SdfPath& Id); 58 | ~HnRenderEnvMapTask(); 59 | 60 | virtual void Sync(pxr::HdSceneDelegate* Delegate, 61 | pxr::HdTaskContext* TaskCtx, 62 | pxr::HdDirtyBits* DirtyBits) override final; 63 | 64 | virtual void Prepare(pxr::HdTaskContext* TaskCtx, 65 | pxr::HdRenderIndex* RenderIndex) override final; 66 | 67 | 68 | virtual void Execute(pxr::HdTaskContext* TaskCtx) override final; 69 | 70 | virtual bool IsActive(pxr::HdRenderIndex& RenderIndex) const override final; 71 | 72 | private: 73 | pxr::TfToken m_RenderPassName; 74 | 75 | std::unique_ptr m_EnvMapRenderer; 76 | 77 | pxr::HdRenderIndex* m_RenderIndex = nullptr; 78 | }; 79 | 80 | } // namespace USD 81 | 82 | } // namespace Diligent 83 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/InitializeMinMaxShadowMap.fx: -------------------------------------------------------------------------------- 1 | #include "AtmosphereShadersCommon.fxh" 2 | 3 | Texture2D g_tex2DSliceUVDirAndOrigin; 4 | 5 | Texture2DArray g_tex2DLightSpaceDepthMap; 6 | SamplerState g_tex2DLightSpaceDepthMap_sampler; 7 | 8 | #if USE_COMBINED_MIN_MAX_TEXTURE 9 | cbuffer cbPostProcessingAttribs 10 | { 11 | EpipolarLightScatteringAttribs g_PPAttribs; 12 | } 13 | #else 14 | cbuffer cbMiscDynamicParams 15 | { 16 | MiscDynamicParams g_MiscParams; 17 | } 18 | #endif 19 | 20 | // Note that min/max shadow map does not contain finest resolution level 21 | // The first level it contains corresponds to step == 2 22 | void InitializeMinMaxShadowMapPS(in FullScreenTriangleVSOutput VSOut, 23 | out float2 f2MinMaxDepth : SV_Target) 24 | { 25 | uint uiSliceInd; 26 | float fCascadeInd; 27 | #if USE_COMBINED_MIN_MAX_TEXTURE 28 | fCascadeInd = floor(VSOut.f4PixelPos.y / float(g_PPAttribs.uiNumEpipolarSlices)); 29 | uiSliceInd = uint(VSOut.f4PixelPos.y - fCascadeInd * float(g_PPAttribs.uiNumEpipolarSlices)); 30 | fCascadeInd += g_PPAttribs.fFirstCascadeToRayMarch; 31 | #else 32 | uiSliceInd = uint(VSOut.f4PixelPos.y); 33 | fCascadeInd = g_MiscParams.fCascadeInd; 34 | #endif 35 | // Load slice direction in shadow map 36 | float4 f4SliceUVDirAndOrigin = g_tex2DSliceUVDirAndOrigin.Load( uint3(uiSliceInd, fCascadeInd, 0) ); 37 | // Calculate current sample position on the ray 38 | float2 f2CurrUV = f4SliceUVDirAndOrigin.zw + f4SliceUVDirAndOrigin.xy * floor(VSOut.f4PixelPos.x) * 2.f; 39 | 40 | float4 f4MinDepth = float4(1.0, 1.0, 1.0, 1.0); 41 | float4 f4MaxDepth = float4(0.0, 0.0, 0.0, 0.0); 42 | // Gather 8 depths which will be used for PCF filtering for this sample and its immediate neighbor 43 | // along the epipolar slice 44 | // Note that if the sample is located outside the shadow map, Gather() will return 0 as 45 | // specified by the samLinearBorder0. As a result volumes outside the shadow map will always be lit 46 | for( float i=0.0; i<=1.0; ++i ) 47 | { 48 | float4 f4Depths = g_tex2DLightSpaceDepthMap.Gather(g_tex2DLightSpaceDepthMap_sampler, float3(f2CurrUV + i * f4SliceUVDirAndOrigin.xy, fCascadeInd) ); 49 | f4MinDepth = min(f4MinDepth, f4Depths); 50 | f4MaxDepth = max(f4MaxDepth, f4Depths); 51 | } 52 | 53 | f4MinDepth.xy = min(f4MinDepth.xy, f4MinDepth.zw); 54 | f4MinDepth.x = min(f4MinDepth.x, f4MinDepth.y); 55 | 56 | f4MaxDepth.xy = max(f4MaxDepth.xy, f4MaxDepth.zw); 57 | f4MaxDepth.x = max(f4MaxDepth.x, f4MaxDepth.y); 58 | #if !IS_32BIT_MIN_MAX_MAP 59 | const float R16_UNORM_PRECISION = 1.0 / float(1<<16); 60 | f4MinDepth.x = floor(f4MinDepth.x/R16_UNORM_PRECISION)*R16_UNORM_PRECISION; 61 | f4MaxDepth.x = ceil(f4MaxDepth.x/R16_UNORM_PRECISION)*R16_UNORM_PRECISION; 62 | #endif 63 | f2MinMaxDepth = float2(f4MinDepth.x, f4MaxDepth.x); 64 | } 65 | -------------------------------------------------------------------------------- /Shaders/Shadows/private/ShadowConversions.fx: -------------------------------------------------------------------------------- 1 | 2 | #include "FullScreenTriangleVSOutput.fxh" 3 | #include "BasicStructures.fxh" 4 | #include "Shadows.fxh" 5 | 6 | struct ConversionAttribs 7 | { 8 | int iCascade; 9 | float fHorzFilterRadius; 10 | float fVertFilterRadius; 11 | float fEVSMPositiveExponent; 12 | 13 | float fEVSMNegativeExponent; 14 | bool Is32BitEVSM; 15 | }; 16 | 17 | cbuffer cbConversionAttribs 18 | { 19 | ConversionAttribs g_Attribs; 20 | } 21 | 22 | Texture2DArray g_tex2DShadowMap; 23 | 24 | float GetSampleWeight(int x, float FilterRadius) 25 | { 26 | float fTexelMin = max(float(x), min(0.5 - FilterRadius, 0.0)); 27 | float fTexelMax = min(float(x) + 1.0, max(0.5 + FilterRadius, 1.0)); 28 | return fTexelMax - fTexelMin; 29 | } 30 | 31 | float4 VSMHorzPS(FullScreenTriangleVSOutput VSOut) : SV_Target 32 | { 33 | float2 f2Moments = float2(0.0, 0.0); 34 | int range = int(floor(g_Attribs.fHorzFilterRadius + 0.5)); 35 | float fTotalWeight = 0.0; 36 | for (int i = -range; i <= +range; ++i) 37 | { 38 | float fWeight = GetSampleWeight(i, g_Attribs.fHorzFilterRadius); 39 | float fDepth = g_tex2DShadowMap.Load( int4( int(VSOut.f4PixelPos.x) + i, int(VSOut.f4PixelPos.y), g_Attribs.iCascade, 0) ).r; 40 | f2Moments += float2(fDepth, fDepth*fDepth) * fWeight; 41 | fTotalWeight += fWeight; 42 | } 43 | return float4(f2Moments / fTotalWeight, 0.0, 0.0); 44 | } 45 | 46 | float4 EVSMHorzPS(FullScreenTriangleVSOutput VSOut) : SV_Target 47 | { 48 | float2 f2Exponents = GetEVSMExponents(g_Attribs.fEVSMPositiveExponent, g_Attribs.fEVSMNegativeExponent, g_Attribs.Is32BitEVSM); 49 | 50 | float4 f4Moments = float4(0.0, 0.0, 0.0, 0.0); 51 | int range = int(floor(g_Attribs.fHorzFilterRadius + 0.5)); 52 | float fTotalWeight = 0.0; 53 | for (int i = -range; i <= +range; ++i) 54 | { 55 | float fWeight = GetSampleWeight(i, g_Attribs.fHorzFilterRadius); 56 | float fDepth = g_tex2DShadowMap.Load( int4( int(VSOut.f4PixelPos.x) + i, int(VSOut.f4PixelPos.y), g_Attribs.iCascade, 0) ).r; 57 | float2 f2EVSMDepth = WarpDepthEVSM(fDepth, f2Exponents); 58 | f4Moments += float4(f2EVSMDepth.x, f2EVSMDepth.x*f2EVSMDepth.x, f2EVSMDepth.y, f2EVSMDepth.y*f2EVSMDepth.y) * fWeight; 59 | fTotalWeight += fWeight; 60 | } 61 | return f4Moments / fTotalWeight; 62 | } 63 | 64 | float4 VertBlurPS(FullScreenTriangleVSOutput VSOut) : SV_Target 65 | { 66 | float4 f4Moments = float4(0.0, 0.0, 0.0, 0.0); 67 | int range = int(floor(g_Attribs.fVertFilterRadius + 0.5)); 68 | float fTotalWeight = 0.0; 69 | for (int i = -range; i <= +range; ++i) 70 | { 71 | float fWeight = GetSampleWeight(i, g_Attribs.fVertFilterRadius); 72 | f4Moments += g_tex2DShadowMap.Load( int4( int(VSOut.f4PixelPos.x), int(VSOut.f4PixelPos.y) + i, 0, 0) ) * fWeight; 73 | fTotalWeight += fWeight; 74 | } 75 | return f4Moments / fTotalWeight; 76 | } 77 | -------------------------------------------------------------------------------- /.github/workflows/msvc_analysis.yml: -------------------------------------------------------------------------------- 1 | name: MSVC Code Analysis 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | run-analysis: 7 | strategy: 8 | matrix: 9 | include: 10 | - host_name: "Win10" 11 | platform: "Win32" 12 | toolset: "x64" 13 | build_type: "Debug" 14 | # Only build Direct3D11 backend as Core libraries are analysed in the Core module 15 | cmake_args: "-DDILIGENT_NO_OPENGL=ON -DDILIGENT_NO_DIRECT3D12=ON -DDILIGENT_NO_VULKAN=ON" 16 | cmake_generator: "Visual Studio 17 2022" 17 | 18 | runs-on: windows-2022 19 | name: ${{ matrix.host_name }} -> MSVC Analysis, ${{ matrix.toolset }}, ${{ matrix.build_type }} 20 | 21 | permissions: 22 | # required for all workflows 23 | security-events: write 24 | # only required for workflows in private repositories 25 | actions: read 26 | contents: read 27 | 28 | steps: 29 | - name: Checkout 30 | uses: DiligentGraphics/github-action/checkout@v9 31 | 32 | - name: Set up build environment 33 | if: success() 34 | uses: DiligentGraphics/github-action/setup-build-env@v9 35 | with: 36 | platform: ${{ matrix.platform }} 37 | cmake-generator: ${{ matrix.cmake_generator }} 38 | 39 | - name: Configure CMake 40 | if: success() 41 | uses: DiligentGraphics/github-action/configure-cmake@v9 42 | with: 43 | generator: ${{ matrix.cmake_generator }} 44 | vs-arch: ${{ matrix.toolset }} 45 | build-type: ${{ matrix.build_type }} 46 | cmake-args: ${{ matrix.cmake_args }} 47 | 48 | - name: Build 49 | if: success() 50 | uses: DiligentGraphics/github-action/build@v9 51 | 52 | - name: Run MSVC Code Analysis 53 | uses: microsoft/msvc-code-analysis-action@v0.1.1 54 | # Provide a unique ID to access the sarif output path 55 | id: run-analysis 56 | with: 57 | cmakeBuildDirectory: ${{ env.DILIGENT_BUILD_DIR }} 58 | buildConfiguration: ${{ matrix.build_type }} 59 | # Ruleset file that will determine what checks will be run 60 | ruleset: NativeRecommendedRules.ruleset 61 | # Paths to ignore analysis of CMake targets and includes 62 | ignoredPaths: '${{ github.workspace }}/DiligentCore;${{ github.workspace }}/DiligentTools;${{ github.workspace }}/DiligentFX/ThirdParty' 63 | 64 | # Upload SARIF file to GitHub Code Scanning Alerts 65 | - name: Upload SARIF to GitHub 66 | uses: github/codeql-action/upload-sarif@v3 67 | with: 68 | sarif_file: ${{ steps.run-analysis.outputs.sarif }} 69 | checkout_path: ${{ github.workspace }}/DiligentFX 70 | 71 | # Upload SARIF file as an Artifact to download and view 72 | - name: Upload SARIF as an Artifact 73 | uses: actions/upload-artifact@v4 74 | with: 75 | name: sarif-file 76 | path: ${{ steps.run-analysis.outputs.sarif }} 77 | -------------------------------------------------------------------------------- /Shaders/PostProcess/EpipolarLightScattering/private/RenderCoordinateTexture.fx: -------------------------------------------------------------------------------- 1 | #include "AtmosphereShadersCommon.fxh" 2 | 3 | cbuffer cbPostProcessingAttribs 4 | { 5 | EpipolarLightScatteringAttribs g_PPAttribs; 6 | }; 7 | 8 | Texture2D g_tex2DCamSpaceZ; 9 | SamplerState g_tex2DCamSpaceZ_sampler; 10 | 11 | Texture2D g_tex2DSliceEndPoints; 12 | 13 | void GenerateCoordinateTexturePS(FullScreenTriangleVSOutput VSOut, 14 | // IMPORTANT: non-system generated pixel shader input 15 | // arguments must have the exact same name as vertex shader 16 | // outputs and must go in the same order. 17 | 18 | out float2 f2XY : SV_Target0, 19 | out float fCamSpaceZ : SV_Target1) 20 | 21 | { 22 | float4 f4SliceEndPoints = g_tex2DSliceEndPoints.Load( int3(VSOut.f4PixelPos.y,0,0) ); 23 | 24 | // If slice entry point is outside [-1,1]x[-1,1] area, the slice is completely invisible 25 | // and we can skip it from further processing. 26 | // Note that slice exit point can lie outside the screen, if sample locations are optimized 27 | if (!IsValidScreenLocation(f4SliceEndPoints.xy, g_PPAttribs.f4ScreenResolution)) 28 | { 29 | // Discard invalid slices 30 | // Such slices will not be marked in the stencil and as a result will always be skipped 31 | discard; 32 | } 33 | 34 | float2 f2UV = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY); 35 | 36 | // Note that due to the rasterization rules, UV coordinates are biased by 0.5 texel size. 37 | // 38 | // 0.5 1.5 2.5 3.5 39 | // | X | X | X | X | .... 40 | // 0 1 2 3 4 f2UV * f2TexDim 41 | // X - locations where rasterization happens 42 | // 43 | // We need remove this offset: 44 | float fSamplePosOnEpipolarLine = f2UV.x - 0.5 / float(g_PPAttribs.uiMaxSamplesInSlice); 45 | // fSamplePosOnEpipolarLine is now in the range [0, 1 - 1/MAX_SAMPLES_IN_SLICE] 46 | // We need to rescale it to be in [0, 1] 47 | fSamplePosOnEpipolarLine *= float(g_PPAttribs.uiMaxSamplesInSlice) / (float(g_PPAttribs.uiMaxSamplesInSlice)-1.0); 48 | fSamplePosOnEpipolarLine = saturate(fSamplePosOnEpipolarLine); 49 | 50 | // Compute interpolated position between entry and exit points: 51 | f2XY = lerp(f4SliceEndPoints.xy, f4SliceEndPoints.zw, fSamplePosOnEpipolarLine); 52 | if (!IsValidScreenLocation(f2XY, g_PPAttribs.f4ScreenResolution)) 53 | { 54 | // Discard pixels that fall behind the screen 55 | // This can happen if slice exit point was optimized 56 | discard; 57 | } 58 | 59 | // Compute camera space z for current location 60 | float2 f2ScreenSpaceUV = NormalizedDeviceXYToTexUV( f2XY ); 61 | fCamSpaceZ = g_tex2DCamSpaceZ.SampleLevel(g_tex2DCamSpaceZ_sampler, f2ScreenSpaceUV, 0); 62 | } 63 | -------------------------------------------------------------------------------- /Shaders/PostProcess/DepthOfField/private/DOF_ComputeTemporalCircleOfConfusion.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "DepthOfFieldStructures.fxh" 3 | #include "BasicStructures.fxh" 4 | #include "PostFX_Common.fxh" 5 | 6 | cbuffer cbCameraAttribs 7 | { 8 | CameraAttribs g_Camera; 9 | } 10 | 11 | cbuffer cbDepthOfFieldAttribs 12 | { 13 | DepthOfFieldAttribs g_DOFAttribs; 14 | } 15 | 16 | Texture2D g_TextureCurrCoC; 17 | Texture2D g_TexturePrevCoC; 18 | Texture2D g_TextureMotion; 19 | 20 | SamplerState g_TextureCurrCoC_sampler; 21 | SamplerState g_TexturePrevCoC_sampler; 22 | 23 | struct PixelStatistic 24 | { 25 | float Mean; 26 | float Variance; 27 | float StdDev; 28 | }; 29 | 30 | float SampleCoCCurr(int2 PixelCoord) 31 | { 32 | return g_TextureCurrCoC.Load(int3(PixelCoord, 0)); 33 | } 34 | 35 | float SampleCoCPrev(int2 PixelCoord) 36 | { 37 | return g_TexturePrevCoC.Load(int3(PixelCoord, 0)); 38 | } 39 | 40 | float SampleCoCPrevBilinear(float2 PixelCoord) 41 | { 42 | return g_TexturePrevCoC.SampleLevel(g_TexturePrevCoC_sampler, PixelCoord * g_Camera.f4ViewportSize.zw, 0.0); 43 | } 44 | 45 | float2 SampleMotion(int2 PixelCoord) 46 | { 47 | return g_TextureMotion.Load(int3(PixelCoord, 0)) * F3NDC_XYZ_TO_UVD_SCALE.xy; 48 | } 49 | 50 | PixelStatistic ComputePixelStatistic(float2 PixelCoord) 51 | { 52 | PixelStatistic Desc; 53 | float M1 = 0.0; 54 | float M2 = 0.0; 55 | 56 | const int StatisticRadius = 1; 57 | for (int x = -StatisticRadius; x <= StatisticRadius; x++) 58 | { 59 | for (int y = -StatisticRadius; y <= StatisticRadius; y++) 60 | { 61 | float2 Location = PixelCoord + float2(x, y); 62 | float CoC = g_TextureCurrCoC.SampleLevel(g_TextureCurrCoC_sampler, Location * g_Camera.f4ViewportSize.zw, 0.0); 63 | 64 | M1 += CoC; 65 | M2 += CoC * CoC; 66 | } 67 | } 68 | 69 | Desc.Mean = M1 / 9.0; 70 | Desc.Variance = (M2 / 9.0) - (Desc.Mean * Desc.Mean); 71 | Desc.StdDev = sqrt(max(Desc.Variance, 0.0f)); 72 | return Desc; 73 | } 74 | 75 | float ComputeTemporalCircleOfConfusionPS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 76 | { 77 | float2 Position = VSOut.f4PixelPos.xy; 78 | float2 Motion = SampleMotion(int2(Position.xy)); 79 | float2 PrevPosition = Position.xy - Motion * g_Camera.f4ViewportSize.xy; 80 | 81 | if (!IsInsideScreen(PrevPosition, g_Camera.f4ViewportSize.xy)) 82 | return SampleCoCCurr(int2(Position.xy)); 83 | 84 | float CoCCurr = SampleCoCCurr(int2(Position)); 85 | float CoCPrev = SampleCoCPrevBilinear(PrevPosition); 86 | 87 | PixelStatistic PixelStat = ComputePixelStatistic(Position); 88 | float CoCMin = PixelStat.Mean - DOF_TEMPORAL_VARIANCE_GAMMA * PixelStat.StdDev; 89 | float CoCMax = PixelStat.Mean + DOF_TEMPORAL_VARIANCE_GAMMA * PixelStat.StdDev; 90 | 91 | return lerp(CoCCurr, clamp(CoCPrev, CoCMin, CoCMax), g_DOFAttribs.TemporalStabilityFactor); 92 | } 93 | -------------------------------------------------------------------------------- /Shaders/PostProcess/TemporalAntiAliasing/public/TemporalAntiAliasingStructures.fxh: -------------------------------------------------------------------------------- 1 | #ifndef _TEMPORAL_ANTI_ALIASING_STRUCTURES_FXH_ 2 | #define _TEMPORAL_ANTI_ALIASING_STRUCTURES_FXH_ 3 | 4 | #ifndef __cplusplus 5 | # include "ShaderDefinitions.fxh" 6 | #elif !defined(_SHADER_DEFINITIONS_FXH_) 7 | # error "Include ShaderDefinitions.fxh before including this file" 8 | #endif 9 | 10 | 11 | // This parameter sets the minimum value for the variance gamma. 12 | // The variance gamma is used to adjust the influence of historical data in the anti-aliasing process. 13 | // A lower value means that the algorithm is less influenced by past frames, making it more responsive to changes but potentially less smooth 14 | #define TAA_MIN_VARIANCE_GAMMA 0.75 15 | 16 | // This parameter sets the maximum value for the variance gamma. 17 | // A higher maximum value allows the algorithm to rely more heavily on historical data, 18 | // which can produce smoother results but may also introduce more motion blur or ghosting effects in fast-moving scenes. 19 | #define TAA_MAX_VARIANCE_GAMMA 2.5 20 | 21 | // This parameter defines the threshold for pixel velocity difference that determines whether a pixel is considered to have "no history." 22 | // If the difference in motion vectors between the current frame and the previous frame exceeds this value, the pixel is treated as if it has no historical data. 23 | // This helps to prevent ghosting effects by not blending pixels with significantly different motion vectors. 24 | #define TAA_MOTION_VECTOR_DIFF_FACTOR 256.0 25 | 26 | // This parameter sets the threshold for depth disocclusion. It is used to determine how much a change in depth between frames should be considered as disocclusion, 27 | // which occurs when previously occluded objects become visible. A small threshold value means that only significant depth changes will be treated as disocclusion, 28 | // which can help in maintaining the stability of the image but may ignore some smaller, yet visually important changes. 29 | #define TAA_DEPTH_DISOCCLUSION_THRESHOLD 0.9 30 | 31 | // This parameter sets the max "distance" between source colour and target colour. 32 | // Setting this to a larger value allows more bright pixels from the history buffer to be leaved unchanged. 33 | #define TAA_VARIANCE_INTERSECTION_MAX_T 10.0 34 | 35 | struct TemporalAntiAliasingAttribs 36 | { 37 | // The value is responsible for interpolating between the current and previous frame. Increasing the value increases temporal stability but may introduce ghosting 38 | float TemporalStabilityFactor DEFAULT_VALUE(0.9375f); 39 | 40 | // If this parameter is set to true, the current frame will be written to the current history buffer without interpolation with the previous history buffer 41 | BOOL ResetAccumulation DEFAULT_VALUE(FALSE); 42 | 43 | BOOL SkipRejection DEFAULT_VALUE(FALSE); 44 | 45 | float Padding0 DEFAULT_VALUE(0.0); 46 | }; 47 | 48 | #endif //_TEMPORAL_ANTI_ALIASING_STRUCTURES_FXH_ 49 | -------------------------------------------------------------------------------- /Hydrogent/include/HnTextureUtils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023-2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "TextureLoader.h" 30 | #include "RefCntAutoPtr.hpp" 31 | 32 | namespace Diligent 33 | { 34 | 35 | namespace USD 36 | { 37 | 38 | /// Load texture status. 39 | enum HN_LOAD_TEXTURE_STATUS 40 | { 41 | /// The status is unknown. 42 | HN_LOAD_TEXTURE_STATUS_UNKNOWN, 43 | 44 | /// The texture was successfully loaded. 45 | HN_LOAD_TEXTURE_STATUS_SUCCESS, 46 | 47 | /// Not enough memory to load the texture. 48 | HN_LOAD_TEXTURE_STATUS_BUDGET_EXCEEDED, 49 | 50 | /// The texture path is invalid. 51 | HN_LOAD_TEXTURE_STATUS_INVALID_PATH, 52 | 53 | /// The texture asset was not found. 54 | HN_LOAD_TEXTURE_STATUS_ASSET_NOT_FOUND, 55 | 56 | /// The texture asset is empty. 57 | HN_LOAD_TEXTURE_STATUS_EMPTY_ASSET, 58 | 59 | /// Failed to load the texture. 60 | HN_LOAD_TEXTURE_STATUS_FAILED 61 | }; 62 | 63 | struct HnLoadTextureResult 64 | { 65 | HN_LOAD_TEXTURE_STATUS LoadStatus = HN_LOAD_TEXTURE_STATUS_UNKNOWN; 66 | size_t LoaderMemorySize = 0; 67 | RefCntAutoPtr pLoader = {}; 68 | 69 | operator bool() const { return pLoader != nullptr; } 70 | }; 71 | 72 | HnLoadTextureResult LoadTextureFromSdfPath(const char* SdfPath, 73 | const TextureLoadInfo& LoadInfo, 74 | Int64 MemoryBudget = 0, 75 | size_t LoaderMemorySize = 0); 76 | 77 | Int64 GetTextureLoaderMemoryUsage(); 78 | 79 | } // namespace USD 80 | 81 | } // namespace Diligent 82 | -------------------------------------------------------------------------------- /Hydrogent/src/HnRenderParam.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023-2025 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "HnRenderParam.hpp" 28 | 29 | namespace Diligent 30 | { 31 | 32 | namespace USD 33 | { 34 | 35 | HnRenderParam::HnRenderParam(const Configuration& Config, bool UseShadows) noexcept : 36 | m_Config{Config}, 37 | m_UseShadows{UseShadows} 38 | { 39 | for (auto& Version : m_GlobalAttribVersions) 40 | Version.store(0); 41 | } 42 | 43 | HnRenderParam::~HnRenderParam() 44 | { 45 | } 46 | 47 | void HnRenderParam::AddDirtyRPrim(const pxr::SdfPath& RPrimId, pxr::HdDirtyBits DirtyBits) 48 | { 49 | DirtyRPrimsVector* pDirtyRPrims = nullptr; 50 | { 51 | Threading::SpinLockGuard Guard{m_DirtyRPrimsLock}; 52 | 53 | auto it = m_DirtyRPrimsPerThread.find(std::this_thread::get_id()); 54 | if (it == m_DirtyRPrimsPerThread.end()) 55 | { 56 | it = m_DirtyRPrimsPerThread.emplace(std::this_thread::get_id(), DirtyRPrimsVector{}).first; 57 | it->second.reserve(16); 58 | } 59 | pDirtyRPrims = &it->second; 60 | } 61 | pDirtyRPrims->emplace_back(RPrimId, DirtyBits); 62 | } 63 | 64 | void HnRenderParam::CommitDirtyRPrims(pxr::HdChangeTracker& ChangeTracker) 65 | { 66 | Threading::SpinLockGuard Guard{m_DirtyRPrimsLock}; 67 | 68 | m_LastDirtyRPrimCount = 0; 69 | for (const auto& DirtyRPrims : m_DirtyRPrimsPerThread) 70 | { 71 | for (const auto& RPrim : DirtyRPrims.second) 72 | { 73 | ChangeTracker.MarkRprimDirty(RPrim.first, RPrim.second); 74 | } 75 | m_LastDirtyRPrimCount += DirtyRPrims.second.size(); 76 | } 77 | m_DirtyRPrimsPerThread.clear(); 78 | } 79 | 80 | } // namespace USD 81 | 82 | } // namespace Diligent 83 | -------------------------------------------------------------------------------- /Hydrogent/src/HnExtComputation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #include "HnExtComputation.hpp" 28 | #include "DebugUtilities.hpp" 29 | 30 | namespace Diligent 31 | { 32 | 33 | namespace USD 34 | { 35 | 36 | HnExtComputation* HnExtComputation::Create(const pxr::SdfPath& Id) 37 | { 38 | return new HnExtComputation{Id}; 39 | } 40 | 41 | HnExtComputation::HnExtComputation(const pxr::SdfPath& Id) : 42 | pxr::HdExtComputation{Id} 43 | { 44 | } 45 | 46 | HnExtComputation::~HnExtComputation() 47 | { 48 | } 49 | 50 | void HnExtComputation::Sync(pxr::HdSceneDelegate* SceneDelegate, 51 | pxr::HdRenderParam* RenderParam, 52 | pxr::HdDirtyBits* DirtyBits) 53 | { 54 | pxr::HdExtComputation::_Sync(SceneDelegate, RenderParam, DirtyBits); 55 | 56 | if (*DirtyBits & pxr::HdExtComputation::DirtySceneInput) 57 | { 58 | m_SceneInputsVersion.fetch_add(1); 59 | } 60 | 61 | HnExtComputationImpl::ImplType Type = HnExtComputationImpl::GetType(*this); 62 | if (m_Impl && m_Impl->GetType() != Type) 63 | { 64 | VERIFY(m_Impl->GetType() != HnExtComputationImpl::ImplType::Skinning, 65 | "Deleting skinning computation may result in a crash since render passes may still keep references to the previous-frame Xforms owned by it."); 66 | m_Impl.reset(); 67 | } 68 | 69 | if (!m_Impl) 70 | { 71 | m_Impl = HnExtComputationImpl::Create(*this); 72 | } 73 | 74 | if (m_Impl) 75 | { 76 | m_Impl->Sync(SceneDelegate, RenderParam, DirtyBits); 77 | } 78 | else 79 | { 80 | *DirtyBits = pxr::HdExtComputation::Clean; 81 | } 82 | } 83 | 84 | } // namespace USD 85 | 86 | } // namespace Diligent 87 | -------------------------------------------------------------------------------- /Hydrogent/interface/Tasks/HnEndOITPassTask.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Diligent Graphics LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * In no event and under no legal theory, whether in tort (including negligence), 17 | * contract, or otherwise, unless required by applicable law (such as deliberate 18 | * and grossly negligent acts) or agreed to in writing, shall any Contributor be 19 | * liable for any damages, including any direct, indirect, special, incidental, 20 | * or consequential damages of any character arising as a result of this License or 21 | * out of the use or inability to use the software (including but not limited to damages 22 | * for loss of goodwill, work stoppage, computer failure or malfunction, or any and 23 | * all other commercial damages or losses), even if such Contributor has been advised 24 | * of the possibility of such damages. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "HnTask.hpp" 30 | 31 | #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/PipelineState.h" 32 | #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h" 33 | #include "../../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp" 34 | 35 | namespace Diligent 36 | { 37 | 38 | namespace USD 39 | { 40 | 41 | struct HnEndOITPassTaskParams 42 | { 43 | constexpr bool operator==(const HnEndOITPassTaskParams& rhs) const 44 | { 45 | return true; 46 | } 47 | constexpr bool operator!=(const HnEndOITPassTaskParams& rhs) const 48 | { 49 | return !(*this == rhs); 50 | } 51 | }; 52 | 53 | /// Ends OIT pass 54 | /// - Applies OIT attenuation to the color, base color, material and IBL targets 55 | class HnEndOITPassTask final : public HnTask 56 | { 57 | public: 58 | HnEndOITPassTask(pxr::HdSceneDelegate* ParamsDelegate, const pxr::SdfPath& Id); 59 | ~HnEndOITPassTask(); 60 | 61 | virtual void Sync(pxr::HdSceneDelegate* Delegate, 62 | pxr::HdTaskContext* TaskCtx, 63 | pxr::HdDirtyBits* DirtyBits) override final; 64 | 65 | virtual void Prepare(pxr::HdTaskContext* TaskCtx, 66 | pxr::HdRenderIndex* RenderIndex) override final; 67 | 68 | virtual void Execute(pxr::HdTaskContext* TaskCtx) override final; 69 | 70 | virtual bool IsActive(pxr::HdRenderIndex& RenderIndex) const override final; 71 | 72 | private: 73 | pxr::HdRenderIndex* m_RenderIndex = nullptr; 74 | 75 | RefCntAutoPtr m_ApplyOITAttenuationPSO; 76 | RefCntAutoPtr m_ApplyOITAttenuationSRB; 77 | 78 | Uint32 m_OITResourcesVersion = ~0u; 79 | }; 80 | 81 | } // namespace USD 82 | 83 | } // namespace Diligent 84 | -------------------------------------------------------------------------------- /Shaders/PostProcess/Bloom/private/Bloom_ComputePrefilteredTexture.fx: -------------------------------------------------------------------------------- 1 | #include "FullScreenTriangleVSOutput.fxh" 2 | #include "BloomStructures.fxh" 3 | #include "SRGBUtilities.fxh" 4 | #include "PostFX_Common.fxh" 5 | 6 | cbuffer cbBloomAttribs 7 | { 8 | BloomAttribs g_BloomAttribs; 9 | } 10 | 11 | Texture2D g_TextureInput; 12 | SamplerState g_TextureInput_sampler; 13 | 14 | float3 SampleColor(float2 Texcoord, float2 Offset) 15 | { 16 | return g_TextureInput.SampleLevel(g_TextureInput_sampler, Texcoord + Offset, 0.0); 17 | } 18 | 19 | float KarisAverage(float3 Color) 20 | { 21 | return 1.0 / (1.0 + Luminance(Color)); 22 | } 23 | 24 | float3 Prefilter(float3 Color) 25 | { 26 | float Brightness = max(Color.r, max(Color.g, Color.b)); 27 | float Knee = g_BloomAttribs.Threshold * g_BloomAttribs.SoftTreshold; 28 | float Soft = Brightness - g_BloomAttribs.Threshold + Knee; 29 | Soft = clamp(Soft, 0.0, 2.0 * Knee); 30 | Soft = Soft * Soft * 0.25 / (Knee + 1.0e-5); 31 | 32 | float Contribution = max(Soft, Brightness - g_BloomAttribs.Threshold); 33 | Contribution /= max(Brightness, 1.0e-5); 34 | return Color * Contribution; 35 | } 36 | 37 | float3 ComputePrefilteredTexturePS(in FullScreenTriangleVSOutput VSOut) : SV_Target0 38 | { 39 | float2 TextureResolution; 40 | g_TextureInput.GetDimensions(TextureResolution.x, TextureResolution.y); 41 | 42 | float2 TexelSize = rcp(TextureResolution); 43 | float2 CenterTexcoord = NormalizedDeviceXYToTexUV(VSOut.f2NormalizedXY.xy); 44 | 45 | float3 A = SampleColor(CenterTexcoord, TexelSize * float2(-2.0, +2.0)); 46 | float3 B = SampleColor(CenterTexcoord, TexelSize * float2(+0.0, +2.0)); 47 | float3 C = SampleColor(CenterTexcoord, TexelSize * float2(+2.0, +2.0)); 48 | 49 | float3 D = SampleColor(CenterTexcoord, TexelSize * float2(-2.0, +0.0)); 50 | float3 E = SampleColor(CenterTexcoord, TexelSize * float2(+0.0, +0.0)); 51 | float3 F = SampleColor(CenterTexcoord, TexelSize * float2(+2.0, +0.0)); 52 | 53 | float3 G = SampleColor(CenterTexcoord, TexelSize * float2(-2.0, -2.0)); 54 | float3 H = SampleColor(CenterTexcoord, TexelSize * float2(+0.0, -2.0)); 55 | float3 I = SampleColor(CenterTexcoord, TexelSize * float2(+2.0, -2.0)); 56 | 57 | float3 J = SampleColor(CenterTexcoord, TexelSize * float2(-1.0, +1.0)); 58 | float3 K = SampleColor(CenterTexcoord, TexelSize * float2(+1.0, +1.0)); 59 | float3 L = SampleColor(CenterTexcoord, TexelSize * float2(-1.0, -1.0)); 60 | float3 M = SampleColor(CenterTexcoord, TexelSize * float2(+1.0, -1.0)); 61 | 62 | float Weights[5]; 63 | Weights[0] = 0.125f; 64 | Weights[1] = 0.125f; 65 | Weights[2] = 0.125f; 66 | Weights[3] = 0.125f; 67 | Weights[4] = 0.5f; 68 | 69 | float3 Groups[5]; 70 | Groups[0] = (A + B + D + E) / 4.0f; 71 | Groups[1] = (B + C + E + F) / 4.0f; 72 | Groups[2] = (D + E + G + H) / 4.0f; 73 | Groups[3] = (E + F + H + I) / 4.0f; 74 | Groups[4] = (J + K + L + M) / 4.0f; 75 | 76 | float4 ColorSum = float4(0.0, 0.0, 0.0, 0.0); 77 | for (int GroupId = 0; GroupId < 5; ++GroupId) { 78 | float Weight = Weights[GroupId] * KarisAverage(Groups[GroupId]); 79 | ColorSum += float4(Groups[GroupId], 1.0) * Weight; 80 | } 81 | 82 | return Prefilter(ColorSum.xyz / (ColorSum.w + 1.0e-5)); 83 | } 84 | --------------------------------------------------------------------------------