Update #6 - Added FXAA Antialiasing

This commit is contained in:
LAX1DUDE
2022-12-28 23:47:37 -08:00
parent 855e61836f
commit 3d6bbb672c
15 changed files with 672 additions and 129 deletions

View File

@ -45,8 +45,10 @@ public class PlatformAssets {
File loadFile = new File("resources", path);
byte[] ret = new byte[(int) loadFile.length()];
try(FileInputStream is = new FileInputStream(loadFile)) {
is.read(ret);
is.close();
int i, j = 0;
while(j < ret.length && (i = is.read(ret, j, ret.length - j)) != -1) {
j += i;
}
return ret;
}catch(IOException ex) {
return null;

View File

@ -8,7 +8,7 @@ public class EaglercraftVersion {
/// Customize these to fit your fork:
public static final String projectForkName = "EaglercraftX";
public static final String projectForkVersion = "u5";
public static final String projectForkVersion = "u6";
public static final String projectForkVendor = "lax1dude";
public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8";
@ -23,7 +23,7 @@ public class EaglercraftVersion {
public static final String projectOriginName = "EaglercraftX";
public static final String projectOriginAuthor = "lax1dude";
public static final String projectOriginRevision = "1.8";
public static final String projectOriginVersion = "u5";
public static final String projectOriginVersion = "u6";
public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8";

View File

@ -452,6 +452,8 @@ public class EaglercraftGPU {
SpriteLevelMixer.initialize();
InstancedFontRenderer.initialize();
InstancedParticleRenderer.initialize();
EffectPipelineFXAA.initialize();
SpriteLevelMixer.vshLocal.free();
}
public static final ITextureGL getNativeTexture(int tex) {

View File

@ -0,0 +1,159 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import net.lax1dude.eaglercraft.v1_8.internal.IFramebufferGL;
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
import net.lax1dude.eaglercraft.v1_8.internal.IRenderbufferGL;
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class EffectPipelineFXAA {
private static final Logger logger = LogManager.getLogger("EffectPipelineFXAA");
public static final String fragmentShaderPath = "/assets/eagler/glsl/post_fxaa.fsh";
private static final int _GL_FRAMEBUFFER = 0x8D40;
private static final int _GL_RENDERBUFFER = 0x8D41;
private static final int _GL_COLOR_ATTACHMENT0 = 0x8CE0;
private static final int _GL_DEPTH_ATTACHMENT = 0x8D00;
private static final int _GL_DEPTH_COMPONENT32F = 0x8CAC;
private static IProgramGL shaderProgram = null;
private static IUniformGL u_screenSize2f = null;
private static IFramebufferGL framebuffer = null;
private static int framebufferColor = -1;
private static IRenderbufferGL framebufferDepth = null;
private static int currentWidth = -1;
private static int currentHeight = -1;
static void initialize() {
String fragmentSource = EagRuntime.getResourceString(fragmentShaderPath);
if(fragmentSource == null) {
throw new RuntimeException("EffectPipelineFXAA shader \"" + fragmentShaderPath + "\" is missing!");
}
IShaderGL frag = _wglCreateShader(GL_FRAGMENT_SHADER);
_wglShaderSource(frag, FixedFunctionConstants.VERSION + "\n" + fragmentSource);
_wglCompileShader(frag);
if(_wglGetShaderi(frag, GL_COMPILE_STATUS) != GL_TRUE) {
logger.error("Failed to compile GL_FRAGMENT_SHADER \"" + fragmentShaderPath + "\" for EffectPipelineFXAA!");
String log = _wglGetShaderInfoLog(frag);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
logger.error("[FRAG] {}", lines[i]);
}
}
throw new IllegalStateException("Fragment shader \"" + fragmentShaderPath + "\" could not be compiled!");
}
shaderProgram = _wglCreateProgram();
_wglAttachShader(shaderProgram, SpriteLevelMixer.vshLocal);
_wglAttachShader(shaderProgram, frag);
_wglBindAttribLocation(shaderProgram, 0, "a_position2f");
_wglLinkProgram(shaderProgram);
_wglDetachShader(shaderProgram, SpriteLevelMixer.vshLocal);
_wglDetachShader(shaderProgram, frag);
_wglDeleteShader(frag);
if(_wglGetProgrami(shaderProgram, GL_LINK_STATUS) != GL_TRUE) {
logger.error("Failed to link shader program for EffectPipelineFXAA!");
String log = _wglGetProgramInfoLog(shaderProgram);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
logger.error("[LINK] {}", lines[i]);
}
}
throw new IllegalStateException("Shader program for EffectPipelineFXAA could not be linked!");
}
u_screenSize2f = _wglGetUniformLocation(shaderProgram, "u_screenSize2f");
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
_wglUniform1i(_wglGetUniformLocation(shaderProgram, "u_screenTexture"), 0);
framebuffer = _wglCreateFramebuffer();
framebufferColor = GlStateManager.generateTexture();
GlStateManager.bindTexture(framebufferColor);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
framebufferDepth = _wglCreateRenderbuffer();
_wglBindRenderbuffer(_GL_RENDERBUFFER, framebufferDepth);
_wglBindFramebuffer(_GL_FRAMEBUFFER, framebuffer);
_wglFramebufferTexture2D(_GL_FRAMEBUFFER, _GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, EaglercraftGPU.getNativeTexture(framebufferColor), 0);
_wglFramebufferRenderbuffer(_GL_FRAMEBUFFER, _GL_DEPTH_ATTACHMENT, _GL_RENDERBUFFER, framebufferDepth);
_wglBindFramebuffer(_GL_FRAMEBUFFER, null);
}
public static void begin(int width, int height) {
if(currentWidth != width || currentHeight != height) {
currentWidth = width;
currentHeight = height;
GlStateManager.bindTexture(framebufferColor);
_wglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer)null);
_wglBindRenderbuffer(_GL_RENDERBUFFER, framebufferDepth);
_wglRenderbufferStorage(_GL_RENDERBUFFER, _GL_DEPTH_COMPONENT32F, width, height);
}
_wglBindFramebuffer(_GL_FRAMEBUFFER, framebuffer);
GlStateManager.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
GlStateManager.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
public static void end() {
_wglBindFramebuffer(_GL_FRAMEBUFFER, null);
EaglercraftGPU.bindGLBufferArray(SpriteLevelMixer.vertexArray);
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
GlStateManager.bindTexture(framebufferColor);
_wglUniform2f(u_screenSize2f, 1.0f / currentWidth, 1.0f / currentHeight);
_wglDrawArrays(GL_TRIANGLES, 0, 6);
}
}

View File

@ -35,8 +35,10 @@ public class SpriteLevelMixer {
public static final String vertexShaderPath = "/assets/eagler/glsl/local.vsh";
public static final String fragmentShaderPath = "/assets/eagler/glsl/texture_mix.fsh";
public static IShaderGL vshLocal = null;
private static IBufferGL vertexBuffer = null;
private static IBufferArrayGL vertexArray = null;
public static IBufferArrayGL vertexArray = null;
private static IProgramGL shaderProgram = null;
private static IUniformGL u_textureLod1f = null;
@ -75,15 +77,15 @@ public class SpriteLevelMixer {
throw new RuntimeException("SpriteLevelMixer shader \"" + fragmentShaderPath + "\" is missing!");
}
IShaderGL vert = _wglCreateShader(GL_VERTEX_SHADER);
vshLocal = _wglCreateShader(GL_VERTEX_SHADER);
IShaderGL frag = _wglCreateShader(GL_FRAGMENT_SHADER);
_wglShaderSource(vert, FixedFunctionConstants.VERSION + "\n" + vertexSource);
_wglCompileShader(vert);
_wglShaderSource(vshLocal, FixedFunctionConstants.VERSION + "\n" + vertexSource);
_wglCompileShader(vshLocal);
if(_wglGetShaderi(vert, GL_COMPILE_STATUS) != GL_TRUE) {
if(_wglGetShaderi(vshLocal, GL_COMPILE_STATUS) != GL_TRUE) {
LOGGER.error("Failed to compile GL_VERTEX_SHADER \"" + vertexShaderPath + "\" for SpriteLevelMixer!");
String log = _wglGetShaderInfoLog(vert);
String log = _wglGetShaderInfoLog(vshLocal);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
@ -110,17 +112,16 @@ public class SpriteLevelMixer {
shaderProgram = _wglCreateProgram();
_wglAttachShader(shaderProgram, vert);
_wglAttachShader(shaderProgram, vshLocal);
_wglAttachShader(shaderProgram, frag);
_wglBindAttribLocation(shaderProgram, 0, "a_position2f");
_wglLinkProgram(shaderProgram);
_wglDetachShader(shaderProgram, vert);
_wglDetachShader(shaderProgram, vshLocal);
_wglDetachShader(shaderProgram, frag);
_wglDeleteShader(vert);
_wglDeleteShader(frag);
if(_wglGetProgrami(shaderProgram, GL_LINK_STATUS) != GL_TRUE) {

View File

@ -126,6 +126,34 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Project Name: NVIDIA FXAA
Project Author: Timothy Lottes, NVIDIA
Project URL: https://gist.github.com/kosua20/0c506b81b3812ac900048059d2383126
Used For: generating and applying patch files in build system
* ==============================================================================
*
*
* NVIDIA FXAA 3.11 by TIMOTHY LOTTES
*
*
* ------------------------------------------------------------------------------
* COPYRIGHT (C) 2010, 2011 NVIDIA CORPORATION. ALL RIGHTS RESERVED.
* ------------------------------------------------------------------------------
* TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
* *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
* OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA
* OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR
* CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR
* LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION,
* OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE
* THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Project Name: java-diff-utils
Project Author: Google, forked by wumpz
Project URL: https://java-diff-utils.github.io/java-diff-utils/

View File

@ -47,18 +47,12 @@ void main() {
float particleSize = u_texCoordSize2f_particleSize1f.z * p_particleSize_texCoordsSize_2i.x;
float f1 = u_transformParam_1_2_3_4_f.x;
float f2 = u_transformParam_1_2_3_4_f.y;
float f3 = u_transformParam_1_2_3_4_f.z;
float f4 = u_transformParam_1_2_3_4_f.w;
float f5 = u_transformParam_5_f;
vec3 pos3f = p_position3f;
pos3f.x += f1 * particleSize * a_position2f.x;
pos3f.x += f4 * particleSize * a_position2f.y;
pos3f.y += f2 * particleSize * a_position2f.y;
pos3f.z += f3 * particleSize * a_position2f.x;
pos3f.z += f5 * particleSize * a_position2f.y;
pos3f.x += u_transformParam_1_2_3_4_f.x * particleSize * a_position2f.x;
pos3f.x += u_transformParam_1_2_3_4_f.w * particleSize * a_position2f.y;
pos3f.y += u_transformParam_1_2_3_4_f.y * particleSize * a_position2f.y;
pos3f.z += u_transformParam_1_2_3_4_f.z * particleSize * a_position2f.x;
pos3f.z += u_transformParam_5_f * particleSize * a_position2f.y;
gl_Position = u_matrixTransform * vec4(pos3f, 1.0);
}

View File

@ -0,0 +1,298 @@
#line 2
/*
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
/*
* This file was modified by lax1dude to remove dead code
*
* Original: https://gist.github.com/kosua20/0c506b81b3812ac900048059d2383126
*
*/
/*
* ============================================================================
*
*
* NVIDIA FXAA 3.11 by TIMOTHY LOTTES
*
*
* ------------------------------------------------------------------------------
* COPYRIGHT (C) 2010, 2011 NVIDIA CORPORATION. ALL RIGHTS RESERVED.
* ------------------------------------------------------------------------------
* TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
* *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
* OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA
* OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR
* CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR
* LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION,
* OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE
* THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
*
*/
precision lowp int;
precision highp float;
precision highp sampler2D;
in vec2 v_position2f;
out vec4 output4f;
uniform sampler2D u_screenTexture;
uniform vec2 u_screenSize2f;
#define FXAA_PC 1
#ifndef FXAA_GREEN_AS_LUMA
// For those using non-linear color,
// and either not able to get luma in alpha, or not wanting to,
// this enables FXAA to run using green as a proxy for luma.
// So with this enabled, no need to pack luma in alpha.
//
// This will turn off AA on anything which lacks some amount of green.
// Pure red and blue or combination of only R and B, will get no AA.
//
// Might want to lower the settings for both,
// fxaaConsoleEdgeThresholdMin
// fxaaQualityEdgeThresholdMin
// In order to insure AA does not get turned off on colors
// which contain a minor amount of green.
//
// 1 = On.
// 0 = Off.
//
#define FXAA_GREEN_AS_LUMA 0
#endif
#ifndef FXAA_DISCARD
// 1 = Use discard on pixels which don't need AA.
// 0 = Return unchanged color on pixels which don't need AA.
#define FXAA_DISCARD 0
#endif
/*============================================================================
API PORTING
============================================================================*/
#define FxaaBool bool
#define FxaaDiscard discard
#define FxaaFloat float
#define FxaaFloat2 vec2
#define FxaaFloat3 vec3
#define FxaaFloat4 vec4
#define FxaaHalf float
#define FxaaHalf2 vec2
#define FxaaHalf3 vec3
#define FxaaHalf4 vec4
#define FxaaInt2 ivec2
#define FxaaSat(x) clamp(x, 0.0, 1.0)
#define FxaaTex sampler2D
/*--------------------------------------------------------------------------*/
#define FxaaTexTop(t, p) texture(t, p)
/*============================================================================
GREEN AS LUMA OPTION SUPPORT FUNCTION
============================================================================*/
#if (FXAA_GREEN_AS_LUMA == 0)
FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return dot(rgba.xyz, vec3(0.299, 0.587, 0.114)); }
#else
FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.y; }
#endif
/*============================================================================
FXAA3 CONSOLE - PC VERSION
============================================================================*/
/*--------------------------------------------------------------------------*/
FxaaFloat4 FxaaPixelShader(
// See FXAA Quality FxaaPixelShader() source for docs on Inputs!
//
// Use noperspective interpolation here (turn off perspective interpolation).
// {xy} = center of pixel
FxaaFloat2 pos,
//
// Used only for FXAA Console, and not used on the 360 version.
// Use noperspective interpolation here (turn off perspective interpolation).
// {xy__} = upper left of pixel
// {__zw} = lower right of pixel
FxaaFloat4 fxaaConsolePosPos,
//
// Input color texture.
// {rgb_} = color in linear or perceptual color space
// if (FXAA_GREEN_AS_LUMA == 0)
// {___a} = luma in perceptual color space (not linear)
FxaaTex tex,
//
// Only used on FXAA Console.
// This must be from a constant/uniform.
// This effects sub-pixel AA quality and inversely sharpness.
// Where N ranges between,
// N = 0.50 (default)
// N = 0.33 (sharper)
// {x___} = -N/screenWidthInPixels
// {_y__} = -N/screenHeightInPixels
// {__z_} = N/screenWidthInPixels
// {___w} = N/screenHeightInPixels
FxaaFloat4 fxaaConsoleRcpFrameOpt,
//
// Only used on FXAA Console.
// Not used on 360, but used on PS3 and PC.
// This must be from a constant/uniform.
// {x___} = -2.0/screenWidthInPixels
// {_y__} = -2.0/screenHeightInPixels
// {__z_} = 2.0/screenWidthInPixels
// {___w} = 2.0/screenHeightInPixels
FxaaFloat4 fxaaConsoleRcpFrameOpt2,
//
// Only used on FXAA Console.
// This used to be the FXAA_CONSOLE__EDGE_SHARPNESS define.
// It is here now to allow easier tuning.
// This does not effect PS3, as this needs to be compiled in.
// Use FXAA_CONSOLE__PS3_EDGE_SHARPNESS for PS3.
// Due to the PS3 being ALU bound,
// there are only three safe values here: 2 and 4 and 8.
// These options use the shaders ability to a free *|/ by 2|4|8.
// For all other platforms can be a non-power of two.
// 8.0 is sharper (default!!!)
// 4.0 is softer
// 2.0 is really soft (good only for vector graphics inputs)
FxaaFloat fxaaConsoleEdgeSharpness,
//
// Only used on FXAA Console.
// This used to be the FXAA_CONSOLE__EDGE_THRESHOLD define.
// It is here now to allow easier tuning.
// This does not effect PS3, as this needs to be compiled in.
// Use FXAA_CONSOLE__PS3_EDGE_THRESHOLD for PS3.
// Due to the PS3 being ALU bound,
// there are only two safe values here: 1/4 and 1/8.
// These options use the shaders ability to a free *|/ by 2|4|8.
// The console setting has a different mapping than the quality setting.
// Other platforms can use other values.
// 0.125 leaves less aliasing, but is softer (default!!!)
// 0.25 leaves more aliasing, and is sharper
FxaaFloat fxaaConsoleEdgeThreshold,
//
// Only used on FXAA Console.
// This used to be the FXAA_CONSOLE__EDGE_THRESHOLD_MIN define.
// It is here now to allow easier tuning.
// Trims the algorithm from processing darks.
// The console setting has a different mapping than the quality setting.
// This does not apply to PS3,
// PS3 was simplified to avoid more shader instructions.
// 0.06 - faster but more aliasing in darks
// 0.05 - default
// 0.04 - slower and less aliasing in darks
// Special notes when using FXAA_GREEN_AS_LUMA,
// Likely want to set this to zero.
// As colors that are mostly not-green
// will appear very dark in the green channel!
// Tune by looking at mostly non-green content,
// then start at zero and increase until aliasing is a problem.
FxaaFloat fxaaConsoleEdgeThresholdMin
) {
/*--------------------------------------------------------------------------*/
FxaaFloat lumaNw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xy));
FxaaFloat lumaSw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xw));
FxaaFloat lumaNe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zy));
FxaaFloat lumaSe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zw));
/*--------------------------------------------------------------------------*/
FxaaFloat4 rgbyM = FxaaTexTop(tex, pos.xy);
#if (FXAA_GREEN_AS_LUMA == 0)
// TODO Luma
FxaaFloat lumaM = FxaaLuma(rgbyM);
#else
FxaaFloat lumaM = rgbyM.y;
#endif
/*--------------------------------------------------------------------------*/
FxaaFloat lumaMaxNwSw = max(lumaNw, lumaSw);
lumaNe += 1.0/384.0;
FxaaFloat lumaMinNwSw = min(lumaNw, lumaSw);
/*--------------------------------------------------------------------------*/
FxaaFloat lumaMaxNeSe = max(lumaNe, lumaSe);
FxaaFloat lumaMinNeSe = min(lumaNe, lumaSe);
/*--------------------------------------------------------------------------*/
FxaaFloat lumaMax = max(lumaMaxNeSe, lumaMaxNwSw);
FxaaFloat lumaMin = min(lumaMinNeSe, lumaMinNwSw);
/*--------------------------------------------------------------------------*/
FxaaFloat lumaMaxScaled = lumaMax * fxaaConsoleEdgeThreshold;
/*--------------------------------------------------------------------------*/
FxaaFloat lumaMinM = min(lumaMin, lumaM);
FxaaFloat lumaMaxScaledClamped = max(fxaaConsoleEdgeThresholdMin, lumaMaxScaled);
FxaaFloat lumaMaxM = max(lumaMax, lumaM);
FxaaFloat dirSwMinusNe = lumaSw - lumaNe;
FxaaFloat lumaMaxSubMinM = lumaMaxM - lumaMinM;
FxaaFloat dirSeMinusNw = lumaSe - lumaNw;
if(lumaMaxSubMinM < lumaMaxScaledClamped)
{
#if (FXAA_DISCARD == 1)
FxaaDiscard;
#else
return rgbyM;
#endif
}
/*--------------------------------------------------------------------------*/
FxaaFloat2 dir;
dir.x = dirSwMinusNe + dirSeMinusNw;
dir.y = dirSwMinusNe - dirSeMinusNw;
/*--------------------------------------------------------------------------*/
FxaaFloat2 dir1 = normalize(dir.xy);
FxaaFloat4 rgbyN1 = FxaaTexTop(tex, pos.xy - dir1 * fxaaConsoleRcpFrameOpt.zw);
FxaaFloat4 rgbyP1 = FxaaTexTop(tex, pos.xy + dir1 * fxaaConsoleRcpFrameOpt.zw);
/*--------------------------------------------------------------------------*/
FxaaFloat dirAbsMinTimesC = min(abs(dir1.x), abs(dir1.y)) * fxaaConsoleEdgeSharpness;
FxaaFloat2 dir2 = clamp(dir1.xy / dirAbsMinTimesC, -2.0, 2.0);
/*--------------------------------------------------------------------------*/
FxaaFloat2 dir2x = dir2 * fxaaConsoleRcpFrameOpt2.zw;
FxaaFloat4 rgbyN2 = FxaaTexTop(tex, pos.xy - dir2x);
FxaaFloat4 rgbyP2 = FxaaTexTop(tex, pos.xy + dir2x);
/*--------------------------------------------------------------------------*/
FxaaFloat4 rgbyA = rgbyN1 + rgbyP1;
FxaaFloat4 rgbyB = ((rgbyN2 + rgbyP2) * 0.25) + (rgbyA * 0.25);
/*--------------------------------------------------------------------------*/
#if (FXAA_GREEN_AS_LUMA == 0)
// TODO Luma
float lumaB = FxaaLuma(rgbyB);
#else
float lumaB = rgbyB.y;
#endif
if((lumaB < lumaMin) || (lumaB > lumaMax))
rgbyB.xyz = rgbyA.xyz * 0.5;
//
return rgbyB;
}
/*==========================================================================*/
#define edgeSharpness 4.0
#define edgeThreshold 0.125
#define edgeThresholdMin 0.05
void main(){
vec4 posPos;
posPos.xy = v_position2f - (0.5 * u_screenSize2f);
posPos.zw = v_position2f + (0.5 * u_screenSize2f);
vec4 rcpFrameOpt;
rcpFrameOpt.xy = vec2(-0.50, -0.50) * u_screenSize2f;
rcpFrameOpt.zw = vec2( 0.50, 0.50) * u_screenSize2f;
vec4 rcpFrameOpt2;
rcpFrameOpt2.xy = vec2(-2.0, -2.0) * u_screenSize2f;
rcpFrameOpt2.zw = vec2( 2.0, 2.0) * u_screenSize2f;
output4f = vec4(FxaaPixelShader(v_position2f, posPos, u_screenTexture, rcpFrameOpt, rcpFrameOpt2, edgeSharpness, edgeThreshold, edgeThresholdMin).rgb, 1.0);
}