• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#version 450 core
2#extension GL_ARB_separate_shader_objects : enable
3#extension GL_ARB_shading_language_420pack : enable
4
5// includes
6
7#include "render/shaders/common/render_color_conversion_common.h"
8#include "render/shaders/common/render_post_process_common.h"
9#include "render/shaders/common/render_tonemap_common.h"
10
11#define FXAA_USE_PATCHES 1
12#define FXAA_LUMA_GREEN 1
13#include "common/fxaa_reference.h"
14
15// sets
16
17#include "render/shaders/common/render_post_process_layout_common.h"
18
19layout(set = 0, binding = 0) uniform texture2D uTex;
20#if (FXAA_LUMA_GREEN == 0)
21layout(set = 0, binding = 1) uniform texture2D uTexAlpha;
22layout(set = 0, binding = 2) uniform sampler uSampler;
23#else
24layout(set = 0, binding = 1) uniform sampler uSampler;
25#endif
26
27// in / out
28
29layout(location = 0) in vec2 inUv;
30
31layout(location = 0) out vec4 outColor;
32
33float GetFxaaSharpness(const uint sharpness)
34{
35    // enum Sharpness { SOFT = 0, MEDIUM = 1, SHARP = 2 };
36    if (sharpness == 0u) {
37        return 2.0f;
38    } else if (sharpness == 1u) {
39        return 4.0f;
40    } else { // SHARP
41        return 8.0f;
42    }
43}
44
45vec2 GetFxaaThreshold(const uint quality)
46{
47    // enum Quality { LOW = 0, MEDIUM = 1, HIGH = 2 };
48    if (quality == 0u) {
49        return vec2(0.333f, 0.0833f);
50    } else if (quality == 1u) {
51        return vec2(0.125f, 0.0312f);
52    } else { // HIGH
53        return vec2(0.063f, 0.0625f);
54    }
55}
56
57void main(void)
58{
59    const uint sharpness = uint(uPc.factor.x + 0.5f);
60    const float fxaaSharpness = GetFxaaSharpness(sharpness);
61
62    const uint quality = uint(uPc.factor.y + 0.5f);
63    const vec2 fxaaThreshold = GetFxaaThreshold(quality);
64
65    const vec2 textureSizeInv = uPc.viewportSizeInvSize.zw;
66    const vec2 texelCenter = inUv;
67
68    const vec4 aaPixel = FxaaPixelShader(texelCenter, // FxaaFloat2 pos
69        vec4(texelCenter - textureSizeInv.xy * 0.5,
70            texelCenter + textureSizeInv.xy * 0.5),      // FxaaFloat4 fxaaConsolePosPos
71        uTex,                                            // FxaaTex tex
72        uSampler,                                        // FxaaSampler samp
73        vec2(0),                                         // unused FxaaFloat2 fxaaQualityRcpFrame
74        vec4(-textureSizeInv.xy, textureSizeInv.xy),     //  FxaaFloat4 fxaaConsoleRcpFrameOpt,
75        2 * vec4(-textureSizeInv.xy, textureSizeInv.xy), //  FxaaFloat4 fxaaConsoleRcpFrameOpt2,
76        vec4(0),                                         // unused FxaaFloat4 fxaaConsole360RcpFrameOpt2,
77        0, // unused FxaaFloat fxaaQualitySubpix, on the range [0 no subpixel filtering but sharp to 1 maximum and
78           // blurry, .75 default]
79        0, // unused FxaaFloat fxaaQualityEdgeThreshold, on the range [0.063 (slow, overkill, good) to 0.333 (fast),
80           // 0.125 default]
81        0, // unused FxaaFloat fxaaQualityEdgeThresholdMin, on the range [0.0833 (fast) to 0.0312 (good), with 0.0625
82           // called "high quality"]
83        fxaaSharpness, // FxaaFloat fxaaConsoleEdgeSharpness, // 8.0 is sharper, 4.0 is softer, 2.0 is really soft (good
84                       // for vector graphics inputs)
85        fxaaThreshold.x, // FxaaFloat fxaaConsoleEdgeThreshold, on the range [0.063 (slow, overkill, good) to 0.333
86                         // (fast), 0.125 default]
87        fxaaThreshold.y, // FxaaFloat fxaaConsoleEdgeThresholdMin, on the range [0.0833 (fast) to 0.0312 (good), with
88                         // 0.0625 called "high quality"]
89        vec4(0)          // unused FxaaFloat4 fxaaConsole360ConstDir
90    );
91#if (FXAA_LUMA_GREEN == 0)
92    // luma is in uTex alpha, alpha is in separate texture
93    const float alpha = textureLod(sampler2D(uTexAlpha, uSampler), inUv, 0).x;
94
95    outColor = vec4((aaPixel.xyz), alpha);
96#else
97    outColor = aaPixel;
98#endif
99}
100