Skip to content

Commit 496e6eb

Browse files
Merge branch 'DiligentGraphics:master' into master
2 parents c6442d6 + f6ff071 commit 496e6eb

13 files changed

+1615
-43
lines changed

README.md

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,50 @@ To build and run the applications in the module, please follow the [instructions
2727

2828
# Table of Contents
2929

30-
- [Tutorials](https://github.com/DiligentGraphics/DiligentSamples#tutorials)
31-
- [01 - Hello Triangle](https://github.com/DiligentGraphics/DiligentSamples#tutorial-01---hello-triangle)
32-
- [02 - Cube](https://github.com/DiligentGraphics/DiligentSamples#tutorial-02---cube)
33-
- [03 - Texturing](https://github.com/DiligentGraphics/DiligentSamples#tutorial-03---texturing)
34-
- [03 - Texturing-C](https://github.com/DiligentGraphics/DiligentSamples#tutorial-03---texturing-c)
35-
- [03 - Texturing-DotNet](https://github.com/DiligentGraphics/DiligentSamples#tutorial-03---texturing-dotnet)
36-
- [04 - Instancing](https://github.com/DiligentGraphics/DiligentSamples#tutorial-04---instancing)
37-
- [05 - Texture Array](https://github.com/DiligentGraphics/DiligentSamples#tutorial-05---texture-array)
38-
- [06 - Multithreading](https://github.com/DiligentGraphics/DiligentSamples#tutorial-06---multithreading)
39-
- [07 - Geometry Shader](https://github.com/DiligentGraphics/DiligentSamples#tutorial-07---geometry-shader)
40-
- [08 - Tessellation](https://github.com/DiligentGraphics/DiligentSamples#tutorial-08---tessellation)
41-
- [09 - Quads](https://github.com/DiligentGraphics/DiligentSamples#tutorial-09---quads)
42-
- [10 - Data Streaming](https://github.com/DiligentGraphics/DiligentSamples#tutorial-10---data-streaming)
43-
- [11 - Resource Updates](https://github.com/DiligentGraphics/DiligentSamples#tutorial-11---resource-updates)
44-
- [12 - Render Target](https://github.com/DiligentGraphics/DiligentSamples#tutorial-12---render-target)
45-
- [13 - Shadow Map](https://github.com/DiligentGraphics/DiligentSamples#tutorial-13---shadow-map)
46-
- [14 - Compute Shader](https://github.com/DiligentGraphics/DiligentSamples#tutorial-14---compute-shader)
47-
- [15 - Multiple Windows](https://github.com/DiligentGraphics/DiligentSamples#tutorial-15---multiple-windows)
48-
- [16 - Bindless Resources](https://github.com/DiligentGraphics/DiligentSamples#tutorial-16---bindless-resources)
49-
- [17 - MSAA](https://github.com/DiligentGraphics/DiligentSamples#tutorial-17---msaa)
50-
- [18 - Queries](https://github.com/DiligentGraphics/DiligentSamples#tutorial-18---queries)
51-
- [19 - Render Passes](https://github.com/DiligentGraphics/DiligentSamples#tutorial-19---render-passes)
52-
- [20 - Mesh Shader](https://github.com/DiligentGraphics/DiligentSamples#tutorial-20---mesh-shader)
53-
- [21 - Ray Tracing](https://github.com/DiligentGraphics/DiligentSamples#tutorial-21---ray-tracing)
54-
- [22 - Hybrid Rendering](https://github.com/DiligentGraphics/DiligentSamples#tutorial-22---hybrid-rendering)
55-
- [23 - Command Queues](https://github.com/DiligentGraphics/DiligentSamples#tutorial-23---command-queues)
56-
- [24 - Variable Rate Shading](https://github.com/DiligentGraphics/DiligentSamples#tutorial-24---variable-rate-shading)
57-
- [25 - Render State Packager](https://github.com/DiligentGraphics/DiligentSamples#tutorial-25---render-state-packager)
58-
- [26 - Render State Cache](https://github.com/DiligentGraphics/DiligentSamples#tutorial-26---render-state-cache)
59-
- [Samples](https://github.com/DiligentGraphics/DiligentSamples#samples)
60-
- [Atmospheric Light Scattering](https://github.com/DiligentGraphics/DiligentSamples#atmospheric-light-scattering-sample)
61-
- [GLFW Demo](https://github.com/DiligentGraphics/DiligentSamples#glfw-demo)
62-
- [GLTF Viewer](https://github.com/DiligentGraphics/DiligentSamples#gltf-viewer)
63-
- [USD Viewer](https://github.com/DiligentGraphics/DiligentSamples#usd-viewer)
64-
- [Shadows](https://github.com/DiligentGraphics/DiligentSamples#shadows)
65-
- [Dear ImGui Demo](https://github.com/DiligentGraphics/DiligentSamples#dear-imgui-demo)
66-
- [Nuklear Demo](https://github.com/DiligentGraphics/DiligentSamples#nuklear-demo)
67-
- [Hello AR](https://github.com/DiligentGraphics/DiligentSamples#hello-ar)
68-
- [Asteroids](https://github.com/DiligentGraphics/DiligentSamples#asteroids)
69-
- [Unity Plugin](https://github.com/DiligentGraphics/DiligentSamples#unity-plugin)
70-
- [Build and Run Instructions](https://github.com/DiligentGraphics/DiligentSamples#build-and-run-instructions)
71-
- [License](https://github.com/DiligentGraphics/DiligentSamples#license)
72-
- [Contributing](https://github.com/DiligentGraphics/DiligentSamples#contributing)
30+
- [Tutorials](#tutorials)
31+
- [01 - Hello Triangle](#tutorial-01---hello-triangle)
32+
- [02 - Cube](#tutorial-02---cube)
33+
- [03 - Texturing](#tutorial-03---texturing)
34+
- [03 - Texturing-C](#tutorial-03---texturing-c)
35+
- [03 - Texturing-DotNet](#tutorial-03---texturing-dotnet)
36+
- [04 - Instancing](#tutorial-04---instancing)
37+
- [05 - Texture Array](#tutorial-05---texture-array)
38+
- [06 - Multithreading](#tutorial-06---multithreading)
39+
- [07 - Geometry Shader](#tutorial-07---geometry-shader)
40+
- [08 - Tessellation](#tutorial-08---tessellation)
41+
- [09 - Quads](#tutorial-09---quads)
42+
- [10 - Data Streaming](#tutorial-10---data-streaming)
43+
- [11 - Resource Updates](#tutorial-11---resource-updates)
44+
- [12 - Render Target](#tutorial-12---render-target)
45+
- [13 - Shadow Map](#tutorial-13---shadow-map)
46+
- [14 - Compute Shader](#tutorial-14---compute-shader)
47+
- [15 - Multiple Windows](#tutorial-15---multiple-windows)
48+
- [16 - Bindless Resources](#tutorial-16---bindless-resources)
49+
- [17 - MSAA](#tutorial-17---msaa)
50+
- [18 - Queries](#tutorial-18---queries)
51+
- [19 - Render Passes](#tutorial-19---render-passes)
52+
- [20 - Mesh Shader](#tutorial-20---mesh-shader)
53+
- [21 - Ray Tracing](#tutorial-21---ray-tracing)
54+
- [22 - Hybrid Rendering](#tutorial-22---hybrid-rendering)
55+
- [23 - Command Queues](#tutorial-23---command-queues)
56+
- [24 - Variable Rate Shading](#tutorial-24---variable-rate-shading)
57+
- [25 - Render State Packager](#tutorial-25---render-state-packager)
58+
- [26 - Render State Cache](#tutorial-26---render-state-cache)
59+
- [27 - Post-Processing](#tutorial-27---post-processing)
60+
- [Samples](#samples)
61+
- [Atmospheric Light Scattering](#atmospheric-light-scattering-sample)
62+
- [GLFW Demo](#glfw-demo)
63+
- [GLTF Viewer](#gltf-viewer)
64+
- [USD Viewer](#usd-viewer)
65+
- [Shadows](#shadows)
66+
- [Dear ImGui Demo](#dear-imgui-demo)
67+
- [Nuklear Demo](#nuklear-demo)
68+
- [Hello AR](#hello-ar)
69+
- [Asteroids](#asteroids)
70+
- [Unity Plugin](#unity-plugin)
71+
- [Build and Run Instructions](#build-and-run-instructions)
72+
- [License](#license)
73+
- [Contributing](#contributing)
7374

7475
# Tutorials
7576

@@ -281,6 +282,13 @@ application starts.
281282
![](Tutorials/Tutorial26_StateCache/Screenshot.jpg)
282283

283284

285+
## [Tutorial 27 - Post-Processing](https://github.com/DiligentGraphics/DiligentSamples/tree/master/Tutorials/Tutorial27_PostProcessing)
286+
287+
This tutorial demonstrates how to use post-processing effects from the DiligentFX module.
288+
289+
![](Tutorials/Tutorial27_PostProcessing/Screenshot.jpg)
290+
291+
284292
# Samples
285293

286294
## [Atmospheric Light Scattering sample](Samples/Atmosphere)

Tutorials/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ if(PLATFORM_WIN32 OR PLATFORM_LINUX OR PLATFORM_MACOS)
4949
add_subdirectory(Tutorial25_StatePackager)
5050
add_subdirectory(Tutorial26_StateCache)
5151
endif()
52+
add_subdirectory(Tutorial27_PostProcessing)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assets/textures/papermill.ktx
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
cmake_minimum_required (VERSION 3.6)
2+
3+
project(Tutorial27_PostProcessing CXX)
4+
5+
file(COPY ../../Samples/GLTFViewer/assets/textures/papermill.ktx DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/assets/textures)
6+
7+
set(SOURCE
8+
src/Tutorial27_PostProcessing.cpp
9+
../Common/src/TexturedCube.cpp
10+
)
11+
12+
set(INCLUDE
13+
src/Tutorial27_PostProcessing.hpp
14+
../Common/src/TexturedCube.hpp
15+
)
16+
17+
set(SHADERS
18+
assets/shaders/GeometryStructures.fxh
19+
assets/shaders/GenerateGeometry.vsh
20+
assets/shaders/GenerateGeometry.psh
21+
assets/shaders/ComputeLighting.fx
22+
assets/shaders/ApplyToneMap.fx
23+
)
24+
25+
set(TEXTURES
26+
assets/textures/papermill.ktx
27+
)
28+
29+
set(ASSETS
30+
${TEXTURES}
31+
)
32+
33+
set(ALL_SHADERS ${SHADERS})
34+
35+
add_sample_app("Tutorial27_PostProcessing" "DiligentSamples/Tutorials" "${SOURCE}" "${INCLUDE}" "${ALL_SHADERS}" "${ASSETS}")
36+
37+
target_link_libraries(Tutorial27_PostProcessing PRIVATE DiligentFX)
38+
39+
if (PLATFORM_WIN32 AND GL_SUPPORTED)
40+
target_link_libraries(Tutorial27_PostProcessing PRIVATE Diligent-GLAdapterSelector)
41+
endif()
42+
43+
set_source_files_properties(${ALL_SHADERS} PROPERTIES
44+
VS_DEPLOYMENT_LOCATION "shaders"
45+
MACOSX_PACKAGE_LOCATION Resources/shaders
46+
)
47+
48+
set_source_files_properties(${TEXTURES} PROPERTIES
49+
VS_DEPLOYMENT_LOCATION "textures"
50+
MACOSX_PACKAGE_LOCATION "Resources/textures"
51+
)
52+
53+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/assets PREFIX Assets FILES ${ASSETS} ${SHADERS})
98.7 KB
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "FullScreenTriangleVSOutput.fxh"
2+
#include "PBR_Structures.fxh"
3+
#include "ToneMapping.fxh"
4+
#include "SRGBUtilities.fxh"
5+
6+
cbuffer cbPBRRendererAttibs
7+
{
8+
PBRRendererShaderParameters g_PBRRendererAttibs;
9+
}
10+
11+
Texture2D<float3> g_TextureHDR;
12+
13+
float4 ApplyToneMapPS(FullScreenTriangleVSOutput VSOut) : SV_Target0
14+
{
15+
ToneMappingAttribs TMAttribs;
16+
TMAttribs.iToneMappingMode = TONE_MAPPING_MODE;
17+
TMAttribs.bAutoExposure = false;
18+
TMAttribs.fMiddleGray = g_PBRRendererAttibs.MiddleGray;
19+
TMAttribs.bLightAdaptation = false;
20+
TMAttribs.fWhitePoint = g_PBRRendererAttibs.WhitePoint;
21+
TMAttribs.fLuminanceSaturation = 1.0;
22+
23+
float3 HDRColor = g_TextureHDR.Load(int3(VSOut.f4PixelPos.xy, 0));
24+
float3 SDRColor = ToneMap(HDRColor, TMAttribs, g_PBRRendererAttibs.AverageLogLum);
25+
26+
#if CONVERT_OUTPUT_TO_SRGB
27+
SDRColor = FastLinearToSRGB(SDRColor);
28+
#endif
29+
return float4(SDRColor, 1.0);
30+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include "BasicStructures.fxh"
2+
#include "PBR_Structures.fxh"
3+
#include "FullScreenTriangleVSOutput.fxh"
4+
5+
#define FLT_EPS 5.960464478e-8
6+
7+
cbuffer cbCameraAttribs
8+
{
9+
CameraAttribs g_Camera;
10+
}
11+
12+
cbuffer cbPBRRendererAttibs
13+
{
14+
PBRRendererShaderParameters g_PBRRendererAttibs;
15+
}
16+
17+
Texture2D<float3> g_TextureBaseColor;
18+
Texture2D<float2> g_TextureMaterialData;
19+
Texture2D<float4> g_TextureNormal;
20+
Texture2D<float> g_TextureDepth;
21+
Texture2D<float4> g_TextureSSR;
22+
23+
TextureCube<float3> g_TextureEnvironmentMap;
24+
SamplerState g_TextureEnvironmentMap_sampler;
25+
26+
TextureCube<float3> g_TextureIrradianceMap;
27+
SamplerState g_TextureIrradianceMap_sampler;
28+
29+
TextureCube<float3> g_TexturePrefilteredEnvironmentMap;
30+
SamplerState g_TexturePrefilteredEnvironmentMap_sampler;
31+
32+
Texture2D<float2> g_TextureBRDFIntegrationMap;
33+
SamplerState g_TextureBRDFIntegrationMap_sampler;
34+
35+
struct SurfaceInformation
36+
{
37+
float3 BaseColor;
38+
float Roughness;
39+
float Metalness;
40+
float3 Normal;
41+
};
42+
43+
float3 FresnelSchlickRoughness(float CosTheta, float3 F0, float roughness)
44+
{
45+
float Alpha = 1.0 - roughness;
46+
return F0 + (max(float3(Alpha, Alpha, Alpha), F0) - F0) * pow(clamp(1.0 - CosTheta, 0.0, 1.0), 5.0);
47+
}
48+
49+
float3 SampleEnvironmentMap(float3 Coord)
50+
{
51+
return g_PBRRendererAttibs.IBLScale * g_TextureEnvironmentMap.SampleLevel(g_TextureEnvironmentMap_sampler, float3(+1.0, -1.0, +1.0) * Coord, 0.5);
52+
}
53+
54+
float3 SampleIrradianceMap(float3 Coord)
55+
{
56+
return g_PBRRendererAttibs.IBLScale * g_TextureIrradianceMap.Sample(g_TextureIrradianceMap_sampler, float3(+1.0, -1.0, +1.0) * Coord);
57+
}
58+
59+
float3 SamplePrefilteredEnvironmentMap(float3 Coord, float MipLevel)
60+
{
61+
return g_PBRRendererAttibs.IBLScale * g_TexturePrefilteredEnvironmentMap.SampleLevel(g_TexturePrefilteredEnvironmentMap_sampler, float3(+1.0, -1.0, +1.0) * Coord, MipLevel);
62+
}
63+
64+
float2 SampleBRDFIntegrationMap(float2 Coord)
65+
{
66+
return g_TextureBRDFIntegrationMap.Sample(g_TextureBRDFIntegrationMap_sampler, Coord);
67+
}
68+
69+
float3 ComputeDiffuseIBL(float3 N)
70+
{
71+
return SampleIrradianceMap(N);
72+
}
73+
74+
float3 ComputeSpecularIBL(float2 Location, float3 F0, float3 N, float3 V, float Roughness)
75+
{
76+
float NdotV = saturate(dot(N, V));
77+
float3 R = reflect(-V, N);
78+
float2 BRDF_LUT = SampleBRDFIntegrationMap(float2(NdotV, Roughness));
79+
float4 SSR = g_TextureSSR.Load(int3(Location, 0));
80+
float3 T1 = SamplePrefilteredEnvironmentMap(R, Roughness * g_PBRRendererAttibs.PrefilteredCubeMipLevels);
81+
float3 T2 = (F0 * BRDF_LUT.x + BRDF_LUT.yyy);
82+
return lerp(T1, SSR.rgb, SSR.w * g_Camera.f4ExtraData[0].w) * T2;
83+
}
84+
85+
SurfaceInformation ExtractGBuffer(FullScreenTriangleVSOutput VSOut)
86+
{
87+
float2 MaterialData = g_TextureMaterialData.Load(int3(VSOut.f4PixelPos.xy, 0));
88+
89+
SurfaceInformation Information;
90+
Information.BaseColor = g_TextureBaseColor.Load(int3(VSOut.f4PixelPos.xy, 0));
91+
Information.Roughness = MaterialData.x;
92+
Information.Metalness = MaterialData.y;
93+
Information.Normal = normalize(g_TextureNormal.Load(int3(VSOut.f4PixelPos.xy, 0)).xyz);
94+
return Information;
95+
}
96+
97+
float3 CreateViewDir(float2 NormalizedXY)
98+
{
99+
float4 RayStart = mul(float4(NormalizedXY, DepthToNormalizedDeviceZ(0.0), 1.0f), g_Camera.mViewProjInv);
100+
float4 RayEnd = mul(float4(NormalizedXY, DepthToNormalizedDeviceZ(1.0), 1.0f), g_Camera.mViewProjInv);
101+
102+
RayStart.xyz /= RayStart.w;
103+
RayEnd.xyz /= RayEnd.w;
104+
return normalize(RayStart.xyz - RayEnd.xyz);;
105+
}
106+
107+
float4 ComputeLightingPS(FullScreenTriangleVSOutput VSOut) : SV_Target0
108+
{
109+
float Depth = g_TextureDepth.Load(int3(VSOut.f4PixelPos.xy, 0));
110+
float3 ViewDir = CreateViewDir(VSOut.f2NormalizedXY);
111+
if (Depth >= 1.0 - FLT_EPS)
112+
return float4(SampleEnvironmentMap(-ViewDir), 1.0);
113+
114+
SurfaceInformation SurfInfo = ExtractGBuffer(VSOut);
115+
float3 F0 = lerp(float3(0.04, 0.04, 0.04), SurfInfo.BaseColor, SurfInfo.Metalness);
116+
float3 F = FresnelSchlickRoughness(saturate(dot(SurfInfo.Normal, ViewDir)), F0, SurfInfo.Roughness);
117+
118+
float3 kS = F;
119+
float3 kD = (float3(1.0, 1.0, 1.0) - kS) * (1.0 - SurfInfo.Metalness);
120+
121+
float3 Diffuse = SurfInfo.BaseColor * ComputeDiffuseIBL(SurfInfo.Normal);
122+
float3 Specular = ComputeSpecularIBL(VSOut.f4PixelPos.xy, F0, SurfInfo.Normal, ViewDir, SurfInfo.Roughness);
123+
124+
return float4(kD * Diffuse + Specular, 1.0);
125+
}

0 commit comments

Comments
 (0)