cemu_graphic_packs/Enhancement/BreathOfTheWild_0FXAA/0f2b9ee517917425_00000000000003c9_ps.txt
alexkiri ed36f4ad5f [BOTW] FXAA (#88)
* Added resolution independent FXAA for BotW

* Renamed to give FXAA priority over base graphics packs
2017-09-30 11:43:15 +02:00

71 lines
2.9 KiB
Plaintext

#version 420
#extension GL_ARB_texture_gather : enable
// shader 0f2b9ee517917425
//replaces broken aa in inventory screen with fxaa.
//original shader dumped using cemu 1.9.1, BotW 1.3.1
//credit goes to https://gist.github.com/sakrist/7912905
uniform ivec4 uf_remappedPS[2];
layout(binding = 0) uniform sampler2D textureUnitPS0;// Tex0 addr 0xf49b1800 res 1280x720x1 dim 1 tm: 4 format 0019 compSel: 0 1 2 3 mipView: 0x0 (num 0x1) sliceView: 0x0 (num 0x1) Sampler0 ClampX/Y/Z: 2 2 2 border: 1
layout(binding = 1) uniform sampler2D textureUnitPS1;// Tex1 addr 0x38784000 res 1280x720x1 dim 1 tm: 4 format 0001 compSel: 0 4 4 5 mipView: 0x0 (num 0x1) sliceView: 0x0 (num 0x1) Sampler1 ClampX/Y/Z: 2 2 2 border: 1
layout(location = 0) in vec4 passParameterSem2;
layout(location = 0) out vec4 passPixelColor0;
uniform vec2 uf_fragCoordScale;
const float FXAA_SPAN_MAX = 8.0;
const float FXAA_REDUCE_MUL = 1.0 / 8.0;
const float FXAA_REDUCE_MIN = 1.0 / 128.0;
const ivec2 res = textureSize(textureUnitPS0,0);
const vec2 frameBufSize = vec2( float(res.x), float(res.y) );
void main(void) {
vec2 texCoords = passParameterSem2.xy;
vec3 rgbNW = texture2D(textureUnitPS0, texCoords + (vec2(-1.0, -1.0) / frameBufSize)).xyz;
vec3 rgbNE = texture2D(textureUnitPS0, texCoords + (vec2(1.0, -1.0) / frameBufSize)).xyz;
vec3 rgbSW = texture2D(textureUnitPS0, texCoords + (vec2(-1.0, 1.0) / frameBufSize)).xyz;
vec3 rgbSE = texture2D(textureUnitPS0, texCoords + (vec2(1.0, 1.0) / frameBufSize)).xyz;
vec3 rgbM = texture2D(textureUnitPS0, texCoords).xyz;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
float lumaNE = dot(rgbNE, luma);
float lumaSW = dot(rgbSW, luma);
float lumaSE = dot(rgbSE, luma);
float lumaM = dot(rgbM, luma);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
float dirReduce = max(
(lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),
FXAA_REDUCE_MIN);
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
dir * rcpDirMin)) / frameBufSize;
vec3 rgbA = (1.0 / 2.0) * (
texture2D(textureUnitPS0, texCoords.xy + dir * (1.0 / 3.0 - 0.5)).xyz +
texture2D(textureUnitPS0, texCoords.xy + dir * (2.0 / 3.0 - 0.5)).xyz);
vec3 rgbB = rgbA * (1.0 / 2.0) + (1.0 / 4.0) * (
texture2D(textureUnitPS0, texCoords.xy + dir * (0.0 / 3.0 - 0.5)).xyz +
texture2D(textureUnitPS0, texCoords.xy + dir * (3.0 / 3.0 - 0.5)).xyz);
float lumaB = dot(rgbB, luma);
if ((lumaB < lumaMin) || (lumaB > lumaMax)) {
passPixelColor0.xyz = rgbA;
}
else {
passPixelColor0.xyz = rgbB;
}
}
void oldmain() {
passPixelColor0 = texture(textureUnitPS0, passParameterSem2.xy);
}