diff options
| author | Marco Foco <[email protected]> | 2016-03-07 15:47:07 +0100 |
|---|---|---|
| committer | Marco Foco <[email protected]> | 2016-03-08 16:04:19 +0100 |
| commit | cd6e0492903f8a9eb5efa14263d7d9ab092517de (patch) | |
| tree | 05c010b75bf777335565819dcceb140886c5a7e9 /samples/d3d11/shaders | |
| download | faceworks-cd6e0492903f8a9eb5efa14263d7d9ab092517de.tar.xz faceworks-cd6e0492903f8a9eb5efa14263d7d9ab092517de.zip | |
FaceWorks 1.0
Diffstat (limited to 'samples/d3d11/shaders')
22 files changed, 1713 insertions, 0 deletions
diff --git a/samples/d3d11/shaders/common.hlsli b/samples/d3d11/shaders/common.hlsli new file mode 100644 index 0000000..8651031 --- /dev/null +++ b/samples/d3d11/shaders/common.hlsli @@ -0,0 +1,97 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/common.hlsli +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#ifndef COMMON_HLSLI +#define COMMON_HLSLI + +#pragma pack_matrix(row_major) + +#include "resources.h" + +struct Vertex +{ + float3 m_pos : POSITION; + float3 m_normal : NORMAL; + float2 m_uv : UV; + float3 m_tangent : TANGENT; + float m_curvature : CURVATURE; +}; + +cbuffer cbDebug : CB_DEBUG // matches struct CbufDebug in util.h +{ + float g_debug; // Mapped to spacebar - 0 if up, 1 if down + float g_debugSlider0; // Mapped to debug slider in UI + float g_debugSlider1; // ... + float g_debugSlider2; // ... + float g_debugSlider3; // ... +} + +cbuffer cbFrame : CB_FRAME // matches struct CbufFrame in util.h +{ + float4x4 g_matWorldToClip; + float3 g_posCamera; + + float3 g_vecDirectionalLight; + float3 g_rgbDirectionalLight; + + float4x4 g_matWorldToUvzwShadow; + float3x3 g_matWorldToUvzShadowNormal; // Matrix for transforming normals to shadow map space + float dummy; // Padding + + float g_vsmMinVariance; // Minimum variance for variance shadow maps + float g_shadowSharpening; + float g_tessScale; // Scale of adaptive tessellation + + float g_deepScatterIntensity; // Multiplier on whole deep scattering result + float g_deepScatterNormalOffset; // Normal offset for shadow lookup to calculate thickness + + float g_exposure; // Exposure multiplier +} + +TextureCube<float3> g_texCubeDiffuse : TEX_CUBE_DIFFUSE; +TextureCube<float3> g_texCubeSpec : TEX_CUBE_SPEC; +Texture2D<float> g_texShadowMap : TEX_SHADOW_MAP; +Texture2D<float2> g_texVSM : TEX_VSM; +Texture2D g_texCurvatureLUT : TEX_CURVATURE_LUT; +Texture2D g_texShadowLUT : TEX_SHADOW_LUT; + +SamplerState g_ssPointClamp : SAMP_POINT_CLAMP; +SamplerState g_ssBilinearClamp : SAMP_BILINEAR_CLAMP; +SamplerState g_ssTrilinearRepeat : SAMP_TRILINEAR_REPEAT; +SamplerState g_ssTrilinearRepeatAniso : SAMP_TRILINEAR_REPEAT_ANISO; +SamplerComparisonState g_scsPCF : SAMP_PCF; + +float square(float x) { return x*x; } + +#endif // COMMON_HLSLI diff --git a/samples/d3d11/shaders/copy_ps.hlsl b/samples/d3d11/shaders/copy_ps.hlsl new file mode 100644 index 0000000..6e79416 --- /dev/null +++ b/samples/d3d11/shaders/copy_ps.hlsl @@ -0,0 +1,48 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/copy_ps.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + + +#include "common.hlsli" + +cbuffer cbShader : CB_SHADER +{ + float4x4 g_matTransformColor; +} + +Texture2D g_texSource : TEX_SOURCE; + +float4 main(in float2 i_uv : UV) : SV_Target +{ + return mul(g_texSource.Sample(g_ssTrilinearRepeat, i_uv), g_matTransformColor); +} diff --git a/samples/d3d11/shaders/create_vsm_ps.hlsl b/samples/d3d11/shaders/create_vsm_ps.hlsl new file mode 100644 index 0000000..9736891 --- /dev/null +++ b/samples/d3d11/shaders/create_vsm_ps.hlsl @@ -0,0 +1,43 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/create_vsm_ps.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" + +Texture2D<float> g_texSource : TEX_SOURCE; + +float2 main(in float2 i_uv : UV) : SV_Target +{ + float z = g_texSource.Sample(g_ssPointClamp, i_uv); + return float2(z, z*z); +} diff --git a/samples/d3d11/shaders/curvature_ps.hlsl b/samples/d3d11/shaders/curvature_ps.hlsl new file mode 100644 index 0000000..e4de321 --- /dev/null +++ b/samples/d3d11/shaders/curvature_ps.hlsl @@ -0,0 +1,42 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/curvature_ps.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" + +void main( + in float i_color : COLOR, + out float4 o_rgba : SV_Target) +{ + o_rgba = float4(i_color.xxx, 1.0); +} diff --git a/samples/d3d11/shaders/curvature_vs.hlsl b/samples/d3d11/shaders/curvature_vs.hlsl new file mode 100644 index 0000000..b14f5fa --- /dev/null +++ b/samples/d3d11/shaders/curvature_vs.hlsl @@ -0,0 +1,49 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/curvature_vs.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" + +cbuffer cbShader : CB_SHADER +{ + float2 g_curvatureScaleBias; +} + +void main( + in Vertex i_vtx, + out float o_color : COLOR, + out float4 o_posClip : SV_Position) +{ + o_color = sqrt(i_vtx.m_curvature * g_curvatureScaleBias.x + g_curvatureScaleBias.y); + o_posClip = mul(float4(i_vtx.m_pos, 1.0), g_matWorldToClip); +} diff --git a/samples/d3d11/shaders/eye.hlsli b/samples/d3d11/shaders/eye.hlsli new file mode 100644 index 0000000..65919cf --- /dev/null +++ b/samples/d3d11/shaders/eye.hlsli @@ -0,0 +1,132 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/eye.hlsli +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#ifndef EYE_HLSLI +#define EYE_HLSLI + +#include "common.hlsli" +#include "lighting.hlsli" +#include "GFSDK_FaceWorks.hlsli" + +#pragma warning(disable: 3571) // pow() doesn't handle negative numbers + +cbuffer cbShader : CB_SHADER +{ + float g_normalStrength; + float g_specReflectance; + float g_gloss; + float3 g_rgbDeepScatter; + + // Iris parameters + float g_irisRadiusSource; // Radius of iris in iris texture (in UV units) + float g_irisRadiusDest; // Radius of iris in schlera texture (in UV units) + float g_irisEdgeHardness; // Controls hardness/softness of iris edge + float g_irisDilation; // How much the iris is dilated + + GFSDK_FaceWorks_CBData g_faceworksData; +} + +Texture2D<float3> g_texDiffuseSclera : TEX_DIFFUSE0; +Texture2D<float3> g_texDiffuseIris : TEX_DIFFUSE1; +Texture2D<float3> g_texNormal : TEX_NORMAL; + + + +void EyeMegashader( + in Vertex i_vtx, + in float3 i_vecCamera, + in float4 i_uvzwShadow, + out float3 o_rgbLit, + uniform bool useSSS, + uniform bool useDeepScatter) +{ + float2 uv = i_vtx.m_uv; + + // Calculate diffuse color, overlaying iris on sclera + + float3 rgbDiffuse = g_texDiffuseSclera.Sample(g_ssTrilinearRepeatAniso, uv); + float irisAlpha = 0.0; + + float radiusDest = length(uv - 0.5.xx); + if (radiusDest < g_irisRadiusDest) + { + // Use a power function to remap the radius, to simulate dilation of the iris + float radiusSource = (1.0 - pow(1.0 - radiusDest / g_irisRadiusDest, 1.0 - g_irisDilation)) * g_irisRadiusSource; + float2 uvIris = (uv - 0.5.xx) * (radiusSource / radiusDest) + 0.5.xx; + float3 rgbIris = g_texDiffuseIris.Sample(g_ssTrilinearRepeatAniso, uvIris); + + // Calculate alpha using a smoothstep-like falloff at the edge of the iris + irisAlpha = saturate((g_irisRadiusDest - radiusDest) * g_irisEdgeHardness); + irisAlpha = (3.0 - 2.0 * irisAlpha) * square(irisAlpha); + rgbDiffuse = lerp(rgbDiffuse, rgbIris, irisAlpha); + } + + // Sample other textures + float3 normalTangent = UnpackNormal(g_texNormal.Sample(g_ssTrilinearRepeatAniso, uv), + g_normalStrength); + + float3 normalTangentBlurred; + if (useSSS || useDeepScatter) + { + // Sample normal map with level clamped based on blur, to get normal for SSS + float level = GFSDK_FaceWorks_CalculateMipLevelForBlurredNormal( + g_faceworksData, g_texNormal, g_ssTrilinearRepeatAniso, uv); + normalTangentBlurred = UnpackNormal( + g_texNormal.SampleLevel(g_ssTrilinearRepeatAniso, uv, level), + g_normalStrength); + } + + // Lerp normals to flat, and gloss to 1.0 in the iris region + normalTangent = lerp(normalTangent, float3(0, 0, 1), irisAlpha); + normalTangentBlurred = lerp(normalTangentBlurred, float3(0, 0, 1), irisAlpha); + float gloss = lerp(g_gloss, 1.0, irisAlpha); + + LightingMegashader( + i_vtx, + i_vecCamera, + i_uvzwShadow, + rgbDiffuse, + normalTangent, + normalTangentBlurred, + g_specReflectance, + gloss, + g_rgbDeepScatter, + g_faceworksData, + o_rgbLit, + true, // useNormalMap + useSSS, + useDeepScatter); +} + +#endif // EYE_HLSLI diff --git a/samples/d3d11/shaders/gaussian_ps.hlsl b/samples/d3d11/shaders/gaussian_ps.hlsl new file mode 100644 index 0000000..7d3f81f --- /dev/null +++ b/samples/d3d11/shaders/gaussian_ps.hlsl @@ -0,0 +1,91 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/gaussian_ps.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" + +cbuffer cbShader : CB_SHADER +{ + float2 g_vecBlur; +} + +Texture2D<float2> g_texSrc : TEX_SOURCE; + +// Gaussian blur coefficients - x = weight, y = position offset +// Python code to generate: +// import math +// n = 21 +// points = [-3.0 + 6.0 * float(i) / float(n - 1) for i in range(n)] +// weights = [math.exp(-0.5 * x**2) for x in points] +// weightSum = sum(weights) +// print(("static const float2 s_aGaussian%d[] =\n{\n" % n) + ''.join( +// " { %0.5f, %4.2f },\n" % (weights[i]/weightSum, points[i]) for i in range(n)) + "};") + +static const float2 s_aGaussian21[] = +{ + { 0.00133, -3.00 }, + { 0.00313, -2.70 }, + { 0.00673, -2.40 }, + { 0.01322, -2.10 }, + { 0.02372, -1.80 }, + { 0.03892, -1.50 }, + { 0.05835, -1.20 }, + { 0.07995, -0.90 }, + { 0.10012, -0.60 }, + { 0.11460, -0.30 }, + { 0.11987, 0.00 }, + { 0.11460, 0.30 }, + { 0.10012, 0.60 }, + { 0.07995, 0.90 }, + { 0.05835, 1.20 }, + { 0.03892, 1.50 }, + { 0.02372, 1.80 }, + { 0.01322, 2.10 }, + { 0.00673, 2.40 }, + { 0.00313, 2.70 }, + { 0.00133, 3.00 }, +}; + +float2 main(in float2 i_uv : UV) : SV_Target +{ + float2 sum = 0.0; + + [unroll] for (int i = 0; i < 21; ++i) + { + float weight = s_aGaussian21[i].x; + float2 offset = s_aGaussian21[i].y * g_vecBlur; + sum += weight * g_texSrc.Sample(g_ssBilinearClamp, i_uv + offset); + } + + return sum; +} diff --git a/samples/d3d11/shaders/hair_ps.hlsl b/samples/d3d11/shaders/hair_ps.hlsl new file mode 100644 index 0000000..c2fb2ac --- /dev/null +++ b/samples/d3d11/shaders/hair_ps.hlsl @@ -0,0 +1,82 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/hair_ps.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" +#include "lighting.hlsli" + +cbuffer cbShader : CB_SHADER +{ + float g_specReflectance; + float g_gloss; +} + +Texture2D<float4> g_texDiffuse : TEX_DIFFUSE0; + +void main( + in Vertex i_vtx, + in float3 i_vecCamera : CAMERA, + in float4 i_uvzwShadow : UVZW_SHADOW, + in bool front : SV_IsFrontFace, + out float4 o_rgbaLit : SV_Target) +{ + float2 uv = i_vtx.m_uv; + + // Sample textures + + float4 rgbaDiffuse = g_texDiffuse.Sample(g_ssTrilinearRepeatAniso, uv); + + // Perform lighting + + if (!front) + i_vtx.m_normal = -i_vtx.m_normal; + + LightingMegashader( + i_vtx, + i_vecCamera, + i_uvzwShadow, + rgbaDiffuse.rgb, + 0.0.xxx, + 0.0.xxx, + g_specReflectance, + g_gloss, + 0.0.xxx, + (GFSDK_FaceWorks_CBData)0, + o_rgbaLit.rgb, + false, // useNormalMap + false, // useSSS + false); // useDeepScatter + + // Write texture alpha for transparency + o_rgbaLit.a = rgbaDiffuse.a; +} diff --git a/samples/d3d11/shaders/lighting.hlsli b/samples/d3d11/shaders/lighting.hlsli new file mode 100644 index 0000000..52258d2 --- /dev/null +++ b/samples/d3d11/shaders/lighting.hlsli @@ -0,0 +1,293 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/lighting.hlsli +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#ifndef LIGHTING_HLSLI +#define LIGHTING_HLSLI + +#include "common.hlsli" +#include "tonemap.hlsli" +#include "GFSDK_FaceWorks.hlsli" + + + +// Normal mapping + +float3 UnpackNormal( + float3 sample, + float normalStrength) +{ + return lerp(float3(0, 0, 1), + sample * 2.0 - 1.0, + normalStrength); +} + + + +// Shadow filtering, using variance shadow maps + +float EvaluateShadowVSM( + float4 uvzwShadow, + float3 normalGeom) +{ + float3 uvzShadow = uvzwShadow.xyz / uvzwShadow.w; + + float2 vsmValue = g_texVSM.Sample(g_ssBilinearClamp, uvzShadow.xy); + float mean = vsmValue.x; + float variance = max(g_vsmMinVariance, vsmValue.y - mean*mean); + + return saturate(variance / (variance + square(uvzShadow.z - mean))); +} + + + +// Diffuse lighting + +float3 EvaluateDiffuseLight( + float3 normalGeom, + float3 normalShade, + float shadow) +{ + // Directional light diffuse + float NdotL = saturate(dot(normalShade, g_vecDirectionalLight)); + float3 rgbLightDiffuse = g_rgbDirectionalLight * (NdotL * shadow); + + // IBL diffuse + rgbLightDiffuse += g_texCubeDiffuse.Sample(g_ssTrilinearRepeat, normalShade); + + return rgbLightDiffuse; +} + +float3 EvaluateSSSDiffuseLight( + float3 normalGeom, + float3 normalShade, + float3 normalBlurred, + float shadow, + float curvature, + GFSDK_FaceWorks_CBData faceworksData) +{ + // Directional light diffuse + float3 rgbSSS = GFSDK_FaceWorks_EvaluateSSSDirectLight( + faceworksData, + normalGeom, normalShade, normalBlurred, + g_vecDirectionalLight, curvature, + g_texCurvatureLUT, g_ssBilinearClamp); + float3 rgbShadow = GFSDK_FaceWorks_EvaluateSSSShadow( + faceworksData, + normalGeom, g_vecDirectionalLight, shadow, + g_texShadowLUT, g_ssBilinearClamp); + float3 rgbLightDiffuse = g_rgbDirectionalLight * rgbSSS * rgbShadow; + + // IBL diffuse + float3 normalAmbient0, normalAmbient1, normalAmbient2; + GFSDK_FaceWorks_CalculateNormalsForAmbientLight( + normalShade, normalBlurred, + normalAmbient0, normalAmbient1, normalAmbient2); + float3 rgbAmbient0 = g_texCubeDiffuse.Sample(g_ssTrilinearRepeat, normalAmbient0); + float3 rgbAmbient1 = g_texCubeDiffuse.Sample(g_ssTrilinearRepeat, normalAmbient1); + float3 rgbAmbient2 = g_texCubeDiffuse.Sample(g_ssTrilinearRepeat, normalAmbient2); + rgbLightDiffuse += GFSDK_FaceWorks_EvaluateSSSAmbientLight( + rgbAmbient0, rgbAmbient1, rgbAmbient2); + + return rgbLightDiffuse; +} + + + +// Specular lighting + +float3 EvaluateSpecularLight( + float3 normalGeom, + float3 normalShade, + float3 vecCamera, + float specReflectance, + float gloss, + float shadow) +{ + // Directional light spec + + float3 vecHalf = normalize(g_vecDirectionalLight + vecCamera); + float NdotL = saturate(dot(normalShade, g_vecDirectionalLight)); + float NdotH = saturate(dot(normalShade, vecHalf)); + float LdotH = dot(g_vecDirectionalLight, vecHalf); + float NdotV = saturate(dot(normalShade, vecCamera)); + float specPower = exp2(gloss * 13.0); + + // Evaluate NDF and visibility function: + // Two-lobe Blinn-Phong, with double gloss on second lobe + float specLobeBlend = 0.05; + float specPower0 = specPower; + float specPower1 = square(specPower); + float ndf0 = pow(NdotH, specPower0) * (specPower0 + 2.0) * 0.5; + float schlickSmithFactor0 = rsqrt(specPower0 * (3.14159 * 0.25) + (3.14159 * 0.5)); + float visibilityFn0 = 0.25 / (lerp(schlickSmithFactor0, 1, NdotL) * + lerp(schlickSmithFactor0, 1, NdotV)); + float ndf1 = pow(NdotH, specPower1) * (specPower1 + 2.0) * 0.5; + float schlickSmithFactor1 = rsqrt(specPower1 * (3.14159 * 0.25) + (3.14159 * 0.5)); + float visibilityFn1 = 0.25 / (lerp(schlickSmithFactor1, 1, NdotL) * + lerp(schlickSmithFactor1, 1, NdotV)); + float ndfResult = lerp(ndf0 * visibilityFn0, ndf1 * visibilityFn1, specLobeBlend); + + float fresnel = lerp(specReflectance, 1.0, pow(1.0 - LdotH, 5.0)); + float specResult = ndfResult * fresnel; + // Darken spec where the *geometric* NdotL gets too low - + // avoids it showing up on bumps in shadowed areas + float edgeDarken = saturate(5.0 * dot(normalGeom, g_vecDirectionalLight)); + float3 rgbLitSpecular = g_rgbDirectionalLight * (NdotL * edgeDarken * specResult * shadow); + + // IBL spec - again two-lobe + float3 vecReflect = reflect(-vecCamera, normalShade); + float gloss0 = gloss; + float gloss1 = saturate(2.0 * gloss); + float fresnelIBL0 = lerp(specReflectance, 1.0, + pow(1.0 - NdotV, 5.0) / (-3.0 * gloss0 + 4.0)); + float mipLevel0 = -9.0 * gloss0 + 9.0; + float3 iblSpec0 = fresnelIBL0 * g_texCubeSpec.SampleLevel( + g_ssTrilinearRepeat, vecReflect, mipLevel0); + float fresnelIBL1 = lerp(specReflectance, 1.0, + pow(1.0 - NdotV, 5.0) / (-3.0 * gloss1 + 4.0)); + float mipLevel1 = -9.0 * gloss1 + 9.0; + float3 iblSpec1 = fresnelIBL1 * g_texCubeSpec.SampleLevel( + g_ssTrilinearRepeat, vecReflect, mipLevel1); + rgbLitSpecular += lerp(iblSpec0, iblSpec1, specLobeBlend); + + return rgbLitSpecular; +} + + + +// Master lighting routine + +void LightingMegashader( + in Vertex i_vtx, + in float3 i_vecCamera, + in float4 i_uvzwShadow, + in float3 rgbDiffuse, + in float3 normalTangent, + in float3 normalTangentBlurred, + in float specReflectance, + in float gloss, + in float3 rgbDeepScatter, + in GFSDK_FaceWorks_CBData faceworksData, + out float3 o_rgbLit, + uniform bool useNormalMap, + uniform bool useSSS, + uniform bool useDeepScatter) +{ + float3 normalGeom = normalize(i_vtx.m_normal); + float3 vecCamera = normalize(i_vecCamera); + float2 uv = i_vtx.m_uv; + + float3 normalShade, normalBlurred; + if (useNormalMap) + { + // Transform normal maps to world space + + float3x3 matTangentToWorld = float3x3( + normalize(i_vtx.m_tangent), + normalize(cross(normalGeom, i_vtx.m_tangent)), + normalGeom); + + normalShade = normalize(mul(normalTangent, matTangentToWorld)); + + if (useSSS || useDeepScatter) + { + normalBlurred = normalize(mul(normalTangentBlurred, matTangentToWorld)); + } + } + else + { + normalShade = normalGeom; + normalBlurred = normalGeom; + } + + // Evaluate shadow map + float shadow = EvaluateShadowVSM(i_uvzwShadow, normalGeom); + + float3 rgbLitDiffuse; + if (useSSS) + { + // Evaluate diffuse lighting + float3 rgbDiffuseLight = EvaluateSSSDiffuseLight( + normalGeom, normalShade, normalBlurred, + shadow, i_vtx.m_curvature, faceworksData); + rgbLitDiffuse = rgbDiffuseLight * rgbDiffuse; + + // Remap shadow to 1/3-as-wide penumbra to match shadow from LUT. + shadow = GFSDK_FaceWorks_SharpenShadow(shadow, g_shadowSharpening); + } + else + { + // Remap shadow to 1/3-as-wide penumbra to match shadow in SSS case. + shadow = GFSDK_FaceWorks_SharpenShadow(shadow, g_shadowSharpening); + + // Evaluate diffuse lighting + float3 rgbDiffuseLight = EvaluateDiffuseLight(normalGeom, normalShade, shadow); + rgbLitDiffuse = rgbDiffuseLight * rgbDiffuse; + } + + // Evaluate specular lighting + float3 rgbLitSpecular = EvaluateSpecularLight( + normalGeom, normalShade, vecCamera, + specReflectance, gloss, + shadow); + + // Put it all together + o_rgbLit = rgbLitDiffuse + rgbLitSpecular; + + if (useDeepScatter) + { + float3 uvzShadow = i_uvzwShadow.xyz / i_uvzwShadow.w; + + // Apply normal offset to avoid silhouette edge artifacts + // !!!UNDONE: move this to vertex shader + float3 normalShadow = mul(normalGeom, g_matWorldToUvzShadowNormal); + uvzShadow += normalShadow * g_deepScatterNormalOffset; + + float thickness = GFSDK_FaceWorks_EstimateThicknessFromParallelShadowPoisson32( + faceworksData, + g_texShadowMap, g_ssBilinearClamp, uvzShadow); + + float deepScatterFactor = GFSDK_FaceWorks_EvaluateDeepScatterDirectLight( + faceworksData, + normalBlurred, g_vecDirectionalLight, thickness); + rgbDeepScatter *= g_deepScatterIntensity; + o_rgbLit += (g_deepScatterIntensity * deepScatterFactor) * rgbDeepScatter * + rgbDiffuse * g_rgbDirectionalLight; + } + + // Apply tonemapping to the result + o_rgbLit = Tonemap(o_rgbLit); +} + +#endif // LIGHTING_HLSLI diff --git a/samples/d3d11/shaders/resources.h b/samples/d3d11/shaders/resources.h new file mode 100644 index 0000000..3226c8d --- /dev/null +++ b/samples/d3d11/shaders/resources.h @@ -0,0 +1,75 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/resources.h +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#ifndef RESOURCES_H +#define RESOURCES_H + +// This file is included from both C++ and HLSL; it defines shared resource slot assignments + +#ifdef __cplusplus +# define CBREG(n) n +# define TEXREG(n) n +# define SAMPREG(n) n +#else +# define CBREG(n) register(b##n) +# define TEXREG(n) register(t##n) +# define SAMPREG(n) register(s##n) +#endif + +#define CB_DEBUG CBREG(0) +#define CB_FRAME CBREG(1) +#define CB_SHADER CBREG(2) + +#define TEX_CUBE_DIFFUSE TEXREG(0) +#define TEX_CUBE_SPEC TEXREG(1) +#define TEX_SHADOW_MAP TEXREG(2) +#define TEX_VSM TEXREG(3) +#define TEX_DIFFUSE0 TEXREG(4) +#define TEX_DIFFUSE1 TEXREG(5) +#define TEX_NORMAL TEXREG(6) +#define TEX_SPEC TEXREG(7) +#define TEX_GLOSS TEXREG(8) +#define TEX_SSS_MASK TEXREG(9) +#define TEX_DEEP_SCATTER_COLOR TEXREG(10) +#define TEX_SOURCE TEXREG(11) +#define TEX_CURVATURE_LUT TEXREG(12) +#define TEX_SHADOW_LUT TEXREG(13) + +#define SAMP_POINT_CLAMP SAMPREG(0) +#define SAMP_BILINEAR_CLAMP SAMPREG(1) +#define SAMP_TRILINEAR_REPEAT SAMPREG(2) +#define SAMP_TRILINEAR_REPEAT_ANISO SAMPREG(3) +#define SAMP_PCF SAMPREG(4) + +#endif // RESOURCES_H diff --git a/samples/d3d11/shaders/screen_vs.hlsl b/samples/d3d11/shaders/screen_vs.hlsl new file mode 100644 index 0000000..c5c945b --- /dev/null +++ b/samples/d3d11/shaders/screen_vs.hlsl @@ -0,0 +1,45 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/screen_vs.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + + +#include "common.hlsli" + +void main( + in Vertex i_vtx, + out float2 o_uv : UV, + out float4 o_posClip : SV_Position) +{ + o_posClip = float4(i_vtx.m_pos.xy, 0.0, 1.0); + o_uv = i_vtx.m_uv; +} diff --git a/samples/d3d11/shaders/shadow_vs.hlsl b/samples/d3d11/shaders/shadow_vs.hlsl new file mode 100644 index 0000000..f55bb2d --- /dev/null +++ b/samples/d3d11/shaders/shadow_vs.hlsl @@ -0,0 +1,53 @@ +// 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 +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/shadow_vs.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" + +cbuffer cbShader : CB_SHADER +{ + float4x4 g_matWorldToClipShadow; +} + +void main( + in Vertex i_vtx, + out float4 o_posClip : SV_Position) +{ + o_posClip = mul(float4(i_vtx.m_pos, 1.0), g_matWorldToClipShadow); +} diff --git a/samples/d3d11/shaders/skin.hlsli b/samples/d3d11/shaders/skin.hlsli new file mode 100644 index 0000000..fd4f953 --- /dev/null +++ b/samples/d3d11/shaders/skin.hlsli @@ -0,0 +1,108 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/skin.hlsli +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#ifndef SKIN_HLSLI +#define SKIN_HLSLI + +#include "common.hlsli" +#include "lighting.hlsli" +#include "GFSDK_FaceWorks.hlsli" + +cbuffer cbShader : CB_SHADER +{ + float g_normalStrength; + float g_gloss; + + GFSDK_FaceWorks_CBData g_faceworksData; +} + +Texture2D<float3> g_texDiffuse : TEX_DIFFUSE0; +Texture2D<float3> g_texNormal : TEX_NORMAL; +Texture2D<float> g_texSpec : TEX_SPEC; +Texture2D<float3> g_texDeepScatterColor : TEX_DEEP_SCATTER_COLOR; + + + +void SkinMegashader( + in Vertex i_vtx, + in float3 i_vecCamera, + in float4 i_uvzwShadow, + out float3 o_rgbLit, + uniform bool useSSS, + uniform bool useDeepScatter) +{ + float2 uv = i_vtx.m_uv; + + // Sample textures + + float3 rgbDiffuse = g_texDiffuse.Sample(g_ssTrilinearRepeatAniso, uv); + float3 normalTangent = UnpackNormal(g_texNormal.Sample(g_ssTrilinearRepeatAniso, uv), + g_normalStrength); + float specReflectance = g_texSpec.Sample(g_ssTrilinearRepeatAniso, uv); + + float3 normalTangentBlurred; + if (useSSS || useDeepScatter) + { + // Sample normal map with level clamped based on blur, to get normal for SSS + float level = GFSDK_FaceWorks_CalculateMipLevelForBlurredNormal( + g_faceworksData, g_texNormal, g_ssTrilinearRepeatAniso, uv); + normalTangentBlurred = UnpackNormal( + g_texNormal.SampleLevel(g_ssTrilinearRepeatAniso, uv, level), + g_normalStrength); + } + + float3 rgbDeepScatter; + if (useDeepScatter) + { + rgbDeepScatter = g_texDeepScatterColor.Sample(g_ssTrilinearRepeatAniso, uv); + } + + LightingMegashader( + i_vtx, + i_vecCamera, + i_uvzwShadow, + rgbDiffuse, + normalTangent, + normalTangentBlurred, + specReflectance, + g_gloss, + rgbDeepScatter, + g_faceworksData, + o_rgbLit, + true, // useNormalMap + useSSS, + useDeepScatter); +} + +#endif // SKIN_HLSLI diff --git a/samples/d3d11/shaders/skybox_ps.hlsl b/samples/d3d11/shaders/skybox_ps.hlsl new file mode 100644 index 0000000..9a68f25 --- /dev/null +++ b/samples/d3d11/shaders/skybox_ps.hlsl @@ -0,0 +1,43 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/skybox_ps.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" +#include "tonemap.hlsli" + +TextureCube<float3> g_texSkybox : TEX_SOURCE; + +float3 main(in float3 i_vecView : VIEW) : SV_Target +{ + return Tonemap(g_texSkybox.Sample(g_ssTrilinearRepeat, i_vecView)); +} diff --git a/samples/d3d11/shaders/skybox_vs.hlsl b/samples/d3d11/shaders/skybox_vs.hlsl new file mode 100644 index 0000000..77c3cec --- /dev/null +++ b/samples/d3d11/shaders/skybox_vs.hlsl @@ -0,0 +1,52 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/skybox_vs.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" + +cbuffer cbShader : CB_SHADER +{ + float4x4 g_matClipToWorldAxes; +} + +void main( + in Vertex i_vtx, + out float3 o_vecView : VIEW, + out float4 o_posClip : SV_Position) +{ + // Set z = 1 to draw skybox at the back of the depth range + o_posClip = float4(i_vtx.m_pos.xy, 1.0, 1.0); + + float4 vecView = mul(o_posClip, g_matClipToWorldAxes); + o_vecView = vecView.xyz / vecView.w; +} diff --git a/samples/d3d11/shaders/tess.hlsli b/samples/d3d11/shaders/tess.hlsli new file mode 100644 index 0000000..718a43b --- /dev/null +++ b/samples/d3d11/shaders/tess.hlsli @@ -0,0 +1,46 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/tess.hlsli +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#ifndef TESS_HLSLI +#define TESS_HLSLI + +struct PatchConstData +{ + float m_tessFactor[3] : SV_TessFactor; + float m_insideTessFactor : SV_InsideTessFactor; +}; + +static const float s_tessFactorMax = 3.0; + +#endif // TESS_HLSLI diff --git a/samples/d3d11/shaders/tess_ds.hlsl b/samples/d3d11/shaders/tess_ds.hlsl new file mode 100644 index 0000000..800a3b6 --- /dev/null +++ b/samples/d3d11/shaders/tess_ds.hlsl @@ -0,0 +1,75 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/tess_ds.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" +#include "tess.hlsli" + +[domain("tri")] +void main( + in OutputPatch<Vertex, 3> i_cps, + in PatchConstData i_pcd, + in float3 i_bary : SV_DomainLocation, + out Vertex o_vtx, + out float3 o_vecCamera : CAMERA, + out float4 o_uvzwShadow : UVZW_SHADOW, + out float4 o_posClip : SV_Position) +{ + // Lerp all attributes but position + o_vtx.m_normal = i_bary.x * i_cps[0].m_normal + i_bary.y * i_cps[1].m_normal + i_bary.z * i_cps[2].m_normal; + o_vtx.m_uv = i_bary.x * i_cps[0].m_uv + i_bary.y * i_cps[1].m_uv + i_bary.z * i_cps[2].m_uv; + o_vtx.m_tangent = i_bary.x * i_cps[0].m_tangent + i_bary.y * i_cps[1].m_tangent + i_bary.z * i_cps[2].m_tangent; + o_vtx.m_curvature = i_bary.x * i_cps[0].m_curvature + i_bary.y * i_cps[1].m_curvature + i_bary.z * i_cps[2].m_curvature; + + // Calculate output position using Phong tessellation + // (http://perso.telecom-paristech.fr/~boubek/papers/PhongTessellation/) + + // Compute lerped position + float3 posVtx = i_bary.x * i_cps[0].m_pos + i_bary.y * i_cps[1].m_pos + i_bary.z * i_cps[2].m_pos; + + // Calculate deltas to project onto three tangent planes + float3 vecProj0 = dot(i_cps[0].m_pos - posVtx, i_cps[0].m_normal) * i_cps[0].m_normal; + float3 vecProj1 = dot(i_cps[1].m_pos - posVtx, i_cps[1].m_normal) * i_cps[1].m_normal; + float3 vecProj2 = dot(i_cps[2].m_pos - posVtx, i_cps[2].m_normal) * i_cps[2].m_normal; + + // Lerp between projection vectors + float3 vecOffset = i_bary.x * vecProj0 + i_bary.y * vecProj1 + i_bary.z * vecProj2; + + // Add a fraction of the offset vector to the lerped position + posVtx += 0.5 * vecOffset; + + o_vtx.m_pos = posVtx; + o_vecCamera = g_posCamera - posVtx; + o_uvzwShadow = mul(float4(posVtx, 1.0), g_matWorldToUvzwShadow); + o_posClip = mul(float4(posVtx, 1.0), g_matWorldToClip); +} diff --git a/samples/d3d11/shaders/tess_hs.hlsl b/samples/d3d11/shaders/tess_hs.hlsl new file mode 100644 index 0000000..630ea60 --- /dev/null +++ b/samples/d3d11/shaders/tess_hs.hlsl @@ -0,0 +1,124 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/tess_hs.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" +#include "tess.hlsli" + +void calcHSConstants( + in InputPatch<Vertex, 3> i_cps, + out PatchConstData o_pcd) +{ + // Backface culling: check if the camera is behind all three tangent planes + float3 vecNdotV = + { + dot(g_posCamera - i_cps[0].m_pos, i_cps[0].m_normal), + dot(g_posCamera - i_cps[1].m_pos, i_cps[1].m_normal), + dot(g_posCamera - i_cps[2].m_pos, i_cps[2].m_normal), + }; + if (all(vecNdotV < 0.0)) + { + o_pcd.m_tessFactor[0] = 0.0; + o_pcd.m_tessFactor[1] = 0.0; + o_pcd.m_tessFactor[2] = 0.0; + o_pcd.m_insideTessFactor = 0.0; + return; + } + + // Frustum culling: check if all three verts are out on the same side of the frustum + // This isn't quite correct because the displacement could make a patch visible even if + // it fails this test; but in practice this is nearly impossible to notice + float4 posClip0 = mul(float4(i_cps[0].m_pos, 1.0), g_matWorldToClip); + float4 posClip1 = mul(float4(i_cps[1].m_pos, 1.0), g_matWorldToClip); + float4 posClip2 = mul(float4(i_cps[2].m_pos, 1.0), g_matWorldToClip); + float3 xs = { posClip0.x, posClip1.x, posClip2.x }; + float3 ys = { posClip0.y, posClip1.y, posClip2.y }; + float3 ws = { posClip0.w, posClip1.w, posClip2.w }; + if (all(xs < -ws) || all(xs > ws) || all(ys < -ws) || all(ys > ws)) + { + o_pcd.m_tessFactor[0] = 0.0; + o_pcd.m_tessFactor[1] = 0.0; + o_pcd.m_tessFactor[2] = 0.0; + o_pcd.m_insideTessFactor = 0.0; + return; + } + + // Adaptive tessellation based on a screen-space error estimate using curvature + + // Calculate approximate screen-space edge length, but including z length as well, + // so we don't undertessellate edges that are foreshortened + float edge0 = length(i_cps[2].m_pos - i_cps[1].m_pos) / (0.5 * (posClip2.w + posClip1.w)); + float edge1 = length(i_cps[0].m_pos - i_cps[2].m_pos) / (0.5 * (posClip0.w + posClip2.w)); + float edge2 = length(i_cps[1].m_pos - i_cps[0].m_pos) / (0.5 * (posClip1.w + posClip0.w)); + + // Calculate dots of the two normals on each edge - used to give more tessellation + // in areas with higher curvature + float normalDot0 = dot(i_cps[2].m_normal, i_cps[1].m_normal); + float normalDot1 = dot(i_cps[0].m_normal, i_cps[2].m_normal); + float normalDot2 = dot(i_cps[1].m_normal, i_cps[0].m_normal); + + // Calculate target screen-space error + static const float errPxTarget = 0.5; + static const float tanHalfFov = tan(0.5 * 0.5); + static const float errTarget = errPxTarget * 2.0 * tanHalfFov / 1080.0; + + // Calculate tess factors using curve fitting approximation to screen-space error + // derived from curvature and edge length + static const float tessScale = 0.41 / sqrt(errTarget); + o_pcd.m_tessFactor[0] = g_tessScale * sqrt(edge0) * pow(1.0 - saturate(normalDot0), 0.27); + o_pcd.m_tessFactor[1] = g_tessScale * sqrt(edge1) * pow(1.0 - saturate(normalDot1), 0.27); + o_pcd.m_tessFactor[2] = g_tessScale * sqrt(edge2) * pow(1.0 - saturate(normalDot2), 0.27); + + // Clamp to supported range + o_pcd.m_tessFactor[0] = clamp(o_pcd.m_tessFactor[0], 1.0, s_tessFactorMax); + o_pcd.m_tessFactor[1] = clamp(o_pcd.m_tessFactor[1], 1.0, s_tessFactorMax); + o_pcd.m_tessFactor[2] = clamp(o_pcd.m_tessFactor[2], 1.0, s_tessFactorMax); + + // Set interior tess factor to maximum of edge factors + o_pcd.m_insideTessFactor = max(max(o_pcd.m_tessFactor[0], + o_pcd.m_tessFactor[1]), + o_pcd.m_tessFactor[2]); +} + +[domain("tri")] +[maxtessfactor(s_tessFactorMax)] +[outputcontrolpoints(3)] +[outputtopology("triangle_cw")] +[partitioning("fractional_odd")] +[patchconstantfunc("calcHSConstants")] +Vertex main( + in InputPatch<Vertex, 3> i_cps, + in uint iCp : SV_OutputControlPointID) +{ + return i_cps[iCp]; +} diff --git a/samples/d3d11/shaders/tess_vs.hlsl b/samples/d3d11/shaders/tess_vs.hlsl new file mode 100644 index 0000000..6d9818c --- /dev/null +++ b/samples/d3d11/shaders/tess_vs.hlsl @@ -0,0 +1,43 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/tess_vs.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" +#include "tess.hlsli" + +void main( + in Vertex i_vtx, + out Vertex o_vtx) +{ + o_vtx = i_vtx; +} diff --git a/samples/d3d11/shaders/thickness_ps.hlsl b/samples/d3d11/shaders/thickness_ps.hlsl new file mode 100644 index 0000000..9db96b4 --- /dev/null +++ b/samples/d3d11/shaders/thickness_ps.hlsl @@ -0,0 +1,62 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/thickness_ps.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" +#include "GFSDK_FaceWorks.hlsli" + +cbuffer cbShader : CB_SHADER +{ + GFSDK_FaceWorks_CBData g_faceworksData; +} + +void main( + in Vertex i_vtx, + in float3 i_vecCamera : CAMERA, + in float4 i_uvzwShadow : UVZW_SHADOW, + out float4 o_rgba : SV_Target) +{ + float3 normalGeom = normalize(i_vtx.m_normal); + float3 uvzShadow = i_uvzwShadow.xyz / i_uvzwShadow.w; + + // Apply normal offset to avoid silhouette edge artifacts + // !!!UNDONE: move this to vertex shader + float3 normalShadow = mul(normalGeom, g_matWorldToUvzShadowNormal); + uvzShadow += normalShadow * g_deepScatterNormalOffset; + + float thickness = GFSDK_FaceWorks_EstimateThicknessFromParallelShadowPoisson32( + g_faceworksData, + g_texShadowMap, g_ssBilinearClamp, uvzShadow); + + o_rgba = float4(thickness.xxx * 0.05, 1.0); +} diff --git a/samples/d3d11/shaders/tonemap.hlsli b/samples/d3d11/shaders/tonemap.hlsli new file mode 100644 index 0000000..f6e8355 --- /dev/null +++ b/samples/d3d11/shaders/tonemap.hlsli @@ -0,0 +1,62 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/tonemap.hlsli +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#ifndef TONEMAP_HLSLI +#define TONEMAP_HLSLI + +#include "common.hlsli" + +float3 Tonemap(float3 rgb) +{ + // Apply exposure + rgb *= g_exposure; + + // Apply the magic Jim Hejl tonemapping curve (see: + // http://www.slideshare.net/ozlael/hable-john-uncharted2-hdr-lighting, slide #140) + static const bool useTonemapping = true; + if (useTonemapping) + { + rgb = max(0, rgb - 0.004); + rgb = (rgb * (6.2 * rgb + 0.5)) / (rgb * (6.2 * rgb + 1.7) + 0.06); + } + else + { + // Just convert to SRGB gamma space + rgb = (rgb < 0.0031308) ? (12.92 * rgb) : (1.055 * pow(rgb, 1.0/2.4) - 0.055); + } + + return rgb; +} + +#endif // TONEMAP_HLSLI diff --git a/samples/d3d11/shaders/world_vs.hlsl b/samples/d3d11/shaders/world_vs.hlsl new file mode 100644 index 0000000..02eb768 --- /dev/null +++ b/samples/d3d11/shaders/world_vs.hlsl @@ -0,0 +1,48 @@ +//---------------------------------------------------------------------------------- +// File: FaceWorks/samples/sample_d3d11/shaders/world_vs.hlsl +// SDK Version: v1.0 +// Email: [email protected] +// Site: http://developer.nvidia.com/ +// +// Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +//---------------------------------------------------------------------------------- + +#include "common.hlsli" + +void main( + in Vertex i_vtx, + out Vertex o_vtx, + out float3 o_vecCamera : CAMERA, + out float4 o_uvzwShadow : UVZW_SHADOW, + out float4 o_posClip : SV_Position) +{ + o_vtx = i_vtx; + o_vecCamera = g_posCamera - i_vtx.m_pos; + o_uvzwShadow = mul(float4(i_vtx.m_pos, 1.0), g_matWorldToUvzwShadow); + o_posClip = mul(float4(i_vtx.m_pos, 1.0), g_matWorldToClip); +} |