custommods
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
//FXAA 3.11 from http://blog.simonrodriguez.fr/articles/30-07-2016_implementing_fxaa.html
|
||||
float quality[12] = float[12] (1.0, 1.0, 1.0, 1.0, 1.0, 1.5, 2.0, 2.0, 2.0, 2.0, 4.0, 8.0);
|
||||
|
||||
void FXAA311(inout vec3 color) {
|
||||
float edgeThresholdMin = 0.03125;
|
||||
float edgeThresholdMax = 0.0625;
|
||||
float subpixelQuality = 0.75;
|
||||
int iterations = 12;
|
||||
|
||||
vec2 view = 1.0 / vec2(viewWidth, viewHeight);
|
||||
|
||||
float lumaCenter = GetLuminance(color);
|
||||
float lumaDown = GetLuminance(texture2D(colortex1, texCoord + vec2( 0.0, -1.0) * view).rgb);
|
||||
float lumaUp = GetLuminance(texture2D(colortex1, texCoord + vec2( 0.0, 1.0) * view).rgb);
|
||||
float lumaLeft = GetLuminance(texture2D(colortex1, texCoord + vec2(-1.0, 0.0) * view).rgb);
|
||||
float lumaRight = GetLuminance(texture2D(colortex1, texCoord + vec2( 1.0, 0.0) * view).rgb);
|
||||
|
||||
float lumaMin = min(lumaCenter, min(min(lumaDown, lumaUp), min(lumaLeft, lumaRight)));
|
||||
float lumaMax = max(lumaCenter, max(max(lumaDown, lumaUp), max(lumaLeft, lumaRight)));
|
||||
|
||||
float lumaRange = lumaMax - lumaMin;
|
||||
|
||||
if (lumaRange > max(edgeThresholdMin, lumaMax * edgeThresholdMax)) {
|
||||
float lumaDownLeft = GetLuminance(texture2D(colortex1, texCoord + vec2(-1.0, -1.0) * view).rgb);
|
||||
float lumaUpRight = GetLuminance(texture2D(colortex1, texCoord + vec2( 1.0, 1.0) * view).rgb);
|
||||
float lumaUpLeft = GetLuminance(texture2D(colortex1, texCoord + vec2(-1.0, 1.0) * view).rgb);
|
||||
float lumaDownRight = GetLuminance(texture2D(colortex1, texCoord + vec2( 1.0, -1.0) * view).rgb);
|
||||
|
||||
float lumaDownUp = lumaDown + lumaUp;
|
||||
float lumaLeftRight = lumaLeft + lumaRight;
|
||||
|
||||
float lumaLeftCorners = lumaDownLeft + lumaUpLeft;
|
||||
float lumaDownCorners = lumaDownLeft + lumaDownRight;
|
||||
float lumaRightCorners = lumaDownRight + lumaUpRight;
|
||||
float lumaUpCorners = lumaUpRight + lumaUpLeft;
|
||||
|
||||
float edgeHorizontal = abs(-2.0 * lumaLeft + lumaLeftCorners ) +
|
||||
abs(-2.0 * lumaCenter + lumaDownUp ) * 2.0 +
|
||||
abs(-2.0 * lumaRight + lumaRightCorners);
|
||||
float edgeVertical = abs(-2.0 * lumaUp + lumaUpCorners ) +
|
||||
abs(-2.0 * lumaCenter + lumaLeftRight ) * 2.0 +
|
||||
abs(-2.0 * lumaDown + lumaDownCorners );
|
||||
|
||||
bool isHorizontal = (edgeHorizontal >= edgeVertical);
|
||||
|
||||
float luma1 = isHorizontal ? lumaDown : lumaLeft;
|
||||
float luma2 = isHorizontal ? lumaUp : lumaRight;
|
||||
float gradient1 = luma1 - lumaCenter;
|
||||
float gradient2 = luma2 - lumaCenter;
|
||||
|
||||
bool is1Steepest = abs(gradient1) >= abs(gradient2);
|
||||
float gradientScaled = 0.25 * max(abs(gradient1), abs(gradient2));
|
||||
|
||||
float stepLength = isHorizontal ? view.y : view.x;
|
||||
|
||||
float lumaLocalAverage = 0.0;
|
||||
|
||||
if (is1Steepest) {
|
||||
stepLength = - stepLength;
|
||||
lumaLocalAverage = 0.5 * (luma1 + lumaCenter);
|
||||
} else {
|
||||
lumaLocalAverage = 0.5 * (luma2 + lumaCenter);
|
||||
}
|
||||
|
||||
vec2 currentUv = texCoord;
|
||||
if (isHorizontal) {
|
||||
currentUv.y += stepLength * 0.5;
|
||||
} else {
|
||||
currentUv.x += stepLength * 0.5;
|
||||
}
|
||||
|
||||
vec2 offset = isHorizontal ? vec2(view.x, 0.0) : vec2(0.0, view.y);
|
||||
|
||||
vec2 uv1 = currentUv - offset;
|
||||
vec2 uv2 = currentUv + offset;
|
||||
|
||||
float lumaEnd1 = GetLuminance(texture2D(colortex1, uv1).rgb);
|
||||
float lumaEnd2 = GetLuminance(texture2D(colortex1, uv2).rgb);
|
||||
lumaEnd1 -= lumaLocalAverage;
|
||||
lumaEnd2 -= lumaLocalAverage;
|
||||
|
||||
bool reached1 = abs(lumaEnd1) >= gradientScaled;
|
||||
bool reached2 = abs(lumaEnd2) >= gradientScaled;
|
||||
bool reachedBoth = reached1 && reached2;
|
||||
|
||||
if (!reached1) {
|
||||
uv1 -= offset;
|
||||
}
|
||||
if (!reached2) {
|
||||
uv2 += offset;
|
||||
}
|
||||
|
||||
if (!reachedBoth) {
|
||||
for(int i = 2; i < iterations; i++) {
|
||||
if (!reached1) {
|
||||
lumaEnd1 = GetLuminance(texture2D(colortex1, uv1).rgb);
|
||||
lumaEnd1 = lumaEnd1 - lumaLocalAverage;
|
||||
}
|
||||
if (!reached2) {
|
||||
lumaEnd2 = GetLuminance(texture2D(colortex1, uv2).rgb);
|
||||
lumaEnd2 = lumaEnd2 - lumaLocalAverage;
|
||||
}
|
||||
|
||||
reached1 = abs(lumaEnd1) >= gradientScaled;
|
||||
reached2 = abs(lumaEnd2) >= gradientScaled;
|
||||
reachedBoth = reached1 && reached2;
|
||||
|
||||
if (!reached1) {
|
||||
uv1 -= offset * quality[i];
|
||||
}
|
||||
if (!reached2) {
|
||||
uv2 += offset * quality[i];
|
||||
}
|
||||
|
||||
if (reachedBoth) break;
|
||||
}
|
||||
}
|
||||
|
||||
float distance1 = isHorizontal ? (texCoord.x - uv1.x) : (texCoord.y - uv1.y);
|
||||
float distance2 = isHorizontal ? (uv2.x - texCoord.x) : (uv2.y - texCoord.y);
|
||||
|
||||
bool isDirection1 = distance1 < distance2;
|
||||
float distanceFinal = min(distance1, distance2);
|
||||
|
||||
float edgeThickness = (distance1 + distance2);
|
||||
|
||||
float pixelOffset = - distanceFinal / edgeThickness + 0.5;
|
||||
|
||||
bool isLumaCenterSmaller = lumaCenter < lumaLocalAverage;
|
||||
|
||||
bool correctVariation = ((isDirection1 ? lumaEnd1 : lumaEnd2) < 0.0) != isLumaCenterSmaller;
|
||||
|
||||
float finalOffset = correctVariation ? pixelOffset : 0.0;
|
||||
|
||||
float lumaAverage = (1.0 / 12.0) * (2.0 * (lumaDownUp + lumaLeftRight) + lumaLeftCorners + lumaRightCorners);
|
||||
float subPixelOffset1 = clamp(abs(lumaAverage - lumaCenter) / lumaRange, 0.0, 1.0);
|
||||
float subPixelOffset2 = (-2.0 * subPixelOffset1 + 3.0) * subPixelOffset1 * subPixelOffset1;
|
||||
float subPixelOffsetFinal = subPixelOffset2 * subPixelOffset2 * subpixelQuality;
|
||||
|
||||
finalOffset = max(finalOffset, subPixelOffsetFinal);
|
||||
|
||||
|
||||
// Compute the final UV coordinates.
|
||||
vec2 finalUv = texCoord;
|
||||
if (isHorizontal) {
|
||||
finalUv.y += finalOffset * stepLength;
|
||||
} else {
|
||||
finalUv.x += finalOffset * stepLength;
|
||||
}
|
||||
|
||||
color = texture2D(colortex1, finalUv).rgb;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Complementary Shaders by EminGT, based on BSL Shaders by Capt Tatsu
|
||||
*/
|
||||
|
||||
#include "/lib/util/reprojection.glsl"
|
||||
|
||||
ivec2 neighbourhoodOffsets[8] = ivec2[8](
|
||||
ivec2(-1, -1),
|
||||
ivec2( 0, -1),
|
||||
ivec2( 1, -1),
|
||||
ivec2(-1, 0),
|
||||
ivec2( 1, 0),
|
||||
ivec2(-1, 1),
|
||||
ivec2( 0, 1),
|
||||
ivec2( 1, 1)
|
||||
);
|
||||
|
||||
void NeighbourhoodClamping(vec3 color, inout vec3 tempColor, float depth, inout float edge) {
|
||||
vec3 minclr = color, maxclr = color;
|
||||
|
||||
ivec2 texelCoord = ivec2(gl_FragCoord.xy);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
float depthCheck = texelFetch(depthtex1, texelCoord + neighbourhoodOffsets[i], 0).r;
|
||||
if (abs(GetLinearDepth(depthCheck) - GetLinearDepth(depth)) > 0.09) edge = 0.25;
|
||||
vec3 clr = texelFetch(colortex1, texelCoord + neighbourhoodOffsets[i], 0).rgb;
|
||||
minclr = min(minclr, clr); maxclr = max(maxclr, clr);
|
||||
}
|
||||
|
||||
tempColor = clamp(tempColor, minclr, maxclr);
|
||||
}
|
||||
|
||||
void TAA(inout vec3 color, inout vec4 temp) {
|
||||
float depth = texture2D(depthtex1, texCoord).r;
|
||||
float noTAA = texture2D(colortex7, texCoord).r;
|
||||
if (depth < 0.56 || noTAA > 0.5) { // Fixes entities and hand
|
||||
return;
|
||||
}
|
||||
|
||||
vec3 coord = vec3(texCoord, depth);
|
||||
vec2 prvCoord = Reprojection(coord);
|
||||
|
||||
vec2 view = vec2(viewWidth, viewHeight);
|
||||
vec3 tempColor = texture2D(colortex2, prvCoord).gba;
|
||||
if (tempColor == vec3(0.0)) { // Fixes the first frame
|
||||
temp = vec4(temp.r, color);
|
||||
return;
|
||||
}
|
||||
|
||||
float edge = 0.0;
|
||||
NeighbourhoodClamping(color, tempColor, depth, edge);
|
||||
|
||||
vec2 velocity = (texCoord - prvCoord.xy) * view;
|
||||
|
||||
float blendFactor = float(prvCoord.x > 0.0 && prvCoord.x < 1.0 &&
|
||||
prvCoord.y > 0.0 && prvCoord.y < 1.0);
|
||||
#if AA == 2 || AA == 3
|
||||
float blendMinimum = 0.3;
|
||||
#elif AA == 4
|
||||
float blendMinimum = 0.6;
|
||||
#endif
|
||||
float blendVariable = 0.25;
|
||||
float blendConstant = 0.65;
|
||||
|
||||
float lengthVelocity = length(velocity) * 50;
|
||||
blendFactor *= max(exp(-lengthVelocity) * blendVariable + blendConstant - lengthVelocity * edge, blendMinimum);
|
||||
|
||||
color = mix(color, tempColor, blendFactor);
|
||||
temp = vec4(temp.r, color);
|
||||
//if (edge > 0.05) color.rgb = vec3(1.0, 0.0, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user