-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplyPostEffects.psh
More file actions
94 lines (80 loc) · 3.34 KB
/
ApplyPostEffects.psh
File metadata and controls
94 lines (80 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "FullScreenTriangleVSOutput.fxh"
#include "BasicStructures.fxh"
#include "PBR_Structures.fxh"
#include "RenderPBR_Structures.fxh"
#include "PBR_Shading.fxh"
#include "ToneMapping.fxh"
#include "SRGBUtilities.fxh"
cbuffer cbFrameAttribs
{
PBRFrameAttribs g_Frame;
}
Texture2D<float4> g_tex2DRadiance;
Texture2D<float4> g_tex2DNormal;
Texture2D<float4> g_tex2DSSR;
Texture2D<float4> g_tex2DSpecularIBL;
Texture2D<float4> g_tex2DMaterialData;
Texture2D<float4> g_tex2DBaseColor;
Texture2D<float> g_tex2DSSAO;
Texture2D<float4> g_tex2DPreintegratedGGX;
SamplerState g_tex2DPreintegratedGGX_sampler;
float4 main(in FullScreenTriangleVSOutput VSOut) : SV_Target
{
float4 OutColor = g_tex2DRadiance.Load(int3(VSOut.f4PixelPos.xy, 0));
float3 Normal = g_tex2DNormal.Load(int3(VSOut.f4PixelPos.xy, 0)).xyz;
float4 SSRRadiance = g_tex2DSSR.Load(int3(VSOut.f4PixelPos.xy, 0));
float4 SpecularIBL = g_tex2DSpecularIBL.Load(int3(VSOut.f4PixelPos.xy, 0));
float4 BaseColor = g_tex2DBaseColor.Load(int3(VSOut.f4PixelPos.xy, 0));
float4 Material = g_tex2DMaterialData.Load(int3(VSOut.f4PixelPos.xy, 0));
float SSAOValue = g_tex2DSSAO.Load(int3(VSOut.f4PixelPos.xy, 0)).r;
float SSRScale = g_Frame.PrevCamera.f4ExtraData[0].x;
float DebugMode = g_Frame.PrevCamera.f4ExtraData[0].y;
float Roughness = Material.x;
float Metallic = Material.y;
SurfaceReflectanceInfo SrfInfo = GetSurfaceReflectanceMR(BaseColor.rgb, Metallic, Roughness);
float4 WorldPos = mul(float4(VSOut.f2NormalizedXY, DepthToNormalizedDeviceZ(0.5), 1.0), g_Frame.Camera.mViewProjInv);
float3 ViewDir = normalize(g_Frame.Camera.f4Position.xyz - WorldPos.xyz / WorldPos.w);
IBLSamplingInfo IBLInfo = GetIBLSamplingInfo(SrfInfo,
g_tex2DPreintegratedGGX,
g_tex2DPreintegratedGGX_sampler,
Normal,
ViewDir);
float3 SSR = GetSpecularIBL_GGX(SrfInfo, IBLInfo, SSRRadiance.rgb);
if (DebugMode == 0.0)
{
OutColor.rgb += (SSR.rgb - SpecularIBL.rgb) * SSRRadiance.w * OutColor.a * SSRScale;
// Old: OutColor.rgb *= SSAOValue;
float3 diffuseApprox = OutColor.rgb - SpecularIBL.rgb * OutColor.a;
OutColor.rgb = diffuseApprox * SSAOValue + SpecularIBL.rgb * OutColor.a;
}
else if (DebugMode == 1.0)
{
OutColor.rgb = SSRRadiance.rgb;
}
else if (DebugMode == 2.0)
{
OutColor.rgb = SSR.rgb;
}
else if (DebugMode == 3.0)
{
OutColor.rgb = float3(SSRRadiance.w, SSRRadiance.w, SSRRadiance.w);
}
{
// Perform tone mapping
ToneMappingAttribs TMAttribs;
TMAttribs.iToneMappingMode = TONE_MAPPING_MODE;
TMAttribs.bAutoExposure = false;
TMAttribs.fMiddleGray = g_Frame.Renderer.MiddleGray;
TMAttribs.bLightAdaptation = false;
TMAttribs.fWhitePoint = g_Frame.Renderer.WhitePoint;
TMAttribs.fLuminanceSaturation = 1.0;
OutColor.rgb = ToneMap(OutColor.rgb, TMAttribs, g_Frame.Renderer.AverageLogLum);
}
#if CONVERT_OUTPUT_TO_SRGB
{
OutColor.rgb = FastLinearToSRGB(OutColor.rgb);
}
#endif
OutColor.a = 1.0;
return OutColor;
}