2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
/*=============================================================================
|
|
|
|
|
PostProcessDownsample.usf: PostProcessing down sample.
|
|
|
|
|
=============================================================================*/
|
|
|
|
|
|
|
|
|
|
#include "Common.usf"
|
|
|
|
|
#include "PostProcessCommon.usf"
|
|
|
|
|
|
|
|
|
|
// vertex shader entry point
|
|
|
|
|
void MainDownsampleVS(
|
|
|
|
|
in float4 InPosition : ATTRIBUTE0,
|
|
|
|
|
in float2 UV : ATTRIBUTE1,
|
|
|
|
|
out float2 OutUV : TEXCOORD0,
|
|
|
|
|
out float4 OutPosition : SV_POSITION
|
|
|
|
|
)
|
|
|
|
|
{
|
2014-04-23 17:26:59 -04:00
|
|
|
DrawRectangle(InPosition, UV, OutPosition, OutUV);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2015-09-14 19:37:33 -04:00
|
|
|
// xy: UV offset, zw:unused
|
|
|
|
|
float4 DownsampleParams;
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
// pixel shader entry point
|
2015-09-14 19:37:33 -04:00
|
|
|
void MainPS(noperspective float2 InUV : TEXCOORD0, out float4 OutColor : SV_Target0)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2015-09-14 19:37:33 -04:00
|
|
|
float2 Offset = DownsampleParams.xy;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
#if METHOD == 0
|
2015-09-14 19:37:33 -04:00
|
|
|
// Output: low quality, 1 filtered sample
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
OutColor = Texture2DSample(PostprocessInput0, PostprocessInput0Sampler, InUV);
|
2015-09-14 19:37:33 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
#elif METHOD == 1
|
2015-09-14 19:37:33 -04:00
|
|
|
// Output: float4(RGBA), 4 filtered samples
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
float2 UV[4];
|
|
|
|
|
|
|
|
|
|
// blur during downsample (4x4 kernel) to get better quality especially for HDR content, can be made an option of this shader
|
|
|
|
|
UV[0] = InUV + Offset * float2(-1, -1);
|
|
|
|
|
UV[1] = InUV + Offset * float2( 1, -1);
|
|
|
|
|
UV[2] = InUV + Offset * float2(-1, 1);
|
|
|
|
|
UV[3] = InUV + Offset * float2( 1, 1);
|
|
|
|
|
|
|
|
|
|
float4 Sample[4];
|
|
|
|
|
|
2015-09-14 19:37:33 -04:00
|
|
|
UNROLL for(uint i = 0; i < 4; ++i)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
Sample[i] = Texture2DSample(PostprocessInput0, PostprocessInput0Sampler, UV[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutColor = (Sample[0] + Sample[1] + Sample[2] + Sample[3]) * 0.25f;
|
|
|
|
|
|
2015-09-14 19:37:33 -04:00
|
|
|
// fixed rarely occuring yellow color tint of the whole viewport (certain view port size, need to investigate more)
|
2014-03-14 14:13:41 -04:00
|
|
|
OutColor.rgb = max(float3(0,0,0), OutColor.rgb);
|
|
|
|
|
#else
|
2015-09-14 19:37:33 -04:00
|
|
|
// Output: float4(RGB,depth), 4 unfiltered samples (no leaking)
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
float2 UV[4];
|
|
|
|
|
|
|
|
|
|
// no filtering (2x2 kernel) to get no leaking in Depth of Field
|
2015-09-14 19:37:33 -04:00
|
|
|
UV[0] = InUV + Offset * float2(-1, -1);
|
|
|
|
|
UV[1] = InUV + Offset * float2( 1, -1);
|
|
|
|
|
UV[2] = InUV + Offset * float2(-1, 1);
|
|
|
|
|
UV[3] = InUV + Offset * float2( 1, 1);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
float3 Sample[4];
|
|
|
|
|
|
2015-09-14 19:37:33 -04:00
|
|
|
UNROLL for(uint i = 0; i < 4; ++i)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
Sample[i] = Texture2DSample(PostprocessInput0, PostprocessInput0Sampler, UV[i]).rgb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo: this still leaks as we need to mask in focus pixels
|
|
|
|
|
OutColor = float4((Sample[0] + Sample[1] + Sample[2] + Sample[3]) * 0.25f, CalcSceneDepth(UV[0]));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|