2020-08-11 12:07:21 -04:00
|
|
|
#define SMAA_RT_METRICS viewport
|
|
|
|
|
|
|
|
#define SMAA_PRESET_ULTRA 1
|
|
|
|
#define SMAA_GLSL_4 1
|
|
|
|
#define SMAA_INCLUDE_VS 0
|
|
|
|
#define SMAA_INCLUDE_PS 1
|
|
|
|
|
|
|
|
layout(std430, push_constant, binding = 4) uniform PushConstant {
|
|
|
|
vec4 viewport;
|
|
|
|
vec4 options;
|
2020-09-22 15:25:06 -04:00
|
|
|
vec4 transform_ops;
|
2020-08-11 12:07:21 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#include "smaa.glsl"
|
2020-08-19 22:09:32 -04:00
|
|
|
#include "common.nocompile.glsl"
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
layout (location = 0) in vec2 inUV;
|
|
|
|
layout(location = 1) in vec4 inOffset;
|
|
|
|
|
|
|
|
layout (location = 0) out vec4 outColor;
|
|
|
|
|
|
|
|
layout (binding = 1) uniform sampler2D colorSampler;
|
|
|
|
layout (binding = 2) uniform sampler2D backSampler;
|
|
|
|
layout (binding = 3) uniform sampler2D blendSampler;
|
|
|
|
layout (binding = 4) uniform sampler2D sobelSampler;
|
2020-09-22 20:05:51 -04:00
|
|
|
layout (binding = 5) uniform sampler2D averageLuminanceSampler;
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
float calculate_sobel() {
|
|
|
|
float x = 1.0 / viewport.z;
|
|
|
|
float y = 1.0 / viewport.w;
|
|
|
|
vec4 horizEdge = vec4( 0.0 );
|
|
|
|
horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y - y ) ) * 1.0;
|
|
|
|
horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y ) ) * 2.0;
|
|
|
|
horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y + y ) ) * 1.0;
|
|
|
|
horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y - y ) ) * 1.0;
|
|
|
|
horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y ) ) * 2.0;
|
|
|
|
horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y + y ) ) * 1.0;
|
|
|
|
vec4 vertEdge = vec4( 0.0 );
|
|
|
|
vertEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y - y ) ) * 1.0;
|
|
|
|
vertEdge -= texture( sobelSampler, vec2( inUV.x , inUV.y - y ) ) * 2.0;
|
|
|
|
vertEdge -= texture( sobelSampler, vec2( inUV.x + x, inUV.y - y ) ) * 1.0;
|
|
|
|
vertEdge += texture( sobelSampler, vec2( inUV.x - x, inUV.y + y ) ) * 1.0;
|
|
|
|
vertEdge += texture( sobelSampler, vec2( inUV.x , inUV.y + y ) ) * 2.0;
|
|
|
|
vertEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y + y ) ) * 1.0;
|
|
|
|
return sqrt((horizEdge.rgb * horizEdge.rgb) + (vertEdge.rgb * vertEdge.rgb)).r;
|
|
|
|
}
|
|
|
|
|
2020-09-22 20:05:51 -04:00
|
|
|
// adapted from https://bruop.github.io/exposure/
|
|
|
|
|
|
|
|
vec3 convertRGB2XYZ(vec3 _rgb)
|
|
|
|
{
|
|
|
|
// Reference:
|
|
|
|
// RGB/XYZ Matrices
|
|
|
|
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
|
|
|
|
vec3 xyz;
|
|
|
|
xyz.x = dot(vec3(0.4124564, 0.3575761, 0.1804375), _rgb);
|
|
|
|
xyz.y = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);
|
|
|
|
xyz.z = dot(vec3(0.0193339, 0.1191920, 0.9503041), _rgb);
|
|
|
|
return xyz;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 convertXYZ2RGB(vec3 _xyz)
|
|
|
|
{
|
|
|
|
vec3 rgb;
|
|
|
|
rgb.x = dot(vec3( 3.2404542, -1.5371385, -0.4985314), _xyz);
|
|
|
|
rgb.y = dot(vec3(-0.9692660, 1.8760108, 0.0415560), _xyz);
|
|
|
|
rgb.z = dot(vec3( 0.0556434, -0.2040259, 1.0572252), _xyz);
|
|
|
|
return rgb;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 convertXYZ2Yxy(vec3 _xyz)
|
|
|
|
{
|
|
|
|
// Reference:
|
|
|
|
// http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_xyY.html
|
|
|
|
float inv = 1.0/dot(_xyz, vec3(1.0, 1.0, 1.0) );
|
|
|
|
return vec3(_xyz.y, _xyz.x*inv, _xyz.y*inv);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 convertYxy2XYZ(vec3 _Yxy)
|
|
|
|
{
|
|
|
|
// Reference:
|
|
|
|
// http://www.brucelindbloom.com/index.html?Eqn_xyY_to_XYZ.html
|
|
|
|
vec3 xyz;
|
|
|
|
xyz.x = _Yxy.x*_Yxy.y/_Yxy.z;
|
|
|
|
xyz.y = _Yxy.x;
|
|
|
|
xyz.z = _Yxy.x*(1.0 - _Yxy.y - _Yxy.z)/_Yxy.z;
|
|
|
|
return xyz;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 convertRGB2Yxy(vec3 _rgb)
|
|
|
|
{
|
|
|
|
return convertXYZ2Yxy(convertRGB2XYZ(_rgb) );
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 convertYxy2RGB(vec3 _Yxy)
|
|
|
|
{
|
|
|
|
return convertXYZ2RGB(convertYxy2XYZ(_Yxy) );
|
|
|
|
}
|
|
|
|
|
|
|
|
float reinhard2(float _x, float _whiteSqr)
|
|
|
|
{
|
|
|
|
return (_x * (1.0 + _x/_whiteSqr) ) / (1.0 + _x);
|
|
|
|
}
|
|
|
|
|
2020-08-11 12:07:21 -04:00
|
|
|
void main() {
|
2020-08-17 08:05:30 -04:00
|
|
|
// passthrough
|
|
|
|
if(options.w == 1) {
|
|
|
|
outColor = texture(colorSampler, inUV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-11 12:07:21 -04:00
|
|
|
vec3 sceneColor = vec3(0);
|
|
|
|
if(options.x == 1) // enable AA
|
|
|
|
sceneColor = SMAANeighborhoodBlendingPS(inUV, inOffset, colorSampler, blendSampler).rgb;
|
|
|
|
else
|
|
|
|
sceneColor = texture(colorSampler, inUV).rgb;
|
|
|
|
|
|
|
|
float sobel = 0.0;
|
|
|
|
if(textureSize(sobelSampler, 0).x > 1)
|
|
|
|
sobel = calculate_sobel();
|
|
|
|
|
|
|
|
vec3 sobelColor = vec3(0, 1, 1);
|
|
|
|
|
|
|
|
vec3 hdrColor = sceneColor; // fading removed
|
2020-09-22 15:25:06 -04:00
|
|
|
|
2020-09-22 20:05:51 -04:00
|
|
|
float avg_lum = texture(averageLuminanceSampler, inUV).r;
|
|
|
|
|
2020-09-22 15:25:06 -04:00
|
|
|
vec3 transformed_color = hdrColor;
|
2020-09-22 20:05:51 -04:00
|
|
|
|
|
|
|
if(transform_ops.y == 1) {
|
|
|
|
transformed_color = vec3(1.0) - exp(-transformed_color * options.z);
|
|
|
|
} else if(transform_ops.y == 2) {
|
|
|
|
vec3 Yxy = convertRGB2Yxy(transformed_color);
|
|
|
|
|
|
|
|
// hard-coded for now
|
|
|
|
float whitePoint = 4.0;
|
|
|
|
|
|
|
|
float lp = Yxy.x / (9.6 * avg_lum + 0.0001);
|
|
|
|
|
|
|
|
// Replace this line with other tone mapping functions
|
|
|
|
// Here we applying the curve to the luminance exclusively
|
|
|
|
Yxy.x = reinhard2(lp, whitePoint);
|
|
|
|
|
|
|
|
transformed_color = convertYxy2RGB(Yxy);
|
|
|
|
}
|
2020-09-22 15:25:06 -04:00
|
|
|
|
2020-09-22 20:05:51 -04:00
|
|
|
if(transform_ops.x == 1) {
|
|
|
|
transformed_color = from_linear_to_srgb(transformed_color);
|
|
|
|
}
|
2020-09-22 15:25:06 -04:00
|
|
|
|
|
|
|
outColor = vec4(transformed_color + (sobelColor * sobel), 1.0);
|
2020-08-11 12:07:21 -04:00
|
|
|
}
|