diff options
| author | Nathan Hoobler <[email protected]> | 2016-03-22 11:40:34 -0400 |
|---|---|---|
| committer | Nathan Hoobler <[email protected]> | 2016-03-22 11:40:34 -0400 |
| commit | b4ab266c9010aaff5404f6a508a2e592eb367d36 (patch) | |
| tree | 1e9eefa78e90485397b50ce5e780a1d0cb38b493 /src | |
| download | volumetriclighting-b4ab266c9010aaff5404f6a508a2e592eb367d36.tar.xz volumetriclighting-b4ab266c9010aaff5404f6a508a2e592eb367d36.zip | |
initial commit
Diffstat (limited to 'src')
29 files changed, 6784 insertions, 0 deletions
diff --git a/src/NvVolumetricLighting.cpp b/src/NvVolumetricLighting.cpp new file mode 100644 index 0000000..e5c7fa5 --- /dev/null +++ b/src/NvVolumetricLighting.cpp @@ -0,0 +1,250 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#include <Nv/VolumetricLighting/NvVolumetricLighting.h> +#include <NvAllocatorCallback.h> + +#include "common.h" +#include "context_common.h" + +#if defined( NV_PLATFORM_D3D11 ) +# include "d3d11/context_d3d11.h" +#endif + +// [Add other platforms here] + +//////////////////////////////////////////////////////////////////////////////// + +namespace +{ + bool g_isLoaded = false; +} + +/*============================================================================== + Override memory operators +==============================================================================*/ +namespace +{ + // Default allocator + class DefaultAllocator : public Nv::NvAllocatorCallback + { + virtual void* allocate(size_t size, const char* typeName, const char* filename, int line) + { + LOG("GWVL Allocation: %u bytes (%s:%d)", size, filename, line); + return malloc(size); + } + + virtual void deallocate(void* ptr) + { + free(ptr); + } + } g_defaultAllocator; + + // Actual allocator to use + Nv::NvAllocatorCallback * g_allocator; +} + +#pragma push_macro("new") +#undef new +void * operator new(size_t size, const char * filename, int line) +{ + return g_allocator->allocate(size, "Gameworks Volumetric Lighting", filename, line); +} + +void operator delete(void * ptr, const char * filename, int line) +{ + filename; line; + g_allocator->deallocate(ptr); +} + +void operator delete (void * ptr) +{ + g_allocator->deallocate(ptr); +} + +void * operator new[](size_t size, const char * filename, int line) +{ + return g_allocator->allocate(size, "Gameworks Volumetric Lighting", filename, line); +} + +void operator delete[](void * ptr, const char * filename, int line) +{ + filename; line; + g_allocator->deallocate(ptr); +} + +void operator delete[](void * ptr) +{ + g_allocator->deallocate(ptr); +} +#pragma pop_macro("new") + +/*============================================================================== + Assert handler +==============================================================================*/ + +namespace +{ + Nv::NvAssertHandler * g_assert; + + class DefaultAssertHandler : public Nv::NvAssertHandler + { + virtual void operator()(const char* exp, const char* file, int line, bool& ignore) + { + LOG("%s(%d): Assertion Failed (%s)", file, line, exp); + BREAK(); + } + } g_defaultAssertHandler; +}; + +namespace nvidia +{ + NvAssertHandler& NvGetAssertHandler() + { + return *g_assert; + } +} + +//////////////////////////////////////////////////////////////////////////////// +namespace Nv { namespace VolumetricLighting { +//////////////////////////////////////////////////////////////////////////////// + +/*============================================================================== + API Functions +==============================================================================*/ + +//------------------------------------------------------------------------------ +//! Load the library and initialize global state +NV_VOLUMETRICLIGHTING_API(Status) OpenLibrary(NvAllocatorCallback * allocator, NvAssertHandler * assert_handler, const VersionDesc & link_version) +{ + if ( link_version.Major != LIBRARY_VERSION.Major || link_version.Minor != LIBRARY_VERSION.Minor) + return Status::INVALID_VERSION; + + g_allocator = (allocator) ? allocator : &g_defaultAllocator; + g_assert = (assert_handler) ? assert_handler : &g_defaultAssertHandler; + + g_isLoaded = true; + return Status::OK; +} + +//------------------------------------------------------------------------------ +//! Release the library and resources, and un-initialize all global state +NV_VOLUMETRICLIGHTING_API(Status) CloseLibrary() +{ + if (g_isLoaded == false) + return Status::UNINITIALIZED; + + g_isLoaded = false; + return Status::OK; +} + +//------------------------------------------------------------------------------ +//! Create a new context for rendering to a specified framebuffer +NV_VOLUMETRICLIGHTING_API(Status) CreateContext(Context & out_ctx, const PlatformDesc * pPlatformDesc, const ContextDesc * pContextDesc) +{ + if (g_isLoaded == false) + return Status::UNINITIALIZED; + + if (pPlatformDesc == nullptr || pContextDesc == nullptr) + return Status::INVALID_PARAMETER; + + out_ctx = nullptr; + switch (pPlatformDesc->platform) + { + +# if defined(NV_PLATFORM_D3D11) + case PlatformName::D3D11: + { + ContextImp_D3D11 * ctx_imp = nullptr; + Status create_status = ContextImp_D3D11::Create(&ctx_imp, pPlatformDesc, pContextDesc); + if (create_status != Status::OK) + { + return create_status; + } + else + { + out_ctx = static_cast<ContextImp_Common *>(ctx_imp); + return Status::OK; + } + } +# endif + // [Add other platforms here] + + default: + return Status::INVALID_PARAMETER; + } +} + +//------------------------------------------------------------------------------ +//! Release the context and any associated resources +NV_VOLUMETRICLIGHTING_API(Status) ReleaseContext(Context & ctx) +{ + if (ctx) + { + ContextImp_Common * vl_ctx = reinterpret_cast<ContextImp_Common *>(ctx); + delete vl_ctx; + ctx = nullptr; + return Status::OK; + } + else + { + return Status::INVALID_PARAMETER; + } +} + +//------------------------------------------------------------------------------ +//! Begin accumulation of lighting volumes for a view +NV_VOLUMETRICLIGHTING_API(Status) BeginAccumulation(Context ctx, PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc, DebugFlags debugFlags) +{ + return reinterpret_cast<ContextImp_Common *>(ctx)->BeginAccumulation(renderCtx, sceneDepth, pViewerDesc, pMediumDesc, debugFlags); +} + +//------------------------------------------------------------------------------ +//! Add a lighting volume to the accumulated results +NV_VOLUMETRICLIGHTING_API(Status) RenderVolume(Context ctx, PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) +{ + return reinterpret_cast<ContextImp_Common *>(ctx)->RenderVolume(renderCtx, shadowMap, pShadowMapDesc, pLightDesc, pVolumeDesc); +} + +//------------------------------------------------------------------------------ +//! Finish accumulation of lighting volumes +NV_VOLUMETRICLIGHTING_API(Status) EndAccumulation(Context ctx, PlatformRenderCtx renderCtx) +{ + return reinterpret_cast<ContextImp_Common *>(ctx)->EndAccumulation(renderCtx); +} + +//------------------------------------------------------------------------------ +//! Resolve the results and composite into the provided scene +NV_VOLUMETRICLIGHTING_API(Status) ApplyLighting(Context ctx, PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) +{ + return reinterpret_cast<ContextImp_Common *>(ctx)->ApplyLighting(renderCtx, sceneTarget, sceneDepth, pPostprocessDesc); +} + +//////////////////////////////////////////////////////////////////////////////// +}; /*namespace VolumetricLighting*/ }; /*namespace Nv*/ +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/build/vs2012/NvVolumetricLighting.sln b/src/build/vs2012/NvVolumetricLighting.sln new file mode 100644 index 0000000..32872d8 --- /dev/null +++ b/src/build/vs2012/NvVolumetricLighting.sln @@ -0,0 +1,30 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NvVolumetricLighting", "./NvVolumetricLighting.vcxproj", "{24C9474A-2D4C-EA01-97B4-6B52DA9A5490}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + checked|x64 = checked|x64 + debug|x64 = debug|x64 + profile|x64 = profile|x64 + release|x64 = release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.checked|x64.ActiveCfg = checked|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.checked|x64.Build.0 = checked|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.debug|x64.ActiveCfg = debug|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.debug|x64.Build.0 = debug|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.profile|x64.ActiveCfg = profile|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.profile|x64.Build.0 = profile|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.release|x64.ActiveCfg = release|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.release|x64.Build.0 = release|x64 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddins) = postSolution + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + EndGlobalSection +EndGlobal diff --git a/src/build/vs2012/NvVolumetricLighting.vcxproj b/src/build/vs2012/NvVolumetricLighting.vcxproj new file mode 100644 index 0000000..8561fd3 --- /dev/null +++ b/src/build/vs2012/NvVolumetricLighting.vcxproj @@ -0,0 +1,454 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="debug|x64"> + <Configuration>debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="profile|x64"> + <Configuration>profile</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="checked|x64"> + <Configuration>checked</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="release|x64"> + <Configuration>release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ApplicationEnvironment>title</ApplicationEnvironment> + <!-- - - - --> + <PlatformToolset>v110</PlatformToolset> + <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='profile|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <PlatformToolset>v110</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='checked|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <PlatformToolset>v110</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <PlatformToolset>v110</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='profile|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='checked|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'"> + <OutDir>./../../../redist/win64\</OutDir> + <IntDir>./x64/NvVolumetricLighting/debug\</IntDir> + <TargetExt>.dll</TargetExt> + <TargetName>NvVolumetricLighting.win64.D</TargetName> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <CodeAnalysisRules /> + <CodeAnalysisRuleAssemblies /> + <SkipCopyingSymbolsToOutputDirectory>true</SkipCopyingSymbolsToOutputDirectory> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'"> + <ClCompile> + <CallingConvention>Cdecl</CallingConvention> + <IntrinsicFunctions>true</IntrinsicFunctions> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <OpenMPSupport>false</OpenMPSupport> + <SuppressStartupBanner>true</SuppressStartupBanner> + <FloatingPointModel>Fast</FloatingPointModel> + <AdditionalOptions>/W4 /Oy- /EHsc -D_ITERATOR_DEBUG_LEVEL=0 /d2Zi+</AdditionalOptions> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>./{user:ShaderOutputPath};$(WindowsSDK_IncludePath);./../..;./../../../include;$(IntDir);./../../../external/NvFoundation/1.1/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_UNICODE;UNICODE;_WINDOWS;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_DEPRECATE;_LIB;NV_FOUNDATION_DLL=1;_WIN64;NV_PLATFORM_D3D11=1;NV_DEBUG=1;NV_CHECKED=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>false</ExceptionHandling> + <WarningLevel>Level4</WarningLevel> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile></PrecompiledHeaderFile> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + </ClCompile> + <Link> + <AdditionalOptions>/MACHINE:x64 /SUBSYSTEM:WINDOWS /NOLOGO</AdditionalOptions> + <AdditionalDependencies>d3d11.lib;comctl32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(OutDir)NvVolumetricLighting.win64.D.dll</OutputFile> + <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <ProgramDatabaseFile>$(OutDir)/NvVolumetricLighting.win64.D.dll.pdb</ProgramDatabaseFile> + <SubSystem>Console</SubSystem> + <ImportLibrary>./../../../lib/win64/NvVolumetricLighting.win64.D.lib</ImportLibrary> + <GenerateDebugInformation>true</GenerateDebugInformation> + <TargetMachine>MachineX64</TargetMachine> + </Link> + <ResourceCompile> + </ResourceCompile> + <ProjectReference> + </ProjectReference> + <PostBuildEvent> + <Command>XCOPY /Y /F "../../../redist/win64/$(TargetFileName)" "../../../samples/bin/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='profile|x64'"> + <OutDir>./../../../redist/win64\</OutDir> + <IntDir>./x64/NvVolumetricLighting/profile\</IntDir> + <TargetExt>.dll</TargetExt> + <TargetName>NvVolumetricLighting.win64.P</TargetName> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <CodeAnalysisRules /> + <CodeAnalysisRuleAssemblies /> + <SkipCopyingSymbolsToOutputDirectory>true</SkipCopyingSymbolsToOutputDirectory> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='profile|x64'"> + <ClCompile> + <IntrinsicFunctions>true</IntrinsicFunctions> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <FunctionLevelLinking>true</FunctionLevelLinking> + <OpenMPSupport>false</OpenMPSupport> + <SuppressStartupBanner>true</SuppressStartupBanner> + <FloatingPointModel>Fast</FloatingPointModel> + <AdditionalOptions>/W4 /Oy- /EHsc /d2Zi+</AdditionalOptions> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>./{user:ShaderOutputPath};$(WindowsSDK_IncludePath);./../..;./../../../include;$(IntDir);./../../../external/NvFoundation/1.1/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_UNICODE;UNICODE;_WINDOWS;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_DEPRECATE;_LIB;NV_FOUNDATION_DLL=1;_WIN64;NV_PLATFORM_D3D11=1;NV_PROFILE=1;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>false</ExceptionHandling> + <WarningLevel>Level4</WarningLevel> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile></PrecompiledHeaderFile> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + </ClCompile> + <Link> + <AdditionalOptions>/MACHINE:x64 /SUBSYSTEM:WINDOWS /NOLOGO</AdditionalOptions> + <AdditionalDependencies>d3d11.lib;comctl32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(OutDir)NvVolumetricLighting.win64.P.dll</OutputFile> + <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <ProgramDatabaseFile>$(OutDir)/NvVolumetricLighting.win64.P.dll.pdb</ProgramDatabaseFile> + <SubSystem>Console</SubSystem> + <ImportLibrary>./../../../lib/win64/NvVolumetricLighting.win64.P.lib</ImportLibrary> + <GenerateDebugInformation>true</GenerateDebugInformation> + <TargetMachine>MachineX64</TargetMachine> + </Link> + <ResourceCompile> + </ResourceCompile> + <ProjectReference> + </ProjectReference> + <PostBuildEvent> + <Command>XCOPY /Y /F "../../../redist/win64/$(TargetFileName)" "../../../samples/bin/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='checked|x64'"> + <OutDir>./../../../redist/win64\</OutDir> + <IntDir>./x64/NvVolumetricLighting/checked\</IntDir> + <TargetExt>.dll</TargetExt> + <TargetName>NvVolumetricLighting.win64.C</TargetName> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <CodeAnalysisRules /> + <CodeAnalysisRuleAssemblies /> + <SkipCopyingSymbolsToOutputDirectory>true</SkipCopyingSymbolsToOutputDirectory> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='checked|x64'"> + <ClCompile> + <IntrinsicFunctions>true</IntrinsicFunctions> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <FunctionLevelLinking>true</FunctionLevelLinking> + <OpenMPSupport>false</OpenMPSupport> + <SuppressStartupBanner>true</SuppressStartupBanner> + <FloatingPointModel>Fast</FloatingPointModel> + <AdditionalOptions>/W4 /Oy- /EHsc /d2Zi+</AdditionalOptions> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>./{user:ShaderOutputPath};$(WindowsSDK_IncludePath);./../..;./../../../include;$(IntDir);./../../../external/NvFoundation/1.1/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_UNICODE;UNICODE;_WINDOWS;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_DEPRECATE;_LIB;NV_FOUNDATION_DLL=1;_WIN64;NV_PLATFORM_D3D11=1;NV_CHECKED=1;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>false</ExceptionHandling> + <WarningLevel>Level4</WarningLevel> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile></PrecompiledHeaderFile> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + </ClCompile> + <Link> + <AdditionalOptions>/MACHINE:x64 /SUBSYSTEM:WINDOWS /NOLOGO</AdditionalOptions> + <AdditionalDependencies>d3d11.lib;comctl32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(OutDir)NvVolumetricLighting.win64.C.dll</OutputFile> + <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <ProgramDatabaseFile>$(OutDir)/NvVolumetricLighting.win64.C.dll.pdb</ProgramDatabaseFile> + <SubSystem>Console</SubSystem> + <ImportLibrary>./../../../lib/win64/NvVolumetricLighting.win64.C.lib</ImportLibrary> + <GenerateDebugInformation>true</GenerateDebugInformation> + <TargetMachine>MachineX64</TargetMachine> + </Link> + <ResourceCompile> + </ResourceCompile> + <ProjectReference> + </ProjectReference> + <PostBuildEvent> + <Command>XCOPY /Y /F "../../../redist/win64/$(TargetFileName)" "../../../samples/bin/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'"> + <OutDir>./../../../redist/win64\</OutDir> + <IntDir>./x64/NvVolumetricLighting/release\</IntDir> + <TargetExt>.dll</TargetExt> + <TargetName>NvVolumetricLighting.win64</TargetName> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <CodeAnalysisRules /> + <CodeAnalysisRuleAssemblies /> + <SkipCopyingSymbolsToOutputDirectory>true</SkipCopyingSymbolsToOutputDirectory> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'"> + <ClCompile> + <IntrinsicFunctions>true</IntrinsicFunctions> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <FunctionLevelLinking>true</FunctionLevelLinking> + <OpenMPSupport>false</OpenMPSupport> + <SuppressStartupBanner>true</SuppressStartupBanner> + <FloatingPointModel>Fast</FloatingPointModel> + <AdditionalOptions>/W4 /Oy- /EHsc /d2Zi+</AdditionalOptions> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>./{user:ShaderOutputPath};$(WindowsSDK_IncludePath);./../..;./../../../include;$(IntDir);./../../../external/NvFoundation/1.1/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_UNICODE;UNICODE;_WINDOWS;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_DEPRECATE;_LIB;NV_FOUNDATION_DLL=1;_WIN64;NV_PLATFORM_D3D11=1;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>false</ExceptionHandling> + <WarningLevel>Level4</WarningLevel> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile></PrecompiledHeaderFile> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + </ClCompile> + <Link> + <AdditionalOptions>/MACHINE:x64 /SUBSYSTEM:WINDOWS /NOLOGO</AdditionalOptions> + <AdditionalDependencies>d3d11.lib;comctl32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(OutDir)NvVolumetricLighting.win64.dll</OutputFile> + <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <ProgramDatabaseFile>$(OutDir)/NvVolumetricLighting.win64.dll.pdb</ProgramDatabaseFile> + <SubSystem>Console</SubSystem> + <ImportLibrary>./../../../lib/win64/NvVolumetricLighting.win64.lib</ImportLibrary> + <GenerateDebugInformation>true</GenerateDebugInformation> + <TargetMachine>MachineX64</TargetMachine> + </Link> + <ResourceCompile> + </ResourceCompile> + <ProjectReference> + </ProjectReference> + <PostBuildEvent> + <Command>XCOPY /Y /F "../../../redist/win64/$(TargetFileName)" "../../../samples/bin/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="..\..\..\include\Nv\VolumetricLighting\NvVolumetricLighting.h"> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\..\common.h"> + </ClInclude> + <ClInclude Include="..\..\context_common.h"> + </ClInclude> + <ClCompile Include="..\..\context_common.cpp"> + </ClCompile> + <ClCompile Include="..\..\NvVolumetricLighting.cpp"> + </ClCompile> + </ItemGroup> + <ItemGroup> + <CustomBuild Include="..\..\shaders\Quad_VS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\Quad_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/Quad_VS.mux.h;$(IntDir)shaders/Quad_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\Quad_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/Quad_VS.mux.h;$(IntDir)shaders/Quad_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\Quad_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/Quad_VS.mux.h;$(IntDir)shaders/Quad_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\Quad_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/Quad_VS.mux.h;$(IntDir)shaders/Quad_VS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\RenderVolume_VS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\RenderVolume_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/RenderVolume_VS.mux.h;$(IntDir)shaders/RenderVolume_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\RenderVolume_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/RenderVolume_VS.mux.h;$(IntDir)shaders/RenderVolume_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\RenderVolume_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/RenderVolume_VS.mux.h;$(IntDir)shaders/RenderVolume_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\RenderVolume_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/RenderVolume_VS.mux.h;$(IntDir)shaders/RenderVolume_VS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\RenderVolume_HS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Ths_5_0" ..\..\shaders\RenderVolume_HS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/RenderVolume_HS.mux.h;$(IntDir)shaders/RenderVolume_HS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Ths_5_0" ..\..\shaders\RenderVolume_HS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/RenderVolume_HS.mux.h;$(IntDir)shaders/RenderVolume_HS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Ths_5_0" ..\..\shaders\RenderVolume_HS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/RenderVolume_HS.mux.h;$(IntDir)shaders/RenderVolume_HS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Ths_5_0" ..\..\shaders\RenderVolume_HS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/RenderVolume_HS.mux.h;$(IntDir)shaders/RenderVolume_HS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\RenderVolume_DS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tds_5_0" ..\..\shaders\RenderVolume_DS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/RenderVolume_DS.mux.h;$(IntDir)shaders/RenderVolume_DS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tds_5_0" ..\..\shaders\RenderVolume_DS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/RenderVolume_DS.mux.h;$(IntDir)shaders/RenderVolume_DS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tds_5_0" ..\..\shaders\RenderVolume_DS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/RenderVolume_DS.mux.h;$(IntDir)shaders/RenderVolume_DS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tds_5_0" ..\..\shaders\RenderVolume_DS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/RenderVolume_DS.mux.h;$(IntDir)shaders/RenderVolume_DS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\Apply_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Apply_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/Apply_PS.mux.h;$(IntDir)shaders/Apply_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Apply_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/Apply_PS.mux.h;$(IntDir)shaders/Apply_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Apply_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/Apply_PS.mux.h;$(IntDir)shaders/Apply_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Apply_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/Apply_PS.mux.h;$(IntDir)shaders/Apply_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\ComputePhaseLookup_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\ComputePhaseLookup_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/ComputePhaseLookup_PS.mux.h;$(IntDir)shaders/ComputePhaseLookup_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\ComputePhaseLookup_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/ComputePhaseLookup_PS.mux.h;$(IntDir)shaders/ComputePhaseLookup_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\ComputePhaseLookup_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/ComputePhaseLookup_PS.mux.h;$(IntDir)shaders/ComputePhaseLookup_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\ComputePhaseLookup_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/ComputePhaseLookup_PS.mux.h;$(IntDir)shaders/ComputePhaseLookup_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\Debug_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Debug_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/Debug_PS.mux.h;$(IntDir)shaders/Debug_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Debug_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/Debug_PS.mux.h;$(IntDir)shaders/Debug_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Debug_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/Debug_PS.mux.h;$(IntDir)shaders/Debug_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Debug_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/Debug_PS.mux.h;$(IntDir)shaders/Debug_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\DownsampleDepth_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\DownsampleDepth_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/DownsampleDepth_PS.mux.h;$(IntDir)shaders/DownsampleDepth_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\DownsampleDepth_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/DownsampleDepth_PS.mux.h;$(IntDir)shaders/DownsampleDepth_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\DownsampleDepth_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/DownsampleDepth_PS.mux.h;$(IntDir)shaders/DownsampleDepth_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\DownsampleDepth_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/DownsampleDepth_PS.mux.h;$(IntDir)shaders/DownsampleDepth_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\RenderVolume_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\RenderVolume_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/RenderVolume_PS.mux.h;$(IntDir)shaders/RenderVolume_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\RenderVolume_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/RenderVolume_PS.mux.h;$(IntDir)shaders/RenderVolume_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\RenderVolume_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/RenderVolume_PS.mux.h;$(IntDir)shaders/RenderVolume_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\RenderVolume_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/RenderVolume_PS.mux.h;$(IntDir)shaders/RenderVolume_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\Resolve_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Resolve_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/Resolve_PS.mux.h;$(IntDir)shaders/Resolve_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Resolve_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/Resolve_PS.mux.h;$(IntDir)shaders/Resolve_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Resolve_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/Resolve_PS.mux.h;$(IntDir)shaders/Resolve_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Resolve_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/Resolve_PS.mux.h;$(IntDir)shaders/Resolve_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\TemporalFilter_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\TemporalFilter_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/TemporalFilter_PS.mux.h;$(IntDir)shaders/TemporalFilter_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\TemporalFilter_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/TemporalFilter_PS.mux.h;$(IntDir)shaders/TemporalFilter_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\TemporalFilter_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/TemporalFilter_PS.mux.h;$(IntDir)shaders/TemporalFilter_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\TemporalFilter_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/TemporalFilter_PS.mux.h;$(IntDir)shaders/TemporalFilter_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\ComputeLightLUT_CS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tcs_5_0" ..\..\shaders\ComputeLightLUT_CS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/ComputeLightLUT_CS.mux.h;$(IntDir)shaders/ComputeLightLUT_CS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tcs_5_0" ..\..\shaders\ComputeLightLUT_CS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/ComputeLightLUT_CS.mux.h;$(IntDir)shaders/ComputeLightLUT_CS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tcs_5_0" ..\..\shaders\ComputeLightLUT_CS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/ComputeLightLUT_CS.mux.h;$(IntDir)shaders/ComputeLightLUT_CS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tcs_5_0" ..\..\shaders\ComputeLightLUT_CS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/ComputeLightLUT_CS.mux.h;$(IntDir)shaders/ComputeLightLUT_CS.mux.bytecode;</Outputs> + </CustomBuild> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\..\d3d11\compiled_shaders_d3d11.h"> + </ClInclude> + <ClInclude Include="..\..\d3d11\context_d3d11.h"> + </ClInclude> + <ClInclude Include="..\..\d3d11\d3d11_util.h"> + </ClInclude> + <ClCompile Include="..\..\d3d11\compiled_shaders_d3d11.cpp"> + </ClCompile> + <ClCompile Include="..\..\d3d11\context_d3d11.cpp"> + </ClCompile> + <ClCompile Include="..\..\d3d11\d3d11_util.cpp"> + </ClCompile> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"></ImportGroup> +</Project> diff --git a/src/build/vs2012/NvVolumetricLighting.vcxproj.filters b/src/build/vs2012/NvVolumetricLighting.vcxproj.filters new file mode 100644 index 0000000..b0d05b6 --- /dev/null +++ b/src/build/vs2012/NvVolumetricLighting.vcxproj.filters @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="public"><!-- -->
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\include\Nv\VolumetricLighting\NvVolumetricLighting.h">
+ <Filter>public</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <Filter Include="common"><!-- -->
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\common.h">
+ <Filter>common</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\context_common.h">
+ <Filter>common</Filter>
+ </ClInclude>
+ <ClCompile Include="..\..\context_common.cpp">
+ <Filter>common</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\NvVolumetricLighting.cpp">
+ <Filter>common</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <Filter Include="shaders"><!-- Shadermux -->
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="..\..\shaders\Quad_VS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\RenderVolume_VS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\RenderVolume_HS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\RenderVolume_DS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\Apply_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\ComputePhaseLookup_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\Debug_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\DownsampleDepth_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\RenderVolume_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\Resolve_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\TemporalFilter_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\ComputeLightLUT_CS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ </ItemGroup>
+ <ItemGroup>
+ <Filter Include="d3d11"><!-- -->
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\d3d11\compiled_shaders_d3d11.h">
+ <Filter>d3d11</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\d3d11\context_d3d11.h">
+ <Filter>d3d11</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\d3d11\d3d11_util.h">
+ <Filter>d3d11</Filter>
+ </ClInclude>
+ <ClCompile Include="..\..\d3d11\compiled_shaders_d3d11.cpp">
+ <Filter>d3d11</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\d3d11\context_d3d11.cpp">
+ <Filter>d3d11</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\d3d11\d3d11_util.cpp">
+ <Filter>d3d11</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project>
\ No newline at end of file diff --git a/src/build/vs2013/NvVolumetricLighting.sln b/src/build/vs2013/NvVolumetricLighting.sln new file mode 100644 index 0000000..a6f3508 --- /dev/null +++ b/src/build/vs2013/NvVolumetricLighting.sln @@ -0,0 +1,30 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NvVolumetricLighting", "./NvVolumetricLighting.vcxproj", "{24C9474A-2D4C-EA01-97B4-6B52DA9A5490}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + checked|x64 = checked|x64 + debug|x64 = debug|x64 + profile|x64 = profile|x64 + release|x64 = release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.checked|x64.ActiveCfg = checked|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.checked|x64.Build.0 = checked|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.debug|x64.ActiveCfg = debug|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.debug|x64.Build.0 = debug|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.profile|x64.ActiveCfg = profile|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.profile|x64.Build.0 = profile|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.release|x64.ActiveCfg = release|x64 + {24C9474A-2D4C-EA01-97B4-6B52DA9A5490}.release|x64.Build.0 = release|x64 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddins) = postSolution + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + EndGlobalSection +EndGlobal diff --git a/src/build/vs2013/NvVolumetricLighting.vcxproj b/src/build/vs2013/NvVolumetricLighting.vcxproj new file mode 100644 index 0000000..1f95b60 --- /dev/null +++ b/src/build/vs2013/NvVolumetricLighting.vcxproj @@ -0,0 +1,454 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="debug|x64"> + <Configuration>debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="profile|x64"> + <Configuration>profile</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="checked|x64"> + <Configuration>checked</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="release|x64"> + <Configuration>release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ApplicationEnvironment>title</ApplicationEnvironment> + <!-- - - - --> + <PlatformToolset>v110</PlatformToolset> + <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <PlatformToolset>v120</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='profile|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <PlatformToolset>v120</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='checked|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <PlatformToolset>v120</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <PlatformToolset>v120</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='profile|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='checked|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'"> + <OutDir>./../../../redist/win64\</OutDir> + <IntDir>./x64/NvVolumetricLighting/debug\</IntDir> + <TargetExt>.dll</TargetExt> + <TargetName>NvVolumetricLighting.win64.D</TargetName> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <CodeAnalysisRules /> + <CodeAnalysisRuleAssemblies /> + <SkipCopyingSymbolsToOutputDirectory>true</SkipCopyingSymbolsToOutputDirectory> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'"> + <ClCompile> + <CallingConvention>Cdecl</CallingConvention> + <IntrinsicFunctions>true</IntrinsicFunctions> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <OpenMPSupport>false</OpenMPSupport> + <SuppressStartupBanner>true</SuppressStartupBanner> + <FloatingPointModel>Fast</FloatingPointModel> + <AdditionalOptions>/W4 /Oy- /EHsc -D_ITERATOR_DEBUG_LEVEL=0 /d2Zi+</AdditionalOptions> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>./{user:ShaderOutputPath};./../..;./../../../include;$(IntDir);./../../../external/NvFoundation/1.1/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_UNICODE;UNICODE;_WINDOWS;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_DEPRECATE;_LIB;NV_FOUNDATION_DLL=1;_WIN64;NV_PLATFORM_D3D11=1;NV_DEBUG=1;NV_CHECKED=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>false</ExceptionHandling> + <WarningLevel>Level4</WarningLevel> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile></PrecompiledHeaderFile> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + </ClCompile> + <Link> + <AdditionalOptions>/MACHINE:x64 /SUBSYSTEM:WINDOWS /NOLOGO</AdditionalOptions> + <AdditionalDependencies>d3d11.lib;comctl32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(OutDir)NvVolumetricLighting.win64.D.dll</OutputFile> + <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <ProgramDatabaseFile>$(OutDir)/NvVolumetricLighting.win64.D.dll.pdb</ProgramDatabaseFile> + <SubSystem>Console</SubSystem> + <ImportLibrary>./../../../lib/win64/NvVolumetricLighting.win64.D.lib</ImportLibrary> + <GenerateDebugInformation>true</GenerateDebugInformation> + <TargetMachine>MachineX64</TargetMachine> + </Link> + <ResourceCompile> + </ResourceCompile> + <ProjectReference> + </ProjectReference> + <PostBuildEvent> + <Command>XCOPY /Y /F "../../../redist/win64/$(TargetFileName)" "../../../samples/bin/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='profile|x64'"> + <OutDir>./../../../redist/win64\</OutDir> + <IntDir>./x64/NvVolumetricLighting/profile\</IntDir> + <TargetExt>.dll</TargetExt> + <TargetName>NvVolumetricLighting.win64.P</TargetName> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <CodeAnalysisRules /> + <CodeAnalysisRuleAssemblies /> + <SkipCopyingSymbolsToOutputDirectory>true</SkipCopyingSymbolsToOutputDirectory> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='profile|x64'"> + <ClCompile> + <IntrinsicFunctions>true</IntrinsicFunctions> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <FunctionLevelLinking>true</FunctionLevelLinking> + <OpenMPSupport>false</OpenMPSupport> + <SuppressStartupBanner>true</SuppressStartupBanner> + <FloatingPointModel>Fast</FloatingPointModel> + <AdditionalOptions>/W4 /Oy- /EHsc /d2Zi+</AdditionalOptions> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>./{user:ShaderOutputPath};./../..;./../../../include;$(IntDir);./../../../external/NvFoundation/1.1/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_UNICODE;UNICODE;_WINDOWS;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_DEPRECATE;_LIB;NV_FOUNDATION_DLL=1;_WIN64;NV_PLATFORM_D3D11=1;NV_PROFILE=1;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>false</ExceptionHandling> + <WarningLevel>Level4</WarningLevel> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile></PrecompiledHeaderFile> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + </ClCompile> + <Link> + <AdditionalOptions>/MACHINE:x64 /SUBSYSTEM:WINDOWS /NOLOGO</AdditionalOptions> + <AdditionalDependencies>d3d11.lib;comctl32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(OutDir)NvVolumetricLighting.win64.P.dll</OutputFile> + <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <ProgramDatabaseFile>$(OutDir)/NvVolumetricLighting.win64.P.dll.pdb</ProgramDatabaseFile> + <SubSystem>Console</SubSystem> + <ImportLibrary>./../../../lib/win64/NvVolumetricLighting.win64.P.lib</ImportLibrary> + <GenerateDebugInformation>true</GenerateDebugInformation> + <TargetMachine>MachineX64</TargetMachine> + </Link> + <ResourceCompile> + </ResourceCompile> + <ProjectReference> + </ProjectReference> + <PostBuildEvent> + <Command>XCOPY /Y /F "../../../redist/win64/$(TargetFileName)" "../../../samples/bin/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='checked|x64'"> + <OutDir>./../../../redist/win64\</OutDir> + <IntDir>./x64/NvVolumetricLighting/checked\</IntDir> + <TargetExt>.dll</TargetExt> + <TargetName>NvVolumetricLighting.win64.C</TargetName> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <CodeAnalysisRules /> + <CodeAnalysisRuleAssemblies /> + <SkipCopyingSymbolsToOutputDirectory>true</SkipCopyingSymbolsToOutputDirectory> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='checked|x64'"> + <ClCompile> + <IntrinsicFunctions>true</IntrinsicFunctions> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <FunctionLevelLinking>true</FunctionLevelLinking> + <OpenMPSupport>false</OpenMPSupport> + <SuppressStartupBanner>true</SuppressStartupBanner> + <FloatingPointModel>Fast</FloatingPointModel> + <AdditionalOptions>/W4 /Oy- /EHsc /d2Zi+</AdditionalOptions> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>./{user:ShaderOutputPath};./../..;./../../../include;$(IntDir);./../../../external/NvFoundation/1.1/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_UNICODE;UNICODE;_WINDOWS;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_DEPRECATE;_LIB;NV_FOUNDATION_DLL=1;_WIN64;NV_PLATFORM_D3D11=1;NV_CHECKED=1;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>false</ExceptionHandling> + <WarningLevel>Level4</WarningLevel> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile></PrecompiledHeaderFile> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + </ClCompile> + <Link> + <AdditionalOptions>/MACHINE:x64 /SUBSYSTEM:WINDOWS /NOLOGO</AdditionalOptions> + <AdditionalDependencies>d3d11.lib;comctl32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(OutDir)NvVolumetricLighting.win64.C.dll</OutputFile> + <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <ProgramDatabaseFile>$(OutDir)/NvVolumetricLighting.win64.C.dll.pdb</ProgramDatabaseFile> + <SubSystem>Console</SubSystem> + <ImportLibrary>./../../../lib/win64/NvVolumetricLighting.win64.C.lib</ImportLibrary> + <GenerateDebugInformation>true</GenerateDebugInformation> + <TargetMachine>MachineX64</TargetMachine> + </Link> + <ResourceCompile> + </ResourceCompile> + <ProjectReference> + </ProjectReference> + <PostBuildEvent> + <Command>XCOPY /Y /F "../../../redist/win64/$(TargetFileName)" "../../../samples/bin/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'"> + <OutDir>./../../../redist/win64\</OutDir> + <IntDir>./x64/NvVolumetricLighting/release\</IntDir> + <TargetExt>.dll</TargetExt> + <TargetName>NvVolumetricLighting.win64</TargetName> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <CodeAnalysisRules /> + <CodeAnalysisRuleAssemblies /> + <SkipCopyingSymbolsToOutputDirectory>true</SkipCopyingSymbolsToOutputDirectory> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'"> + <ClCompile> + <IntrinsicFunctions>true</IntrinsicFunctions> + <RuntimeTypeInfo>false</RuntimeTypeInfo> + <FunctionLevelLinking>true</FunctionLevelLinking> + <OpenMPSupport>false</OpenMPSupport> + <SuppressStartupBanner>true</SuppressStartupBanner> + <FloatingPointModel>Fast</FloatingPointModel> + <AdditionalOptions>/W4 /Oy- /EHsc /d2Zi+</AdditionalOptions> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>./{user:ShaderOutputPath};./../..;./../../../include;$(IntDir);./../../../external/NvFoundation/1.1/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_UNICODE;UNICODE;_WINDOWS;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_DEPRECATE;_LIB;NV_FOUNDATION_DLL=1;_WIN64;NV_PLATFORM_D3D11=1;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>false</ExceptionHandling> + <WarningLevel>Level4</WarningLevel> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile></PrecompiledHeaderFile> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + </ClCompile> + <Link> + <AdditionalOptions>/MACHINE:x64 /SUBSYSTEM:WINDOWS /NOLOGO</AdditionalOptions> + <AdditionalDependencies>d3d11.lib;comctl32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(OutDir)NvVolumetricLighting.win64.dll</OutputFile> + <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <ProgramDatabaseFile>$(OutDir)/NvVolumetricLighting.win64.dll.pdb</ProgramDatabaseFile> + <SubSystem>Console</SubSystem> + <ImportLibrary>./../../../lib/win64/NvVolumetricLighting.win64.lib</ImportLibrary> + <GenerateDebugInformation>true</GenerateDebugInformation> + <TargetMachine>MachineX64</TargetMachine> + </Link> + <ResourceCompile> + </ResourceCompile> + <ProjectReference> + </ProjectReference> + <PostBuildEvent> + <Command>XCOPY /Y /F "../../../redist/win64/$(TargetFileName)" "../../../samples/bin/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="..\..\..\include\Nv\VolumetricLighting\NvVolumetricLighting.h"> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\..\common.h"> + </ClInclude> + <ClInclude Include="..\..\context_common.h"> + </ClInclude> + <ClCompile Include="..\..\context_common.cpp"> + </ClCompile> + <ClCompile Include="..\..\NvVolumetricLighting.cpp"> + </ClCompile> + </ItemGroup> + <ItemGroup> + <CustomBuild Include="..\..\shaders\Quad_VS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\Quad_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/Quad_VS.mux.h;$(IntDir)shaders/Quad_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\Quad_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/Quad_VS.mux.h;$(IntDir)shaders/Quad_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\Quad_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/Quad_VS.mux.h;$(IntDir)shaders/Quad_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\Quad_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/Quad_VS.mux.h;$(IntDir)shaders/Quad_VS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\RenderVolume_VS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\RenderVolume_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/RenderVolume_VS.mux.h;$(IntDir)shaders/RenderVolume_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\RenderVolume_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/RenderVolume_VS.mux.h;$(IntDir)shaders/RenderVolume_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\RenderVolume_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/RenderVolume_VS.mux.h;$(IntDir)shaders/RenderVolume_VS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tvs_5_0" ..\..\shaders\RenderVolume_VS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/RenderVolume_VS.mux.h;$(IntDir)shaders/RenderVolume_VS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\RenderVolume_HS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Ths_5_0" ..\..\shaders\RenderVolume_HS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/RenderVolume_HS.mux.h;$(IntDir)shaders/RenderVolume_HS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Ths_5_0" ..\..\shaders\RenderVolume_HS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/RenderVolume_HS.mux.h;$(IntDir)shaders/RenderVolume_HS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Ths_5_0" ..\..\shaders\RenderVolume_HS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/RenderVolume_HS.mux.h;$(IntDir)shaders/RenderVolume_HS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Ths_5_0" ..\..\shaders\RenderVolume_HS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/RenderVolume_HS.mux.h;$(IntDir)shaders/RenderVolume_HS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\RenderVolume_DS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tds_5_0" ..\..\shaders\RenderVolume_DS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/RenderVolume_DS.mux.h;$(IntDir)shaders/RenderVolume_DS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tds_5_0" ..\..\shaders\RenderVolume_DS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/RenderVolume_DS.mux.h;$(IntDir)shaders/RenderVolume_DS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tds_5_0" ..\..\shaders\RenderVolume_DS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/RenderVolume_DS.mux.h;$(IntDir)shaders/RenderVolume_DS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tds_5_0" ..\..\shaders\RenderVolume_DS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/RenderVolume_DS.mux.h;$(IntDir)shaders/RenderVolume_DS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\Apply_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Apply_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/Apply_PS.mux.h;$(IntDir)shaders/Apply_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Apply_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/Apply_PS.mux.h;$(IntDir)shaders/Apply_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Apply_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/Apply_PS.mux.h;$(IntDir)shaders/Apply_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Apply_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/Apply_PS.mux.h;$(IntDir)shaders/Apply_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\ComputePhaseLookup_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\ComputePhaseLookup_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/ComputePhaseLookup_PS.mux.h;$(IntDir)shaders/ComputePhaseLookup_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\ComputePhaseLookup_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/ComputePhaseLookup_PS.mux.h;$(IntDir)shaders/ComputePhaseLookup_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\ComputePhaseLookup_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/ComputePhaseLookup_PS.mux.h;$(IntDir)shaders/ComputePhaseLookup_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\ComputePhaseLookup_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/ComputePhaseLookup_PS.mux.h;$(IntDir)shaders/ComputePhaseLookup_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\Debug_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Debug_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/Debug_PS.mux.h;$(IntDir)shaders/Debug_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Debug_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/Debug_PS.mux.h;$(IntDir)shaders/Debug_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Debug_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/Debug_PS.mux.h;$(IntDir)shaders/Debug_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Debug_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/Debug_PS.mux.h;$(IntDir)shaders/Debug_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\DownsampleDepth_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\DownsampleDepth_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/DownsampleDepth_PS.mux.h;$(IntDir)shaders/DownsampleDepth_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\DownsampleDepth_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/DownsampleDepth_PS.mux.h;$(IntDir)shaders/DownsampleDepth_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\DownsampleDepth_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/DownsampleDepth_PS.mux.h;$(IntDir)shaders/DownsampleDepth_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\DownsampleDepth_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/DownsampleDepth_PS.mux.h;$(IntDir)shaders/DownsampleDepth_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\RenderVolume_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\RenderVolume_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/RenderVolume_PS.mux.h;$(IntDir)shaders/RenderVolume_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\RenderVolume_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/RenderVolume_PS.mux.h;$(IntDir)shaders/RenderVolume_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\RenderVolume_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/RenderVolume_PS.mux.h;$(IntDir)shaders/RenderVolume_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\RenderVolume_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/RenderVolume_PS.mux.h;$(IntDir)shaders/RenderVolume_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\Resolve_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Resolve_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/Resolve_PS.mux.h;$(IntDir)shaders/Resolve_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Resolve_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/Resolve_PS.mux.h;$(IntDir)shaders/Resolve_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Resolve_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/Resolve_PS.mux.h;$(IntDir)shaders/Resolve_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\Resolve_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/Resolve_PS.mux.h;$(IntDir)shaders/Resolve_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\TemporalFilter_PS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\TemporalFilter_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/TemporalFilter_PS.mux.h;$(IntDir)shaders/TemporalFilter_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\TemporalFilter_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/TemporalFilter_PS.mux.h;$(IntDir)shaders/TemporalFilter_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\TemporalFilter_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/TemporalFilter_PS.mux.h;$(IntDir)shaders/TemporalFilter_PS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tps_5_0" ..\..\shaders\TemporalFilter_PS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/TemporalFilter_PS.mux.h;$(IntDir)shaders/TemporalFilter_PS.mux.bytecode;</Outputs> + </CustomBuild> + <CustomBuild Include="..\..\shaders\ComputeLightLUT_CS.hlsl"> + <Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tcs_5_0" ..\..\shaders\ComputeLightLUT_CS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='debug|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(IntDir)shaders/ComputeLightLUT_CS.mux.h;$(IntDir)shaders/ComputeLightLUT_CS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='profile|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tcs_5_0" ..\..\shaders\ComputeLightLUT_CS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='profile|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='profile|x64'">$(IntDir)shaders/ComputeLightLUT_CS.mux.h;$(IntDir)shaders/ComputeLightLUT_CS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='checked|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tcs_5_0" ..\..\shaders\ComputeLightLUT_CS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='checked|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='checked|x64'">$(IntDir)shaders/ComputeLightLUT_CS.mux.h;$(IntDir)shaders/ComputeLightLUT_CS.mux.bytecode;</Outputs> + <Command Condition="'$(Configuration)|$(Platform)'=='release|x64'">"../../../tools/shadermux.exe" -l 0 -w -f -o "$(IntDir)shaders" -p d3d11 -c "/Tcs_5_0" ..\..\shaders\ComputeLightLUT_CS.hlsl</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='release|x64'">Precompiling shader permutations for %(Identity)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='release|x64'">$(IntDir)shaders/ComputeLightLUT_CS.mux.h;$(IntDir)shaders/ComputeLightLUT_CS.mux.bytecode;</Outputs> + </CustomBuild> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\..\d3d11\compiled_shaders_d3d11.h"> + </ClInclude> + <ClInclude Include="..\..\d3d11\context_d3d11.h"> + </ClInclude> + <ClInclude Include="..\..\d3d11\d3d11_util.h"> + </ClInclude> + <ClCompile Include="..\..\d3d11\compiled_shaders_d3d11.cpp"> + </ClCompile> + <ClCompile Include="..\..\d3d11\context_d3d11.cpp"> + </ClCompile> + <ClCompile Include="..\..\d3d11\d3d11_util.cpp"> + </ClCompile> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"></ImportGroup> +</Project> diff --git a/src/build/vs2013/NvVolumetricLighting.vcxproj.filters b/src/build/vs2013/NvVolumetricLighting.vcxproj.filters new file mode 100644 index 0000000..b0d05b6 --- /dev/null +++ b/src/build/vs2013/NvVolumetricLighting.vcxproj.filters @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="public"><!-- -->
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\include\Nv\VolumetricLighting\NvVolumetricLighting.h">
+ <Filter>public</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <Filter Include="common"><!-- -->
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\common.h">
+ <Filter>common</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\context_common.h">
+ <Filter>common</Filter>
+ </ClInclude>
+ <ClCompile Include="..\..\context_common.cpp">
+ <Filter>common</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\NvVolumetricLighting.cpp">
+ <Filter>common</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <Filter Include="shaders"><!-- Shadermux -->
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="..\..\shaders\Quad_VS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\RenderVolume_VS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\RenderVolume_HS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\RenderVolume_DS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\Apply_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\ComputePhaseLookup_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\Debug_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\DownsampleDepth_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\RenderVolume_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\Resolve_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\TemporalFilter_PS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ <CustomBuild Include="..\..\shaders\ComputeLightLUT_CS.hlsl">
+ <Filter>shaders</Filter>
+ </CustomBuild>
+ </ItemGroup>
+ <ItemGroup>
+ <Filter Include="d3d11"><!-- -->
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\d3d11\compiled_shaders_d3d11.h">
+ <Filter>d3d11</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\d3d11\context_d3d11.h">
+ <Filter>d3d11</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\d3d11\d3d11_util.h">
+ <Filter>d3d11</Filter>
+ </ClInclude>
+ <ClCompile Include="..\..\d3d11\compiled_shaders_d3d11.cpp">
+ <Filter>d3d11</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\d3d11\context_d3d11.cpp">
+ <Filter>d3d11</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\d3d11\d3d11_util.cpp">
+ <Filter>d3d11</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project>
\ No newline at end of file diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..4c76a87 --- /dev/null +++ b/src/common.h @@ -0,0 +1,261 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#ifndef COMMON_H +#define COMMON_H +//////////////////////////////////////////////////////////////////////////////// + +#include <NvPreprocessor.h> +#include <NvAssert.h> +#include <NvIntrinsics.h> +#include <NvMath.h> +#include <NvFoundationMath.h> +#include <NvCTypes.h> + +#if (NV_WIN32 || NV_WIN64) +#include <Windows.h> +#endif + +namespace Nv +{ + using namespace nvidia; +} // namespace Nv + +//////////////////////////////////////////////////////////////////////////////// + +/*============================================================================== + GFSDK Conversion stubs +==============================================================================*/ + +NV_FORCE_INLINE Nv::NvVec2 NVCtoNV(const NvcVec2 & rhs) +{ + return *reinterpret_cast<const Nv::NvVec2 *>(&rhs); +} + +NV_FORCE_INLINE Nv::NvVec3 NVCtoNV(const NvcVec3 & rhs) +{ + return *reinterpret_cast<const Nv::NvVec3 *>(&rhs); +} + +NV_FORCE_INLINE Nv::NvVec4 NVCtoNV(const NvcVec4 & rhs) +{ + return *reinterpret_cast<const Nv::NvVec4 *>(&rhs); +} + +NV_FORCE_INLINE Nv::NvMat44 NVCtoNV(const NvcMat44 & rhs) +{ + return *reinterpret_cast<const Nv::NvMat44 *>(&rhs); +} + +NV_FORCE_INLINE Nv::NvMat44 Inverse(const Nv::NvMat44 & in) +{ + const float * m = in.front(); + float inv[16]; + float det; + int i; + + inv[0] = m[5] * m[10] * m[15] - + m[5] * m[11] * m[14] - + m[9] * m[6] * m[15] + + m[9] * m[7] * m[14] + + m[13] * m[6] * m[11] - + m[13] * m[7] * m[10]; + + inv[4] = -m[4] * m[10] * m[15] + + m[4] * m[11] * m[14] + + m[8] * m[6] * m[15] - + m[8] * m[7] * m[14] - + m[12] * m[6] * m[11] + + m[12] * m[7] * m[10]; + + inv[8] = m[4] * m[9] * m[15] - + m[4] * m[11] * m[13] - + m[8] * m[5] * m[15] + + m[8] * m[7] * m[13] + + m[12] * m[5] * m[11] - + m[12] * m[7] * m[9]; + + inv[12] = -m[4] * m[9] * m[14] + + m[4] * m[10] * m[13] + + m[8] * m[5] * m[14] - + m[8] * m[6] * m[13] - + m[12] * m[5] * m[10] + + m[12] * m[6] * m[9]; + + inv[1] = -m[1] * m[10] * m[15] + + m[1] * m[11] * m[14] + + m[9] * m[2] * m[15] - + m[9] * m[3] * m[14] - + m[13] * m[2] * m[11] + + m[13] * m[3] * m[10]; + + inv[5] = m[0] * m[10] * m[15] - + m[0] * m[11] * m[14] - + m[8] * m[2] * m[15] + + m[8] * m[3] * m[14] + + m[12] * m[2] * m[11] - + m[12] * m[3] * m[10]; + + inv[9] = -m[0] * m[9] * m[15] + + m[0] * m[11] * m[13] + + m[8] * m[1] * m[15] - + m[8] * m[3] * m[13] - + m[12] * m[1] * m[11] + + m[12] * m[3] * m[9]; + + inv[13] = m[0] * m[9] * m[14] - + m[0] * m[10] * m[13] - + m[8] * m[1] * m[14] + + m[8] * m[2] * m[13] + + m[12] * m[1] * m[10] - + m[12] * m[2] * m[9]; + + inv[2] = m[1] * m[6] * m[15] - + m[1] * m[7] * m[14] - + m[5] * m[2] * m[15] + + m[5] * m[3] * m[14] + + m[13] * m[2] * m[7] - + m[13] * m[3] * m[6]; + + inv[6] = -m[0] * m[6] * m[15] + + m[0] * m[7] * m[14] + + m[4] * m[2] * m[15] - + m[4] * m[3] * m[14] - + m[12] * m[2] * m[7] + + m[12] * m[3] * m[6]; + + inv[10] = m[0] * m[5] * m[15] - + m[0] * m[7] * m[13] - + m[4] * m[1] * m[15] + + m[4] * m[3] * m[13] + + m[12] * m[1] * m[7] - + m[12] * m[3] * m[5]; + + inv[14] = -m[0] * m[5] * m[14] + + m[0] * m[6] * m[13] + + m[4] * m[1] * m[14] - + m[4] * m[2] * m[13] - + m[12] * m[1] * m[6] + + m[12] * m[2] * m[5]; + + inv[3] = -m[1] * m[6] * m[11] + + m[1] * m[7] * m[10] + + m[5] * m[2] * m[11] - + m[5] * m[3] * m[10] - + m[9] * m[2] * m[7] + + m[9] * m[3] * m[6]; + + inv[7] = m[0] * m[6] * m[11] - + m[0] * m[7] * m[10] - + m[4] * m[2] * m[11] + + m[4] * m[3] * m[10] + + m[8] * m[2] * m[7] - + m[8] * m[3] * m[6]; + + inv[11] = -m[0] * m[5] * m[11] + + m[0] * m[7] * m[9] + + m[4] * m[1] * m[11] - + m[4] * m[3] * m[9] - + m[8] * m[1] * m[7] + + m[8] * m[3] * m[5]; + + inv[15] = m[0] * m[5] * m[10] - + m[0] * m[6] * m[9] - + m[4] * m[1] * m[10] + + m[4] * m[2] * m[9] + + m[8] * m[1] * m[6] - + m[8] * m[2] * m[5]; + + det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12]; + + if (det == 0) + return Nv::NvMat44(Nv::NvZero); + + det = 1.0f / det; + + for (i = 0; i < 16; i++) + inv[i] = inv[i] * det; + + return Nv::NvMat44(inv); +} +/*============================================================================== + Helper macros +==============================================================================*/ + +#if (NV_DEBUG) +# include <stdio.h> +# include <assert.h> +# if (NV_WIN32 || NV_WIN64) +# define LOG(fmt, ...) { char debug_string[1024]; _snprintf_c(debug_string, 1024, fmt "\n", ##__VA_ARGS__); OutputDebugStringA(debug_string); } +# define BREAK() DebugBreak(); +# else +# define LOG(fmt, ...) printf(fmt "\n", ##__VA_ARGS__) +# define BREAK() abort(); +# endif +# define ASSERT_LOG(test, msg, ...) if (!(test)) { LOG(msg, ##__VA_ARGS__); NV_ALWAYS_ASSERT(); } +#else +# define LOG(fmt, ...) +# define ASSERT_LOG(test, msg, ...) +# define BREAK() +#endif + +// Validate internal call +#define V_(f) { Status v_s = f; if (v_s != Status::OK) return v_s; } + +// Validate D3D call +#define VD3D_(f) { HRESULT v_hr = f; if (FAILED(v_hr)) {LOG("Call Failure: %u", v_hr); return Status::API_ERROR;} } + +// Validate resource creation +#define V_CREATE(x, f) x = f; if (x == nullptr) return Status::RESOURCE_FAILURE; + +#define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0])) +#define SAFE_DELETE(x) if((x) != nullptr) {delete (x); (x)=nullptr;} +#define SAFE_RELEASE(x) if((x) != nullptr) {((IUnknown *)(x))->Release(); (x)=nullptr;} +#define SAFE_RELEASE_ARRAY(x) for (unsigned _sr_count=0; _sr_count<SIZE_OF_ARRAY(x); ++_sr_count) {if((x)[_sr_count] != nullptr) {((IUnknown *)(x)[_sr_count])->Release(); (x)[_sr_count]=nullptr;}} +#define SAFE_DELETE_ARRAY(x) if (x != nullptr) {SAFE_RELEASE_ARRAY(x); delete[] x; x=nullptr;} + +/*============================================================================== + Memory Management +==============================================================================*/ + +void * operator new(size_t size, const char * filename, int line); +void operator delete(void * ptr, const char * filename, int line); +void operator delete (void * ptr); +void * operator new[](size_t size, const char * filename, int line); +void operator delete[](void * ptr, const char * filename, int line); +void operator delete[](void * ptr); + +#if (NV_CHECKED) +# define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) +# define new new(__FILENAME__, __LINE__) +#else +# define new new("NvVolumetricLighting.dll", 0) +#endif + +//////////////////////////////////////////////////////////////////////////////// +#endif // COMMON_H diff --git a/src/context_common.cpp b/src/context_common.cpp new file mode 100644 index 0000000..f8bfd1f --- /dev/null +++ b/src/context_common.cpp @@ -0,0 +1,431 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#include <Nv/VolumetricLighting/NvVolumetricLighting.h> + +#include "common.h" +#include "context_common.h" + +//////////////////////////////////////////////////////////////////////////////// +namespace Nv { namespace VolumetricLighting { +//////////////////////////////////////////////////////////////////////////////// + +ContextImp_Common::ContextImp_Common(const ContextDesc * pContextDesc) +{ + isInitialized_ = false; + jitterIndex_ = 0; + lastFrameIndex_ = -1; + nextFrameIndex_ = -0; + intrinsics::memCopy(&this->contextDesc_, pContextDesc, sizeof(ContextDesc)); +} + +/*============================================================================== + API Hooks +==============================================================================*/ + + +Status ContextImp_Common::BeginAccumulation(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc, DebugFlags debugFlags) +{ + debugFlags_ = (uint32_t) debugFlags; + intrinsics::memCopy(&viewerDesc_, pViewerDesc, sizeof(ViewerDesc)); + V_( BeginAccumulation_Start(renderCtx, sceneDepth, pViewerDesc, pMediumDesc) ); + V_( BeginAccumulation_UpdateMediumLUT(renderCtx) ); + V_( BeginAccumulation_CopyDepth(renderCtx, sceneDepth) ); + V_( BeginAccumulation_End(renderCtx, sceneDepth, pViewerDesc, pMediumDesc) ); + return Status::OK; +} + +Status ContextImp_Common::RenderVolume(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) +{ + V_( RenderVolume_Start(renderCtx, shadowMap, pShadowMapDesc, pLightDesc, pVolumeDesc) ); + switch (pLightDesc->eType) + { + case LightType::DIRECTIONAL: + V_( RenderVolume_DoVolume_Directional(renderCtx, shadowMap, pShadowMapDesc, pLightDesc, pVolumeDesc) ); + break; + + case LightType::SPOTLIGHT: + V_( RenderVolume_DoVolume_Spotlight(renderCtx, shadowMap, pShadowMapDesc, pLightDesc, pVolumeDesc) ); + break; + + case LightType::OMNI: + V_( RenderVolume_DoVolume_Omni(renderCtx, shadowMap, pShadowMapDesc, pLightDesc, pVolumeDesc) ); + break; + + default: + // Error -- unsupported light type + return Status::INVALID_PARAMETER; + break; + } + V_( RenderVolume_End(renderCtx, shadowMap, pShadowMapDesc, pLightDesc, pVolumeDesc) ); + return Status::OK; +} + +Status ContextImp_Common::EndAccumulation(PlatformRenderCtx renderCtx) +{ + V_( EndAccumulation_Imp(renderCtx) ); + return Status::OK; +} + +Status ContextImp_Common::ApplyLighting(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) +{ + V_( ApplyLighting_Start(renderCtx, sceneTarget, sceneDepth, pPostprocessDesc) ); + if (getFilterMode() == FilterMode::TEMPORAL) + { + V_( ApplyLighting_Resolve(renderCtx, pPostprocessDesc) ); + V_( ApplyLighting_TemporalFilter(renderCtx, sceneDepth, pPostprocessDesc) ); + } + else if (isInternalMSAA()) + { + V_( ApplyLighting_Resolve(renderCtx, pPostprocessDesc) ); + } + V_( ApplyLighting_Composite(renderCtx, sceneTarget, sceneDepth, pPostprocessDesc) ); + V_( ApplyLighting_End(renderCtx, sceneTarget, sceneDepth, pPostprocessDesc) ); + + // Update frame counters as needed + jitterIndex_ = (jitterIndex_ + 1) % MAX_JITTER_STEPS; + lastFrameIndex_ = nextFrameIndex_; + nextFrameIndex_ = (nextFrameIndex_ + 1) % 2; + return Status::OK; +} + +/*============================================================================== + Helper methods +==============================================================================*/ + +uint32_t ContextImp_Common::getOutputBufferWidth() const +{ + return contextDesc_.framebuffer.uWidth; +} + +uint32_t ContextImp_Common::getOutputBufferHeight() const +{ + return contextDesc_.framebuffer.uHeight; +} + +uint32_t ContextImp_Common::getOutputViewportWidth() const +{ + return viewerDesc_.uViewportWidth; +} + +uint32_t ContextImp_Common::getOutputViewportHeight() const +{ + return viewerDesc_.uViewportHeight; +} + +uint32_t ContextImp_Common::getOutputSampleCount() const +{ + return contextDesc_.framebuffer.uSamples; +} + +float ContextImp_Common::getInternalScale() const +{ + switch (contextDesc_.eDownsampleMode) + { + default: + case DownsampleMode::FULL: + return 1.00f; + + case DownsampleMode::HALF: + return 0.50f; + + case DownsampleMode::QUARTER: + return 0.25f; + } +} + +uint32_t ContextImp_Common::getInternalBufferWidth() const +{ + switch (contextDesc_.eDownsampleMode) + { + default: + case DownsampleMode::FULL: + return contextDesc_.framebuffer.uWidth; + + case DownsampleMode::HALF: + return contextDesc_.framebuffer.uWidth >> 1; + + case DownsampleMode::QUARTER: + return contextDesc_.framebuffer.uWidth >> 2; + } +} + +uint32_t ContextImp_Common::getInternalBufferHeight() const +{ + switch (contextDesc_.eDownsampleMode) + { + default: + case DownsampleMode::FULL: + return contextDesc_.framebuffer.uHeight; + + case DownsampleMode::HALF: + return contextDesc_.framebuffer.uHeight >> 1; + + case DownsampleMode::QUARTER: + return contextDesc_.framebuffer.uHeight >> 2; + } +} + +uint32_t ContextImp_Common::getInternalViewportWidth() const +{ + switch (contextDesc_.eDownsampleMode) + { + default: + case DownsampleMode::FULL: + return viewerDesc_.uViewportWidth; + + case DownsampleMode::HALF: + return viewerDesc_.uViewportWidth >> 1; + + case DownsampleMode::QUARTER: + return viewerDesc_.uViewportWidth >> 2; + } +} + +uint32_t ContextImp_Common::getInternalViewportHeight() const +{ + switch (contextDesc_.eDownsampleMode) + { + default: + case DownsampleMode::FULL: + return viewerDesc_.uViewportHeight; + + case DownsampleMode::HALF: + return viewerDesc_.uViewportHeight >> 1; + + case DownsampleMode::QUARTER: + return viewerDesc_.uViewportHeight >> 2; + } +} + +uint32_t ContextImp_Common::getInternalSampleCount() const +{ + switch (contextDesc_.eInternalSampleMode) + { + default: + case MultisampleMode::SINGLE: + return 1; + + case MultisampleMode::MSAA2: + return 2; + + case MultisampleMode::MSAA4: + return 4; + } +} + +bool ContextImp_Common::isOutputMSAA() const +{ + return (getOutputSampleCount() > 1); +} + +bool ContextImp_Common::isInternalMSAA() const +{ + return (getInternalSampleCount() > 1); +} + +FilterMode ContextImp_Common::getFilterMode() const +{ + return contextDesc_.eFilterMode; +} + +NvVec2 ContextImp_Common::getJitter() const +{ + if (getFilterMode() == FilterMode::TEMPORAL) + { + auto HaltonSequence = [](int index, int base) -> float + { + float result = 0; + float f = 1; + int i = index + 1; + while (i > 0) + { + f = f / float(base); + result += f * (i % base); + i = i / base; + } + return result; + }; + + return NvVec2((HaltonSequence(jitterIndex_, 2) - 0.5f), (HaltonSequence(jitterIndex_, 3) - 0.5f)); + } + else + { + return NvVec2(0, 0); + } +} + +uint32_t ContextImp_Common::getCoarseResolution(const VolumeDesc *pVolumeDesc) const +{ + switch (pVolumeDesc->eTessQuality) + { + default: + case TessellationQuality::HIGH: + return pVolumeDesc->uMaxMeshResolution / 64; + + case TessellationQuality::MEDIUM: + return pVolumeDesc->uMaxMeshResolution / 32; + + case TessellationQuality::LOW: + return pVolumeDesc->uMaxMeshResolution / 16; + } +} +/*============================================================================== + Constant Buffer Setup +==============================================================================*/ + +void ContextImp_Common::SetupCB_PerContext(PerContextCB * cb) +{ + cb->vOutputSize = NvVec2(static_cast<float>(getOutputBufferWidth()), static_cast<float>(getOutputBufferHeight())); + cb->vOutputSize_Inv = NvVec2(1.f / cb->vOutputSize.x, 1.f / cb->vOutputSize.y); + cb->vBufferSize = NvVec2(static_cast<float>(getInternalBufferWidth()), static_cast<float>(getInternalBufferHeight())); + cb->vBufferSize_Inv = NvVec2(1.f / cb->vBufferSize.x, 1.f / cb->vBufferSize.y); + cb->fResMultiplier = 1.f / getInternalScale(); + cb->uSampleCount = getInternalSampleCount(); +} + +void ContextImp_Common::SetupCB_PerFrame(ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc, PerFrameCB * cb) +{ + cb->mProj = NVCtoNV(pViewerDesc->mProj); + cb->mViewProj = NVCtoNV(pViewerDesc->mViewProj); + cb->mViewProj_Inv = Inverse(cb->mViewProj); + cb->vOutputViewportSize = NvVec2(static_cast<float>(getOutputViewportWidth()), static_cast<float>(getOutputViewportHeight())); + cb->vOutputViewportSize_Inv = NvVec2(1.f / cb->vOutputViewportSize.x, 1.f / cb->vOutputViewportSize.y); + cb->vViewportSize = NvVec2(static_cast<float>(getInternalViewportWidth()), static_cast<float>(getInternalViewportHeight())); + cb->vViewportSize_Inv = NvVec2(1.f / cb->vViewportSize.x, 1.f / cb->vViewportSize.y); + cb->vEyePosition = NVCtoNV(pViewerDesc->vEyePosition); + cb->vJitterOffset = getJitter(); + float proj_33 = cb->mProj(2, 2); + float proj_34 = cb->mProj(2, 3); + cb->fZNear = -proj_34 / proj_33; + cb->fZFar = proj_34 / (1.0f - proj_33); + + const float SCATTER_EPSILON = 0.000001f; + NvVec3 total_scatter = NvVec3(SCATTER_EPSILON, SCATTER_EPSILON, SCATTER_EPSILON); + cb->uNumPhaseTerms = pMediumDesc->uNumPhaseTerms; + for (uint32_t p = 0; p < pMediumDesc->uNumPhaseTerms; ++p) + { + cb->uPhaseFunc[p][0] = static_cast<uint32_t>(pMediumDesc->PhaseTerms[p].ePhaseFunc); + NvVec3 density = NVCtoNV(pMediumDesc->PhaseTerms[p].vDensity); + cb->vPhaseParams[p] = NvVec4(density.x, density.y, density.z, pMediumDesc->PhaseTerms[p].fEccentricity); + total_scatter += density; + } + NvVec3 absorption = NVCtoNV(pMediumDesc->vAbsorption); + cb->vScatterPower.x = 1-exp(-total_scatter.x); + cb->vScatterPower.y = 1-exp(-total_scatter.y); + cb->vScatterPower.z = 1-exp(-total_scatter.z); + cb->vSigmaExtinction = total_scatter + absorption; +} + +void ContextImp_Common::SetupCB_PerVolume(ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc, PerVolumeCB * cb) +{ + cb->mLightToWorld = NVCtoNV(pLightDesc->mLightToWorld); + cb->vLightIntensity = NVCtoNV(pLightDesc->vIntensity); + switch (pLightDesc->eType) + { + case LightType::DIRECTIONAL: + cb->vLightDir = NVCtoNV(pLightDesc->Directional.vDirection); + break; + + case LightType::SPOTLIGHT: + cb->vLightDir = NVCtoNV(pLightDesc->Spotlight.vDirection); + cb->vLightPos = NVCtoNV(pLightDesc->Spotlight.vPosition); + cb->fLightZNear = pLightDesc->Spotlight.fZNear; + cb->fLightZFar = pLightDesc->Spotlight.fZFar; + cb->fLightFalloffAngle = pLightDesc->Spotlight.fFalloff_CosTheta; + cb->fLightFalloffPower = pLightDesc->Spotlight.fFalloff_Power; + cb->vAttenuationFactors = *reinterpret_cast<const NvVec4 *>(pLightDesc->Spotlight.fAttenuationFactors); + break; + + case LightType::OMNI: + cb->vLightPos = NVCtoNV(pLightDesc->Omni.vPosition); + cb->fLightZNear = pLightDesc->Omni.fZNear; + cb->fLightZFar = pLightDesc->Omni.fZFar; + cb->vAttenuationFactors = *reinterpret_cast<const NvVec4 *>(pLightDesc->Omni.fAttenuationFactors); + default: + break; + }; + cb->fDepthBias = pVolumeDesc->fDepthBias; + + cb->uMeshResolution = getCoarseResolution(pVolumeDesc); + + NvVec4 vw1 = cb->mLightToWorld.transform(NvVec4(-1, -1, 1, 1)); + NvVec4 vw2 = cb->mLightToWorld.transform(NvVec4( 1, 1, 1, 1)); + vw1 = vw1 / vw1.w; + vw2 = vw2 / vw2.w; + float fCrossLength = ((vw1).getXYZ() - (vw2).getXYZ()).magnitude(); + float fSideLength = sqrtf(0.5f*fCrossLength*fCrossLength); + cb->fGridSectionSize = fSideLength / static_cast<float>(cb->uMeshResolution); + cb->fTargetRaySize = pVolumeDesc->fTargetRayResolution; + + for (int i=0;i<MAX_SHADOWMAP_ELEMENTS;++i) + { + cb->vElementOffsetAndScale[i].x = (float)pShadowMapDesc->Elements[i].uOffsetX / pShadowMapDesc->uWidth; + cb->vElementOffsetAndScale[i].y = (float)pShadowMapDesc->Elements[i].uOffsetY / pShadowMapDesc->uHeight; + cb->vElementOffsetAndScale[i].z = (float)pShadowMapDesc->Elements[i].uWidth / pShadowMapDesc->uWidth; + cb->vElementOffsetAndScale[i].w = (float)pShadowMapDesc->Elements[i].uHeight / pShadowMapDesc->uHeight; + cb->mLightProj[i] = NVCtoNV(pShadowMapDesc->Elements[i].mViewProj); + cb->mLightProj_Inv[i] = Inverse(cb->mLightProj[i]); + cb->uElementIndex[i][0] = pShadowMapDesc->Elements[i].mArrayIndex; + } + + cb->vShadowMapDim.x = static_cast<float>(pShadowMapDesc->uWidth); + cb->vShadowMapDim.y = static_cast<float>(pShadowMapDesc->uHeight); +} + +void ContextImp_Common::SetupCB_PerApply(PostprocessDesc const* pPostprocessDesc, PerApplyCB * cb) +{ + if (getFilterMode() == FilterMode::TEMPORAL) + { + cb->fHistoryFactor = (lastFrameIndex_ == -1) ? 0.0f : pPostprocessDesc->fTemporalFactor; + cb->fFilterThreshold = pPostprocessDesc->fFilterThreshold; + if (lastFrameIndex_ == -1) + { + lastViewProj_ = NVCtoNV(pPostprocessDesc->mUnjitteredViewProj); + lastFrameIndex_ = (nextFrameIndex_+1)%2; + } + else + { + lastViewProj_ = nextViewProj_; + } + nextViewProj_ = NVCtoNV(pPostprocessDesc->mUnjitteredViewProj); + cb->mHistoryXform = lastViewProj_ * Inverse(nextViewProj_); + } + else + { + cb->mHistoryXform = NvMat44(NvIdentity); + cb->fFilterThreshold = 0.0f; + cb->fHistoryFactor = 0.0f; + } + cb->vFogLight = NVCtoNV(pPostprocessDesc->vFogLight); + cb->fMultiScattering = pPostprocessDesc->fMultiscatter; +} + +//////////////////////////////////////////////////////////////////////////////// +}; /*namespace VolumetricLighting*/ }; /*namespace Nv*/ +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/context_common.h b/src/context_common.h new file mode 100644 index 0000000..386c4b7 --- /dev/null +++ b/src/context_common.h @@ -0,0 +1,249 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#ifndef CONTEXT_COMMON_H +#define CONTEXT_COMMON_H +//////////////////////////////////////////////////////////////////////////////// + +#include <Nv/VolumetricLighting/NvVolumetricLighting.h> + +#include "common.h" + +/*============================================================================== + Forward Declarations +==============================================================================*/ + +#pragma warning(disable: 4100) +//////////////////////////////////////////////////////////////////////////////// +namespace Nv { namespace VolumetricLighting { +//////////////////////////////////////////////////////////////////////////////// + +/*============================================================================== + Constants +==============================================================================*/ +const uint32_t MAX_JITTER_STEPS = 8; + +// These need to match the values in ComputeLightLUT_CS.hlsl +const uint32_t LIGHT_LUT_DEPTH_RESOLUTION = 128; +const uint32_t LIGHT_LUT_WDOTV_RESOLUTION = 512; + +/*============================================================================== + Base Context Implementation +==============================================================================*/ + +class ContextImp_Common +{ +public: + // Clean up common resources + virtual ~ContextImp_Common() {}; + + //-------------------------------------------------------------------------- + // API Hooks + Status BeginAccumulation(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc, DebugFlags debugFlags); + Status RenderVolume(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc); + Status EndAccumulation(PlatformRenderCtx renderCtx); + Status ApplyLighting(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc); + +protected: + + //-------------------------------------------------------------------------- + // Implementation Stubs + + // BeginAccumulation + virtual Status BeginAccumulation_Start(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc) = 0; + virtual Status BeginAccumulation_UpdateMediumLUT(PlatformRenderCtx renderCtx) = 0; + virtual Status BeginAccumulation_CopyDepth(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth) = 0; + virtual Status BeginAccumulation_End(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc) = 0; + + // RenderVolume + virtual Status RenderVolume_Start(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) = 0; + virtual Status RenderVolume_DoVolume_Directional(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) = 0; + virtual Status RenderVolume_DoVolume_Spotlight(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) = 0; + virtual Status RenderVolume_DoVolume_Omni(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) = 0; + virtual Status RenderVolume_End(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) = 0; + + // EndAccumulation + virtual Status EndAccumulation_Imp(PlatformRenderCtx renderCtx) = 0; + + // ApplyLighting + virtual Status ApplyLighting_Start(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) = 0; + virtual Status ApplyLighting_Resolve(PlatformRenderCtx renderCtx, PostprocessDesc const* pPostprocessDesc) = 0; + virtual Status ApplyLighting_TemporalFilter(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) = 0; + virtual Status ApplyLighting_Composite(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) = 0; + virtual Status ApplyLighting_End(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) = 0; + + //-------------------------------------------------------------------------- + // Constructors + // Protected constructor - Should only ever instantiate children + ContextImp_Common() {}; + + // Call this from base-class for actual initialization + ContextImp_Common(const ContextDesc * pContextDesc); + + //-------------------------------------------------------------------------- + // Helper functions + NvVec2 getJitter() const; + uint32_t getOutputBufferWidth() const; + uint32_t getOutputBufferHeight() const; + uint32_t getOutputViewportWidth() const; + uint32_t getOutputViewportHeight() const; + uint32_t getOutputSampleCount() const; + float getInternalScale() const; + uint32_t getInternalBufferWidth() const; + uint32_t getInternalBufferHeight() const; + uint32_t getInternalViewportWidth() const; + uint32_t getInternalViewportHeight() const; + uint32_t getInternalSampleCount() const; + bool isOutputMSAA() const; + bool isInternalMSAA() const; + FilterMode getFilterMode() const; + uint32_t getCoarseResolution(const VolumeDesc * pVolumeDesc) const; + + + //-------------------------------------------------------------------------- + // Constant Buffers + + struct PerContextCB + { + // c0 + NvVec2 vOutputSize; + NvVec2 vOutputSize_Inv; + // c1 + NvVec2 vBufferSize; + NvVec2 vBufferSize_Inv; + // c2 + float fResMultiplier; + uint32_t uSampleCount; + float pad1[2]; + }; + void SetupCB_PerContext(PerContextCB * cb); + + struct PerFrameCB + { + // c0+4 + NvMat44 mProj; + // c4+4 + NvMat44 mViewProj; + // c8+4 + NvMat44 mViewProj_Inv; + // c12 + NvVec2 vOutputViewportSize; + NvVec2 vOutputViewportSize_Inv; + // c13 + NvVec2 vViewportSize; + NvVec2 vViewportSize_Inv; + // c14 + NvVec3 vEyePosition; + float pad1[1]; + // c15 + NvVec2 vJitterOffset; + float fZNear; + float fZFar; + // c16 + NvVec3 vScatterPower; + uint32_t uNumPhaseTerms; + // c17 + NvVec3 vSigmaExtinction; + float pad2[1]; + // c18+MAX_PHASE_TERMS (4) + uint32_t uPhaseFunc[MAX_PHASE_TERMS][4]; + // c22 + NvVec4 vPhaseParams[MAX_PHASE_TERMS]; + }; + void SetupCB_PerFrame(ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc, PerFrameCB * cb); + + struct PerVolumeCB + { + // c0+4 + NvMat44 mLightToWorld; + // c4 + float fLightFalloffAngle; + float fLightFalloffPower; + float fGridSectionSize; + float fLightToEyeDepth; + // c5 + float fLightZNear; + float fLightZFar; + float pad[2]; + // c6 + NvVec4 vAttenuationFactors; + // c7+16 + NvMat44 mLightProj[4]; + // c23+16 + NvMat44 mLightProj_Inv[4]; + // c39 + NvVec3 vLightDir; + float fDepthBias; + // c40 + NvVec3 vLightPos; + uint32_t uMeshResolution; + // c41 + NvVec3 vLightIntensity; + float fTargetRaySize; + // c42+4 + NvVec4 vElementOffsetAndScale[4]; + // c46 + NvVec4 vShadowMapDim; + // c47+4 + // Only first index of each "row" is used. + // (Need to do this because HLSL can only stride arrays by full offset) + uint32_t uElementIndex[4][4]; + }; + void SetupCB_PerVolume(ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc, PerVolumeCB * cb); + + struct PerApplyCB + { + // c0 + NvMat44 mHistoryXform; + // c4 + float fFilterThreshold; + float fHistoryFactor; + float pad1[2]; + // c5 + NvVec3 vFogLight; + float fMultiScattering; + }; + void SetupCB_PerApply(PostprocessDesc const* pPostprocessDesc, PerApplyCB * cb); + + //-------------------------------------------------------------------------- + // Miscellaneous internal state + bool isInitialized_; + uint32_t debugFlags_; + ContextDesc contextDesc_; + ViewerDesc viewerDesc_; + uint32_t jitterIndex_; + int32_t lastFrameIndex_; + int32_t nextFrameIndex_; + NvMat44 lastViewProj_; + NvMat44 nextViewProj_; +}; + +//////////////////////////////////////////////////////////////////////////////// +}; /*namespace VolumetricLighting*/ }; /*namespace Nv*/ +//////////////////////////////////////////////////////////////////////////////// +#endif // CONTEXT_COMMON_H diff --git a/src/d3d11/compiled_shaders_d3d11.cpp b/src/d3d11/compiled_shaders_d3d11.cpp new file mode 100644 index 0000000..2a23501 --- /dev/null +++ b/src/d3d11/compiled_shaders_d3d11.cpp @@ -0,0 +1,43 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#include <stdint.h> +namespace d3d11 { namespace shaders { + #include <shaders/Apply_PS.mux.bytecode> + #include <shaders/ComputeLightLUT_CS.mux.bytecode> + #include <shaders/ComputePhaseLookup_PS.mux.bytecode> + #include <shaders/Debug_PS.mux.bytecode> + #include <shaders/DownsampleDepth_PS.mux.bytecode> + #include <shaders/Quad_VS.mux.bytecode> + #include <shaders/RenderVolume_VS.mux.bytecode> + #include <shaders/RenderVolume_HS.mux.bytecode> + #include <shaders/RenderVolume_DS.mux.bytecode> + #include <shaders/RenderVolume_PS.mux.bytecode> + #include <shaders/Resolve_PS.mux.bytecode> + #include <shaders/TemporalFilter_PS.mux.bytecode> +}; /* namespace shaders */ }; /* namespace d3d11 */ diff --git a/src/d3d11/compiled_shaders_d3d11.h b/src/d3d11/compiled_shaders_d3d11.h new file mode 100644 index 0000000..885b1c3 --- /dev/null +++ b/src/d3d11/compiled_shaders_d3d11.h @@ -0,0 +1,52 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#ifndef COMPILED_SHADERS_D3D11_H +#define COMPILED_SHADERS_D3D11_H +//////////////////////////////////////////////////////////////////////////////// +#include <stdint.h> +namespace d3d11 { namespace shaders { + #include <shaders/Apply_PS.mux.h> + #include <shaders/ComputeLightLUT_CS.mux.h> + #include <shaders/ComputePhaseLookup_PS.mux.h> + #include <shaders/Debug_PS.mux.h> + #include <shaders/DownsampleDepth_PS.mux.h> + #include <shaders/Quad_VS.mux.h> + #include <shaders/RenderVolume_VS.mux.h> + #include <shaders/RenderVolume_HS.mux.h> + #include <shaders/RenderVolume_DS.mux.h> + #include <shaders/RenderVolume_PS.mux.h> + #include <shaders/Resolve_PS.mux.h> + #include <shaders/TemporalFilter_PS.mux.h> +}; /* namespace shaders */ }; /* namespace d3d11 */ +// We use the namespaces to avoid conflicts if supporting multiple APIs +// but they aren't needed wherever these would be included. +using namespace d3d11; +using namespace shaders; +//////////////////////////////////////////////////////////////////////////////// +#endif // COMPILED_SHADERS_D3D11_H diff --git a/src/d3d11/context_d3d11.cpp b/src/d3d11/context_d3d11.cpp new file mode 100644 index 0000000..9bb2f4a --- /dev/null +++ b/src/d3d11/context_d3d11.cpp @@ -0,0 +1,1257 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#include "common.h" +#include "context_d3d11.h" +#include "compiled_shaders_d3d11.h" +#include "d3d11_util.h" + +#include <stdint.h> +#include <d3d11.h> + +#pragma warning(disable: 4100) +//////////////////////////////////////////////////////////////////////////////// +namespace Nv { namespace VolumetricLighting { +//////////////////////////////////////////////////////////////////////////////// +const uint8_t STENCIL_REF = 0xFF; + +/*============================================================================== + Create a context and load/allocate/generate resources +==============================================================================*/ + +Status ContextImp_D3D11::Create(ContextImp_D3D11 ** out_ctx, const PlatformDesc * pPlatformDesc, const ContextDesc * pContextDesc) +{ + ID3D11Device * pDevice = pPlatformDesc->d3d11.pDevice; + if (pDevice->GetFeatureLevel() < D3D_FEATURE_LEVEL_11_0) + return Status::UNSUPPORTED_DEVICE; + + *out_ctx = new ContextImp_D3D11(pContextDesc); + Status result = (*out_ctx)->CreateResources(pDevice); + if (result != Status::OK) + { + delete *out_ctx; + *out_ctx = nullptr; + return result; + } + else + { + return Status::OK; + } +} + +Status ContextImp_D3D11::CreateResources(ID3D11Device * device) +{ + //-------------------------------------------------------------------------- + // Shaders +# define LOAD_SHADERS(x) LoadShaders(device, ##x##::permutation_code, ##x##::permutation_length, shaders::##x##::PERMUTATION_ENTRY_COUNT, shaders.##x) + VD3D_(LOAD_SHADERS(Apply_PS)); + VD3D_(LOAD_SHADERS(ComputeLightLUT_CS)); + VD3D_(LOAD_SHADERS(ComputePhaseLookup_PS)); + VD3D_(LOAD_SHADERS(Debug_PS)); + VD3D_(LOAD_SHADERS(DownsampleDepth_PS)); + VD3D_(LOAD_SHADERS(Quad_VS)); + VD3D_(LOAD_SHADERS(RenderVolume_VS)); + VD3D_(LOAD_SHADERS(RenderVolume_HS)); + VD3D_(LOAD_SHADERS(RenderVolume_DS)); + VD3D_(LOAD_SHADERS(RenderVolume_PS)); + VD3D_(LOAD_SHADERS(Resolve_PS)); + VD3D_(LOAD_SHADERS(TemporalFilter_PS)); +# undef LOAD_SHADERS + + //-------------------------------------------------------------------------- + // Constant Buffers + V_CREATE(pPerContextCB, ConstantBuffer<PerContextCB>::Create(device)); + V_CREATE(pPerFrameCB, ConstantBuffer<PerFrameCB>::Create(device)); + V_CREATE(pPerVolumeCB, ConstantBuffer<PerVolumeCB>::Create(device)); + V_CREATE(pPerApplyCB, ConstantBuffer<PerApplyCB>::Create(device)); + + //-------------------------------------------------------------------------- + // Shader Resources + V_CREATE(pDepth_, DepthTarget::Create(device, getInternalBufferWidth(), getInternalBufferHeight(), getInternalSampleCount(), DXGI_FORMAT_D24_UNORM_S8_UINT, 1, "NvVl::Depth")); + V_CREATE(pPhaseLUT_, RenderTarget::Create(device, 1, LIGHT_LUT_WDOTV_RESOLUTION, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Phase LUT")); + V_CREATE(pLightLUT_P_[0], RenderTarget::Create(device, LIGHT_LUT_DEPTH_RESOLUTION, LIGHT_LUT_WDOTV_RESOLUTION, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Light LUT Point [0]")); + V_CREATE(pLightLUT_P_[1], RenderTarget::Create(device, LIGHT_LUT_DEPTH_RESOLUTION, LIGHT_LUT_WDOTV_RESOLUTION, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Light LUT Point [1]")); + V_CREATE(pLightLUT_S1_[0], RenderTarget::Create(device, LIGHT_LUT_DEPTH_RESOLUTION, LIGHT_LUT_WDOTV_RESOLUTION, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Light LUT Spot 1 [0]")); + V_CREATE(pLightLUT_S1_[1], RenderTarget::Create(device, LIGHT_LUT_DEPTH_RESOLUTION, LIGHT_LUT_WDOTV_RESOLUTION, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Light LUT Spot 1 [1]")); + V_CREATE(pLightLUT_S2_[0], RenderTarget::Create(device, LIGHT_LUT_DEPTH_RESOLUTION, LIGHT_LUT_WDOTV_RESOLUTION, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Light LUT Spot 2 [0]")); + V_CREATE(pLightLUT_S2_[1], RenderTarget::Create(device, LIGHT_LUT_DEPTH_RESOLUTION, LIGHT_LUT_WDOTV_RESOLUTION, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Light LUT Spot 2 [1]")); + V_CREATE(pAccumulation_, RenderTarget::Create(device, getInternalBufferWidth(), getInternalBufferHeight(), getInternalSampleCount(), DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Accumulation")); + + if (isInternalMSAA() || getFilterMode() == FilterMode::TEMPORAL) + { + V_CREATE(pResolvedAccumulation_, RenderTarget::Create(device, getInternalBufferWidth(), getInternalBufferHeight(), 1, DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Resolved Accumulation")); + V_CREATE(pResolvedDepth_, RenderTarget::Create(device, getInternalBufferWidth(), getInternalBufferHeight(), 1, DXGI_FORMAT_R16G16_FLOAT, "NvVl::Resolved Depth")); + } + + if (getFilterMode() == FilterMode::TEMPORAL) + { + for (int i=0; i<2; ++i) + { + V_CREATE(pFilteredDepth_[i], RenderTarget::Create(device, getInternalBufferWidth(), getInternalBufferHeight(), 1, DXGI_FORMAT_R16G16_FLOAT, "NvVl::Filtered Depth")); + V_CREATE(pFilteredAccumulation_[i], RenderTarget::Create(device, getInternalBufferWidth(), getInternalBufferHeight(), 1, DXGI_FORMAT_R16G16B16A16_FLOAT, "NvVl::Filtered Accumulation")); + } + } + + //-------------------------------------------------------------------------- + // States + // Rasterizer State + { + CD3D11_RASTERIZER_DESC rsDesc((CD3D11_DEFAULT())); + rsDesc.FrontCounterClockwise = TRUE; + rsDesc.CullMode = D3D11_CULL_NONE; + rsDesc.DepthClipEnable = FALSE; + VD3D_(device->CreateRasterizerState(&rsDesc, &states.rs.cull_none)); + } + { + CD3D11_RASTERIZER_DESC rsDesc((CD3D11_DEFAULT())); + rsDesc.FrontCounterClockwise = TRUE; + rsDesc.CullMode = D3D11_CULL_FRONT; + rsDesc.DepthClipEnable = FALSE; + VD3D_(device->CreateRasterizerState(&rsDesc, &states.rs.cull_front)); + } + { + CD3D11_RASTERIZER_DESC rsDesc((CD3D11_DEFAULT())); + rsDesc.FillMode = D3D11_FILL_WIREFRAME; + rsDesc.FrontCounterClockwise = TRUE; + rsDesc.CullMode = D3D11_CULL_NONE; + rsDesc.DepthClipEnable = FALSE; + VD3D_(device->CreateRasterizerState(&rsDesc, &states.rs.wireframe)); + } + // Sampler State + { + CD3D11_SAMPLER_DESC ssDesc((CD3D11_DEFAULT())); + ssDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + VD3D_(device->CreateSamplerState(&ssDesc, &states.ss.point)); + } + { + CD3D11_SAMPLER_DESC ssDesc((CD3D11_DEFAULT())); + ssDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; + VD3D_(device->CreateSamplerState(&ssDesc, &states.ss.linear)); + } + // Depth-Stencil + { + // Depth Disabled + CD3D11_DEPTH_STENCIL_DESC dsDesc((CD3D11_DEFAULT())); + dsDesc.DepthEnable = FALSE; + VD3D_(device->CreateDepthStencilState(&dsDesc, &states.ds.no_depth)); + } + { + // Write-only Depth DS + CD3D11_DEPTH_STENCIL_DESC dsDesc((CD3D11_DEFAULT())); + dsDesc.DepthFunc = D3D11_COMPARISON_ALWAYS; + VD3D_(device->CreateDepthStencilState(&dsDesc, &states.ds.write_only_depth)); + } + { + // Render Volume DS + CD3D11_DEPTH_STENCIL_DESC dsDesc((CD3D11_DEFAULT())); + dsDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; + dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; + dsDesc.StencilEnable = TRUE; + dsDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + dsDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; + dsDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + dsDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + dsDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; + dsDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + VD3D_(device->CreateDepthStencilState(&dsDesc, &states.ds.render_volume)); + } + { + // Render Volume Boundary DS + CD3D11_DEPTH_STENCIL_DESC dsDesc((CD3D11_DEFAULT())); + dsDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; + dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; + dsDesc.StencilEnable = TRUE; + dsDesc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER; + dsDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + dsDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + dsDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; + dsDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + VD3D_(device->CreateDepthStencilState(&dsDesc, &states.ds.render_volume_boundary)); + } + { + // Render volume cap DS + CD3D11_DEPTH_STENCIL_DESC dsDesc((CD3D11_DEFAULT())); + dsDesc.DepthEnable = FALSE; + dsDesc.StencilEnable = TRUE; + dsDesc.FrontFace.StencilFunc = D3D11_COMPARISON_LESS_EQUAL; + dsDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; + dsDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + dsDesc.BackFace.StencilFunc = D3D11_COMPARISON_LESS_EQUAL; + dsDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; + dsDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + VD3D_(device->CreateDepthStencilState(&dsDesc, &states.ds.render_volume_cap)); + } + { + // Finish Volume DS + CD3D11_DEPTH_STENCIL_DESC dsDesc((CD3D11_DEFAULT())); + dsDesc.DepthEnable = FALSE; + dsDesc.StencilEnable = TRUE; + dsDesc.StencilWriteMask = 0x00; + dsDesc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER; + dsDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + dsDesc.BackFace.StencilFunc = D3D11_COMPARISON_GREATER; + dsDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; + dsDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; + VD3D_(device->CreateDepthStencilState(&dsDesc, &states.ds.finish_volume)); + } + { + // Read-Only Depth DS + CD3D11_DEPTH_STENCIL_DESC dsDesc((CD3D11_DEFAULT())); + dsDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; + dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; + VD3D_(device->CreateDepthStencilState(&dsDesc, &states.ds.read_only_depth)); + } + // Blend State + { + CD3D11_BLEND_DESC bsDesc((CD3D11_DEFAULT())); + bsDesc.RenderTarget[0].RenderTargetWriteMask = 0x00000000; + VD3D_(device->CreateBlendState(&bsDesc, &states.bs.no_color)); + } + { + CD3D11_BLEND_DESC bsDesc((CD3D11_DEFAULT())); + VD3D_(device->CreateBlendState(&bsDesc, &states.bs.no_blending)); + } + { + CD3D11_BLEND_DESC bsDesc((CD3D11_DEFAULT())); + bsDesc.RenderTarget[0].BlendEnable = TRUE; + bsDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; + bsDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_BLEND_FACTOR; + bsDesc.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; + bsDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bsDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_BLEND_FACTOR; + bsDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; + VD3D_(device->CreateBlendState(&bsDesc, &states.bs.additive)); + } + { + CD3D11_BLEND_DESC bsDesc((CD3D11_DEFAULT())); + bsDesc.RenderTarget[0].BlendEnable = TRUE; + bsDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; + bsDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_BLEND_FACTOR; + bsDesc.RenderTarget[0].DestBlend = D3D11_BLEND_SRC1_COLOR; + bsDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bsDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO; + bsDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; + VD3D_(device->CreateBlendState(&bsDesc, &states.bs.additive_modulate)); + } + { + CD3D11_BLEND_DESC bsDesc((CD3D11_DEFAULT())); + bsDesc.RenderTarget[0].BlendEnable = TRUE; + bsDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; + bsDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; + bsDesc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO; + bsDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bsDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO; + bsDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_SRC1_ALPHA; + VD3D_(device->CreateBlendState(&bsDesc, &states.bs.debug_blend)); + } + return Status::OK; +} + +/*============================================================================== + Constructor / Destructor +==============================================================================*/ + +ContextImp_D3D11::ContextImp_D3D11(const ContextDesc * pContextDesc) : ContextImp_Common(pContextDesc) +{ + shaders.Apply_PS = nullptr; + shaders.ComputeLightLUT_CS = nullptr; + shaders.ComputePhaseLookup_PS = nullptr; + shaders.Debug_PS = nullptr; + shaders.DownsampleDepth_PS = nullptr; + shaders.Quad_VS = nullptr; + shaders.RenderVolume_VS = nullptr; + shaders.RenderVolume_HS = nullptr; + shaders.RenderVolume_DS = nullptr; + shaders.RenderVolume_PS = nullptr; + shaders.Resolve_PS = nullptr; + shaders.TemporalFilter_PS = nullptr; + + pPerContextCB = nullptr; + pPerFrameCB = nullptr; + pPerVolumeCB = nullptr; + pPerApplyCB = nullptr; + + pDepth_ = nullptr; + pPhaseLUT_ = nullptr; + pLightLUT_P_[0] = nullptr; + pLightLUT_P_[1] = nullptr; + pLightLUT_S1_[0] = nullptr; + pLightLUT_S1_[1] = nullptr; + pLightLUT_S2_[0] = nullptr; + pLightLUT_S2_[1] = nullptr; + pAccumulation_ = nullptr; + pResolvedAccumulation_ = nullptr; + pResolvedDepth_ = nullptr; + for (int i=0; i<2; ++i) + { + pFilteredAccumulation_[i] = nullptr; + pFilteredDepth_[i] = nullptr; + } + + states.rs.cull_none = nullptr; + states.rs.cull_front = nullptr; + states.rs.wireframe = nullptr; + states.ss.point = nullptr; + states.ss.linear = nullptr; + states.ds.no_depth = nullptr; + states.ds.write_only_depth = nullptr; + states.ds.read_only_depth = nullptr; + states.ds.render_volume = nullptr; + states.ds.render_volume_boundary = nullptr; + states.ds.render_volume_cap = nullptr; + states.ds.finish_volume = nullptr; + states.bs.no_color = nullptr; + states.bs.no_blending = nullptr; + states.bs.additive = nullptr; + states.bs.additive_modulate = nullptr; + states.bs.debug_blend = nullptr; +} + +ContextImp_D3D11::~ContextImp_D3D11() +{ + SAFE_DELETE_ARRAY(shaders.Apply_PS); + SAFE_DELETE_ARRAY(shaders.ComputeLightLUT_CS); + SAFE_DELETE_ARRAY(shaders.ComputePhaseLookup_PS); + SAFE_DELETE_ARRAY(shaders.Debug_PS); + SAFE_DELETE_ARRAY(shaders.DownsampleDepth_PS); + SAFE_DELETE_ARRAY(shaders.Quad_VS); + SAFE_DELETE_ARRAY(shaders.RenderVolume_VS); + SAFE_DELETE_ARRAY(shaders.RenderVolume_HS); + SAFE_DELETE_ARRAY(shaders.RenderVolume_DS); + SAFE_DELETE_ARRAY(shaders.RenderVolume_PS); + SAFE_DELETE_ARRAY(shaders.Resolve_PS); + SAFE_DELETE_ARRAY(shaders.TemporalFilter_PS); + + SAFE_DELETE(pPerContextCB); + SAFE_DELETE(pPerFrameCB); + SAFE_DELETE(pPerVolumeCB); + SAFE_DELETE(pPerApplyCB); + + SAFE_DELETE(pDepth_); + SAFE_DELETE(pPhaseLUT_); + SAFE_DELETE(pLightLUT_P_[0]); + SAFE_DELETE(pLightLUT_P_[1]); + SAFE_DELETE(pLightLUT_S1_[0]); + SAFE_DELETE(pLightLUT_S1_[1]); + SAFE_DELETE(pLightLUT_S2_[0]); + SAFE_DELETE(pLightLUT_S2_[1]); + SAFE_DELETE(pAccumulation_); + SAFE_DELETE(pResolvedAccumulation_); + SAFE_DELETE(pResolvedDepth_); + for (int i = 0; i < 2; ++i) + { + SAFE_DELETE(pFilteredAccumulation_[i]); + SAFE_DELETE(pFilteredDepth_[i]); + } + + SAFE_RELEASE(states.rs.cull_none); + SAFE_RELEASE(states.rs.cull_front); + SAFE_RELEASE(states.rs.wireframe); + SAFE_RELEASE(states.ss.point); + SAFE_RELEASE(states.ss.linear); + SAFE_RELEASE(states.ds.no_depth); + SAFE_RELEASE(states.ds.write_only_depth); + SAFE_RELEASE(states.ds.read_only_depth); + SAFE_RELEASE(states.ds.render_volume); + SAFE_RELEASE(states.ds.render_volume_boundary); + SAFE_RELEASE(states.ds.render_volume_cap); + SAFE_RELEASE(states.ds.finish_volume); + SAFE_RELEASE(states.bs.no_color); + SAFE_RELEASE(states.bs.no_blending); + SAFE_RELEASE(states.bs.additive); + SAFE_RELEASE(states.bs.additive_modulate); + SAFE_RELEASE(states.bs.debug_blend); +} + +/*============================================================================== + BeginAccumulation +==============================================================================*/ + +Status ContextImp_D3D11::BeginAccumulation_Start(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + + NV_PERFEVENT_BEGIN(dxCtx, "NvVl::BeginAccumulation"); + + if (!isInitialized_) + { + // Update the per-context constant buffer on the first frame it's used + isInitialized_ = true; + SetupCB_PerContext(pPerContextCB->Map(dxCtx)); + pPerContextCB->Unmap(dxCtx); + } + + // Setup the constant buffer + SetupCB_PerFrame(pViewerDesc, pMediumDesc, pPerFrameCB->Map(dxCtx)); + pPerFrameCB->Unmap(dxCtx); + + ID3D11Buffer* pCBs[] = { + pPerContextCB->getCB(), + pPerFrameCB->getCB(), + nullptr, // pPerVolumeCB - Invalid + nullptr // pPerApplyCB - Invalid + }; + dxCtx->VSSetConstantBuffers(0, 4, pCBs); + dxCtx->PSSetConstantBuffers(0, 4, pCBs); + + ID3D11SamplerState * pSamplers[] = { + states.ss.point, + states.ss.linear + }; + dxCtx->PSSetSamplers(0, 2, pSamplers); + + return Status::OK; +} + +Status ContextImp_D3D11::BeginAccumulation_UpdateMediumLUT(PlatformRenderCtx renderCtx) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + NV_PERFEVENT(dxCtx, "UpdateMediumLUT"); + + FLOAT black[] = {0,0,0,0}; + dxCtx->ClearRenderTargetView(pPhaseLUT_->getRTV(), black); + + D3D11_VIEWPORT viewport; + viewport.TopLeftX = 0.0f; + viewport.TopLeftY = 0.0f; + viewport.Width = 1; + viewport.Height = LIGHT_LUT_WDOTV_RESOLUTION; + viewport.MinDepth = 0.f; + viewport.MaxDepth = 1.f; + dxCtx->RSSetViewports(1, &viewport); + + ID3D11RenderTargetView * RTVs[] = { pPhaseLUT_->getRTV() }; + dxCtx->OMSetRenderTargets(1, RTVs, nullptr); + dxCtx->OMSetDepthStencilState(states.ds.no_depth, 0); + dxCtx->OMSetBlendState(states.bs.no_blending, nullptr, 0xFFFFFFFF); + dxCtx->PSSetShader(shaders.ComputePhaseLookup_PS[ComputePhaseLookup_PS::SINGLE], nullptr, 0); + V_( DrawFullscreen(dxCtx) ); + return Status::OK; +} + +Status ContextImp_D3D11::BeginAccumulation_CopyDepth(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + ID3D11ShaderResourceView * sceneDepth_SRV = sceneDepth; + NV_PERFEVENT(dxCtx, "CopyDepth"); + + dxCtx->ClearDepthStencilView(pDepth_->getDSV(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); + + D3D11_VIEWPORT viewport; + viewport.TopLeftX = 0.0f; + viewport.TopLeftY = 0.0f; + viewport.Width = static_cast<float>(getInternalViewportWidth()); + viewport.Height = static_cast<float>(getInternalViewportHeight()); + viewport.MinDepth = 0.f; + viewport.MaxDepth = 1.f; + dxCtx->RSSetViewports(1, &viewport); + + dxCtx->PSSetShaderResources(0, 1, &sceneDepth_SRV); + ID3D11RenderTargetView * NULL_RTVs[] = { nullptr }; + dxCtx->OMSetRenderTargets(1, NULL_RTVs, pDepth_->getDSV()); + dxCtx->OMSetDepthStencilState(states.ds.write_only_depth, 0); + dxCtx->OMSetBlendState(states.bs.no_color, nullptr, 0xFFFFFFFF); + DownsampleDepth_PS::Desc ps_desc = DownsampleDepth_PS::Desc(isOutputMSAA() ? DownsampleDepth_PS::SAMPLEMODE_MSAA : DownsampleDepth_PS::SAMPLEMODE_SINGLE); + dxCtx->PSSetShader(shaders.DownsampleDepth_PS[ps_desc], nullptr, 0); + V_( DrawFullscreen(dxCtx) ); + return Status::OK; +} + +Status ContextImp_D3D11::BeginAccumulation_End(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + FLOAT black[] = {0,0,0,0}; + dxCtx->ClearRenderTargetView(pAccumulation_->getRTV(), black); + + NV_PERFEVENT_END(dxCtx); + return Status::OK; +} + +/*============================================================================== + RenderVolume +==============================================================================*/ +Status ContextImp_D3D11::RenderVolume_Start(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + NV_PERFEVENT_BEGIN(dxCtx, "NvVl::RenderVolume"); + + // Setup the constant buffer + SetupCB_PerVolume(pShadowMapDesc, pLightDesc, pVolumeDesc, pPerVolumeCB->Map(dxCtx)); + pPerVolumeCB->Unmap(dxCtx); + + dxCtx->ClearDepthStencilView(pDepth_->getDSV(), D3D11_CLEAR_STENCIL, 1.0f, STENCIL_REF); + + // Set up all the state common for this pass + ID3D11Buffer * pCBs[] = { + pPerContextCB->getCB(), + pPerFrameCB->getCB(), + pPerVolumeCB->getCB(), + nullptr // pPerApplyCB: Invalid + }; + dxCtx->VSSetConstantBuffers(0, 4, pCBs); + dxCtx->HSSetConstantBuffers(0, 4, pCBs); + dxCtx->DSSetConstantBuffers(0, 4, pCBs); + dxCtx->PSSetConstantBuffers(0, 4, pCBs); + dxCtx->CSSetConstantBuffers(0, 4, pCBs); + + ID3D11SamplerState * pSamplers[] = { + states.ss.point, + states.ss.linear + }; + dxCtx->VSSetSamplers(0, 2, pSamplers); + dxCtx->HSSetSamplers(0, 2, pSamplers); + dxCtx->DSSetSamplers(0, 2, pSamplers); + dxCtx->PSSetSamplers(0, 2, pSamplers); + dxCtx->CSSetSamplers(0, 2, pSamplers); + + return Status::OK; +} + +Status ContextImp_D3D11::RenderVolume_DoVolume_Directional(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + ID3D11ShaderResourceView * pShadowMap_SRV = shadowMap.d3d11; + + NV_PERFEVENT(dxCtx, "Directional"); + + uint32_t mesh_resolution = getCoarseResolution(pVolumeDesc); + + //-------------------------------------------------------------------------- + // Draw tessellated grid + + D3D11_VIEWPORT viewport; + viewport.TopLeftX = 0.0f; + viewport.TopLeftY = 0.0f; + viewport.Width = static_cast<float>(getInternalViewportWidth()); + viewport.Height = static_cast<float>(getInternalViewportHeight()); + viewport.MinDepth = 0.f; + viewport.MaxDepth = 1.f; + dxCtx->RSSetViewports(1, &viewport); + dxCtx->RSSetState(states.rs.cull_none); + dxCtx->OMSetBlendState(states.bs.additive, nullptr, 0xFFFFFFFF); + + ID3D11RenderTargetView * RTVs[] = { pAccumulation_->getRTV() }; + dxCtx->OMSetRenderTargets(1, RTVs, pDepth_->getDSV()); + + // Determine DS/HS permutation + RenderVolume_HS::Desc hs_desc; + hs_desc.flags.MAXTESSFACTOR = (RenderVolume_HS::eMAXTESSFACTOR) pVolumeDesc->eTessQuality; + + RenderVolume_DS::Desc ds_desc; + + switch (pShadowMapDesc->eType) + { + case ShadowMapLayout::SIMPLE: + case ShadowMapLayout::CASCADE_ATLAS: + hs_desc.flags.SHADOWMAPTYPE = RenderVolume_HS::SHADOWMAPTYPE_ATLAS; + ds_desc.flags.SHADOWMAPTYPE = RenderVolume_DS::SHADOWMAPTYPE_ATLAS; + break; + + case ShadowMapLayout::CASCADE_ARRAY: + hs_desc.flags.SHADOWMAPTYPE = RenderVolume_HS::SHADOWMAPTYPE_ARRAY; + ds_desc.flags.SHADOWMAPTYPE = RenderVolume_DS::SHADOWMAPTYPE_ARRAY; + break; + + default: + return Status::INVALID_PARAMETER; + }; + + switch (pShadowMapDesc->uElementCount) + { + case 0: + if (pShadowMapDesc->eType != ShadowMapLayout::SIMPLE) + { + return Status::INVALID_PARAMETER; + } + case 1: + hs_desc.flags.CASCADECOUNT = RenderVolume_HS::CASCADECOUNT_1; + ds_desc.flags.CASCADECOUNT = RenderVolume_DS::CASCADECOUNT_1; + break; + + case 2: + hs_desc.flags.CASCADECOUNT = RenderVolume_HS::CASCADECOUNT_2; + ds_desc.flags.CASCADECOUNT = RenderVolume_DS::CASCADECOUNT_2; + break; + + case 3: + hs_desc.flags.CASCADECOUNT = RenderVolume_HS::CASCADECOUNT_3; + ds_desc.flags.CASCADECOUNT = RenderVolume_DS::CASCADECOUNT_3; + break; + + case 4: + hs_desc.flags.CASCADECOUNT = RenderVolume_HS::CASCADECOUNT_4; + ds_desc.flags.CASCADECOUNT = RenderVolume_DS::CASCADECOUNT_4; + break; + + default: + return Status::INVALID_PARAMETER; + }; + hs_desc.flags.VOLUMETYPE = RenderVolume_HS::VOLUMETYPE_FRUSTUM; + ds_desc.flags.VOLUMETYPE = RenderVolume_DS::VOLUMETYPE_FRUSTUM; + + // Determine PS permutation + RenderVolume_PS::Desc ps_desc; + ps_desc.flags.SAMPLEMODE = isInternalMSAA() ? RenderVolume_PS::SAMPLEMODE_MSAA : RenderVolume_PS::SAMPLEMODE_SINGLE; + ps_desc.flags.LIGHTMODE = RenderVolume_PS::LIGHTMODE_DIRECTIONAL; + ps_desc.flags.PASSMODE = RenderVolume_PS::PASSMODE_GEOMETRY; + ps_desc.flags.ATTENUATIONMODE = RenderVolume_PS::ATTENUATIONMODE_NONE; // unused for directional + + dxCtx->HSSetShader(shaders.RenderVolume_HS[hs_desc], nullptr, 0); + dxCtx->DSSetShader(shaders.RenderVolume_DS[ds_desc], nullptr, 0); + dxCtx->PSSetShader(shaders.RenderVolume_PS[ps_desc], nullptr, 0); + + ID3D11ShaderResourceView * SRVs[] = { + nullptr, + pShadowMap_SRV, + nullptr, + nullptr, + pPhaseLUT_->getSRV(), + }; + dxCtx->VSSetShaderResources(0, 5, SRVs); + dxCtx->HSSetShaderResources(0, 5, SRVs); + dxCtx->DSSetShaderResources(0, 5, SRVs); + dxCtx->PSSetShaderResources(0, 5, SRVs); + + dxCtx->OMSetDepthStencilState(states.ds.render_volume, STENCIL_REF); + + DrawFrustumGrid(dxCtx, mesh_resolution); + dxCtx->HSSetShader(nullptr, nullptr, 0); + dxCtx->DSSetShader(nullptr, nullptr, 0); + + //-------------------------------------------------------------------------- + // Remove the illumination from the base of the scene (re-lit by sky later) + DrawFrustumBase(dxCtx, mesh_resolution); + + //-------------------------------------------------------------------------- + // Render the bounds of the frustum + if (debugFlags_ & (uint32_t)DebugFlags::WIREFRAME) + return Status::OK; + + ps_desc.flags.PASSMODE = RenderVolume_PS::PASSMODE_SKY; + dxCtx->PSSetShader(shaders.RenderVolume_PS[ps_desc], nullptr, 0); + dxCtx->OMSetDepthStencilState(states.ds.render_volume_boundary, STENCIL_REF); + DrawFullscreen(dxCtx); + + //-------------------------------------------------------------------------- + // Finish the rendering by filling in stenciled gaps + dxCtx->OMSetDepthStencilState(states.ds.finish_volume, STENCIL_REF); + dxCtx->OMSetRenderTargets(1, RTVs, pDepth_->getReadOnlyDSV()); + SRVs[2] = pDepth_->getSRV(); + dxCtx->PSSetShaderResources(2, 1, &SRVs[2]); + ps_desc.flags.PASSMODE = RenderVolume_PS::PASSMODE_FINAL; + dxCtx->PSSetShader(shaders.RenderVolume_PS[ps_desc], nullptr, 0); + DrawFullscreen(dxCtx); + + return Status::OK; +} + +Status ContextImp_D3D11::RenderVolume_DoVolume_Spotlight(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + ID3D11ShaderResourceView * pShadowMap_SRV = shadowMap.d3d11; + + NV_PERFEVENT(dxCtx, "Spotlight"); + + uint32_t mesh_resolution = getCoarseResolution(pVolumeDesc); + + ID3D11ShaderResourceView * SRVs[16] = { nullptr }; + ID3D11UnorderedAccessView * UAVs[16] = { nullptr }; + + //-------------------------------------------------------------------------- + // Create look-up table + if (pLightDesc->Spotlight.eFalloffMode == SpotlightFalloffMode::NONE) + { + NV_PERFEVENT(dxCtx, "Generate Light LUT"); + ComputeLightLUT_CS::Desc cs_desc; + cs_desc.flags.LIGHTMODE = ComputeLightLUT_CS::LIGHTMODE_OMNI; + cs_desc.flags.ATTENUATIONMODE = (ComputeLightLUT_CS::eATTENUATIONMODE) pLightDesc->Spotlight.eAttenuationMode; + + UAVs[0] = pLightLUT_P_[0]->getUAV(); + dxCtx->CSSetUnorderedAccessViews(0, 1, UAVs, 0); + SRVs[4] = pPhaseLUT_->getSRV(); + dxCtx->CSSetShaderResources(0, 6, SRVs); + cs_desc.flags.COMPUTEPASS = ComputeLightLUT_CS::COMPUTEPASS_CALCULATE; + dxCtx->CSSetShader(shaders.ComputeLightLUT_CS[cs_desc], nullptr, 0); + dxCtx->Dispatch(LIGHT_LUT_DEPTH_RESOLUTION / 32, LIGHT_LUT_WDOTV_RESOLUTION / 8, 1); + + UAVs[0] = pLightLUT_P_[1]->getUAV(); + dxCtx->CSSetUnorderedAccessViews(0, 1, UAVs, 0); + SRVs[5] = pLightLUT_P_[0]->getSRV(); + dxCtx->CSSetShaderResources(0, 6, SRVs); + cs_desc.flags.COMPUTEPASS = ComputeLightLUT_CS::COMPUTEPASS_SUM; + dxCtx->CSSetShader(shaders.ComputeLightLUT_CS[cs_desc], nullptr, 0); + dxCtx->Dispatch(1, LIGHT_LUT_WDOTV_RESOLUTION / 4, 1); + + dxCtx->CSSetShader(nullptr, nullptr, 0); + UAVs[0] = nullptr; + dxCtx->CSSetUnorderedAccessViews(0, 1, UAVs, 0); + } + else if (pLightDesc->Spotlight.eFalloffMode == SpotlightFalloffMode::FIXED) + { + NV_PERFEVENT(dxCtx, "Generate Light LUT"); + ComputeLightLUT_CS::Desc cs_desc; + cs_desc.flags.LIGHTMODE = ComputeLightLUT_CS::LIGHTMODE_SPOTLIGHT; + cs_desc.flags.ATTENUATIONMODE = (ComputeLightLUT_CS::eATTENUATIONMODE) pLightDesc->Spotlight.eAttenuationMode; + + UAVs[0] = pLightLUT_P_[0]->getUAV(); + UAVs[1] = pLightLUT_S1_[0]->getUAV(); + UAVs[2] = pLightLUT_S2_[0]->getUAV(); + dxCtx->CSSetUnorderedAccessViews(0, 3, UAVs, 0); + SRVs[4] = pPhaseLUT_->getSRV(); + dxCtx->CSSetShaderResources(0, 8, SRVs); + cs_desc.flags.COMPUTEPASS = ComputeLightLUT_CS::COMPUTEPASS_CALCULATE; + dxCtx->CSSetShader(shaders.ComputeLightLUT_CS[cs_desc], nullptr, 0); + dxCtx->Dispatch(LIGHT_LUT_DEPTH_RESOLUTION / 32, LIGHT_LUT_WDOTV_RESOLUTION / 8, 1); + + UAVs[0] = pLightLUT_P_[1]->getUAV(); + UAVs[1] = pLightLUT_S1_[1]->getUAV(); + UAVs[2] = pLightLUT_S2_[1]->getUAV(); + dxCtx->CSSetUnorderedAccessViews(0, 3, UAVs, 0); + SRVs[5] = pLightLUT_P_[0]->getSRV(); + SRVs[6] = pLightLUT_S1_[0]->getSRV(); + SRVs[7] = pLightLUT_S2_[0]->getSRV(); + dxCtx->CSSetShaderResources(0, 8, SRVs); + cs_desc.flags.COMPUTEPASS = ComputeLightLUT_CS::COMPUTEPASS_SUM; + dxCtx->CSSetShader(shaders.ComputeLightLUT_CS[cs_desc], nullptr, 0); + dxCtx->Dispatch(1, LIGHT_LUT_WDOTV_RESOLUTION / 4, 3); + + dxCtx->CSSetShader(nullptr, nullptr, 0); + UAVs[0] = nullptr; + UAVs[1] = nullptr; + UAVs[2] = nullptr; + dxCtx->CSSetUnorderedAccessViews(0, 3, UAVs, 0); + } + + //-------------------------------------------------------------------------- + // Draw tessellated grid + + D3D11_VIEWPORT viewport; + viewport.TopLeftX = 0.0f; + viewport.TopLeftY = 0.0f; + viewport.Width = static_cast<float>(getInternalViewportWidth()); + viewport.Height = static_cast<float>(getInternalViewportHeight()); + viewport.MinDepth = 0.f; + viewport.MaxDepth = 1.f; + dxCtx->RSSetViewports(1, &viewport); + dxCtx->RSSetState(states.rs.cull_none); + dxCtx->OMSetBlendState(states.bs.additive, nullptr, 0xFFFFFFFF); + + ID3D11RenderTargetView * RTVs[] = { pAccumulation_->getRTV() }; + dxCtx->OMSetRenderTargets(1, RTVs, pDepth_->getDSV()); + + // Determine DS/HS permutation + RenderVolume_HS::Desc hs_desc; + hs_desc.flags.SHADOWMAPTYPE = RenderVolume_HS::SHADOWMAPTYPE_ATLAS; + hs_desc.flags.CASCADECOUNT = RenderVolume_HS::CASCADECOUNT_1; + hs_desc.flags.VOLUMETYPE = RenderVolume_HS::VOLUMETYPE_FRUSTUM; + hs_desc.flags.MAXTESSFACTOR = (RenderVolume_HS::eMAXTESSFACTOR) pVolumeDesc->eTessQuality; + + RenderVolume_DS::Desc ds_desc; + ds_desc.flags.SHADOWMAPTYPE = RenderVolume_DS::SHADOWMAPTYPE_ATLAS; + ds_desc.flags.CASCADECOUNT = RenderVolume_DS::CASCADECOUNT_1; + ds_desc.flags.VOLUMETYPE = RenderVolume_DS::VOLUMETYPE_FRUSTUM; + + // Determine PS permutation + RenderVolume_PS::Desc ps_desc; + ps_desc.flags.SAMPLEMODE = isInternalMSAA() ? RenderVolume_PS::SAMPLEMODE_MSAA : RenderVolume_PS::SAMPLEMODE_SINGLE; + ps_desc.flags.LIGHTMODE = RenderVolume_PS::LIGHTMODE_SPOTLIGHT; + ps_desc.flags.PASSMODE = RenderVolume_PS::PASSMODE_GEOMETRY; + ps_desc.flags.ATTENUATIONMODE = (RenderVolume_PS::eATTENUATIONMODE) pLightDesc->Spotlight.eAttenuationMode; + ps_desc.flags.FALLOFFMODE = (RenderVolume_PS::eFALLOFFMODE) pLightDesc->Spotlight.eFalloffMode; + + dxCtx->HSSetShader(shaders.RenderVolume_HS[hs_desc], nullptr, 0); + dxCtx->DSSetShader(shaders.RenderVolume_DS[ds_desc], nullptr, 0); + dxCtx->PSSetShader(shaders.RenderVolume_PS[ps_desc], nullptr, 0); + + SRVs[1] = pShadowMap_SRV; + SRVs[4] = pPhaseLUT_->getSRV(); + SRVs[5] = pLightLUT_P_[1]->getSRV(); + SRVs[6] = pLightLUT_S1_[1]->getSRV(); + SRVs[7] = pLightLUT_S2_[1]->getSRV(); + dxCtx->VSSetShaderResources(0, 8, SRVs); + dxCtx->HSSetShaderResources(0, 8, SRVs); + dxCtx->DSSetShaderResources(0, 8, SRVs); + dxCtx->PSSetShaderResources(0, 8, SRVs); + + dxCtx->OMSetDepthStencilState(states.ds.render_volume, STENCIL_REF); + DrawFrustumGrid(dxCtx, mesh_resolution); + dxCtx->HSSetShader(nullptr, nullptr, 0); + dxCtx->DSSetShader(nullptr, nullptr, 0); + + //-------------------------------------------------------------------------- + // Render the bounds of the spotlight volume + dxCtx->RSSetState(states.rs.cull_front); + DrawFrustumCap(dxCtx, mesh_resolution); + + //-------------------------------------------------------------------------- + // Finish the rendering by filling in stenciled gaps + dxCtx->OMSetDepthStencilState(states.ds.finish_volume, STENCIL_REF); + dxCtx->OMSetRenderTargets(1, RTVs, pDepth_->getReadOnlyDSV()); + SRVs[2] = pDepth_->getSRV(); + dxCtx->PSSetShaderResources(2, 1, &SRVs[2]); + ps_desc.flags.PASSMODE = RenderVolume_PS::PASSMODE_FINAL; + dxCtx->PSSetShader(shaders.RenderVolume_PS[ps_desc], nullptr, 0); + DrawFullscreen(dxCtx); + + return Status::OK; +} + +Status ContextImp_D3D11::RenderVolume_DoVolume_Omni(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + ID3D11ShaderResourceView * pShadowMap_SRV = shadowMap.d3d11; + + NV_PERFEVENT(dxCtx, "Omni"); + + uint32_t mesh_resolution = getCoarseResolution(pVolumeDesc); + + ID3D11ShaderResourceView * SRVs[] = { + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr + }; + + ID3D11UnorderedAccessView * UAVs[] = { + nullptr + }; + + //-------------------------------------------------------------------------- + // Create look-up table + { + NV_PERFEVENT(dxCtx, "Generate Light LUT"); + ComputeLightLUT_CS::Desc cs_desc; + cs_desc.flags.LIGHTMODE = ComputeLightLUT_CS::LIGHTMODE_OMNI; + cs_desc.flags.ATTENUATIONMODE = (ComputeLightLUT_CS::eATTENUATIONMODE) pLightDesc->Omni.eAttenuationMode; + + UAVs[0] = pLightLUT_P_[0]->getUAV(); + dxCtx->CSSetUnorderedAccessViews(0, 1, UAVs, 0); + SRVs[4] = pPhaseLUT_->getSRV(); + dxCtx->CSSetShaderResources(0, 6, SRVs); + cs_desc.flags.COMPUTEPASS = ComputeLightLUT_CS::COMPUTEPASS_CALCULATE; + dxCtx->CSSetShader(shaders.ComputeLightLUT_CS[cs_desc], nullptr, 0); + dxCtx->Dispatch(LIGHT_LUT_DEPTH_RESOLUTION / 32, LIGHT_LUT_WDOTV_RESOLUTION / 8, 1); + + UAVs[0] = pLightLUT_P_[1]->getUAV(); + dxCtx->CSSetUnorderedAccessViews(0, 1, UAVs, 0); + SRVs[5] = pLightLUT_P_[0]->getSRV(); + dxCtx->CSSetShaderResources(0, 6, SRVs); + cs_desc.flags.COMPUTEPASS = ComputeLightLUT_CS::COMPUTEPASS_SUM; + dxCtx->CSSetShader(shaders.ComputeLightLUT_CS[cs_desc], nullptr, 0); + dxCtx->Dispatch(1, LIGHT_LUT_WDOTV_RESOLUTION / 4, 1); + + dxCtx->CSSetShader(nullptr, nullptr, 0); + UAVs[0] = nullptr; + dxCtx->CSSetUnorderedAccessViews(0, 1, UAVs, 0); + } + + //-------------------------------------------------------------------------- + // Draw tessellated grid + D3D11_VIEWPORT viewport; + viewport.TopLeftX = 0.0f; + viewport.TopLeftY = 0.0f; + viewport.Width = static_cast<float>(getInternalViewportWidth()); + viewport.Height = static_cast<float>(getInternalViewportHeight()); + viewport.MinDepth = 0.f; + viewport.MaxDepth = 1.f; + dxCtx->RSSetViewports(1, &viewport); + dxCtx->RSSetState(states.rs.cull_none); + dxCtx->OMSetBlendState(states.bs.additive, nullptr, 0xFFFFFFFF); + + ID3D11RenderTargetView * RTVs[] = { pAccumulation_->getRTV() }; + dxCtx->OMSetRenderTargets(1, RTVs, pDepth_->getDSV()); + + // Determine DS/HS permutation + RenderVolume_HS::Desc hs_desc; + hs_desc.flags.SHADOWMAPTYPE = RenderVolume_HS::SHADOWMAPTYPE_ARRAY; + hs_desc.flags.CASCADECOUNT = RenderVolume_HS::CASCADECOUNT_1; + hs_desc.flags.VOLUMETYPE = RenderVolume_HS::VOLUMETYPE_PARABOLOID; + hs_desc.flags.MAXTESSFACTOR = (RenderVolume_HS::eMAXTESSFACTOR) pVolumeDesc->eTessQuality; + + RenderVolume_DS::Desc ds_desc; + ds_desc.flags.SHADOWMAPTYPE = RenderVolume_DS::SHADOWMAPTYPE_ARRAY; + ds_desc.flags.CASCADECOUNT = RenderVolume_DS::CASCADECOUNT_1; + ds_desc.flags.VOLUMETYPE = RenderVolume_DS::VOLUMETYPE_PARABOLOID; + + // Determine PS permutation + RenderVolume_PS::Desc ps_desc; + ps_desc.flags.SAMPLEMODE = isInternalMSAA() ? RenderVolume_PS::SAMPLEMODE_MSAA : RenderVolume_PS::SAMPLEMODE_SINGLE; + ps_desc.flags.LIGHTMODE = RenderVolume_PS::LIGHTMODE_OMNI; + ps_desc.flags.PASSMODE = RenderVolume_PS::PASSMODE_GEOMETRY; + ps_desc.flags.ATTENUATIONMODE = (RenderVolume_PS::eATTENUATIONMODE) pLightDesc->Omni.eAttenuationMode; + + dxCtx->HSSetShader(shaders.RenderVolume_HS[hs_desc], nullptr, 0); + dxCtx->DSSetShader(shaders.RenderVolume_DS[ds_desc], nullptr, 0); + dxCtx->PSSetShader(shaders.RenderVolume_PS[ps_desc], nullptr, 0); + + SRVs[1] = pShadowMap_SRV; + SRVs[5] = pLightLUT_P_[1]->getSRV(); + dxCtx->VSSetShaderResources(0, 6, SRVs); + dxCtx->HSSetShaderResources(0, 6, SRVs); + dxCtx->DSSetShaderResources(0, 6, SRVs); + dxCtx->PSSetShaderResources(0, 6, SRVs); + + dxCtx->OMSetDepthStencilState(states.ds.render_volume, STENCIL_REF); + DrawOmniVolume(dxCtx, mesh_resolution); + dxCtx->HSSetShader(nullptr, nullptr, 0); + dxCtx->DSSetShader(nullptr, nullptr, 0); + + //-------------------------------------------------------------------------- + // Finish the rendering by filling in stenciled gaps + dxCtx->OMSetDepthStencilState(states.ds.finish_volume, STENCIL_REF); + dxCtx->OMSetRenderTargets(1, RTVs, pDepth_->getReadOnlyDSV()); + SRVs[2] = pDepth_->getSRV(); + dxCtx->PSSetShaderResources(2, 1, &SRVs[2]); + ps_desc.flags.PASSMODE = RenderVolume_PS::PASSMODE_FINAL; + dxCtx->PSSetShader(shaders.RenderVolume_PS[ps_desc], nullptr, 0); + DrawFullscreen(dxCtx); + + return Status::OK; +} + +Status ContextImp_D3D11::RenderVolume_End(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + ID3D11RenderTargetView * NULL_RTV = nullptr; + dxCtx->OMSetRenderTargets(1, &NULL_RTV, nullptr); + NV_PERFEVENT_END(dxCtx); + return Status::OK; +} + +/*============================================================================== + EndAccumulation +==============================================================================*/ +Status ContextImp_D3D11::EndAccumulation_Imp(PlatformRenderCtx renderCtx) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + dxCtx; + return Status::OK; +} + +/*============================================================================== + ApplyLighting +==============================================================================*/ +Status ContextImp_D3D11::ApplyLighting_Start(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + + NV_PERFEVENT_BEGIN(dxCtx, "NvVl::ApplyLighting"); + + // Setup the constant buffer + SetupCB_PerApply(pPostprocessDesc, pPerApplyCB->Map(dxCtx)); + pPerApplyCB->Unmap(dxCtx); + + ID3D11Buffer* pCBs[] = { + pPerContextCB->getCB(), + pPerFrameCB->getCB(), + nullptr, // pPerVolumeCB - Invalid + pPerApplyCB->getCB(), + }; + dxCtx->VSSetConstantBuffers(0, 4, pCBs); + dxCtx->PSSetConstantBuffers(0, 4, pCBs); + + ID3D11SamplerState * pSamplers[] = { + states.ss.point, + states.ss.linear + }; + dxCtx->PSSetSamplers(0, 2, pSamplers); + dxCtx->OMSetDepthStencilState(states.ds.no_depth, 0xFF); + dxCtx->OMSetBlendState(states.bs.no_blending, nullptr, 0xFFFFFFFF); + + D3D11_VIEWPORT viewport; + viewport.TopLeftX = 0.0f; + viewport.TopLeftY = 0.0f; + viewport.Width = static_cast<float>(getInternalViewportWidth()); + viewport.Height = static_cast<float>(getInternalViewportHeight()); + viewport.MinDepth = 0.f; + viewport.MaxDepth = 1.f; + dxCtx->RSSetViewports(1, &viewport); + + pAccumulatedOutput_ = pAccumulation_; + + return Status::OK; +} + +Status ContextImp_D3D11::ApplyLighting_Resolve(PlatformRenderCtx renderCtx, PostprocessDesc const* pPostprocessDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + + NV_PERFEVENT(dxCtx, "Resolve"); + + Resolve_PS::Desc ps_desc; + ps_desc.flags.SAMPLEMODE = isInternalMSAA() ? Resolve_PS::SAMPLEMODE_MSAA : Resolve_PS::SAMPLEMODE_SINGLE; + dxCtx->PSSetShader(shaders.Resolve_PS[ps_desc], nullptr, 0); + ID3D11ShaderResourceView * SRVs[] = { + pAccumulation_->getSRV(), + pDepth_->getSRV() + }; + dxCtx->PSSetShaderResources(0, 2, SRVs); + ID3D11RenderTargetView * RTVs[] = { + pResolvedAccumulation_->getRTV(), + pResolvedDepth_->getRTV() + }; + dxCtx->OMSetRenderTargets(2, RTVs, nullptr); + DrawFullscreen(dxCtx); + pAccumulatedOutput_ = pResolvedAccumulation_; + ID3D11RenderTargetView * NULL_RTVs[] = { nullptr, nullptr }; + dxCtx->OMSetRenderTargets(2, NULL_RTVs, nullptr); + return Status::OK; +} + +Status ContextImp_D3D11::ApplyLighting_TemporalFilter(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + + NV_PERFEVENT(dxCtx, "TemporalFilter"); + + dxCtx->PSSetShader(shaders.TemporalFilter_PS[TemporalFilter_PS::SINGLE], nullptr, 0); + ID3D11ShaderResourceView * SRVs[] = { + pResolvedAccumulation_->getSRV(), + pFilteredAccumulation_[lastFrameIndex_]->getSRV(), + pResolvedDepth_->getSRV(), + nullptr, + pFilteredDepth_[lastFrameIndex_]->getSRV() + }; + dxCtx->PSSetShaderResources(0, 4, SRVs); + ID3D11RenderTargetView * RTVs[] = { + pFilteredAccumulation_[nextFrameIndex_]->getRTV(), + pFilteredDepth_[nextFrameIndex_]->getRTV() + }; + dxCtx->OMSetRenderTargets(2, RTVs, nullptr); + DrawFullscreen(dxCtx); + pAccumulatedOutput_ = pFilteredAccumulation_[nextFrameIndex_]; + ID3D11RenderTargetView * NULL_RTVs[] = { nullptr, nullptr }; + dxCtx->OMSetRenderTargets(2, NULL_RTVs, nullptr); + return Status::OK; +} + +Status ContextImp_D3D11::ApplyLighting_Composite(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + ID3D11RenderTargetView * pScene_RTV = sceneTarget.d3d11; + ID3D11ShaderResourceView * pSceneDepth_SRV = sceneDepth.d3d11; + + NV_PERFEVENT(dxCtx, "Composite"); + + D3D11_VIEWPORT viewport; + viewport.TopLeftX = 0.0f; + viewport.TopLeftY = 0.0f; + viewport.Width = static_cast<float>(getOutputViewportWidth()); + viewport.Height = static_cast<float>(getOutputViewportHeight()); + viewport.MinDepth = 0.f; + viewport.MaxDepth = 1.f; + dxCtx->RSSetViewports(1, &viewport); + + if (debugFlags_ & (uint32_t)DebugFlags::NO_BLENDING) + { + dxCtx->OMSetBlendState(states.bs.debug_blend, nullptr, 0xFFFFFFFF); + } + else + { + FLOAT blend_factor[] = { pPostprocessDesc->fBlendfactor, pPostprocessDesc->fBlendfactor, pPostprocessDesc->fBlendfactor, pPostprocessDesc->fBlendfactor }; + dxCtx->OMSetBlendState(states.bs.additive_modulate, blend_factor, 0xFFFFFFFF); + } + dxCtx->OMSetRenderTargets(1, &pScene_RTV, nullptr); + + Apply_PS::Desc ps_desc; + ps_desc.flags.SAMPLEMODE = isOutputMSAA() ? Apply_PS::SAMPLEMODE_MSAA : Apply_PS::SAMPLEMODE_SINGLE; + switch (pPostprocessDesc->eUpsampleQuality) + { + default: + case UpsampleQuality::POINT: + ps_desc.flags.UPSAMPLEMODE = Apply_PS::UPSAMPLEMODE_POINT; + break; + + case UpsampleQuality::BILINEAR: + ps_desc.flags.UPSAMPLEMODE = Apply_PS::UPSAMPLEMODE_BILINEAR; + break; + + case UpsampleQuality::BILATERAL: + ps_desc.flags.UPSAMPLEMODE = Apply_PS::UPSAMPLEMODE_BILATERAL; + break; + } + if (pPostprocessDesc->bDoFog == false) + ps_desc.flags.FOGMODE = Apply_PS::FOGMODE_NONE; + else if (pPostprocessDesc->bIgnoreSkyFog == true) + ps_desc.flags.FOGMODE = Apply_PS::FOGMODE_NOSKY; + else + ps_desc.flags.FOGMODE = Apply_PS::FOGMODE_FULL; + dxCtx->PSSetShader(shaders.Apply_PS[ps_desc], nullptr, 0); + ID3D11ShaderResourceView * SRVs[] = { + pAccumulatedOutput_->getSRV(), + pSceneDepth_SRV, + nullptr, + nullptr, + pPhaseLUT_->getSRV() + }; + if (pFilteredDepth_[nextFrameIndex_]) + SRVs[2] = pFilteredDepth_[nextFrameIndex_]->getSRV(); + dxCtx->PSSetShaderResources(0, 5, SRVs); + DrawFullscreen(dxCtx); + + ID3D11RenderTargetView * NULL_RTV = nullptr; + dxCtx->OMSetRenderTargets(1, &NULL_RTV, nullptr); + return Status::OK; +} + +Status ContextImp_D3D11::ApplyLighting_End(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc) +{ + ID3D11DeviceContext * dxCtx = renderCtx; + dxCtx; + NV_PERFEVENT_END(dxCtx); + return Status::OK; +} + +/*============================================================================== + Utility functions +==============================================================================*/ + +Status ContextImp_D3D11::DrawFullscreen(ID3D11DeviceContext * dxCtx) +{ + NV_PERFEVENT(dxCtx, "DrawFullscreen"); + dxCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + dxCtx->IASetVertexBuffers(0,0,nullptr, nullptr,nullptr); + dxCtx->IASetInputLayout(nullptr); + dxCtx->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0); + dxCtx->RSSetState(states.rs.cull_none); + dxCtx->VSSetShader(shaders.Quad_VS[Quad_VS::SINGLE], nullptr, 0); + dxCtx->HSSetShader(nullptr, nullptr, 0); + dxCtx->DSSetShader(nullptr, nullptr, 0); + dxCtx->Draw(3, 0); + return Status::OK; +} + +Status ContextImp_D3D11::DrawFrustumGrid(ID3D11DeviceContext * dxCtx, uint32_t resolution) +{ + NV_PERFEVENT(dxCtx, "DrawFrustumGrid"); + dxCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST); + dxCtx->IASetVertexBuffers(0,0,nullptr, nullptr,nullptr); + dxCtx->IASetInputLayout(nullptr); + dxCtx->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0); + RenderVolume_VS::Desc vs_desc; + vs_desc.flags.MESHMODE = RenderVolume_VS::MESHMODE_FRUSTUM_GRID; + dxCtx->VSSetShader(shaders.RenderVolume_VS[vs_desc], nullptr, 0); + + if (debugFlags_ & (uint32_t)DebugFlags::WIREFRAME) + { + dxCtx->RSSetState(states.rs.wireframe); + dxCtx->OMSetBlendState(states.bs.no_blending, nullptr, 0xFFFFFFFF); + dxCtx->PSSetShader(shaders.Debug_PS[Debug_PS::SINGLE], nullptr, 0); + } + + uint32_t vtx_count = 4 * resolution * resolution; + dxCtx->Draw(vtx_count, 0); + return Status::OK; +} + +Status ContextImp_D3D11::DrawFrustumBase(ID3D11DeviceContext * dxCtx, uint32_t resolution) +{ + NV_PERFEVENT(dxCtx, "DrawFrustumBase"); + dxCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + dxCtx->IASetVertexBuffers(0,0,nullptr, nullptr,nullptr); + dxCtx->IASetInputLayout(nullptr); + dxCtx->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0); + RenderVolume_VS::Desc vs_desc; + vs_desc.flags.MESHMODE = RenderVolume_VS::MESHMODE_FRUSTUM_BASE; + dxCtx->VSSetShader(shaders.RenderVolume_VS[vs_desc], nullptr, 0); + dxCtx->HSSetShader(nullptr, nullptr, 0); + dxCtx->DSSetShader(nullptr, nullptr, 0); + + if (debugFlags_ & (uint32_t)DebugFlags::WIREFRAME) + { + dxCtx->RSSetState(states.rs.wireframe); + dxCtx->OMSetBlendState(states.bs.no_blending, nullptr, 0xFFFFFFFF); + dxCtx->PSSetShader(shaders.Debug_PS[Debug_PS::SINGLE], nullptr, 0); + } + + dxCtx->Draw(6, 0); + return Status::OK; +} + +Status ContextImp_D3D11::DrawFrustumCap(ID3D11DeviceContext * dxCtx, uint32_t resolution) +{ + NV_PERFEVENT(dxCtx, "DrawFrustumCap"); + dxCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + dxCtx->IASetVertexBuffers(0,0,nullptr, nullptr,nullptr); + dxCtx->IASetInputLayout(nullptr); + dxCtx->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0); + RenderVolume_VS::Desc vs_desc; + vs_desc.flags.MESHMODE = RenderVolume_VS::MESHMODE_FRUSTUM_CAP; + dxCtx->VSSetShader(shaders.RenderVolume_VS[vs_desc], nullptr, 0); + dxCtx->HSSetShader(nullptr, nullptr, 0); + dxCtx->DSSetShader(nullptr, nullptr, 0); + + if (debugFlags_ & (uint32_t)DebugFlags::WIREFRAME) + { + dxCtx->RSSetState(states.rs.wireframe); + dxCtx->OMSetBlendState(states.bs.no_blending, nullptr, 0xFFFFFFFF); + dxCtx->PSSetShader(shaders.Debug_PS[Debug_PS::SINGLE], nullptr, 0); + } + + uint32_t vtx_count = 4*3*(resolution+1) + 6; + dxCtx->Draw(vtx_count, 0); + return Status::OK; +} + +Status ContextImp_D3D11::DrawOmniVolume(ID3D11DeviceContext * dxCtx, uint32_t resolution) +{ + NV_PERFEVENT(dxCtx, "DrawOmniVolume"); + dxCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST); + dxCtx->IASetVertexBuffers(0,0,nullptr, nullptr,nullptr); + dxCtx->IASetInputLayout(nullptr); + dxCtx->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0); + RenderVolume_VS::Desc vs_desc; + vs_desc.flags.MESHMODE = RenderVolume_VS::MESHMODE_OMNI_VOLUME; + dxCtx->VSSetShader(shaders.RenderVolume_VS[vs_desc], nullptr, 0); + + if (debugFlags_ & (uint32_t)DebugFlags::WIREFRAME) + { + dxCtx->RSSetState(states.rs.wireframe); + dxCtx->OMSetBlendState(states.bs.no_blending, nullptr, 0xFFFFFFFF); + dxCtx->PSSetShader(shaders.Debug_PS[Debug_PS::SINGLE], nullptr, 0); + } + + uint32_t vtx_count = 6 * 4 * resolution * resolution; + dxCtx->Draw(vtx_count, 0); + return Status::OK; +} +//////////////////////////////////////////////////////////////////////////////// +}; /*namespace Nv*/ }; /*namespace VolumetricLighting*/ +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/d3d11/context_d3d11.h b/src/d3d11/context_d3d11.h new file mode 100644 index 0000000..82a6931 --- /dev/null +++ b/src/d3d11/context_d3d11.h @@ -0,0 +1,191 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#ifndef CONTEXT_D3D11_H +#define CONTEXT_D3D11_H +//////////////////////////////////////////////////////////////////////////////// +#include <Nv/VolumetricLighting/NvVolumetricLighting.h> + +#include <vector> // TODO: remove this dependency +#include "context_common.h" +/*============================================================================== + Forward Declarations +==============================================================================*/ +// D3D11 Types +struct ID3D11VertexShader; +struct ID3D11HullShader; +struct ID3D11DomainShader; +struct ID3D11GeometryShader; +struct ID3D11PixelShader; +struct ID3D11ComputeShader; +struct ID3D11RasterizerState; +struct ID3D11SamplerState; +struct ID3D11DepthStencilState; +struct ID3D11BlendState; +struct ID3D11InputLayout; +struct ID3D11Buffer; + +// Helper Types +class Texture2D; +class RenderTarget; +class DepthTarget; +template <class T> class ConstantBuffer; + +//////////////////////////////////////////////////////////////////////////////// +namespace Nv { namespace VolumetricLighting { +//////////////////////////////////////////////////////////////////////////////// + +class ContextImp_D3D11 : public ContextImp_Common +{ +public: + // Creates the context and resources + static Status Create(ContextImp_D3D11 ** out_ctx, const PlatformDesc * pPlatformDesc, const ContextDesc * pContextDesc); + + // Clean up the context on delete + virtual ~ContextImp_D3D11(); + +protected: + // BeginAccumulation + Status BeginAccumulation_Start(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc); + Status BeginAccumulation_UpdateMediumLUT(PlatformRenderCtx renderCtx); + Status BeginAccumulation_CopyDepth(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth); + Status BeginAccumulation_End(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc); + + // RenderVolume + Status RenderVolume_Start(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc); + Status RenderVolume_DoVolume_Directional(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc); + Status RenderVolume_DoVolume_Spotlight(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc); + Status RenderVolume_DoVolume_Omni(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc); + Status RenderVolume_End(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc); + + // EndAccumulation + Status EndAccumulation_Imp(PlatformRenderCtx renderCtx); + + // ApplyLighting + Status ApplyLighting_Start(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc); + Status ApplyLighting_Resolve(PlatformRenderCtx renderCtx, PostprocessDesc const* pPostprocessDesc); + Status ApplyLighting_TemporalFilter(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc); + Status ApplyLighting_Composite(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc); + Status ApplyLighting_End(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc); + +private: + // Private default constructor + // Should never be called + ContextImp_D3D11() {}; + + // Initializing Destructor + // Setup all code that can't fail + ContextImp_D3D11(const ContextDesc * pContextDesc); + + // Called by Create internally + Status CreateResources(ID3D11Device * device); + + // Do a fullscreen pass with the bound pixel-shader + Status DrawFullscreen(ID3D11DeviceContext * dxCtx); + + Status DrawFrustumGrid(ID3D11DeviceContext * dxCtx, uint32_t resolution); + Status DrawFrustumBase(ID3D11DeviceContext * dxCtx, uint32_t resolution); + Status DrawFrustumCap(ID3D11DeviceContext * dxCtx, uint32_t resolution); + Status DrawOmniVolume(ID3D11DeviceContext * dxCtx, uint32_t resolution); + + struct + { + ID3D11PixelShader ** Apply_PS; + ID3D11ComputeShader ** ComputeLightLUT_CS; + ID3D11PixelShader ** ComputePhaseLookup_PS; + ID3D11PixelShader ** Debug_PS; + ID3D11PixelShader ** DownsampleDepth_PS; + ID3D11VertexShader ** Quad_VS; + ID3D11VertexShader ** RenderVolume_VS; + ID3D11HullShader ** RenderVolume_HS; + ID3D11DomainShader ** RenderVolume_DS; + ID3D11PixelShader ** RenderVolume_PS; + ID3D11PixelShader ** Resolve_PS; + ID3D11PixelShader ** TemporalFilter_PS; + } shaders; + + ConstantBuffer<PerContextCB> * pPerContextCB; + ConstantBuffer<PerFrameCB> * pPerFrameCB; + ConstantBuffer<PerVolumeCB> * pPerVolumeCB; + ConstantBuffer<PerApplyCB> * pPerApplyCB; + + DepthTarget * pDepth_; + RenderTarget * pPhaseLUT_; + RenderTarget * pLightLUT_P_[2]; + RenderTarget * pLightLUT_S1_[2]; + RenderTarget * pLightLUT_S2_[2]; + RenderTarget * pAccumulation_; + RenderTarget * pResolvedAccumulation_; + RenderTarget * pResolvedDepth_; + RenderTarget * pFilteredAccumulation_[2]; + RenderTarget * pFilteredDepth_[2]; + + RenderTarget * pAccumulatedOutput_; + + struct + { + struct + { + ID3D11RasterizerState * cull_none; + ID3D11RasterizerState * cull_front; + ID3D11RasterizerState * wireframe; + } rs; + + struct + { + ID3D11SamplerState * point; + ID3D11SamplerState * linear; + } ss; + + struct + { + ID3D11DepthStencilState * no_depth; + ID3D11DepthStencilState * write_only_depth; + ID3D11DepthStencilState * read_only_depth; + ID3D11DepthStencilState * render_volume; + ID3D11DepthStencilState * render_volume_boundary; + ID3D11DepthStencilState * remove_volume_base; + ID3D11DepthStencilState * render_volume_cap; + ID3D11DepthStencilState * finish_volume; + } ds; + + struct + { + ID3D11BlendState * no_color; + ID3D11BlendState * no_blending; + ID3D11BlendState * additive; + ID3D11BlendState * additive_modulate; + ID3D11BlendState * debug_blend; + } bs; + } states; +}; + +//////////////////////////////////////////////////////////////////////////////// +}; /*namespace VolumetricLighting*/ }; /*namespace Nv*/ +//////////////////////////////////////////////////////////////////////////////// +#endif // CONTEXT_D3D11_H diff --git a/src/d3d11/d3d11_util.cpp b/src/d3d11/d3d11_util.cpp new file mode 100644 index 0000000..4226fdb --- /dev/null +++ b/src/d3d11/d3d11_util.cpp @@ -0,0 +1,347 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#include "common.h" +#include "d3d11_util.h" +#include <d3d11.h> + +/*============================================================================== + Overloaded functions to make shader compilation simpler +==============================================================================*/ +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11VertexShader ** out_shader) + { return device->CreateVertexShader(data, length, nullptr, out_shader); } +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11HullShader ** out_shader) + { return device->CreateHullShader(data, length, nullptr, out_shader); } +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11DomainShader ** out_shader) + { return device->CreateDomainShader(data, length, nullptr, out_shader); } +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11GeometryShader ** out_shader) + { return device->CreateGeometryShader(data, length, nullptr, out_shader); } +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11PixelShader ** out_shader) + { return device->CreatePixelShader(data, length, nullptr, out_shader); } +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11ComputeShader ** out_shader) + { return device->CreateComputeShader(data, length, nullptr, out_shader); } +/*============================================================================== + Texture resource management helpers +==============================================================================*/ + +//------------------------------------------------------------------------------ +ShaderResource::ShaderResource(ID3D11Resource * resource, ID3D11ShaderResourceView * srv, ID3D11UnorderedAccessView * uav) +{ + resource_ = resource; + srv_ = srv; + uav_ = uav; +} + +ShaderResource::~ShaderResource() +{ + SAFE_RELEASE(resource_); + SAFE_RELEASE(srv_); + SAFE_RELEASE(uav_); +} + +//------------------------------------------------------------------------------ +RenderTarget * RenderTarget::Create(ID3D11Device * device, UINT width, UINT height, UINT samples, DXGI_FORMAT format, const char * debug_name) +{ + ID3D11Texture2D * tex = nullptr; + ID3D11ShaderResourceView * srv = nullptr; + ID3D11RenderTargetView * rtv = nullptr; + ID3D11UnorderedAccessView * uav = nullptr; + + CD3D11_TEXTURE2D_DESC texDesc; + texDesc.ArraySize = 1; + texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; + if (samples == 1) + texDesc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS; + texDesc.CPUAccessFlags = 0; + texDesc.Format = format; + texDesc.Width = width; + texDesc.Height = height; + texDesc.MipLevels = 1; + texDesc.MiscFlags = 0; + if (samples > 1) + { + texDesc.SampleDesc.Count = samples; + texDesc.SampleDesc.Quality = 0;//static_cast<UINT>(D3D11_STANDARD_MULTISAMPLE_PATTERN); + } + else + { + texDesc.SampleDesc.Count = 1; + texDesc.SampleDesc.Quality = 0; + } + texDesc.Usage = D3D11_USAGE_DEFAULT; + device->CreateTexture2D(&texDesc, nullptr, &tex); + if (tex == nullptr) + { + return nullptr; + } + + CD3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + srvDesc.Format = texDesc.Format; + if (samples > 1) + { + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS; + } + else + { + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MostDetailedMip = 0; + srvDesc.Texture2D.MipLevels = 1; + } + device->CreateShaderResourceView(tex, &srvDesc, &srv); + if (srv == nullptr) + { + tex->Release(); + return nullptr; + } + + CD3D11_RENDER_TARGET_VIEW_DESC rtvDesc; + rtvDesc.Format = texDesc.Format; + if (samples > 1) + { + rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS; + } + else + { + rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + rtvDesc.Texture2D.MipSlice = 0; + } + device->CreateRenderTargetView(tex, &rtvDesc, &rtv); + if (rtv == nullptr) + { + tex->Release(); + srv->Release(); + return nullptr; + } + + if (samples == 1) + { + CD3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc; + uavDesc.Format = texDesc.Format; + uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; + uavDesc.Texture2D.MipSlice = 0; + device->CreateUnorderedAccessView(tex, &uavDesc, &uav); + if (uav == nullptr) + { + tex->Release(); + srv->Release(); + rtv->Release(); + return nullptr; + } + } +#if (NV_DEBUG || NV_PROFILE) + if (debug_name) + { + tex->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)strlen(debug_name), debug_name); + } +#else + debug_name; +#endif + return new RenderTarget(tex, srv, rtv, uav); +} + +RenderTarget::RenderTarget(ID3D11Resource * resource, ID3D11ShaderResourceView * srv, ID3D11RenderTargetView * rtv, ID3D11UnorderedAccessView * uav) + : ShaderResource(resource, srv, uav) +{ + rtv_ = rtv; +} + +RenderTarget::~RenderTarget() +{ + SAFE_RELEASE(rtv_); +} + +//------------------------------------------------------------------------------ +DepthTarget * DepthTarget::Create(ID3D11Device * device, UINT width, UINT height, UINT samples, DXGI_FORMAT format, uint32_t slices, char * debug_name) +{ + ID3D11Texture2D * tex = nullptr; + ID3D11ShaderResourceView * srv = nullptr; + ID3D11DepthStencilView * dsv = nullptr; + ID3D11DepthStencilView * dsv_ro = nullptr; + + DXGI_FORMAT tex_format; + DXGI_FORMAT srv_format; + DXGI_FORMAT dsv_format; + switch (format) + { + case DXGI_FORMAT_D32_FLOAT: + tex_format = DXGI_FORMAT_R32_TYPELESS; + srv_format = DXGI_FORMAT_R32_FLOAT; + dsv_format = DXGI_FORMAT_D32_FLOAT; + break; + + case DXGI_FORMAT_D24_UNORM_S8_UINT: + tex_format = DXGI_FORMAT_R24G8_TYPELESS; + srv_format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS; + dsv_format = DXGI_FORMAT_D24_UNORM_S8_UINT; + break; + + case DXGI_FORMAT_D16_UNORM: + tex_format = DXGI_FORMAT_R16_TYPELESS; + srv_format = DXGI_FORMAT_R16_UNORM; + dsv_format = DXGI_FORMAT_D16_UNORM; + break; + + default: + return nullptr; + } + + CD3D11_TEXTURE2D_DESC texDesc; + texDesc.ArraySize = slices; + texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL; + texDesc.CPUAccessFlags = 0; + texDesc.Format = tex_format; + texDesc.Width = width; + texDesc.Height = height; + texDesc.MipLevels = 1; + texDesc.MiscFlags = 0; + if (samples > 1) + { + texDesc.SampleDesc.Count = samples; + texDesc.SampleDesc.Quality = 0;//static_cast<UINT>(D3D11_STANDARD_MULTISAMPLE_PATTERN); + } + else + { + texDesc.SampleDesc.Count = 1; + texDesc.SampleDesc.Quality = 0; + } + texDesc.Usage = D3D11_USAGE_DEFAULT; + device->CreateTexture2D(&texDesc, nullptr, &tex); + if (tex == nullptr) + { + return nullptr; + } + + CD3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + srvDesc.Format = srv_format; + if (slices == 1) + { + if (samples > 1) + { + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS; + } + else + { + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MostDetailedMip = 0; + srvDesc.Texture2D.MipLevels = 1; + } + } + else + { + if (samples > 1) + { + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY; + srvDesc.Texture2DMSArray.FirstArraySlice = 0; + srvDesc.Texture2DMSArray.ArraySize = slices; + } + else + { + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; + srvDesc.Texture2DArray.MostDetailedMip = 0; + srvDesc.Texture2DArray.MipLevels = 1; + srvDesc.Texture2DArray.FirstArraySlice = 0; + srvDesc.Texture2DArray.ArraySize = slices; + } + } + device->CreateShaderResourceView(tex, &srvDesc, &srv); + + if (srv == nullptr) + { + tex->Release(); + return nullptr; + } + + CD3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; + dsvDesc.Flags = 0; + dsvDesc.Format = dsv_format; + if (slices == 1) + { + if (samples > 1) + { + dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; + } + else + { + dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; + dsvDesc.Texture2D.MipSlice = 0; + } + } + else + { + if (samples > 1) + { + dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY; + dsvDesc.Texture2DMSArray.FirstArraySlice = 0; + dsvDesc.Texture2DMSArray.ArraySize = slices; + } + else + { + dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; + dsvDesc.Texture2DArray.MipSlice = 0; + dsvDesc.Texture2DArray.FirstArraySlice = 0; + dsvDesc.Texture2DArray.ArraySize = slices; + } + } + + device->CreateDepthStencilView(tex, &dsvDesc, &dsv); + dsvDesc.Flags |= D3D11_DSV_READ_ONLY_DEPTH; + if (dsv_format == DXGI_FORMAT_D24_UNORM_S8_UINT) + dsvDesc.Flags |= D3D11_DSV_READ_ONLY_STENCIL; + device->CreateDepthStencilView(tex, &dsvDesc, &dsv_ro); + if (dsv == nullptr || dsv_ro == nullptr) + { + tex->Release(); + srv->Release(); + return nullptr; + } + +#if (NV_DEBUG || NV_PROFILE) + if (debug_name) + { + tex->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)strlen(debug_name), debug_name); + } +#else + debug_name; +#endif + + return new DepthTarget(tex, srv, dsv, dsv_ro, nullptr); +} + +DepthTarget::DepthTarget(ID3D11Resource * resource, ID3D11ShaderResourceView * srv, ID3D11DepthStencilView * dsv, ID3D11DepthStencilView * readonly_dsv, ID3D11UnorderedAccessView * uav) + : ShaderResource(resource, srv, uav) +{ + dsv_ = dsv; + readonly_dsv_ = readonly_dsv; +} + +DepthTarget::~DepthTarget() +{ + SAFE_RELEASE(dsv_); + SAFE_RELEASE(readonly_dsv_); +} + diff --git a/src/d3d11/d3d11_util.h b/src/d3d11/d3d11_util.h new file mode 100644 index 0000000..e9322cf --- /dev/null +++ b/src/d3d11/d3d11_util.h @@ -0,0 +1,234 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#ifndef D3D11_UTIL_H +#define D3D11_UTIL_H +//////////////////////////////////////////////////////////////////////////////// +#include "common.h" + +#include <d3d11.h> +#include <d3d11_1.h> + +#pragma warning( disable: 4127 ) + +//////////////////////////////////////////////////////////////////////////////// +/*============================================================================== + Overloaded functions to make shader compilation simpler +==============================================================================*/ +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11VertexShader ** out_shader); +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11HullShader ** out_shader); +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11DomainShader ** out_shader); +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11GeometryShader ** out_shader); +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11PixelShader ** out_shader); +HRESULT CompileShader(ID3D11Device * device, const void * data, UINT length, ID3D11ComputeShader ** out_shader); + + +template <class T> +NV_FORCE_INLINE HRESULT LoadShaders(ID3D11Device * device, const void ** shader_codes, const uint32_t * shader_lengths, UINT count, T ** &out_shaders) +{ + HRESULT hr = S_OK; + out_shaders = new T*[count]; + for (UINT i = 0; i < count; ++i) + { + const void * code = shader_codes[i]; + uint32_t length = shader_lengths[i]; + if (code == nullptr) + { + out_shaders[i] = nullptr; + continue; + } + hr = CompileShader(device, code, length, &out_shaders[i]); + ASSERT_LOG(hr == S_OK, "Failure loading shader"); + if (FAILED(hr)) + break; + } + return hr; +} + +/*============================================================================== + Perf Events +==============================================================================*/ + +class ScopedPerfEvent +{ +public: + ScopedPerfEvent(ID3D11DeviceContext * ctx, const wchar_t * msg) + { + ctx->QueryInterface(IID_ID3DUserDefinedAnnotation, reinterpret_cast<void **>(&pPerf)); + if (pPerf) + { + pPerf->BeginEvent(msg); + } + } + + ~ScopedPerfEvent() + { + if (pPerf) + { + pPerf->EndEvent(); + SAFE_RELEASE(pPerf); + } + }; + +private: + ScopedPerfEvent() : pPerf(nullptr) {}; + ID3DUserDefinedAnnotation * pPerf; +}; + +#if (NV_PROFILE) +# define NV_PERFEVENT(c, t) ScopedPerfEvent perfevent_##__COUNTER__##(c, L##t) +# define NV_PERFEVENT_BEGIN(c, t) { \ + ID3DUserDefinedAnnotation * pPerf_##__COUNTER__ ; \ + c->QueryInterface(IID_ID3DUserDefinedAnnotation, reinterpret_cast<void **>(&pPerf_##__COUNTER__##)); \ + if (pPerf_##__COUNTER__##) { pPerf_##__COUNTER__##->BeginEvent(L##t); pPerf_##__COUNTER__##->Release(); } } +# define NV_PERFEVENT_END(c) { \ + ID3DUserDefinedAnnotation * pPerf_##__COUNTER__ ; \ + c->QueryInterface(IID_ID3DUserDefinedAnnotation, reinterpret_cast<void **>(&pPerf_##__COUNTER__##)); \ + if (pPerf_##__COUNTER__##) { pPerf_##__COUNTER__##->EndEvent(); pPerf_##__COUNTER__##->Release(); } } +#else +# define NV_PERFEVENT(c, t) +# define NV_PERFEVENT_BEGIN(c, t) +# define NV_PERFEVENT_END(c) +#endif + +/*============================================================================== + Constant buffer management +==============================================================================*/ + +template <class T> +class ConstantBuffer +{ +public: + static ConstantBuffer<T> * Create(ID3D11Device * device) + { + HRESULT hr; + ID3D11Buffer * cb = nullptr; + + static_assert((sizeof(T) % 16) == 0, "Constant buffer size must be 16-byte aligned"); + + CD3D11_BUFFER_DESC cbDesc; + cbDesc.ByteWidth = sizeof(T); + cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + cbDesc.Usage = D3D11_USAGE_DYNAMIC; + cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + cbDesc.MiscFlags = 0; + cbDesc.StructureByteStride = 1; + hr = device->CreateBuffer(&cbDesc, nullptr, &cb); + if (cb == nullptr) + return nullptr; + return new ConstantBuffer<T>(cb); + } + + ConstantBuffer(ID3D11Buffer * b) + { + buffer_ = b; + } + + ~ConstantBuffer() + { + SAFE_RELEASE(buffer_); + } + + T * Map(ID3D11DeviceContext * ctx) + { + HRESULT hr; + D3D11_MAPPED_SUBRESOURCE data; + hr = ctx->Map(buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &data); + return static_cast<T*>(data.pData); + } + + void Unmap(ID3D11DeviceContext * ctx) + { + ctx->Unmap(buffer_, 0); + } + + ID3D11Buffer * getCB() { return buffer_; } + +private: + ConstantBuffer() {}; + + ID3D11Buffer *buffer_; +}; + +/*============================================================================== + Texture resource management helpers +==============================================================================*/ + +//------------------------------------------------------------------------------ +class ShaderResource +{ +public: + ShaderResource(ID3D11Resource * resource, ID3D11ShaderResourceView * srv, ID3D11UnorderedAccessView * uav); + ~ShaderResource(); + + ID3D11Resource * getResource() { return resource_; } + ID3D11ShaderResourceView * getSRV() { return srv_; } + ID3D11UnorderedAccessView * getUAV() { return uav_; } + +protected: + ShaderResource() {}; + + ID3D11Resource * resource_; + ID3D11ShaderResourceView * srv_; + ID3D11UnorderedAccessView * uav_; +}; + +//------------------------------------------------------------------------------ +class RenderTarget : public ShaderResource +{ +public: + static RenderTarget * Create(ID3D11Device * device, UINT width, UINT height, UINT samples, DXGI_FORMAT format, const char * debug_name=nullptr); + RenderTarget(ID3D11Resource * resource, ID3D11ShaderResourceView * srv, ID3D11RenderTargetView * rtv, ID3D11UnorderedAccessView * uav); + ~RenderTarget(); + + ID3D11RenderTargetView * getRTV() { return rtv_; } + +protected: + RenderTarget() {}; + ID3D11RenderTargetView * rtv_; +}; + +//------------------------------------------------------------------------------ +class DepthTarget : public ShaderResource +{ +public: + static DepthTarget * Create(ID3D11Device * device, UINT width, UINT height, UINT samples, DXGI_FORMAT format, uint32_t slices=1, char * debug_name=nullptr); + DepthTarget(ID3D11Resource * resource, ID3D11ShaderResourceView * srv, ID3D11DepthStencilView * dsv, ID3D11DepthStencilView * readonly_dsv, ID3D11UnorderedAccessView * uav); + ~DepthTarget(); + + ID3D11DepthStencilView * getDSV() { return dsv_; } + ID3D11DepthStencilView * getReadOnlyDSV() { return readonly_dsv_; } + +protected: + DepthTarget() {}; + ID3D11DepthStencilView * dsv_; + ID3D11DepthStencilView * readonly_dsv_; +}; + +//////////////////////////////////////////////////////////////////////////////// +#endif // D3D11_UTIL_H
\ No newline at end of file diff --git a/src/shaders/Apply_PS.hlsl b/src/shaders/Apply_PS.hlsl new file mode 100644 index 0000000..0e19e46 --- /dev/null +++ b/src/shaders/Apply_PS.hlsl @@ -0,0 +1,176 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +- SAMPLEMODE: + - SAMPLEMODE_SINGLE + - SAMPLEMODE_MSAA + +- UPSAMPLEMODE: + - UPSAMPLEMODE_POINT + - UPSAMPLEMODE_BILINEAR + - UPSAMPLEMODE_BILATERAL + +- FOGMODE: + - FOGMODE_NONE + - FOGMODE_NOSKY + - FOGMODE_FULL + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +Texture2D<float4> tGodraysBuffer : register(t0); +#if (SAMPLEMODE == SAMPLEMODE_MSAA) + Texture2DMS<float> tSceneDepth : register(t1); +#elif (SAMPLEMODE == SAMPLEMODE_SINGLE) + Texture2D<float> tSceneDepth : register(t1); +#endif +Texture2D<float2> tGodraysDepth : register(t2); +Texture2D<float4> tPhaseLUT : register(t4); + +struct PS_APPLY_OUTPUT +{ + float4 inscatter : SV_TARGET0; + float4 transmission : SV_TARGET1; +}; + +float3 Tonemap(float3 s) +{ + return s / (float3(1,1,1) + s); +} + +float3 Tonemap_Inv(float3 s) +{ + return s / (float3(1,1,1) - s); +} + + +float CalcVariance(float x, float x_sqr) +{ + return abs(x_sqr - x*x); +} + +PS_APPLY_OUTPUT main(VS_QUAD_OUTPUT input +#if (SAMPLEMODE == SAMPLEMODE_MSAA) + , uint sampleID : SV_SAMPLEINDEX +#endif + ) +{ + PS_APPLY_OUTPUT output; + output.transmission = float4(1,1,1,1); + output.inscatter = float4(0,0,0,1); + + float2 texcoord = input.vTex * g_vViewportSize * g_vBufferSize_Inv; + +#if (SAMPLEMODE == SAMPLEMODE_MSAA) + float scene_depth = tSceneDepth.Load(int2(input.vTex*g_vOutputViewportSize), sampleID).x; +#elif (SAMPLEMODE == SAMPLEMODE_SINGLE) + float scene_depth = tSceneDepth.SampleLevel(sPoint, input.vTex * g_vViewportSize * g_vBufferSize_Inv, 0).x; +#endif + scene_depth = LinearizeDepth(scene_depth, g_fZNear, g_fZFar); + + + + // Quality of the upsampling interpolator + // 0: Point (no up-sample) + // 1: Bilinear + // 2: Bilateral + float3 inscatter_sample = float3(0,0,0); + if (UPSAMPLEMODE == UPSAMPLEMODE_POINT) + { + inscatter_sample = tGodraysBuffer.SampleLevel( sPoint, texcoord, 0).rgb; + } + else if (UPSAMPLEMODE == UPSAMPLEMODE_BILINEAR) + { + inscatter_sample = tGodraysBuffer.SampleLevel( sBilinear, texcoord, 0).rgb; + } + else if (UPSAMPLEMODE == UPSAMPLEMODE_BILATERAL) + { + const float2 NEIGHBOR_OFFSETS[] = { + float2(-1, -1), float2( 0, -1), float2( 1, -1), + float2(-1, 0), float2( 0, 0), float2( 1, 0), + float2(-1, 1), float2( 0, 1), float2( 1, 1) + }; + const float GAUSSIAN_WIDTH = 1.0f; + + float2 max_dimensions = floor(g_vViewportSize); + float2 base_tc = input.vTex * max_dimensions; + + float total_weight = 0; + [unroll] + for (int n=0; n<9; ++n) + { + float2 sample_tc = max( float2(0,0), min(max_dimensions, base_tc + NEIGHBOR_OFFSETS[n])); + + float weight = 0.0f; + float2 sample_location = floor(sample_tc) + float2(0.5f, 0.5f); + weight = GaussianApprox(sample_location - base_tc, GAUSSIAN_WIDTH); + + const float DEPTH_RANGE = 0.10f; + + float2 neighbor_depth = tGodraysDepth.Load(int3(sample_location.xy, 0)).rg; + float depth_diff = abs(scene_depth - neighbor_depth.r); + float neighbor_variance = CalcVariance(neighbor_depth.r, neighbor_depth.g); + float neighbor_stddev = sqrt(neighbor_variance); + float depth_weight = saturate(1 - depth_diff / DEPTH_RANGE); + depth_weight = depth_weight*depth_weight*(1-neighbor_stddev); + weight *= depth_weight; + + inscatter_sample += weight * Tonemap(tGodraysBuffer.Load(int3(sample_location.xy, 0)).rgb); + total_weight += weight; + } + + if (total_weight > 0.0f) + { + inscatter_sample = Tonemap_Inv(inscatter_sample / total_weight); + } + else + { + inscatter_sample = tGodraysBuffer.SampleLevel(sBilinear, texcoord, 0).rgb; + } + } + + output.inscatter.rgb = inscatter_sample.rgb; + if (FOGMODE != FOGMODE_NONE) + { + if ((FOGMODE != FOGMODE_NOSKY) || (scene_depth < 1.f)) + { + float scene_distance = g_fZFar * scene_depth; + float3 sigma_ext = g_vSigmaExtinction; + output.inscatter.rgb += g_fMultiScattering * g_vFogLight * g_vScatterPower * (1-exp(-sigma_ext*scene_distance)) / sigma_ext; + output.transmission.rgb = exp(-sigma_ext*scene_distance); + } + } + + return output; +}
\ No newline at end of file diff --git a/src/shaders/ComputeLightLUT_CS.hlsl b/src/shaders/ComputeLightLUT_CS.hlsl new file mode 100644 index 0000000..fca70dd --- /dev/null +++ b/src/shaders/ComputeLightLUT_CS.hlsl @@ -0,0 +1,192 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +- LIGHTMODE: + - LIGHTMODE_OMNI + - LIGHTMODE_SPOTLIGHT + +- ATTENUATIONMODE: + - ATTENUATIONMODE_NONE + - ATTENUATIONMODE_POLYNOMIAL + - ATTENUATIONMODE_INV_POLYNOMIAL + +- COMPUTEPASS: + - COMPUTEPASS_CALCULATE + - COMPUTEPASS_SUM + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +float4 PackLut(float3 v, float s) +{ + return float4(v/s, s); +} + +float3 UnpackLut(float4 v) +{ + return v.rgb*v.a; +} + +Texture2D<float4> tPhaseLUT : register(t4); +RWTexture2D<float4> rwLightLUT_P : register(u0); +RWTexture2D<float4> rwLightLUT_S1 : register(u1); +RWTexture2D<float4> rwLightLUT_S2 : register(u2); + +// These need to match the values in context_common.h +static const uint LIGHT_LUT_DEPTH_RESOLUTION = 128; +static const uint LIGHT_LUT_WDOTV_RESOLUTION = 512; + +#if (COMPUTEPASS == COMPUTEPASS_CALCULATE) + +static const uint2 BLOCK_SIZE = uint2(32, 8); +groupshared float3 sAccum_P[BLOCK_SIZE.x*BLOCK_SIZE.y]; + +#if (LIGHTMODE == LIGHTMODE_SPOTLIGHT) +groupshared float3 sAccum_S1[BLOCK_SIZE.x*BLOCK_SIZE.y]; +groupshared float3 sAccum_S2[BLOCK_SIZE.x*BLOCK_SIZE.y]; +#endif + +[numthreads( BLOCK_SIZE.x, BLOCK_SIZE.y, 1 )] +void main(uint3 gthreadID : SV_GroupThreadID, uint2 dispatchID : SV_DispatchThreadID, uint2 groupID : SV_GroupID) +{ + uint idx = gthreadID.y*BLOCK_SIZE.x + gthreadID.x; + float2 coord = float2(dispatchID) / float2(LIGHT_LUT_DEPTH_RESOLUTION-1, LIGHT_LUT_WDOTV_RESOLUTION-1); + + float angle = coord.y * PI; + float cos_WV = -cos(angle); + + float3 vW = g_vEyePosition - g_vLightPos; + float Wsqr = dot(vW, vW); + float W_length = sqrt(Wsqr); + float t0 = max(0.0f, W_length-g_fLightZFar); + float t_range = g_fLightZFar + W_length - t0; + float t = t0 + coord.x*t_range; + + float WdotV = cos_WV*W_length; + float Dsqr = max(Wsqr+2*WdotV*t+t*t, 0.0f); + float D = sqrt(Dsqr); + float cos_phi = (t>0 && D>0) ? (t*t + Dsqr - Wsqr) / (2 * t*D) : cos_WV; + float3 extinction = exp(-g_vSigmaExtinction*(D+t)); + float3 phase_factor = GetPhaseFactor(tPhaseLUT, -cos_phi); + float attenuation = AttenuationFunc(D); + float3 inscatter = phase_factor*attenuation*extinction; + + // Scale by dT because we are doing quadrature + inscatter *= t_range / float(LIGHT_LUT_DEPTH_RESOLUTION); + + inscatter = inscatter / g_vScatterPower; + sAccum_P[idx] = inscatter; +#if (LIGHTMODE == LIGHTMODE_SPOTLIGHT) + sAccum_S1[idx] = (D==0) ? 0.0f : inscatter/D; + sAccum_S2[idx] = t*sAccum_S1[idx]; +#endif + + + [unroll] + for (uint d=1; d<32; d = d<<1) + { + if (gthreadID.x >= d) + { + sAccum_P[idx] += sAccum_P[idx - d]; +#if (LIGHTMODE == LIGHTMODE_SPOTLIGHT) + sAccum_S1[idx] += sAccum_S1[idx - d]; + sAccum_S2[idx] += sAccum_S2[idx - d]; +#endif + } + } + + static const float LUT_SCALE = 32.0f / 32768.0f; + rwLightLUT_P[dispatchID] = PackLut(sAccum_P[idx], LUT_SCALE); +#if (LIGHTMODE == LIGHTMODE_SPOTLIGHT) + float max_t = 2*(t0 + t_range); + rwLightLUT_S1[dispatchID] = PackLut(sAccum_S1[idx], LUT_SCALE); + rwLightLUT_S2[dispatchID] = PackLut(sAccum_S2[idx], LUT_SCALE*max_t); +#endif +} + +#elif (COMPUTEPASS == COMPUTEPASS_SUM) + +static const uint2 BLOCK_SIZE = uint2(32, 4); + +Texture2D<float4> tLightLUT_P : register(t5); +Texture2D<float4> tLightLUT_S1 : register(t6); +Texture2D<float4> tLightLUT_S2 : register(t7); + +groupshared float3 sOffset[BLOCK_SIZE.y]; + +[numthreads( BLOCK_SIZE.x, BLOCK_SIZE.y, 1 )] +void main(uint3 gthreadID : SV_GroupThreadID, uint3 dispatchID : SV_DispatchThreadID, uint2 groupID : SV_GroupID) +{ + uint t_offset = 0; + + if (gthreadID.x == 0) + { + sOffset[gthreadID.y] = float3(0, 0, 0); + } + + [unroll] + for (uint t = 0; t < LIGHT_LUT_DEPTH_RESOLUTION; t += BLOCK_SIZE.x) + { + uint2 tc = dispatchID.xy + uint2(t, 0); + float4 s = float4(0,0,0,0); +#if (LIGHTMODE == LIGHTMODE_SPOTLIGHT) + if (dispatchID.z == 2) + s = tLightLUT_S2[tc]; + else if (dispatchID.z == 1) + s = tLightLUT_S1[tc]; + else + s = tLightLUT_P[tc]; +#else + s = tLightLUT_P[tc]; +#endif + float3 v = UnpackLut(s) + sOffset[gthreadID.y]; + if (gthreadID.x == (BLOCK_SIZE.x-1)) + { + sOffset[gthreadID.y] = v; + } + s.a *= LIGHT_LUT_DEPTH_RESOLUTION/32; +#if (LIGHTMODE == LIGHTMODE_SPOTLIGHT) + if (dispatchID.z == 2) + rwLightLUT_S2[tc] = PackLut(v, s.a); + else if (dispatchID.z == 1) + rwLightLUT_S1[tc] = PackLut(v, s.a); + else + rwLightLUT_P[tc] = PackLut(v, s.a); +#else + rwLightLUT_P[tc] = PackLut(v, s.a); +#endif + } +} + +#endif
\ No newline at end of file diff --git a/src/shaders/ComputePhaseLookup_PS.hlsl b/src/shaders/ComputePhaseLookup_PS.hlsl new file mode 100644 index 0000000..7487c40 --- /dev/null +++ b/src/shaders/ComputePhaseLookup_PS.hlsl @@ -0,0 +1,150 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +// using the phase functions directly isn't correct, because they are supposed to be +// integrated over the subtended solid angle. This falls apart as sin(theta) +// approaches 0 (ie. cos(theta) aproaches +1 or -1). +// We apply a sliding scale to the functions to compensate for this somewhat. + +#define NORMALIZE_PHASE_FUNCTIONS 1 + +float ScatterPhase_Isotropic() +{ + return 1.f / (4.f * PI); +} + +float ScatterPhase_Rayleigh(float cosa) +{ + float cos_term = cosa*cosa; // ^2 + float phase_term = (3.f/(16.f*PI)) * (1.f + cos_term); +#if NORMALIZE_PHASE_FUNCTIONS + cos_term *= cos_term; // ^4 + return phase_term*(1-cos_term/8.f); +#else + return phase_term; +#endif +} + +float ScatterPhase_HenyeyGreenstein(float cosa, float g) +{ +#if NORMALIZE_PHASE_FUNCTIONS + // "normalized" Henyey-Greenstein + float g_sqr = g*g; + float num = (1 - abs(g)); + float denom = sqrt( max(1-2*g*cosa+g_sqr, 0) ); + float frac = num/denom; + float scale = g_sqr + (1 - g_sqr) / (4*PI); + return scale * (frac*frac*frac); +#else + // Classic Henyey-Greenstein + float k1 = (1.f-g*g); + float k2 = (1.f + g*g - 2.f*g*cosa); + return (1.f / (4.f*PI)) * k1 / pow(abs(k2), 1.5f); +#endif +} + +float ScatterPhase_MieHazy(float cosa) +{ + float cos_term = 0.5f*(1+cosa); + float cos_term_2 = cos_term*cos_term; // ^2 + float cos_term_4 = cos_term_2*cos_term_2; // ^4 + float cos_term_8 = cos_term_4*cos_term_4; // ^8 + float phase_term = (1.f/(4.f*PI))*(0.5f+(9.f/2.f)*cos_term_8); +#if NORMALIZE_PHASE_FUNCTIONS + return phase_term * (1-cos_term_8/2.0f); +#else + return phase_term; +#endif +} + +float ScatterPhase_MieMurky(float cosa) +{ + float cos_term = 0.5f*(1+cosa); + float cos_term_2 = cos_term*cos_term; // ^2 + float cos_term_4 = cos_term_2*cos_term_2; // ^4 + float cos_term_8 = cos_term_4*cos_term_4; // ^8 + float cos_term_16 = cos_term_8*cos_term_8; // ^16 + float cos_term_32 = cos_term_16*cos_term_16; // ^32 + float phase_term = (1.f/(4.f*PI))*(0.5f+(33.f/2.f)*cos_term_32); +#if NORMALIZE_PHASE_FUNCTIONS + return phase_term * (1-cos_term_32/2.0f); +#else + return phase_term; +#endif +} + +float4 main(VS_QUAD_OUTPUT input) : SV_TARGET +{ + float cos_theta = -cos(PI*input.vTex.y); + float3 phase_factor = float3(0,0,0); + float3 total_scatter = float3(0,0,0); + + // These must match the PhaseFunctionType enum in NvVolumetricLighting.h + static const uint PHASEFUNC_ISOTROPIC = 0; + static const uint PHASEFUNC_RAYLEIGH = 1; + static const uint PHASEFUNC_HG = 2; + static const uint PHASEFUNC_MIEHAZY = 3; + static const uint PHASEFUNC_MIEMURKY = 4; + + for (uint i=0; i<g_uNumPhaseTerms; ++i) + { + float3 term_scatter = g_vPhaseParams[i].rgb; + total_scatter += term_scatter; + if (g_uPhaseFunc[i] == PHASEFUNC_ISOTROPIC) + { + phase_factor += term_scatter*ScatterPhase_Isotropic(); + } + else if (g_uPhaseFunc[i] == PHASEFUNC_RAYLEIGH) + { + phase_factor += term_scatter*ScatterPhase_Rayleigh(cos_theta); + } + else if (g_uPhaseFunc[i] == PHASEFUNC_HG) + { + phase_factor += term_scatter*ScatterPhase_HenyeyGreenstein(cos_theta, g_vPhaseParams[i].a); + } + else if (g_uPhaseFunc[i] == PHASEFUNC_MIEHAZY) + { + phase_factor += term_scatter*ScatterPhase_MieHazy(cos_theta); + } + else if (g_uPhaseFunc[i] == PHASEFUNC_MIEMURKY) + { + phase_factor += term_scatter*ScatterPhase_MieMurky(cos_theta); + } + } + phase_factor = phase_factor / total_scatter; + return float4(phase_factor, 1); +} diff --git a/src/shaders/Debug_PS.hlsl b/src/shaders/Debug_PS.hlsl new file mode 100644 index 0000000..a2cd9cf --- /dev/null +++ b/src/shaders/Debug_PS.hlsl @@ -0,0 +1,42 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +float4 main(PS_POLYGONAL_INPUT input, bool bIsFrontFace : SV_ISFRONTFACE) : SV_TARGET +{ + return bIsFrontFace ? float4(1,0,0,1) : float4(0,1,0,1); +} +
\ No newline at end of file diff --git a/src/shaders/DownsampleDepth_PS.hlsl b/src/shaders/DownsampleDepth_PS.hlsl new file mode 100644 index 0000000..4f4efdd --- /dev/null +++ b/src/shaders/DownsampleDepth_PS.hlsl @@ -0,0 +1,82 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +- SAMPLEMODE: + - SAMPLEMODE_SINGLE + - SAMPLEMODE_MSAA + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +#if (SAMPLEMODE == SAMPLEMODE_SINGLE) +Texture2D<float> tDepthMap : register(t0); +#elif (SAMPLEMODE == SAMPLEMODE_MSAA) +Texture2DMS<float> tDepthMap : register(t0); +#endif + +uint Unused(uint input) +{ + return input; +} + +float main( + VS_QUAD_OUTPUT input + , uint sampleID : SV_SAMPLEINDEX + ) : SV_DEPTH +{ + float2 jitter = float2(0.0f, 0.0f); + uint2 pixelIdx = uint2(input.vPos.xy); + if ( (pixelIdx.x+pixelIdx.y)%2 ) + { + jitter.xy = g_vJitterOffset.xy; + } + else + { + jitter.xy = g_vJitterOffset.yx; + } + +#if defined(__PSSL__) + Unused(sampleID);//Fix a compiler warning with pssl. + float2 tc = (floor(input.vTex.xy*g_vOutputViewportSize) + GetViVjLinearSample() + jitter)*g_vOutputSize_Inv; +#else + float2 tc = (EvaluateAttributeAtSample(input.vTex.xy, sampleID)*g_vOutputViewportSize + jitter)*g_vOutputSize_Inv; +#endif + +#if (SAMPLEMODE == SAMPLEMODE_SINGLE) + return tDepthMap.SampleLevel(sPoint, tc, 0).x; +#elif (SAMPLEMODE == SAMPLEMODE_MSAA) + int2 load_tc = int2(tc*g_vOutputSize); + return tDepthMap.Load(load_tc, 0).x; +#endif +} diff --git a/src/shaders/Quad_VS.hlsl b/src/shaders/Quad_VS.hlsl new file mode 100644 index 0000000..bbb0ae2 --- /dev/null +++ b/src/shaders/Quad_VS.hlsl @@ -0,0 +1,46 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +VS_QUAD_OUTPUT main(uint id : SV_VERTEXID) +{ + VS_QUAD_OUTPUT output; + output.vTex = float2((id << 1) & 2, id & 2); + output.vPos = float4(output.vTex * float2(2,-2) + float2(-1,1), 1, 1); + output.vWorldPos = mul( g_mViewProjInv, output.vPos ); + output.vWorldPos *= 1.0f / output.vWorldPos.w; + return output; +} diff --git a/src/shaders/RenderVolume_DS.hlsl b/src/shaders/RenderVolume_DS.hlsl new file mode 100644 index 0000000..880e9ed --- /dev/null +++ b/src/shaders/RenderVolume_DS.hlsl @@ -0,0 +1,181 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +- SHADOWMAPTYPE: + - SHADOWMAPTYPE_ATLAS + - SHADOWMAPTYPE_ARRAY + +- CASCADECOUNT: + - CASCADECOUNT_1: 1 + - CASCADECOUNT_2: 2 + - CASCADECOUNT_3: 3 + - CASCADECOUNT_4: 4 + +- VOLUMETYPE: + - VOLUMETYPE_FRUSTUM + - VOLUMETYPE_PARABOLOID + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +#define COARSE_CASCADE (CASCADECOUNT-1) + +#if (SHADOWMAPTYPE == SHADOWMAPTYPE_ATLAS) +Texture2D<float> tShadowMap : register(t1); +#elif (SHADOWMAPTYPE == SHADOWMAPTYPE_ARRAY) +Texture2DArray<float> tShadowMap : register(t1); +#endif + +float SampleShadowMap(float2 tex_coord, int cascade) +{ + float depth_value = 1.0f; + float2 lookup_coord = g_vElementOffsetAndScale[cascade].zw * tex_coord + g_vElementOffsetAndScale[cascade].xy; +#if (SHADOWMAPTYPE == SHADOWMAPTYPE_ATLAS) + depth_value = tShadowMap.SampleLevel( sBilinear, lookup_coord, 0).x; +#elif (SHADOWMAPTYPE == SHADOWMAPTYPE_ARRAY) + depth_value = tShadowMap.SampleLevel( sBilinear, float3( lookup_coord, (float)g_uElementIndex[cascade] ), 0).x; +#endif + return depth_value; +} + +float3 ParaboloidProject(float3 P, float zNear, float zFar) +{ + float3 outP; + float lenP = length(P.xyz); + outP.xyz = P.xyz/lenP; + outP.x = outP.x / (outP.z + 1); + outP.y = outP.y / (outP.z + 1); + outP.z = (lenP - zNear) / (zFar - zNear); + return outP; +} + +float3 ParaboloidUnproject(float3 P, float zNear, float zFar) +{ + // Use a quadratic to find the Z component + // then reverse the projection to find the unit vector, and scale + float L = P.z*(zFar-zNear) + zNear; + + float qa = P.x*P.x + P.y*P.y + 1; + float qb = 2*(P.x*P.x + P.y*P.y); + float qc = P.x*P.x + P.y*P.y - 1; + float z = (-qb + sqrt(qb*qb - 4*qa*qc)) / (2*qa); + + float3 outP; + outP.x = P.x * (z + 1); + outP.y = P.y * (z + 1); + outP.z = z; + return outP*L; +} + +HS_POLYGONAL_CONSTANT_DATA_OUTPUT Unused(HS_POLYGONAL_CONSTANT_DATA_OUTPUT input) +{ + return input; +} + +[domain("quad")] +PS_POLYGONAL_INPUT main( HS_POLYGONAL_CONSTANT_DATA_OUTPUT input, float2 uv : SV_DOMAINLOCATION, const OutputPatch<HS_POLYGONAL_CONTROL_POINT_OUTPUT, 4> Patch ) +{ + Unused(input);//Fix a compiler warning with pssl. + + PS_POLYGONAL_INPUT output = (PS_POLYGONAL_INPUT)0; + + float3 vClipIn1 = lerp(Patch[0].vClipPos.xyz, Patch[1].vClipPos.xyz, uv.x); + float3 vClipIn2 = lerp(Patch[3].vClipPos.xyz, Patch[2].vClipPos.xyz, uv.x); + float3 vClipIn = lerp(vClipIn1, vClipIn2, uv.y); + + float4 vPos1 = lerp(Patch[0].vWorldPos, Patch[1].vWorldPos, uv.x); + float4 vPos2 = lerp(Patch[3].vWorldPos, Patch[2].vWorldPos, uv.x); + float4 vWorldPos = lerp(vPos1, vPos2, uv.y); + + if (VOLUMETYPE == VOLUMETYPE_FRUSTUM) + { + if (all(abs(vClipIn.xy) < EDGE_FACTOR)) + { + int iCascade = -1; + float4 vClipPos = float4(0,0,0,1); + + [unroll] + for (int i = COARSE_CASCADE;i >= 0; --i) + { + // Try to refetch from finer cascade + float4 vClipPosCascade = mul( g_mLightProj[i], vWorldPos ); + vClipPosCascade *= 1.f / vClipPosCascade.w; + if (all(abs(vClipPosCascade.xy) < 1.0f)) + { + + float2 vTex = float2(0.5*vClipPosCascade.x + 0.5, -0.5*vClipPosCascade.y + 0.5); + float depthSample = SampleShadowMap(vTex, i); + if (depthSample < 1.0f) + { + + vClipPos.xy = vClipPosCascade.xy; + vClipPos.z = depthSample; + iCascade = i; + } + } + } + + if (iCascade >= 0) + { + vWorldPos = mul( g_mLightProjInv[iCascade], float4(vClipPos.xyz, 1) ); + vWorldPos *= 1.0f / vWorldPos.w; + vWorldPos.xyz = g_vEyePosition + (1.0f-g_fGodrayBias)*(vWorldPos.xyz-g_vEyePosition); + } + } + else + { + vWorldPos = mul(g_mLightToWorld, float4(vClipIn.xy, 1, 1)); + vWorldPos *= 1.0f / vWorldPos.w; + } + } + else if (VOLUMETYPE == VOLUMETYPE_PARABOLOID) + { + vClipIn.xyz = normalize(vClipIn.xyz); + float4 shadowPos = mul(g_mLightProj[0], vWorldPos); + shadowPos.xyz = shadowPos.xyz/shadowPos.w; + uint hemisphereID = (shadowPos.z > 0) ? 0 : 1; + shadowPos.z = abs(shadowPos.z); + shadowPos.xyz = ParaboloidProject(shadowPos.xyz, g_fLightZNear, g_fLightZFar); + float2 shadowTC = float2(0.5f, -0.5f)*shadowPos.xy + 0.5f; + float depthSample = SampleShadowMap(shadowTC, hemisphereID); + float sceneDepth = depthSample*(g_fLightZFar-g_fLightZNear)+g_fLightZNear; + vWorldPos = mul( g_mLightProjInv[0], float4(vClipIn.xyz * sceneDepth, 1)); + vWorldPos *= 1.0f / vWorldPos.w; + } + + // Transform world position with viewprojection matrix + output.vWorldPos = vWorldPos; + output.vPos = mul( g_mViewProj, output.vWorldPos ); + return output; +} diff --git a/src/shaders/RenderVolume_HS.hlsl b/src/shaders/RenderVolume_HS.hlsl new file mode 100644 index 0000000..1689e15 --- /dev/null +++ b/src/shaders/RenderVolume_HS.hlsl @@ -0,0 +1,182 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +- SHADOWMAPTYPE: + - SHADOWMAPTYPE_ATLAS + - SHADOWMAPTYPE_ARRAY + +- CASCADECOUNT: + - CASCADECOUNT_1: 1 + - CASCADECOUNT_2: 2 + - CASCADECOUNT_3: 3 + - CASCADECOUNT_4: 4 + +- VOLUMETYPE: + - VOLUMETYPE_FRUSTUM + - VOLUMETYPE_PARABOLOID + +- MAXTESSFACTOR: + - MAXTESSFACTOR_LOW: 16.0f + - MAXTESSFACTOR_MEDIUM: 32.0f + - MAXTESSFACTOR_HIGH: 64.0f +%% MUX_END %% +*/ + +#define COARSE_CASCADE (CASCADECOUNT-1) + +#include "ShaderCommon.h" + +float3 NearestPos(float3 vStartPos, float3 vEndPos) +{ + float3 vPos = (g_vEyePosition - vStartPos); + float3 vLine = (vEndPos - vStartPos); + float lineLength = length(vLine); + float t = max(0, min(lineLength, dot(vPos, vLine)/lineLength)); + return vStartPos + (t/lineLength)*vLine; +} + +float CalcTessFactor(float3 vStartPos, float3 vEndPos) +{ + float section_size = length(vEndPos - vStartPos); + float3 vWorldPos = 0.5f*(vStartPos+vEndPos); + float3 vEyeVec = (vWorldPos.xyz - g_vEyePosition); + float4 clip_pos = mul( g_mProj, float4(0, 0, length(vEyeVec), 1) ); + float projected_size = abs(section_size * g_mProj._m11 / clip_pos.w); + float desired_splits = (projected_size*g_vOutputViewportSize.y)/(g_fTargetRaySize); + return min(MAXTESSFACTOR, max(1, desired_splits)); +} + +bool IntersectsFrustum(float4 vPos1, float4 vPos2) +{ + return !(vPos1.x > 1.0 && vPos2.x > 1.0 || vPos1.x < -1.0 && vPos2.x < -1.0) + || !(vPos1.y > 1.0 && vPos2.y > 1.0 || vPos1.y < -1.0 && vPos2.y < -1.0) + || !(vPos1.z < 0.0 && vPos2.z < 0.0); +} + +HS_POLYGONAL_CONSTANT_DATA_OUTPUT HS_POLYGONAL_CONSTANT_FUNC( /*uint PatchID : SV_PRIMITIVEID,*/ const OutputPatch<HS_POLYGONAL_CONTROL_POINT_OUTPUT, 4> opPatch) +{ + HS_POLYGONAL_CONSTANT_DATA_OUTPUT output = (HS_POLYGONAL_CONSTANT_DATA_OUTPUT)0; + + bool bIsVisible = false; +#if 1 + //Frustum cull + [unroll] + for (int j=0; j<4; ++j) + { + float4 vScreenClip = mul(g_mViewProj, opPatch[j].vWorldPos); + vScreenClip *= 1.0f / vScreenClip.w; + float4 vOriginPos = float4(0,0,0,1); + if (VOLUMETYPE == VOLUMETYPE_FRUSTUM) + { + vOriginPos = mul(g_mLightToWorld, float4(opPatch[j].vClipPos.xy, 0, 1)); + } + else if (VOLUMETYPE == VOLUMETYPE_PARABOLOID) + { + vOriginPos = float4(g_vLightPos, 1); + } + float4 vScreenClipOrigin = mul(g_mViewProj, vOriginPos); + vScreenClipOrigin *= 1.0f / vScreenClipOrigin.w; + bIsVisible = bIsVisible || IntersectsFrustum(vScreenClip, vScreenClipOrigin); + } +#else + bIsVisible = true; +#endif + + if (bIsVisible) + { + float3 nearest_pos[4]; + for (int j=0; j < 4; ++j) + { + float3 start_pos; + if (VOLUMETYPE == VOLUMETYPE_FRUSTUM) + { + float4 p = mul(g_mLightToWorld, float4(opPatch[j].vClipPos.xy, 0, 1)); + start_pos = p.xyz / p.w; + } + else if (VOLUMETYPE == VOLUMETYPE_PARABOLOID) + start_pos = g_vLightPos; + else + start_pos = float3(0, 0, 0); + nearest_pos[j] = NearestPos(start_pos, opPatch[j].vWorldPos.xyz); + } + + float tess_factor[4]; + [unroll] + for (int k=0; k<4; ++k) + { + float tess_near = CalcTessFactor(nearest_pos[(k+3)%4], nearest_pos[k]); + float tess_far = CalcTessFactor(opPatch[(k+3)%4].vWorldPos.xyz, opPatch[k].vWorldPos.xyz); + tess_factor[k] = max(tess_near, tess_far); + if (VOLUMETYPE == VOLUMETYPE_FRUSTUM) + { + bool bIsEdge = !(all((abs(opPatch[(k + 3) % 4].vClipPos.xy) < EDGE_FACTOR) || (abs(opPatch[k].vClipPos.xy) < EDGE_FACTOR))); + output.fEdges[k] = (bIsEdge) ? 1.0f : tess_factor[k]; + } + else if (VOLUMETYPE == VOLUMETYPE_PARABOLOID) + { + output.fEdges[k] = tess_factor[k]; + } + else + { + output.fEdges[k] = 1; + } + + } + output.fInside[0] = max(tess_factor[1], tess_factor[3]); + output.fInside[1] = max(tess_factor[0], tess_factor[2]); + } + else + { + output.fEdges[0] = 0; + output.fEdges[1] = 0; + output.fEdges[2] = 0; + output.fEdges[3] = 0; + output.fInside[0] = 0; + output.fInside[1] = 0; + } + + return output; +} + +[domain("quad")] +[partitioning("integer")] +[outputtopology("triangle_ccw")] +[outputcontrolpoints(4)] +[patchconstantfunc("HS_POLYGONAL_CONSTANT_FUNC")] +[maxtessfactor(MAXTESSFACTOR)] +HS_POLYGONAL_CONTROL_POINT_OUTPUT main( InputPatch<HS_POLYGONAL_INPUT, 4> ipPatch, uint uCPID : SV_OUTPUTCONTROLPOINTID ) +{ + HS_POLYGONAL_CONTROL_POINT_OUTPUT output = (HS_POLYGONAL_CONTROL_POINT_OUTPUT)0; + output.vWorldPos = ipPatch[uCPID].vWorldPos; + output.vClipPos = ipPatch[uCPID].vClipPos; + return output; +} diff --git a/src/shaders/RenderVolume_PS.hlsl b/src/shaders/RenderVolume_PS.hlsl new file mode 100644 index 0000000..f2724c2 --- /dev/null +++ b/src/shaders/RenderVolume_PS.hlsl @@ -0,0 +1,403 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +%% MUX_BEGIN %% +# Define the shader permutations for code generation + +# Are we operating on single sample or MSAA buffer +- SAMPLEMODE: + - SAMPLEMODE_SINGLE + - SAMPLEMODE_MSAA + +# What type of light are we rendering +- LIGHTMODE: + - LIGHTMODE_DIRECTIONAL + - LIGHTMODE_SPOTLIGHT + - LIGHTMODE_OMNI + +# What sort of pass are we rendering +- PASSMODE: + - PASSMODE_GEOMETRY + - PASSMODE_SKY + - PASSMODE_FINAL + +# What is our distance attenuation function +- ATTENUATIONMODE: + - ATTENUATIONMODE_NONE + - ATTENUATIONMODE_POLYNOMIAL + - ATTENUATIONMODE_INV_POLYNOMIAL + +# What is our spotlight angular falloff mode +- FALLOFFMODE: + - FALLOFFMODE_NONE + - FALLOFFMODE_FIXED + - FALLOFFMODE_CUSTOM + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +#if (PASSMODE == PASSMODE_FINAL) +# if (SAMPLEMODE == SAMPLEMODE_SINGLE) + + Texture2D<float> tSceneDepth : register(t2); + float LoadSceneDepth(uint2 pos, uint s) + { + return tSceneDepth.Load(int3(pos.xy, 0)).x; + } + +# elif (SAMPLEMODE == SAMPLEMODE_MSAA) + + Texture2DMS<float> tSceneDepth : register(t2); + float LoadSceneDepth(uint2 pos, uint s) + { + return tSceneDepth.Load(int2(pos.xy), s).x; + } + +# endif +#else + + float LoadSceneDepth(uint2 pos, uint s) + { + return 1.0f; + } + +#endif + +Texture2D<float4> tPhaseLUT : register(t4); +Texture2D<float4> tLightLUT_P : register(t5); +Texture2D<float4> tLightLUT_S1 : register(t6); +Texture2D<float4> tLightLUT_S2 : register(t7); + +float GetLutCoord_X(float t, float light_dist) +{ + float t0 = max(0.0f, light_dist-g_fLightZFar); + float t_range = g_fLightZFar + light_dist - t0; + return (t-t0) / t_range; +} + +float GetLutCoord_Y(float cos_theta) +{ + return acos(-cos_theta) / PI; +} + +float3 SampleLut(Texture2D tex, float2 tc) +{ + float4 s = tex.SampleLevel(sBilinear, tc, 0); + return s.rgb*s.a; +} +//////////////////////////////////////////////////////////////////////////////// +// Integration code + +#define INTEGRATE(result, fn, data, step_count, t0, t1) \ +{ \ + float t_step = (t1-t0)/float(step_count); \ + float3 sum = float3(0,0,0); \ + sum += fn(data, t0); \ + float t = t0+t_step; \ + [unroll] \ + for (uint istep=1; istep<step_count-1; istep += 2) \ + { \ + sum += 4*fn(data, t); \ + t += t_step; \ + sum += 2*fn(data, t); \ + t += t_step; \ + } \ + sum += 4*fn(data, t); \ + sum += fn(data, t1); \ + result = (t_step/3.0f) * sum; \ +} + +//////////////////////////////////////////////////////////////////////////////// +// Directional Light + +struct LightEvaluatorData_Directional { + float VdotL; + float3 sigma; +}; + +float3 LightEvaluator_Directional(LightEvaluatorData_Directional data, float t) +{ + float3 light_to_world_depth = g_fLightToEyeDepth + t*data.VdotL; + return exp(-data.sigma*(t+light_to_world_depth)); +} + +float3 Integrate_Directional(float eye_dist, float3 vV, float3 vL) +{ + float VdotL = dot(vV, vL); + // Manually integrate over interval + LightEvaluatorData_Directional evaluator; + float3 sigma = g_vSigmaExtinction; + evaluator.VdotL = VdotL; + const uint STEP_COUNT = 6; + float3 integral = float3(0,0,0); + INTEGRATE(integral, LightEvaluator_Directional, evaluator, STEP_COUNT, 0, eye_dist); + return GetPhaseFactor(tPhaseLUT, -VdotL)*integral*exp(g_fLightToEyeDepth*(evaluator.sigma.r+evaluator.sigma.g+evaluator.sigma.b)/3.f); +} + +float3 Integrate_SimpleDirectional(float eye_dist, float3 vV, float3 vL) +{ + // Do basic directional light + float VdotL = dot(vV, vL); + float3 sigma = g_vSigmaExtinction; + return GetPhaseFactor(tPhaseLUT, -VdotL) * (1 - exp(-sigma*eye_dist)) / (sigma); +} + +//////////////////////////////////////////////////////////////////////////////// +// Spotlight + +bool IntersectCone(out float t0, out float t1, float t_max, float cos_theta, float3 vW, float3 vV, float3 vL, float WdotL, float VdotL) +{ + float cos_sqr = cos_theta * cos_theta; + float sin_sqr = 1 - cos_sqr; + float3 v_proj = vV - VdotL*vL; + float3 w_proj = vW - WdotL*vL; + + float A = cos_sqr*dot(v_proj, v_proj) - sin_sqr*VdotL*VdotL; + float B = 2 * cos_sqr*dot(v_proj, w_proj) - 2 * sin_sqr*VdotL*WdotL; + float C = cos_sqr*dot(w_proj, w_proj) - sin_sqr*WdotL*WdotL; + + float det = B*B - 4 * A*C; + float denom = 2 * A; + if (det < 0.0f || denom == 0.0f) + { + t0 = 0; + t1 = 0; + return false; + } + else + { + bool hit = true; + float root = sqrt(det); + t0 = (-B - root) / denom; + t1 = (-B + root) / denom; + + float vW_len = length(vW); + float WdotL_norm = (vW_len > 0.0f) ? WdotL / vW_len : 1.0f; + if (WdotL_norm >= cos_theta) + { + if (VdotL >= cos_theta) + t1 = t_max; + t0 = 0; + } + else if (WdotL_norm <= -cos_theta) + { + if (t0 < 0 && t1>0) + hit = false; + t0 = t0; + t1 = t_max; + } + else + { + if (t0 < 0 && t1 < 0) + hit = false; + else if (dot(vL, vW + t0*vV) < 0) + hit = false; + else if (t1<0) + t1 = t_max; + } + + if (t0 > t_max) + { + t0 = 0; + t1 = 0; + hit = false; + } + + return hit; + } +} + +struct LightEvaluatorData_Spotlight +{ + float3 sigma; + float light_theta; + float light_falloff_power; + float Wsqr; + float WdotV; + float WdotL; + float VdotL; +}; + +float3 LightEvaluator_Spotlight(LightEvaluatorData_Spotlight data, float t) +{ + float Dsqr = max(data.Wsqr+2*data.WdotV*t+t*t, 0.0f); + float D = sqrt(Dsqr); + float cos_phi = (t>0 && D>0) ? (t*t + Dsqr - data.Wsqr) / (2 * t*D) : 0; + float3 phase_factor = GetPhaseFactor(tPhaseLUT, -cos_phi); + float distance_attenuation = AttenuationFunc(D); + float Dproj = data.WdotL + t*data.VdotL; + float cos_alpha = (D>0.0f) ? Dproj/D : 1.0f; + float angle_factor = saturate(cos_alpha-data.light_theta)/(1-data.light_theta); + const float ANGLE_EPSILON = 0.000001f; + float spot_attenuation = (angle_factor > ANGLE_EPSILON) ? pow(abs(angle_factor), data.light_falloff_power) : 0.0f; + float3 media_attenuation = exp(-data.sigma*(t+D)); + return phase_factor*distance_attenuation*spot_attenuation*media_attenuation; +} + +float3 Integrate_Spotlight(float eye_dist, float3 vW, float3 vV, float3 vL) +{ + float3 integral = float3(0, 0, 0); + float WdotL = dot(vW, vL); + float VdotL = dot(vV, vL); + float t0=0, t1=1; + if (IntersectCone(t0, t1, eye_dist, g_fLightFalloffAngle, vW, vV, vL, WdotL, VdotL)) + { + t1 = min(t1, eye_dist); + + if (FALLOFFMODE == FALLOFFMODE_NONE) + { + float light_dist = length(vW); + float3 vW_norm = vW / light_dist; + float2 tc; + tc.x = GetLutCoord_X(t1, light_dist); + tc.y = GetLutCoord_Y(dot(vW_norm, vV)); + integral = SampleLut(tLightLUT_P, tc); + if (t0 > 0) + { + tc.x = GetLutCoord_X(t0, light_dist); + integral -= SampleLut(tLightLUT_P, tc); + } + integral *= g_vScatterPower; + } + else if (FALLOFFMODE == FALLOFFMODE_FIXED) + { + float light_dist = length(vW); + float3 vW_norm = vW / light_dist; + float2 tc; + tc.x = GetLutCoord_X(t1, light_dist); + tc.y = GetLutCoord_Y(dot(vW_norm, vV)); + integral = WdotL*SampleLut(tLightLUT_S1, tc) + VdotL*SampleLut(tLightLUT_S2, tc) - g_fLightFalloffAngle*SampleLut(tLightLUT_P, tc); + if (t0 > 0) + { + tc.x = GetLutCoord_X(t0, light_dist); + integral -= WdotL*SampleLut(tLightLUT_S1, tc) + VdotL*SampleLut(tLightLUT_S2, tc) - g_fLightFalloffAngle*SampleLut(tLightLUT_P, tc); + } + integral *= g_vScatterPower / (1-g_fLightFalloffAngle); + } + if (FALLOFFMODE == FALLOFFMODE_CUSTOM) + { + LightEvaluatorData_Spotlight evaluator; + evaluator.sigma = g_vSigmaExtinction; + evaluator.light_theta = g_fLightFalloffAngle; + evaluator.light_falloff_power = g_fLightFalloffPower; + evaluator.Wsqr = dot(vW, vW); + evaluator.WdotV = dot(vW, vV); + evaluator.WdotL = WdotL; + evaluator.VdotL = VdotL; + const uint STEP_COUNT = 8; + INTEGRATE(integral, LightEvaluator_Spotlight, evaluator, STEP_COUNT, t0, t1); + integral *= 6; + } + } + return integral; +} + +//////////////////////////////////////////////////////////////////////////////// +// Omni + +float3 Integrate_Omni(float eye_dist, float3 vW, float3 vV) +{ + float light_dist = length(vW); + vW = vW / light_dist; + float2 tc; + tc.x = GetLutCoord_X(eye_dist, light_dist); + tc.y = GetLutCoord_Y(dot(vW, vV)); + return g_vScatterPower*SampleLut(tLightLUT_P, tc); +} + +//////////////////////////////////////////////////////////////////////////////// +// Shader Entrypoint + +float4 main( +#if (PASSMODE == PASSMODE_FINAL) + VS_QUAD_OUTPUT pi + , uint sampleID : SV_SAMPLEINDEX +#else + PS_POLYGONAL_INPUT pi +#endif + , bool bIsFrontFace : SV_ISFRONTFACE + ) : SV_TARGET +{ +#if (PASSMODE != PASSMODE_FINAL) + uint sampleID = 0; +#endif + float fSign = 0; + float4 vWorldPos = float4(0, 0, 0, 1); + float eye_dist = 0; + float3 vV = float3(0, 0, 0); + if (PASSMODE == PASSMODE_GEOMETRY) + { + fSign = bIsFrontFace ? -1.0f : 1.0f; + vWorldPos = pi.vWorldPos; + eye_dist = length(vWorldPos.xyz - g_vEyePosition.xyz); + vV = (vWorldPos.xyz - g_vEyePosition.xyz) / eye_dist; + } + else if (PASSMODE == PASSMODE_SKY) + { + fSign = 1.0f; + eye_dist = g_fZFar; + vV = normalize(pi.vWorldPos.xyz - g_vEyePosition.xyz); + vWorldPos.xyz = g_vEyePosition.xyz + vV * eye_dist; + vWorldPos.w = 1; + } + else if (PASSMODE == PASSMODE_FINAL) + { + fSign = 1.0f; + float fSceneDepth = LoadSceneDepth(pi.vPos.xy, sampleID); + float4 vClipPos; + vClipPos.xy = float2(2, -2)*g_vViewportSize_Inv*pi.vPos.xy + float2(-1.0f, 1.0f); + vClipPos.z = fSceneDepth; + vClipPos.w = 1; + vWorldPos = mul(g_mViewProjInv, vClipPos); + vWorldPos *= 1.0f / vWorldPos.w; + eye_dist = length(vWorldPos.xyz - g_vEyePosition.xyz); + vV = (vWorldPos.xyz - g_vEyePosition.xyz) / eye_dist; + } + + float3 vL = g_vLightDir.xyz; + + float3 integral = float3(0,0,0); + if (LIGHTMODE == LIGHTMODE_DIRECTIONAL) + { + integral = Integrate_SimpleDirectional(eye_dist, vV, vL); + } + else if (LIGHTMODE == LIGHTMODE_SPOTLIGHT) + { + float3 vW = g_vEyePosition.xyz - g_vLightPos.xyz; + integral = Integrate_Spotlight(eye_dist, vW, vV, vL); + } + else if (LIGHTMODE == LIGHTMODE_OMNI) + { + float3 vW = g_vEyePosition.xyz - g_vLightPos.xyz; + integral = Integrate_Omni(eye_dist, vW, vV); + } + return float4(fSign*integral*g_vLightIntensity.rgb, 0); +} diff --git a/src/shaders/RenderVolume_VS.hlsl b/src/shaders/RenderVolume_VS.hlsl new file mode 100644 index 0000000..dc5cdb8 --- /dev/null +++ b/src/shaders/RenderVolume_VS.hlsl @@ -0,0 +1,204 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% +- MESHMODE: + - MESHMODE_FRUSTUM_GRID + - MESHMODE_FRUSTUM_BASE + - MESHMODE_FRUSTUM_CAP + - MESHMODE_OMNI_VOLUME + - MESHMODE_GEOMETRY +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +// Bypass vertex shader +HS_POLYGONAL_INPUT main( +#if (MESHMODE == MESHMODE_GEOMETRY) + float4 input_position : POSITION, +#endif + uint id : SV_VERTEXID ) +{ +#if (MESHMODE != MESHMODE_GEOMETRY) + float4 input_position = float4(0,0,0,1); +#endif + HS_POLYGONAL_INPUT output; + // + // Generate the mesh dynamically from the vertex ID + // + if (MESHMODE == MESHMODE_FRUSTUM_GRID) + { + const float patch_size = 2.0f / float(g_uMeshResolution); + uint patch_idx = id / 4; + uint patch_row = patch_idx / g_uMeshResolution; + uint patch_col = patch_idx % g_uMeshResolution; + output.vClipPos.x = patch_size*patch_col - 1.0f; + output.vClipPos.y = patch_size*patch_row - 1.0f; + + uint vtx_idx = id % 4; + float2 vtx_offset; + if (vtx_idx == 0) + { + vtx_offset = float2(0, 0); + } + else if (vtx_idx == 1) + { + vtx_offset = float2(1, 0); + } + else if (vtx_idx == 2) + { + vtx_offset = float2(1, 1); + } + else // if (vtx_idx == 3) + { + vtx_offset = float2(0, 1); + } + output.vClipPos.xy += patch_size * vtx_offset; + + output.vClipPos.z = 1.0f; + output.vClipPos.w = 1.0f; + } + else if (MESHMODE == MESHMODE_FRUSTUM_BASE) + { + uint vtx_idx = id % 3; + output.vClipPos.x = (vtx_idx == 0) ? 1 : -1; + output.vClipPos.y = (vtx_idx == 2) ? -1 : 1; + output.vClipPos.xy *= (id/3 == 0) ? 1 : -1; + output.vClipPos.z = 1.0f; + output.vClipPos.w = 1.0f; + } + else if (MESHMODE == MESHMODE_FRUSTUM_CAP) + { + uint tris_per_face = g_uMeshResolution+1; + uint verts_per_face = 3*tris_per_face; + uint face_idx = id / verts_per_face; + uint vtx_idx = id % 3; + if (face_idx < 4) + { + // Cap Side + const float patch_size = 2.0f / float(g_uMeshResolution); + const uint split_point = (g_uMeshResolution+1)/2; + float3 v; + uint tri_idx = (id%verts_per_face)/3; + if (tri_idx < g_uMeshResolution) + { + if (vtx_idx == 0) + v.x = (tri_idx >= split_point) ? 1 : -1; + else if (vtx_idx == 1) + v.x = patch_size * tri_idx - 1; + else // if (vtx_idx == 2) + v.x = patch_size * (tri_idx+1) - 1; + v.y = (vtx_idx == 0) ? 0 : 1; + } + else + { + if (vtx_idx == 1) + v.x = patch_size*split_point-1; + else + v.x = (vtx_idx == 0) ? -1 : 1; + v.y = (vtx_idx == 1) ? 1 : 0; + } + v.z = 1; + v.xz *= (face_idx/2 == 0) ? 1 : -1; + output.vClipPos.xyz = (face_idx%2 == 0) ? v.zxy : v.xzy*float3(-1,1,1); + } + else + { + // Z=0 + uint tri_idx = (id-4*verts_per_face)/3; + output.vClipPos.x = (vtx_idx == 1) ? 1 : -1; + output.vClipPos.y = (vtx_idx == 2) ? 1 : -1; + output.vClipPos.xy *= (tri_idx == 0) ? 1 : -1; + output.vClipPos.z = 0.0f; + } + output.vClipPos.w = 1.0f; + } + else if (MESHMODE == MESHMODE_OMNI_VOLUME) + { + uint verts_per_face = 4*g_uMeshResolution*g_uMeshResolution; + uint face_idx = id / verts_per_face; + uint face_vert_idx = id % verts_per_face; + + const float patch_size = 2.0f / float(g_uMeshResolution); + uint patch_idx = face_vert_idx / 4; + uint patch_row = patch_idx / g_uMeshResolution; + uint patch_col = patch_idx % g_uMeshResolution; + + float3 P; + P.x = patch_size*patch_col - 1.0f; + P.y = patch_size*patch_row - 1.0f; + + uint vtx_idx = id % 4; + float2 vtx_offset; + if (vtx_idx == 0) + { + vtx_offset = float2(0, 0); + } + else if (vtx_idx == 1) + { + vtx_offset = float2(1, 0); + } + else if (vtx_idx == 2) + { + vtx_offset = float2(1, 1); + } + else // if (vtx_idx == 3) + { + vtx_offset = float2(0, 1); + } + P.xy += patch_size * vtx_offset; + P.z = ((face_idx / 3) == 0) ? 1 : -1; + if ((face_idx % 3) == 0) + P.yzx = P.xyz * (((face_idx / 3) == 0) ? float3(1,1,1) : float3(-1,1,1)); + else if ((face_idx % 3) == 1) + P.xzy = P.xyz * (((face_idx / 3) == 1) ? float3(1,1,1) : float3(-1,1,1)); + else //if ((face_idx % 3) == 2) + P.xyz = P.xyz * (((face_idx / 3) == 0) ? float3(1,1,1) : float3(-1,1,1)); + output.vClipPos = float4(normalize(P.xyz), 1); + } + else + { + output.vClipPos = input_position; + + } + + if (MESHMODE == MESHMODE_OMNI_VOLUME) + { + output.vWorldPos = mul(g_mLightToWorld, float4(g_fLightZFar*output.vClipPos.xyz, 1)); + } + else + { + output.vWorldPos = mul(g_mLightToWorld, output.vClipPos); + } + output.vWorldPos = output.vWorldPos / output.vWorldPos.w; + output.vPos = mul(g_mViewProj, output.vWorldPos); + return output; +} diff --git a/src/shaders/Resolve_PS.hlsl b/src/shaders/Resolve_PS.hlsl new file mode 100644 index 0000000..72c07f9 --- /dev/null +++ b/src/shaders/Resolve_PS.hlsl @@ -0,0 +1,179 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +- SAMPLEMODE: + - SAMPLEMODE_SINGLE + - SAMPLEMODE_MSAA + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +struct RESOLVE_OUTPUT +{ + float3 color : SV_TARGET0; + float2 depth : SV_TARGET1; +}; + +#if (SAMPLEMODE == SAMPLEMODE_MSAA) +Texture2DMS<float4> tGodraysBuffer : register(t0); +Texture2DMS<float> tGodraysDepth : register(t1); +#elif (SAMPLEMODE == SAMPLEMODE_SINGLE) +Texture2D<float4> tGodraysBuffer : register(t0); +Texture2D<float> tGodraysDepth : register(t1); +#endif + +#if (defined(__PSSL__) && (SAMPLEMODE == SAMPLEMODE_MSAA)) +Texture2D<int2> tFMask_color : register(t2); +#endif + +#if defined(__PSSL__) +static const int FMASK_UNKNOWN = 1 << 3; // color "unknown" is always represented as high bit in the 4bit fragment index + +int2 getFmask(Texture2D <int2> tex, int sample_count, int2 coord) +{ + // if 8 or less coverage samples, only load one VGPR (32bits / 4bits per sample) + // if more than 8 coverage samples, we need to load 2 VGPRs + int2 fmask; + if (sample_count <= 8) + { + fmask.x = tex.Load(int3(coord, 0)).x; + fmask.y = 0x88888888; // all invalid -- though in theory we shouldn't need to refer to them at all. + } + else + { + fmask.xy = tex.Load(int3(coord, 0)).xy; + } + return fmask; +} + +int getFptr(int index, int2 fmask) +{ + const int bitShift = 4; // fmask load always returns a 4bit fragment index (fptr) per coverage sample, regardless of actual number of fragments. + const int mask = (1 << bitShift) - 1; + if (index < 8) + return (fmask.x >> (index*bitShift)) & mask; + else + return (fmask.y >> ((index-8)*bitShift)) & mask; +} +#endif + +RESOLVE_OUTPUT main(VS_QUAD_OUTPUT input) +{ + float3 result_color = 0.0f; + float result_depth = 0.0f; + float result_depth_sqr = 0.0f; + +#if (SAMPLEMODE == SAMPLEMODE_MSAA) + uint2 buffer_size; + uint buffer_samples; + tGodraysBuffer.GetDimensions(buffer_size.x, buffer_size.y, buffer_samples); +#elif (SAMPLEMODE == SAMPLEMODE_SINGLE) + uint buffer_samples = 1; +#endif + + int2 base_tc = int2(input.vTex * g_vViewportSize); + const float FILTER_SCALE = 1.0f; + const int KERNEL_WIDTH = 1; + float total_weight = 0.0f; + [unroll] + for (int ox=-KERNEL_WIDTH; ox<=KERNEL_WIDTH; ++ox) + { + if ((base_tc.x + ox) < 0 || (base_tc.x + ox) >= g_vViewportSize.x) continue; + + [unroll] + for (int oy=-KERNEL_WIDTH; oy<=KERNEL_WIDTH; ++oy) + { + if ((base_tc.y + oy) < 0 || (base_tc.y + oy) >= g_vViewportSize.y) continue; + + int2 offset = int2(ox, oy); + int2 tc = base_tc + offset; + +#if (defined(__PSSL__) && (SAMPLEMODE == SAMPLEMODE_MSAA)) + int2 fmask = getFmask(tFMask_color, buffer_samples, tc); +#endif + +#if (SAMPLEMODE == SAMPLEMODE_MSAA) + for (uint s=0; s<buffer_samples; ++s) + { + float2 so = offset + tGodraysBuffer.GetSamplePosition(s); +#elif (SAMPLEMODE == SAMPLEMODE_SINGLE) + { + float2 so = offset; +#endif + bool is_valid_sample = false; +#if (SAMPLEMODE == SAMPLEMODE_MSAA) +# if defined(__PSSL__) + float3 sample_value = float3(0,0,0); + float sample_depth = 0.0f; + int fptr = getFptr(s, fmask); + if (fptr != FMASK_UNKNOWN) + { + sample_value = tGodraysBuffer.Load(tc, fptr).rgb; + sample_depth = tGodraysDepth.Load( tc, fptr ).r; + is_valid_sample = true; + } +# else // !defined(__PSSL__) + is_valid_sample = true; + float3 sample_value = tGodraysBuffer.Load( tc, s ).rgb; + float sample_depth = tGodraysDepth.Load( tc, s ).r; +# endif +#elif (SAMPLEMODE == SAMPLEMODE_SINGLE) + is_valid_sample = true; + float3 sample_value = tGodraysBuffer.Load( int3(tc, 0) ).rgb; + float sample_depth = tGodraysDepth.Load( int3(tc, 0) ).r; +#endif + sample_depth = LinearizeDepth(sample_depth, g_fZNear, g_fZFar); + if (!all(isfinite(sample_value))) + { + is_valid_sample = false; + } + + if (is_valid_sample) + { + so *= g_fResMultiplier; + float weight = GaussianApprox(so, FILTER_SCALE); + result_color += weight * sample_value; + result_depth += weight * sample_depth; + result_depth_sqr += weight * sample_depth*sample_depth; + total_weight += weight; + } + } + } + } + + RESOLVE_OUTPUT output; + output.color = (total_weight > 0.0f) ? result_color/total_weight : float3(0.f, 0.f, 0.f); + output.depth = (total_weight > 0.0f) ? float2(result_depth, result_depth_sqr)/total_weight : 1.0f; + return output; +} diff --git a/src/shaders/ShaderCommon.h b/src/shaders/ShaderCommon.h new file mode 100644 index 0000000..f4b8f80 --- /dev/null +++ b/src/shaders/ShaderCommon.h @@ -0,0 +1,265 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (C) 2013, NVIDIA Corporation. All rights reserved. + +/*=========================================================================== +Constants +===========================================================================*/ + +static const float PI = 3.1415926535898f; +static const float EDGE_FACTOR = 1.0f - (2.0f/64.0f) * (1.0f/64.0f); +static const uint MAX_PHASE_TERMS = 4; + +#ifdef __PSSL__ +static const float2 SAMPLE_POSITIONS[] = { + // 1x + float2( 0, 0)/16.f, + // 2x + float2(-4, 4)/16.f, + float2( 4,-4)/16.f, + // 4x + float2(-6, 6)/16.f, + float2( 6,-6)/16.f, + float2(-2,-2)/16.f, + float2( 2, 2)/16.f, + // 8x + float2(-7,-3)/16.f, + float2( 7, 3)/16.f, + float2( 1,-5)/16.f, + float2(-5, 5)/16.f, + float2(-3,-7)/16.f, + float2( 3, 7)/16.f, + float2( 5,-1)/16.f, + float2(-1, 1)/16.f +}; + +// constant buffers +#define cbuffer ConstantBuffer + +// textures and samplers +#define Texture2DMS MS_Texture2D +#define Texture2DArray Texture2D_Array +#define SampleLevel SampleLOD +#define GetSamplePosition(s) GetSamplePoint(s) + +// semantics +#define SV_DEPTH S_DEPTH_OUTPUT +#define SV_DOMAINLOCATION S_DOMAIN_LOCATION +#define SV_INSIDETESSFACTOR S_INSIDE_TESS_FACTOR +#define SV_INSTANCEID S_INSTANCE_ID +#define SV_ISFRONTFACE S_FRONT_FACE +#define SV_OUTPUTCONTROLPOINTID S_OUTPUT_CONTROL_POINT_ID +#define SV_POSITION S_POSITION +#define SV_POSITION S_POSITION +#define SV_PRIMITIVEID S_PRIMITIVE_ID +#define SV_SAMPLEINDEX S_SAMPLE_INDEX +#define SV_TARGET S_TARGET_OUTPUT +#define SV_TARGET0 S_TARGET_OUTPUT0 +#define SV_TARGET1 S_TARGET_OUTPUT1 +#define SV_TESSFACTOR S_EDGE_TESS_FACTOR +#define SV_VERTEXID S_VERTEX_ID + +// hull and domain shader properties +#define domain DOMAIN_PATCH_TYPE +#define partitioning PARTITIONING_TYPE +#define outputtopology OUTPUT_TOPOLOGY_TYPE +#define outputcontrolpoints OUTPUT_CONTROL_POINTS +#define patchconstantfunc PATCH_CONSTANT_FUNC +#define maxtessfactor MAX_TESS_FACTOR + +// need to figure out how to deal with those exactly: +#define shared +#endif + +/*=========================================================================== +Sampler states +===========================================================================*/ +SamplerState sPoint : register(s0); +SamplerState sBilinear : register(s1); + +/*=========================================================================== +Constant buffers +===========================================================================*/ +shared cbuffer cbContext : register(b0) +{ + float2 g_vOutputSize : packoffset(c0); + float2 g_vOutputSize_Inv : packoffset(c0.z); + float2 g_vBufferSize : packoffset(c1); + float2 g_vBufferSize_Inv : packoffset(c1.z); + float g_fResMultiplier : packoffset(c2); + unsigned int g_uBufferSamples : packoffset(c2.y); +} + +shared cbuffer cbFrame : register(b1) +{ + column_major float4x4 g_mProj : packoffset(c0); + column_major float4x4 g_mViewProj : packoffset(c4); + column_major float4x4 g_mViewProjInv: packoffset(c8); + float2 g_vOutputViewportSize : packoffset(c12); + float2 g_vOutputViewportSize_Inv : packoffset(c12.z); + float2 g_vViewportSize : packoffset(c13); + float2 g_vViewportSize_Inv : packoffset(c13.z); + float3 g_vEyePosition : packoffset(c14); + float2 g_vJitterOffset : packoffset(c15); + float g_fZNear : packoffset(c15.z); + float g_fZFar : packoffset(c15.w); + float3 g_vScatterPower : packoffset(c16); + unsigned int g_uNumPhaseTerms : packoffset(c16.w); + float3 g_vSigmaExtinction : packoffset(c17); + unsigned int g_uPhaseFunc[4] : packoffset(c18); + float4 g_vPhaseParams[4] : packoffset(c22); +}; + +shared cbuffer cbVolume : register(b2) +{ + column_major float4x4 g_mLightToWorld : packoffset(c0); + float g_fLightFalloffAngle : packoffset(c4.x); + float g_fLightFalloffPower : packoffset(c4.y); + float g_fGridSectionSize : packoffset(c4.z); + float g_fLightToEyeDepth : packoffset(c4.w); + float g_fLightZNear : packoffset(c5); + float g_fLightZFar : packoffset(c5.y); + float4 g_vLightAttenuationFactors : packoffset(c6); + column_major float4x4 g_mLightProj[4] : packoffset(c7); + column_major float4x4 g_mLightProjInv[4]: packoffset(c23); + float3 g_vLightDir : packoffset(c39); + float g_fGodrayBias : packoffset(c39.w); + float3 g_vLightPos : packoffset(c40); + unsigned int g_uMeshResolution : packoffset(c40.w); + float3 g_vLightIntensity : packoffset(c41); + float g_fTargetRaySize : packoffset(c41.w); + float4 g_vElementOffsetAndScale[4] : packoffset(c42); + float4 g_vShadowMapDim : packoffset(c46); + unsigned int g_uElementIndex[4] : packoffset(c47); +}; + +shared cbuffer cbApply : register(b3) +{ + column_major float4x4 g_mHistoryXform : packoffset(c0); + float g_fFilterThreshold : packoffset(c4); + float g_fHistoryFactor : packoffset(c4.y); + float3 g_vFogLight : packoffset(c5); + float g_fMultiScattering : packoffset(c5.w); +}; + +/*=========================================================================== +Shader inputs +===========================================================================*/ +struct VS_POLYGONAL_INPUT +{ + float4 vPos : POSITION; +}; + +struct HS_POLYGONAL_INPUT +{ + float4 vPos : SV_POSITION; + float4 vWorldPos : TEXCOORD0; + float4 vClipPos : TEXCOORD1; +}; + +struct HS_POLYGONAL_CONTROL_POINT_OUTPUT +{ + float4 vWorldPos : TEXCOORD0; + float4 vClipPos : TEXCOORD1; +}; + +struct HS_POLYGONAL_CONSTANT_DATA_OUTPUT +{ + float fEdges[4] : SV_TESSFACTOR; + float fInside[2] : SV_INSIDETESSFACTOR; + float debug[4] : TEXCOORD2; +}; + +struct PS_POLYGONAL_INPUT +{ + float4 vPos : SV_POSITION; + float4 vWorldPos : TEXCOORD0; +#ifdef __PSSL__ + float dummy : CLIPPPOSDUMMY; //Workaround for compiler exception in polygon hull shaders. +#endif +}; + +struct VS_QUAD_OUTPUT +{ + float4 vPos : SV_POSITION; + sample float4 vWorldPos : TEXCOORD0; + sample float2 vTex : TEXCOORD1; +}; + +/*=========================================================================== +Common functions +===========================================================================*/ + +float LinearizeDepth(float d, float zn, float zf) +{ + return d * zn / (zf - ((zf - zn) * d)); +} + +float WarpDepth(float z, float zn, float zf) +{ + return z * (1+zf/zn) / (1+z*zf/zn); +} + +float MapDepth(float d, float zn, float zf) +{ + return (d - zn) / (zf - zn); +} + +// Approximates a non-normalized gaussian with Sigma == 1 +float GaussianApprox(float2 sample_pos, float width) +{ + float x_sqr = sample_pos.x*sample_pos.x + sample_pos.y*sample_pos.y; + // exp(-0.5*(x/w)^2) ~ (1-(x/(8*w))^2)^32 + float w = saturate(1.0f - x_sqr/(64.0f * width*width)); + w = w*w; // ^2 + w = w*w; // ^4 + w = w*w; // ^8 + w = w*w; // ^16 + w = w*w; // ^32 + return w; +} + +#if defined(ATTENUATIONMODE) +float AttenuationFunc(float d) +{ + if (ATTENUATIONMODE == ATTENUATIONMODE_POLYNOMIAL) + { + // 1-(A+Bx+Cx^2) + return saturate(1.0f - (g_vLightAttenuationFactors.x + g_vLightAttenuationFactors.y*d + g_vLightAttenuationFactors.z*d*d)); + } + else if (ATTENUATIONMODE == ATTENUATIONMODE_INV_POLYNOMIAL) + { + // 1 / (A+Bx+Cx^2) + D + return saturate(1.0f / (g_vLightAttenuationFactors.x + g_vLightAttenuationFactors.y*d + g_vLightAttenuationFactors.z*d*d) + g_vLightAttenuationFactors.w); + } + else //if (ATTENUATIONMODE == ATTENUATIONMODE_NONE) + { + return 1.0f; + } +} +#endif + +float3 GetPhaseFactor(Texture2D tex, float cos_theta) +{ + float2 tc; + tc.x = 0; + tc.y = acos(clamp(-cos_theta, -1.0f, 1.0f)) / PI; + return g_vScatterPower*tex.SampleLevel(sBilinear, tc, 0).rgb; +} diff --git a/src/shaders/TemporalFilter_PS.hlsl b/src/shaders/TemporalFilter_PS.hlsl new file mode 100644 index 0000000..082e577 --- /dev/null +++ b/src/shaders/TemporalFilter_PS.hlsl @@ -0,0 +1,207 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +/* +Define the shader permutations for code generation +%% MUX_BEGIN %% + +%% MUX_END %% +*/ + +#include "ShaderCommon.h" + +Texture2D<float4> tCurrBuffer : register(t0); +Texture2D<float4> tLastBuffer : register(t1); +Texture2D<float2> tCurrDepth : register(t2); +Texture2D<float2> tLastDepth : register(t3); + +static const int2 NEIGHBOR_OFFSETS[] = { + int2(-1, -1), int2( 0, -1), int2( 1, -1), + int2(-1, 0), int2( 0, 0), int2( 1, 0), + int2(-1, 1), int2( 0, 1), int2( 1, 1) +}; + +#if 1 +static const float NEIGHBOR_WEIGHTS[] = { + 0.015625f, 0.125000f, 0.015625f, + 0.125000f, 1.000000f, 0.125000f, + 0.015625f, 0.125000f, 0.015625f, +}; +#else +static const float NEIGHBOR_WEIGHTS[] = { + 0, 0, 0, + 0, 1, 0, + 0, 0, 0, +}; +#endif + +float RGB_to_Y (float3 input) +{ + return 0.50f*input.g + 0.25f*(input.r + input.b); +} + +float3 RGB_to_YCoCg (float3 input) +{ + float3 ret; + float tmp = 0.25f*(input.r + input.b); + ret.x = 0.50f*input.g + tmp; + ret.y = 0.50f*(input.r - input.b); + ret.z = 0.50f*input.g - tmp; + return ret; +} + +float3 YCoCg_to_RGB(float3 input) +{ + float3 ret; + float Y_val = input.x; float Co = input.y; float Cg = input.z; + float tmp = Y_val - Cg; + ret.r = tmp + Co; + ret.g = Y_val + Cg; + ret.b = tmp - Co; + return ret; +} + +float3 Tonemap( float3 sample_rgb ) +{ + sample_rgb = sample_rgb / (1 + sample_rgb); + return RGB_to_YCoCg(sample_rgb); +} + +float3 Tonemap_Inv( float3 sample_YCoCg ) +{ + float3 sample_rgb = YCoCg_to_RGB(sample_YCoCg); + return sample_rgb / (1 - sample_rgb); +} + +struct FILTER_OUTPUT +{ + float3 color : SV_TARGET0; + float2 depth : SV_TARGET1; +}; + +FILTER_OUTPUT main(VS_QUAD_OUTPUT input) +{ + FILTER_OUTPUT output; + + // load neighbors + float3 curr_sample = float3(0,0,0); + float2 curr_depth = float2(0,0); + float neighborhood_bounds_max = 0; + float neighborhood_bounds_min = 0; + int2 max_dimensions = int2(g_vViewportSize); + int2 base_tc = int2(floor(input.vTex.xy*max_dimensions)); + float total_weight = -1.0f; + + [unroll] + for (int n=0; n<9; ++n) + { + int2 sample_tc = max( int2(0,0), min(max_dimensions, base_tc + NEIGHBOR_OFFSETS[n])); + float3 neighbor_sample = max(float3(0,0,0), tCurrBuffer.Load(int3(sample_tc, 0)).rgb); + float2 neighbor_depth = tCurrDepth.Load(int3(sample_tc, 0)).rg; + bool is_valid = all(isfinite(neighbor_sample.xyz)); + if (is_valid) + { + neighbor_sample = Tonemap(neighbor_sample); + float weight = NEIGHBOR_WEIGHTS[n]; + curr_sample += weight*neighbor_sample; + curr_depth += weight*neighbor_depth; + if (total_weight <= 0.0f) + { + neighborhood_bounds_max = neighbor_sample.x; + neighborhood_bounds_min = neighbor_sample.x; + total_weight = weight; + } + else + { + neighborhood_bounds_max = max(neighborhood_bounds_max, neighbor_sample.x); + neighborhood_bounds_min = min(neighborhood_bounds_min, neighbor_sample.x); + total_weight += weight; + } + } + } + curr_sample = (total_weight > 0) ? curr_sample/total_weight : float3(0,0,0); + curr_depth = (total_weight > 0) ? curr_depth/total_weight : float2(1, 1); + + // Transform and apply history + const float MAX_HISTORY_FACTOR = 0.98f; + float history_factor = g_fHistoryFactor; + + float4 curr_clip; + curr_clip.xy = float2(2, -2) * input.vTex.xy + float2(-1, 1); + curr_clip.z = WarpDepth(curr_depth.x, g_fZNear, g_fZFar); + curr_clip.w = 1; + float4 last_clip = mul( g_mHistoryXform, curr_clip ); + last_clip = last_clip/last_clip.w; + + float2 last_tc = saturate((float2(0.5f, -0.5f)*last_clip.xy+float2(0.5f, 0.5f))) * max_dimensions; + float3 last_sample = tLastBuffer.Load(int3(last_tc, 0)).rgb; + float2 last_depth = tLastDepth.Load(int3(last_tc, 0)).rg; + last_sample = all(isfinite(last_sample)) ? Tonemap(last_sample) : curr_sample; + + history_factor = all(abs(last_clip.xy) <= 1.0f) ? history_factor : 0.0f; + + float2 clip_diff = (last_clip.xy - curr_clip.xy) * g_vViewportSize * g_vViewportSize_Inv.xx; + float clip_dist = length(clip_diff); + float movement_factor = saturate(1.0f - clip_dist/g_fFilterThreshold); + history_factor *= movement_factor*movement_factor*movement_factor; + + float depth_diff = abs(curr_depth.r-last_depth.r); + float local_variance = abs(curr_depth.g - curr_depth.r*curr_depth.r) + abs(last_depth.g - last_depth.r*last_depth.r); + local_variance = max(local_variance, 0.0001f); +#if 0 + float local_stddev = sqrt(local_variance); + float depth_factor = saturate(depth_diff-local_stddev); + depth_factor = local_stddev / (local_stddev + depth_factor); +#else + float depth_factor = saturate(depth_diff-local_variance); + depth_factor = local_variance / (local_variance + depth_factor); +#endif + history_factor *= depth_factor; + + // threshold based on neighbors + // Convert to Y Co Cg, then clip to bounds of neighborhood + float3 blended_sample = curr_sample; + float2 blended_depth = curr_depth; + if (history_factor > 0.0f) + { + const float CLIP_EPSILON = 0.0001f; + float3 clip_vec = last_sample - curr_sample; + float clamped_Y = max(neighborhood_bounds_min, min(neighborhood_bounds_max, last_sample.x)); + float clip_factor_Y = (abs(clip_vec.x) > CLIP_EPSILON) ? abs((clamped_Y-curr_sample.x) / clip_vec.x) : 1.0f; + float clip_factor = clip_factor_Y; + float3 clipped_history = curr_sample + clip_factor*clip_vec; + + history_factor = min(history_factor, MAX_HISTORY_FACTOR); + blended_sample = lerp(curr_sample, clipped_history, history_factor); + blended_depth = lerp(curr_depth, last_depth, history_factor); + } + + output.color = Tonemap_Inv(blended_sample); + output.depth = blended_depth; + return output; +} |