### Define Installation Rules Source: https://github.com/diligentgraphics/diligentfx/blob/master/CMakeLists.txt Configures installation paths for the library binaries and public interface headers when DILIGENT_INSTALL_FX is enabled. ```cmake if(DILIGENT_INSTALL_FX) install(TARGETS DiligentFX ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${DILIGENT_FX_DIR}/$" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${DILIGENT_FX_DIR}/$" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/${DILIGENT_FX_DIR}/$" ) install(DIRECTORY PostProcess/EpipolarLightScattering/interface DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DILIGENT_FX_DIR}/PostProcess/EpipolarLightScattering" ) install(DIRECTORY PostProcess/TemporalAntiAliasing/interface DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DILIGENT_FX_DIR}/PostProcess/TemporalAntiAliasing" ) install(DIRECTORY PostProcess/ScreenSpaceReflection/interface DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DILIGENT_FX_DIR}/PostProcess/ScreenSpaceReflection" ) install(DIRECTORY PostProcess/ScreenSpaceAmbientOcclusion/interface DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DILIGENT_FX_DIR}/PostProcess/ScreenSpaceAmbientOcclusion" ) install(DIRECTORY PostProcess/Bloom/interface DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DILIGENT_FX_DIR}/PostProcess/Bloom" ) install(DIRECTORY Components/interface DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DILIGENT_FX_DIR}/Components" ) install(DIRECTORY PBR/interface DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DILIGENT_FX_DIR}/PBR" ) install(DIRECTORY Radient/interface DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DILIGENT_FX_DIR}/Radient" ) install(DIRECTORY Shaders DESTINATION "." FILES_MATCHING PATTERN "public/*.*" PATTERN "private" EXCLUDE ) endif() ``` -------------------------------- ### Shadow Map Manager Initialization Source: https://github.com/diligentgraphics/diligentfx/blob/master/Components/README.md Example of initializing the ShadowMapManager with specific parameters. ```cpp ShadowMapManager::InitInfo SMMgrInitInfo; SMMgrInitInfo.Format = TEX_FORMAT_D16_UNORM; SMMgrInitInfo.Resolution = 1024; SMMgrInitInfo.NumCascades = 4; SMMgrInitInfo.ShadowMode = SHADOW_MODE_PCF; SMMgrInitInfo.pComparisonSampler = m_pComparisonSampler; m_ShadowMapMgr.Initialize(m_pDevice, SMMgrInitInfo); ``` -------------------------------- ### Shadowing Functionality Setup Source: https://github.com/diligentgraphics/diligentfx/blob/master/Components/README.md Includes necessary header files and defines shadow map/filterable shadow map textures and samplers. ```hlsl #include "BasicStructures.fxh" #include "Shadows.fxh" #if SHADOW_MODE == SHADOW_MODE_PCF Texture2DArray g_tex2DShadowMap; SamplerComparisonState g_tex2DShadowMap_sampler; #else Texture2DArray g_tex2DFilterableShadowMap; SamplerState g_tex2DFilterableShadowMap_sampler; #endif ``` -------------------------------- ### Cascade Partitioning Source: https://github.com/diligentgraphics/diligentfx/blob/master/Components/README.md Example of distributing shadow map cascades using camera and light information. ```cpp ShadowMapManager::DistributeCascadeInfo DistrInfo; DistrInfo.pCameraView = &m_Camera.GetViewMatrix(); DistrInfo.pCameraProj = &m_Camera.GetProjMatrix(); DistrInfo.pLightDir = &m_f3LightDirection; DistrInfo.fPartitioningFactor = 0.95f; m_ShadowMapMgr.DistributeCascades(DistrInfo, m_LightAttribs.ShadowAttribs); ``` -------------------------------- ### Build USD File Format Plugins on Windows Source: https://github.com/diligentgraphics/diligentfx/blob/master/Hydrogent/readme.md Building USD File Format Plugins on Windows with CMake, specifying installation prefix and OpenUSD root. ```bash cmake -S . -B build/Debug -DCMAKE_INSTALL_PREFIX=bin/Debug -Dpxr_ROOT=/build/Debug -DUSD_FILEFORMATS_BUILD_TESTS=OFF cmake --build build/Debug --config debug cmake --install build/Debug --config debug ``` -------------------------------- ### Initialize SSAO Objects Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceAmbientOcclusion/README.md Create the PostFX context and SSAO instances using the device pointer. ```cpp m_PostFXContext = std::make_unique(m_pDevice); m_SSAO = std::make_unique(m_pDevice); ``` -------------------------------- ### Prepare SSAO Resources Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceAmbientOcclusion/README.md Initialize resources for PostFXContext and ScreenSpaceAmbientOcclusion objects every frame before rendering. ```cpp { PostFXContext::FrameDesc FrameDesc; FrameDesc.Index = m_CurrentFrameNumber; // Current frame number. FrameDesc.Width = SCDesc.Width; // Current screen width. FrameDesc.Height = SCDesc.Height; // Current screen height. m_PostFXContext->PrepareResources(m_pDevice, FrameDesc, PostFXContext::FEATURE_FLAG_NONE); ScreenSpaceAmbientOcclusion::FEATURE_FLAGS ActiveFeatures = ...; m_ScreenSpaceAmbientOcclusion->PrepareResources(m_pDevice, m_pImmediateContext, m_PostFXContext.get(), ActiveFeatures); } ``` -------------------------------- ### Configure USD-Libraries interface Source: https://github.com/diligentgraphics/diligentfx/blob/master/Hydrogent/CMakeLists.txt Sets up the USD-Libraries interface target, handling platform-specific include directories and library paths for Visual Studio, Xcode, or other generators. ```cmake add_library(USD-Libraries INTERFACE) if(${CMAKE_GENERATOR} MATCHES "Visual Studio" OR ${CMAKE_GENERATOR} MATCHES "Xcode") # Since we can't use wildcards in generator expressions, we have to # find boost directory for each configuration file(GLOB BOOST_INCLUDE_DEBUG "${DILIGENT_USD_PATH}/Debug/include/boost*") file(GLOB BOOST_INCLUDE_RELEASE "${DILIGENT_USD_PATH}/Release/include/boost*") file(GLOB BOOST_INCLUDE_RELWITHDEBINFO "${DILIGENT_USD_PATH}/RelWithDebInfo/include/boost*") target_include_directories(USD-Libraries INTERFACE ${DILIGENT_USD_PATH}/$/include $<$:${BOOST_INCLUDE_DEBUG}> $<$:${BOOST_INCLUDE_RELEASE}> $<$:${BOOST_INCLUDE_RELWITHDEBINFO}> ) target_link_directories(USD-Libraries INTERFACE ${DILIGENT_USD_PATH}/$/lib ) else() # Load the pxr package, which will bring all USD libraries set(pxr_DIR ${DILIGENT_USD_PATH}) find_package(pxr) target_include_directories(USD-Libraries INTERFACE ${PXR_INCLUDE_DIRS}) endif() ``` -------------------------------- ### Temporal Anti-Aliasing Execution Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/TemporalAntiAliasing/README.md Example of how to invoke the TAA computation after rendering the frame. The color buffer must be in linear space before tone mapping and other post-effects. ```cpp { HLSL::TemporalAntiAliasingAttribs TAASettings{}; TemporalAntiAliasing::RenderAttributes TAARenderAttribs{}; TAARenderAttribs.pDevice = m_pDevice; TAARenderAttribs.pDeviceContext = m_pImmediateContext; TAARenderAttribs.pPostFXContext = m_PostFXContext.get(); TAARenderAttribs.pColorBufferSRV = m_ColorBuffer; // m_Resources[RESOURCE_IDENTIFIER_RADIANCE0 + CurrFrameIdx].GetTextureSRV(); TAARenderAttribs.pTAAAttribs = &TAASettings; m_TAA->Execute(TAARenderAttribs); } ``` -------------------------------- ### Initialize GLTF PBR Renderer Source: https://github.com/diligentgraphics/diligentfx/blob/master/PBR/README.md Populate the CreateInfo structure and instantiate the GLTF_PBR_Renderer class. Note that front face is set to counter-clockwise to account for Y-axis inversion in GLTF. ```cpp auto BackBufferFmt = m_pSwapChain->GetDesc().ColorBufferFormat; auto DepthBufferFmt = m_pSwapChain->GetDesc().DepthBufferFormat; GLTF_PBR_Renderer::CreateInfo RendererCI; RendererCI.RTVFmt = BackBufferFmt; RendererCI.DSVFmt = DepthBufferFmt; RendererCI.AllowDebugView = true; RendererCI.UseIBL = true; RendererCI.FrontCCW = true; m_GLTFRenderer.reset(new GLTF_PBR_Renderer(m_pDevice, m_pImmediateContext, RendererCI)); ``` -------------------------------- ### Prepare Resources Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceReflection/README.md Prepare resources for PostFXContext and ScreenSpaceReflection every frame. ```cpp { PostFXContext::FrameDesc FrameDesc; FrameDesc.Index = m_CurrentFrameNumber; // Current frame number. FrameDesc.Width = SCDesc.Width; // Current screen width. FrameDesc.Height = SCDesc.Height; // Current screen height. m_PostFXContext->PrepareResources(m_pDevice, FrameDesc, PostFXContext::FEATURE_FLAG_NONE); ScreenSpaceReflection::FEATURE_FLAGS ActiveFeatures = ...; m_SSR->PrepareResources(m_pDevice, m_pImmediateContext, m_PostFXContext.get(), ActiveFeatures); } ``` -------------------------------- ### Configure Shader Header Generation Source: https://github.com/diligentgraphics/diligentfx/blob/master/CMakeLists.txt Sets up the output directory for generated shader headers and invokes the conversion process. ```cmake set(SHADER_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/shaders_inc) file(MAKE_DIRECTORY ${SHADER_OUTPUT_DIR}) target_include_directories(DiligentFX PRIVATE ${SHADER_OUTPUT_DIR}) set(SHADERS_LIST_FILE ${SHADER_OUTPUT_DIR}/shaders_list.h) convert_shaders_to_headers("${SHADERS}" ${SHADER_OUTPUT_DIR} ${SHADERS_LIST_FILE} SHADERS_INC_LIST) ``` -------------------------------- ### Fetch Third-Party Dependencies Source: https://github.com/diligentgraphics/diligentfx/blob/master/CMakeLists.txt Uses FetchContent to download and integrate the entt library. ```cmake include(FetchContent) message("Fetching entt repository...") FetchContent_Declare( entt GIT_REPOSITORY https://github.com/skypjack/entt GIT_TAG v3.16.0 ) FetchContent_MakeAvailable(entt) set_directory_root_folder(${entt_SOURCE_DIR} "DiligentFX/ThirdParty/entt") ``` -------------------------------- ### Define USD library list Source: https://github.com/diligentgraphics/diligentfx/blob/master/Hydrogent/CMakeLists.txt Lists the required USD libraries and handles library naming conventions if the pxr package is not found. ```cmake set(USD_LIBS gf ar sdf tf usd plug hd vt hio sdr ndr trace work cameraUtil usdGeom usdSkel usdLux usdImaging usdSkelImaging ) if (NOT pxr_FOUND) # Add usd_ prefix to all USD libraries set(_USD_LIBS "") foreach(lib ${USD_LIBS}) list(APPEND _USD_LIBS "usd_${lib}") endforeach() set(USD_LIBS ${_USD_LIBS}) if (PLATFORM_MACOS) file(GLOB BOOST_PYTHON_LIB_DEBUG "${DILIGENT_USD_PATH}/Debug/lib/*boost_python*") file(GLOB BOOST_PYTHON_LIB_RELEASE "${DILIGENT_USD_PATH}/Release/lib/*boost_python*") file(GLOB BOOST_PYTHON_LIB_RELWITHDEBINFO "${DILIGENT_USD_PATH}/RelWithDebInfo/lib/*boost_python*") target_link_libraries(USD-Libraries INTERFACE $<$:${BOOST_PYTHON_LIB_DEBUG}> $<$:${BOOST_PYTHON_LIB_RELEASE}> $<$:${BOOST_PYTHON_LIB_RELWITHDEBINFO}> ) endif() # Add python library find_package(Python3 COMPONENTS Interpreter Development REQUIRED) target_link_libraries(USD-Libraries INTERFACE Python3::Python) endif() target_link_libraries(USD-Libraries INTERFACE ${USD_LIBS}) ``` -------------------------------- ### Include SSAO Header Files Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceAmbientOcclusion/README.md Include these headers to access the PostFX context and SSAO functionality. ```cpp #include "PostFXContext.hpp" #include "ScreenSpaceAmbientOcclusion.hpp" ``` -------------------------------- ### Rendering Shadow Cascades Source: https://github.com/diligentgraphics/diligentfx/blob/master/Components/README.md Looping through shadow cascades, setting up camera attributes, rendering targets, and drawing meshes. ```cpp auto iNumShadowCascades = m_LightAttribs.ShadowAttribs.iNumCascades; for(int iCascade = 0; iCascade < iNumShadowCascades; ++iCascade) { const auto CascadeProjMatr = m_ShadowMapMgr.GetCascadeTranform(iCascade).Proj; auto WorldToLightViewSpaceMatr = m_LightAttribs.ShadowAttribs.mWorldToLightViewT.Transpose(); auto WorldToLightProjSpaceMatr = WorldToLightViewSpaceMatr * CascadeProjMatr; CameraAttribs ShadowCameraAttribs = {}; ShadowCameraAttribs.mViewT = m_LightAttribs.ShadowAttribs.mWorldToLightViewT; ShadowCameraAttribs.mProjT = CascadeProjMatr.Transpose(); ShadowCameraAttribs.mViewProjT = WorldToLightProjSpaceMatr.Transpose(); { MapHelper CameraData(m_pImmediateContext, m_CameraAttribsCB, MAP_WRITE, MAP_FLAG_DISCARD); *CameraData = ShadowCameraAttribs; } auto* pCascadeDSV = m_ShadowMapMgr.GetCascadeDSV(iCascade); m_pImmediateContext->SetRenderTargets(0, nullptr, pCascadeDSV, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); m_pImmediateContext->ClearDepthStencil(pCascadeDSV, CLEAR_DEPTH_FLAG, 1.f, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); DrawMesh(m_pImmediateContext); } ``` -------------------------------- ### Configure Include Directories Source: https://github.com/diligentgraphics/diligentfx/blob/master/Radient/CMakeLists.txt Sets the public and private include directories for the Radient target. ```cmake target_include_directories(Radient PUBLIC interface PRIVATE include ) ``` -------------------------------- ### Configure DiligentFX-IncludeTest Library Source: https://github.com/diligentgraphics/diligentfx/blob/master/Tests/IncludeTest/CMakeLists.txt Defines the library target, includes source files, and sets up build properties and dependencies. ```cmake cmake_minimum_required (VERSION 3.10) project(DiligentFX-IncludeTest) file(GLOB_RECURSE SOURCE LIST_DIRECTORIES false *.cpp *.c) add_library(DiligentFX-IncludeTest ${SOURCE}) target_include_directories(DiligentFX-IncludeTest PRIVATE ../..) target_link_libraries(DiligentFX-IncludeTest PRIVATE Diligent-BuildSettings) set_common_target_properties(DiligentFX-IncludeTest) if(MSVC) set_target_properties(DiligentFX-IncludeTest PROPERTIES STATIC_LIBRARY_FLAGS "/IGNORE:4221" ) endif() source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE}) set_target_properties(DiligentFX-IncludeTest PROPERTIES FOLDER "DiligentFX/Tests" ) ``` -------------------------------- ### Define DiligentFX Library Source: https://github.com/diligentgraphics/diligentfx/blob/master/CMakeLists.txt Creates the static library and configures target link libraries and include directories. ```cmake file(GLOB_RECURSE SHADERS LIST_DIRECTORIES false Shaders/*.*) add_library(DiligentFX STATIC README.md ${SHADERS}) file(RELATIVE_PATH DILIGENT_FX_DIR "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS OR PLATFORM_LINUX OR PLATFORM_APPLE OR PLATFORM_WEB) option(DILIGENT_INSTALL_FX "Install DiligentFX module headers and libraries" ON) else() set(DILIGENT_INSTALL_FX OFF) endif() target_link_libraries(DiligentFX PRIVATE Diligent-BuildSettings PUBLIC Diligent-GraphicsEngine Diligent-GraphicsTools Diligent-AssetLoader Diligent-TextureLoader Diligent-Imgui ) if (TARGET Diligent-HLSL2GLSLConverterLib) target_compile_definitions(DiligentFX PRIVATE HLSL2GLSL_CONVERTER_SUPPORTED=1) endif() set_common_target_properties(DiligentFX) target_include_directories(DiligentFX PUBLIC . ) ``` -------------------------------- ### Define Radient Library and Properties Source: https://github.com/diligentgraphics/diligentfx/blob/master/Radient/CMakeLists.txt Initializes the Radient static library and applies common project-wide target properties. ```cmake set(RADIENT_SOURCE ${SOURCE} ${INCLUDE} ${INTERFACE} readme.md) add_library(Radient STATIC ${RADIENT_SOURCE}) set_common_target_properties(Radient) ``` -------------------------------- ### Precompute Environment Cubemaps Source: https://github.com/diligentgraphics/diligentfx/blob/master/PBR/README.md Generate irradiance and pre-filtered environment maps for image-based lighting using the renderer's pre-computation methods. ```cpp RefCntAutoPtr EnvironmentMap; CreateTextureFromFile("textures/papermill.ktx", TextureLoadInfo{"Environment map"}, m_pDevice, &EnvironmentMap); m_EnvironmentMapSRV = EnvironmentMap->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE); RefCntAutoPtr IrradianceCube; RefCntAutoPtr PrefilteredEnvMap; IrradianceCube = m_GLTFRenderer->CreateIrradianceCube(m_pImmediateContext); PrefilteredEnvMap = m_GLTFRenderer->CreatePrefilteredEnvMap(m_pImmediateContext); PBR_Renderer::PrecomputeCubemapsAttribs Attribs; Attribs.pEnvironmentMapSRV = m_EnvironmentMapSRV; Attribs.pIrradianceCube = IrradianceCube; Attribs.pPrefilteredEnvMap = PrefilteredEnvMap; m_GLTFRenderer->PrecomputeCubemaps(m_pImmediateContext, Attribs); ``` -------------------------------- ### PBR CMakeLists.txt Source: https://github.com/diligentgraphics/diligentfx/blob/master/PBR/CMakeLists.txt CMakeLists.txt configuration for the PBR module. ```cmake cmake_minimum_required (VERSION 3.10) set(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/PBR_Renderer.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/GLTF_PBR_Renderer.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/USD_Renderer.cpp" ) set(INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/interface/PBR_Renderer.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/interface/GLTF_PBR_Renderer.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/interface/USD_Renderer.hpp" ) target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) target_include_directories(DiligentFX PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/interface" ) ``` -------------------------------- ### Execute PostFX Context Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceAmbientOcclusion/README.md Calculate intermediate resources required for post-processing by executing the PostFX context with camera and depth buffer data. ```cpp { PostFXContext::RenderAttributes PostFXAttibs; PostFXAttibs.pDevice = m_pDevice; PostFXAttibs.pDeviceContext = m_pImmediateContext; PostFXAttibs.pCameraAttribsCB = m_FrameAttribsCB; // m_Resources[RESOURCE_IDENTIFIER_CAMERA_CONSTANT_BUFFER].AsBuffer(); PostFXAttibs.pCurrDepthBufferSRV = m_CurrDepthBuffer; // m_Resources[RESOURCE_IDENTIFIER_DEPTH0 + CurrFrameIdx].GetTextureSRV(); PostFXAttibs.pPrevDepthBufferSRV = m_PrevDepthBuffer; // m_Resources[RESOURCE_IDENTIFIER_DEPTH0 + PrevFrameIdx].GetTextureSRV(); PostFXAttibs.pMotionVectorsSRV = m_MotionBuffer; // m_GBuffer->GetBuffer(GBUFFER_RT_MOTION_VECTORS)->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE); m_PostFXContext->Execute(PostFXAttibs); } ``` -------------------------------- ### Create SSR Objects Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceReflection/README.md Instantiate the PostFXContext and ScreenSpaceReflection objects. ```cpp m_PostFXContext = std::make_unique(m_pDevice); m_SSR = std::make_unique(m_pDevice); ``` -------------------------------- ### Define Hydrogent library Source: https://github.com/diligentgraphics/diligentfx/blob/master/Hydrogent/CMakeLists.txt Initializes the Hydrogent static library with source files and generated shader headers. ```cmake set(HYDROGENT_SOURCE ${SOURCE} ${INCLUDE} ${INTERFACE} ${SHADERS} readme.md) add_library(Hydrogent STATIC ${HYDROGENT_SOURCE} ${SHADERS_LIST_FILE} ${SHADERS_INC_LIST}) set_common_target_properties(Hydrogent) ``` -------------------------------- ### RadientRenderTest CMakeLists.txt Source: https://github.com/diligentgraphics/diligentfx/blob/master/Tests/RadientRenderTest/CMakeLists.txt Defines the project, source files, dependencies, and build properties for the RadientRenderTest executable. ```cmake cmake_minimum_required (VERSION 3.10) project(RadientRenderTest) file(GLOB_RECURSE SOURCE src/*.*) file(GLOB_RECURSE ASSETS assets/*.*) get_target_property(DILIGENT_NATIVE_APP_SOURCE_DIR Diligent-NativeAppBase SOURCE_DIR) add_executable(RadientRenderTest ${SOURCE} ${ASSETS}) set_common_target_properties(RadientRenderTest) target_compile_definitions(RadientRenderTest PRIVATE RADIENT_RENDER_TEST_MANIFEST_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/RadientRenderTests.json" ) target_include_directories(RadientRenderTest PRIVATE ../../Radient/include ${DILIGENT_NATIVE_APP_SOURCE_DIR}/include ) target_link_libraries(RadientRenderTest PRIVATE Diligent-BuildSettings Diligent-TargetPlatform Diligent-Common Diligent-GraphicsEngine Diligent-GPUTestFramework Diligent-JSON DiligentFX Radient EnTT absl::flat_hash_map ) if (MSVC) # Disable warning C4324: structure was padded due to alignment specifier target_compile_options(RadientRenderTest PRIVATE /wd4324) endif() source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${ASSETS}) set_target_properties(RadientRenderTest PROPERTIES FOLDER "DiligentFX/Tests" ) if(PLATFORM_WIN32) copy_required_dlls(RadientRenderTest) endif() ``` -------------------------------- ### Initialize Model Resource Bindings Source: https://github.com/diligentgraphics/diligentfx/blob/master/PBR/README.md After loading a model with the Asset Loader, call InitializeResourceBindings to prepare internal shader resource binding objects. ```cpp m_Model.reset(new GLTF::Model(m_pDevice, m_pImmediateContext, Path)); m_GLTFRenderer->InitializeResourceBindings(*m_Model, m_CameraAttribsCB, m_LightAttribsCB); ``` -------------------------------- ### Initialize Camera Position Source: https://github.com/diligentgraphics/diligentfx/blob/master/Radient/docs/CameraConventions.md Sets the camera position to look at the origin from a distance of 5 units along the positive Z axis. ```cpp RadientEntityDesc CameraDesc{}; CameraDesc.Transform.Position = {0.f, 0.f, 5.f}; ``` -------------------------------- ### Prepare Resources Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/Bloom/README.md Prepare resources for PostFXContext and Bloom objects every frame before rendering. ```cpp PostFXContext::FrameDesc FrameDesc; FrameDesc.Index = m_CurrentFrameNumber; // Current frame number. FrameDesc.Width = SCDesc.Width; // Current screen width. FrameDesc.Height = SCDesc.Height; // Current screen height. m_PostFXContext->PrepareResources(m_pDevice, FrameDesc, PostFXContext::FEATURE_FLAG_NONE); m_Bloom->PrepareResources(m_pDevice, m_pImmediateContext, m_PostFXContext.get(), Bloom::FEATURE_FLAG_NONE); ``` -------------------------------- ### Configure Subdirectories Source: https://github.com/diligentgraphics/diligentfx/blob/master/CMakeLists.txt Adds subdirectories for various components and features based on build options. ```cmake add_subdirectory(Utilities) add_subdirectory(Components) add_subdirectory(PostProcess) add_subdirectory(PBR) if (NOT DILIGENT_NO_RADIENT) add_subdirectory(Radient) endif() if(DILIGENT_USD_PATH) add_subdirectory(Hydrogent) endif() add_subdirectory(Tests) ``` -------------------------------- ### Build OpenUSD on Windows Source: https://github.com/diligentgraphics/diligentfx/blob/master/Hydrogent/readme.md Building OpenUSD with different configurations on Windows using Visual Studio generator. ```bash python .\build_scripts\build_usd.py --build-variant debug .\build\Debug python .\build_scripts\build_usd.py --build-variant release .\build\Release python .\build_scripts\build_usd.py --build-variant relwithdebuginfo .\build\RelWithDebInfo ``` -------------------------------- ### Screen Space Reflection CMake Configuration Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceReflection/CMakeLists.txt Defines sources, includes, and target properties for the Screen Space Reflection module. ```cmake cmake_minimum_required (VERSION 3.10) set(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/ScreenSpaceReflection.cpp" ) set(INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/interface/ScreenSpaceReflection.hpp" ) target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) target_include_directories(DiligentFX PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/interface" "${CMAKE_CURRENT_SOURCE_DIR}/../../Shaders/PostProcess/ScreenSpaceReflection/public" ) ``` -------------------------------- ### Include Header Files Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceReflection/README.md Include the necessary header files for PostFXContext and ScreenSpaceReflection. ```cpp #include "PostFXContext.hpp" #include "ScreenSpaceReflection.hpp" ``` -------------------------------- ### CMakeLists.txt for Temporal Anti-Aliasing Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/TemporalAntiAliasing/CMakeLists.txt This snippet shows the CMake configuration for the Temporal Anti-Aliasing module, defining source files, include directories, and target sources. ```cmake cmake_minimum_required (VERSION 3.10) set(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/TemporalAntiAliasing.cpp" ) set(INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/interface/TemporalAntiAliasing.hpp" ) target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) target_include_directories(DiligentFX PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/interface" ) ``` -------------------------------- ### Render GLTF Model Source: https://github.com/diligentgraphics/diligentfx/blob/master/PBR/README.md Execute the render call by providing the context, model, and rendering parameters. ```cpp m_GLTFRenderer->Render(m_pImmediateContext, *m_Model, m_RenderParams); ``` -------------------------------- ### Include SSAO Shader Structures Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceAmbientOcclusion/README.md Include the necessary HLSL structures within the HLSL namespace for shader-side configuration. ```cpp namespace HLSL { #include "Shaders/Common/public/BasicStructures.fxh" #include "Shaders/PostProcess/ScreenSpaceAmbientOcclusion/public/ScreenSpaceAmbientOcclusionStructures.fxh" } // namespace HLSL ``` -------------------------------- ### Include Header Files Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/Bloom/README.md Include the necessary header files for PostFXContext and Bloom. ```cpp #include "PostFXContext.hpp" #include "Bloom.hpp" ``` -------------------------------- ### Prepare Resources Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/DepthOfField/README.md Prepare resources for PostFXContext and DepthOfField objects every frame. ```cpp PostFXContext::FrameDesc FrameDesc; FrameDesc.Index = m_CurrentFrameNumber; // Current frame number. FrameDesc.Width = SCDesc.Width; // Current screen width. FrameDesc.Height = SCDesc.Height; // Current screen height. m_PostFXContext->PrepareResources(m_pDevice, FrameDesc, PostFXContext::FEATURE_FLAG_NONE); m_DepthOfField->PrepareResources(m_pDevice, m_pImmediateContext, m_PostFXContext.get(), DepthOfField::FEATURE_FLAG_NONE); ``` -------------------------------- ### Convert shaders to headers Source: https://github.com/diligentgraphics/diligentfx/blob/master/Hydrogent/CMakeLists.txt Generates header files from shaders and creates a master list file for inclusion in the build. ```cmake set(SHADER_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/shaders_inc) file(MAKE_DIRECTORY ${SHADER_OUTPUT_DIR}) set(SHADERS_LIST_FILE ${SHADER_OUTPUT_DIR}/shaders_list.h) convert_shaders_to_headers("${SHADERS}" ${SHADER_OUTPUT_DIR} ${SHADERS_LIST_FILE} SHADERS_INC_LIST) ``` -------------------------------- ### Organize Source Groups Source: https://github.com/diligentgraphics/diligentfx/blob/master/CMakeLists.txt Groups source files into folders for IDE project structures. ```cmake get_target_property(SOURCE DiligentFX SOURCES) foreach(FILE ${SOURCE}) # Get the directory of the source file get_filename_component(PARENT_DIR "${FILE}" DIRECTORY) # Remove common directory prefix to make the group string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" GROUP "${PARENT_DIR}") # Make sure we are using windows slashes string(REPLACE "/" "\\" GROUP "${GROUP}") source_group("${GROUP}" FILES "${FILE}") endforeach() ``` -------------------------------- ### Include Header Files Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/TemporalAntiAliasing/README.md Include the necessary header files for PostFXContext and TemporalAntiAliasing. ```cpp #include "PostFXContext.hpp" #include "TemporalAntiAliasing.hpp" ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceAmbientOcclusion/CMakeLists.txt This snippet shows the CMake configuration for the Screen Space Ambient Occlusion module, including source files, include directories, and target definitions. ```cmake cmake_minimum_required (VERSION 3.10) set(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/ScreenSpaceAmbientOcclusion.cpp" ) set(INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/interface/ScreenSpaceAmbientOcclusion.hpp" ) target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE}) target_include_directories(DiligentFX PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/interface" "${CMAKE_CURRENT_SOURCE_DIR}/../../Shaders/PostProcess/ScreenSpaceAmbientOcclusion/public" ) ``` -------------------------------- ### Create TAA and PostFXContext Objects Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/TemporalAntiAliasing/README.md Instantiate the PostFXContext and TemporalAntiAliasing objects. ```cpp m_PostFXContext = std::make_unique(m_pDevice); m_TAA = std::make_unique(m_pDevice); ``` -------------------------------- ### RadientGPUTest CMake Configuration Source: https://github.com/diligentgraphics/diligentfx/blob/master/Tests/RadientGPUTest/CMakeLists.txt Defines the project, source files, dependencies, and platform-specific build properties for the RadientGPUTest executable. ```cmake cmake_minimum_required (VERSION 3.10) project(RadientGPUTest) file(GLOB_RECURSE SOURCE src/*.*) set(MAIN_CPP ../../../DiligentCore/Tests/DiligentCoreAPITest/src/main.cpp) add_executable(RadientGPUTest ${SOURCE} ${MAIN_CPP}) set_common_target_properties(RadientGPUTest) target_include_directories(RadientGPUTest PRIVATE ../../Radient/include ) target_link_libraries(RadientGPUTest PRIVATE Diligent-BuildSettings Diligent-TargetPlatform Diligent-Common Diligent-GraphicsEngine Diligent-GPUTestFramework DiligentFX Radient EnTT absl::flat_hash_map ) if (MSVC) # Disable warning C4324: structure was padded due to alignment specifier target_compile_options(RadientGPUTest PRIVATE /wd4324) endif() source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE}) source_group("DiligentCoreAPITest" FILES ${MAIN_CPP}) set_target_properties(RadientGPUTest PROPERTIES FOLDER "DiligentFX/Tests" ) if(PLATFORM_WIN32) copy_required_dlls(RadientGPUTest) endif() ``` -------------------------------- ### Configure Hydrogent target links and properties Source: https://github.com/diligentgraphics/diligentfx/blob/master/Hydrogent/CMakeLists.txt Sets include directories, links dependencies, and organizes the target in the IDE project structure. ```cmake target_include_directories(Hydrogent PUBLIC interface PRIVATE include ${SHADER_OUTPUT_DIR} ) target_link_libraries(Hydrogent PRIVATE Diligent-BuildSettings NO_WERROR Diligent-GraphicsEngine Diligent-BasicPlatform Diligent-GraphicsTools Diligent-TextureLoader Diligent-Common DiligentFX PUBLIC EnTT USD-Libraries ) set_target_properties(Hydrogent PROPERTIES FOLDER DiligentFX ) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HYDROGENT_SOURCE}) source_group("generated" FILES ${SHADERS_LIST_FILE} ${SHADERS_INC_LIST} ) ``` -------------------------------- ### Create Objects Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/DepthOfField/README.md Instantiate the PostFXContext and DepthOfField objects. ```cpp m_PostFXContext = std::make_unique(m_pDevice); m_DOF = std::make_unique(m_pDevice); ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/Common/CMakeLists.txt This snippet shows the CMake configuration for the DiligentFX target, including source files, interface headers, and include directories. ```cmake cmake_minimum_required (VERSION 3.10) set(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/PostFXRenderTechnique.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/PostFXContext.cpp" ) set(INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/interface/PostFXRenderTechnique.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/interface/PostFXContext.hpp" ) target_sources(DiligentFX PRIVATE ${SOURCE} ${INTERFACE} ${INCLUDE}) target_include_directories(DiligentFX PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/interface" "${CMAKE_CURRENT_SOURCE_DIR}/../../Shaders/PostProcess/Common/public" ) ``` -------------------------------- ### RadientTest CMake Configuration Source: https://github.com/diligentgraphics/diligentfx/blob/master/Tests/RadientTest/CMakeLists.txt Defines the project, source files, include directories, and platform-specific build settings for the RadientTest executable. ```cmake cmake_minimum_required (VERSION 3.10) if (PLATFORM_WEB) set(CMAKE_EXECUTABLE_SUFFIX ".html") endif() project(RadientTest) file(GLOB_RECURSE SOURCE src/*.*) add_executable(RadientTest ${SOURCE}) set_common_target_properties(RadientTest) target_include_directories(RadientTest PRIVATE ../../Radient/include ) if (PLATFORM_WEB) set(RESOURCE_PATH "${PROJECT_SOURCE_DIR}/assets/") set(HTML_TEMPLATE_FILE ${PROJECT_SOURCE_DIR}/resources/emscripten_template.html) target_link_options(RadientTest PRIVATE "SHELL: -s SINGLE_FILE -s ALLOW_MEMORY_GROWTH=1 --preload-file '${RESOURCE_PATH}@'") target_link_options(RadientTest PRIVATE "SHELL: --shell-file '${HTML_TEMPLATE_FILE}'") endif() target_link_libraries(RadientTest PRIVATE gtest_main Diligent-BuildSettings Diligent-TargetPlatform Diligent-TestFramework Diligent-Common Diligent-AssetLoader DiligentFX Radient EnTT absl::flat_hash_map absl::inlined_vector ) if (MSVC) # Disable warning C4324: structure was padded due to alignment specifier target_compile_options(RadientTest PRIVATE /wd4324) endif() source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE}) set_target_properties(RadientTest PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets" XCODE_SCHEME_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets" ) set_target_properties(RadientTest PROPERTIES FOLDER "DiligentFX/Tests" ) ``` -------------------------------- ### Link Dependencies Source: https://github.com/diligentgraphics/diligentfx/blob/master/Radient/CMakeLists.txt Links the required Diligent engine components, EnTT, and Abseil libraries to the Radient target. ```cmake target_link_libraries(Radient PRIVATE Diligent-BuildSettings Diligent-GraphicsEngine Diligent-BasicPlatform Diligent-GraphicsTools Diligent-AssetLoader Diligent-TextureLoader Diligent-Common DiligentFX EnTT absl::btree absl::flat_hash_map absl::inlined_vector ) ``` -------------------------------- ### Prepare Resources for TAA and PostFXContext Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/TemporalAntiAliasing/README.md Call PrepareResources for both PostFXContext and TemporalAntiAliasing objects every frame before rendering. ```cpp { PostFXContext::FrameDesc FrameDesc; FrameDesc.Index = m_CurrentFrameNumber; // Current frame number. FrameDesc.Width = SCDesc.Width; // Current screen width. FrameDesc.Height = SCDesc.Height; // Current screen height. m_PostFXContext->PrepareResources(m_pDevice, FrameDesc, PostFXContext::FEATURE_FLAG_NONE); TemporalAntiAliasing::FEATURE_FLAGS ActiveFeatures = ...; m_TAA->PrepareResources(m_pDevice, m_pImmediateContext, m_PostFXContext.get(), ActiveFeatures); } ``` -------------------------------- ### Set Target Properties and Source Grouping Source: https://github.com/diligentgraphics/diligentfx/blob/master/Radient/CMakeLists.txt Organizes the target into a folder and defines the source group structure for IDEs. ```cmake set_target_properties(Radient PROPERTIES FOLDER DiligentFX ) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${RADIENT_SOURCE}) ``` -------------------------------- ### Create Bloom Objects Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/Bloom/README.md Instantiate the PostFXContext and Bloom objects. ```cpp m_PostFXContext = std::make_unique(m_pDevice); m_Bloom = std::make_unique(m_pDevice); ``` -------------------------------- ### Set compiler definitions and options Source: https://github.com/diligentgraphics/diligentfx/blob/master/Hydrogent/CMakeLists.txt Configures compiler-specific flags and definitions for MSVC and other compilers to ensure compatibility and silence warnings. ```cmake if(MSVC) target_compile_definitions(USD-Libraries INTERFACE NOMINMAX) # Silence compiler warnings and enable RTTI target_compile_options(USD-Libraries INTERFACE /wd4244 /wd4305 /wd4127 /wd4267 /wd4003 /GR) target_compile_options(Hydrogent PRIVATE /permissive-) else() target_compile_definitions(USD-Libraries INTERFACE _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION=1) target_compile_options(USD-Libraries INTERFACE -Wno-deprecated-declarations -Wno-conversion -Wno-deprecated-copy -Wno-missing-field-initializers) # Set default visibility or there will be issues with VtType set_target_properties(Hydrogent PROPERTIES CXX_VISIBILITY_PRESET default) endif() ``` -------------------------------- ### Include Shader Structures Source: https://github.com/diligentgraphics/diligentfx/blob/master/PostProcess/ScreenSpaceReflection/README.md Include shader structure definitions for HLSL. ```cpp namespace HLSL { #include "Shaders/Common/public/BasicStructures.fxh" #include "Shaders/PostProcess/ScreenSpaceReflection/public/ScreenSpaceReflectionStructures.fxh" } // namespace HLSL ```