first commit

This commit is contained in:
Rbanh committed 2024-06-22 15:15:55 -04:00
commit 0f859671ea
308 files changed
+18617

No files matched your search

+166
View File
@@ -0,0 +1,166 @@
//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);
#if FXAA_EDGE_SENSITIVITY == 0
float edgeThreshold = 0.25;
float edgeThresholdMin = 0.0625;
#elif FXAA_EDGE_SENSITIVITY == 1
float edgeThreshold = 0.125;
float edgeThresholdMin = 0.0312;
#elif FXAA_EDGE_SENSITIVITY == 2
float edgeThreshold = 0.063;
float edgeThresholdMin = 0.0156;
#endif
vec3 FXAA311(vec3 color) {
int iterations = 12;
vec2 view = 1.0 / vec2(viewWidth, viewHeight);
float lumaCenter = GetLuminance(color);
float lumaDown = GetLuminance(texture2DLod(colortex1, texCoord + vec2( 0.0, -1.0) * view, 0.0).rgb);
float lumaUp = GetLuminance(texture2DLod(colortex1, texCoord + vec2( 0.0, 1.0) * view, 0.0).rgb);
float lumaLeft = GetLuminance(texture2DLod(colortex1, texCoord + vec2(-1.0, 0.0) * view, 0.0).rgb);
float lumaRight = GetLuminance(texture2DLod(colortex1, texCoord + vec2( 1.0, 0.0) * view, 0.0).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 * edgeThreshold)) {
float lumaDownLeft = GetLuminance(texture2DLod(colortex1, texCoord + vec2(-1.0, -1.0) * view, 0.0).rgb);
float lumaUpRight = GetLuminance(texture2DLod(colortex1, texCoord + vec2( 1.0, 1.0) * view, 0.0).rgb);
float lumaUpLeft = GetLuminance(texture2DLod(colortex1, texCoord + vec2(-1.0, 1.0) * view, 0.0).rgb);
float lumaDownRight = GetLuminance(texture2DLod(colortex1, texCoord + vec2( 1.0, -1.0) * view, 0.0).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(texture2DLod(colortex1, uv1, 0.0).rgb);
float lumaEnd2 = GetLuminance(texture2DLod(colortex1, uv2, 0.0).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(texture2DLod(colortex1, uv1, 0.0).rgb);
lumaEnd1 = lumaEnd1 - lumaLocalAverage;
}
if (!reached2) {
lumaEnd2 = GetLuminance(texture2DLod(colortex1, uv2, 0.0).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 * FXAA_SUBPIXEL;
#ifdef TAA
subPixelOffsetFinal *= 0.5;
#endif
finalOffset = max(finalOffset, subPixelOffsetFinal);
// Compute the final UV coordinates.
vec2 finalUv = texCoord;
if (isHorizontal) {
finalUv.y += finalOffset * stepLength;
} else {
finalUv.x += finalOffset * stepLength;
}
color = texture2DLod(colortex1, finalUv, 0.0).rgb;
}
return color;
}
+182
View File
@@ -0,0 +1,182 @@
/*
BSL Shaders v8 Series by Capt Tatsu
https://bitslablab.com
*/
vec2 neighbourOffsets[8] = vec2[8](
vec2( 0.0, -1.0),
vec2(-1.0, 0.0),
vec2( 1.0, 0.0),
vec2( 0.0, 1.0),
vec2(-1.0, -1.0),
vec2( 1.0, -1.0),
vec2(-1.0, 1.0),
vec2( 1.0, 1.0)
);
vec3 GetBlurredColor(vec2 view) {
float blurFactor = 0.1667;
vec3 color = texture2DLod(colortex1, texCoord + neighbourOffsets[4] * blurFactor / view, 0).rgb;
color+= texture2DLod(colortex1, texCoord + neighbourOffsets[5] * blurFactor / view, 0).rgb;
color+= texture2DLod(colortex1, texCoord + neighbourOffsets[6] * blurFactor / view, 0).rgb;
color+= texture2DLod(colortex1, texCoord + neighbourOffsets[7] * blurFactor / view, 0).rgb;
color /= 4.0;
return color;
}
#ifdef TAA_SELECTIVE
float GetSkipFlag(float depth, vec2 view) {
float skip = texture2D(colortex3, texCoord.xy).b;
float skipDepth = depth;
for (int i = 0; i < 4; i++) {
float sampleDepth = texture2D(depthtex1, texCoord + neighbourOffsets[i + 4] / view).r;
float sampleSkip = texture2D(colortex3, texCoord + neighbourOffsets[i + 4] / view).b;
skip = (sampleDepth < skipDepth && sampleSkip == 0) ? 0 : skip;
skipDepth = min(skipDepth, sampleDepth);
}
return skip;
}
#endif
//Previous frame reprojection from Chocapic13
vec2 Reprojection(vec3 pos) {
pos = pos * 2.0 - 1.0;
vec4 viewPosPrev = gbufferProjectionInverse * vec4(pos, 1.0);
viewPosPrev /= viewPosPrev.w;
viewPosPrev = gbufferModelViewInverse * viewPosPrev;
vec3 cameraOffset = cameraPosition - previousCameraPosition;
cameraOffset *= float(pos.z > 0.56);
vec4 previousPosition = viewPosPrev + vec4(cameraOffset, 0.0);
previousPosition = gbufferPreviousModelView * previousPosition;
previousPosition = gbufferPreviousProjection * previousPosition;
return previousPosition.xy / previousPosition.w * 0.5 + 0.5;
}
//Catmull-Rom sampling from Filmic SMAA presentation
vec3 textureCatmullRom(sampler2D colortex, vec2 texcoord, vec2 view) {
vec2 position = texcoord * view;
vec2 centerPosition = floor(position - 0.5) + 0.5;
vec2 f = position - centerPosition;
vec2 f2 = f * f;
vec2 f3 = f * f2;
float c = 0.7;
vec2 w0 = -c * f3 + 2.0 * c * f2 - c * f;
vec2 w1 = (2.0 - c) * f3 - (3.0 - c) * f2 + 1.0;
vec2 w2 = -(2.0 - c) * f3 + (3.0 - 2.0 * c) * f2 + c * f;
vec2 w3 = c * f3 - c * f2;
vec2 w12 = w1 + w2;
vec2 tc12 = (centerPosition + w2 / w12) / view;
vec2 tc0 = (centerPosition - 1.0) / view;
vec2 tc3 = (centerPosition + 2.0) / view;
vec4 color = vec4(texture2DLod(colortex, vec2(tc12.x, tc0.y ), 0).gba, 1.0) * (w12.x * w0.y ) +
vec4(texture2DLod(colortex, vec2(tc0.x, tc12.y), 0).gba, 1.0) * (w0.x * w12.y) +
vec4(texture2DLod(colortex, vec2(tc12.x, tc12.y), 0).gba, 1.0) * (w12.x * w12.y) +
vec4(texture2DLod(colortex, vec2(tc3.x, tc12.y), 0).gba, 1.0) * (w3.x * w12.y) +
vec4(texture2DLod(colortex, vec2(tc12.x, tc3.y ), 0).gba, 1.0) * (w12.x * w3.y );
return color.rgb / color.a;
}
vec3 RGBToYCoCg(vec3 col) {
return vec3(
col.r * 0.25 + col.g * 0.5 + col.b * 0.25,
col.r * 0.5 - col.b * 0.5,
col.r * -0.25 + col.g * 0.5 + col.b * -0.25
);
}
vec3 YCoCgToRGB(vec3 col) {
float n = col.r - col.b;
return vec3(n + col.g, col.r + col.b, n - col.g);
}
vec3 ClipAABB(vec3 q,vec3 aabb_min, vec3 aabb_max){
vec3 p_clip = 0.5 * (aabb_max + aabb_min);
vec3 e_clip = 0.5 * (aabb_max - aabb_min) + 0.00000001;
vec3 v_clip = q - vec3(p_clip);
vec3 v_unit = v_clip.xyz / e_clip;
vec3 a_unit = abs(v_unit);
float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z));
if (ma_unit > 1.0)
return vec3(p_clip) + v_clip / ma_unit;
else
return q;
}
vec3 NeighbourhoodClipping(vec3 color, vec3 tempColor, vec2 view) {
vec3 minclr = RGBToYCoCg(color);
vec3 maxclr = minclr;
for(int i = 0; i < 8; i++) {
vec2 offset = neighbourOffsets[i] * view;
vec3 clr = texture2DLod(colortex1, texCoord + offset, 0.0).rgb;
clr = RGBToYCoCg(clr);
minclr = min(minclr, clr); maxclr = max(maxclr, clr);
}
tempColor = RGBToYCoCg(tempColor);
tempColor = ClipAABB(tempColor, minclr, maxclr);
return YCoCgToRGB(tempColor);
}
vec4 TemporalAA(inout vec3 color, float tempData) {
vec2 view = vec2(viewWidth, viewHeight);
vec3 blur = GetBlurredColor(view);
float depth = texture2D(depthtex1, texCoord).r;
#ifdef TAA_SELECTIVE
float skip = GetSkipFlag(depth, view);
if (skip > 0.0) {
color = blur;
return vec4(tempData, vec3(0.0));
}
#endif
vec3 coord = vec3(texCoord, depth);
vec2 prvCoord = Reprojection(coord);
vec3 tempColor = textureCatmullRom(colortex2, prvCoord, view);
if(tempColor == vec3(0.0)) {
color = blur;
return vec4(tempData, color);
}
vec3 tempColorRaw = tempColor;
tempColor = NeighbourhoodClipping(color, tempColor, 1.0 / view);
#if TAA_MODE == 0
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
);
blendFactor *= exp(-length(velocity)) * 0.2 + 0.7;
color = mix(color, tempColor, blendFactor);
#endif
vec3 outColor = color;
#if TAA_MODE == 1
color = mix(color, tempColor, 0.5);
#endif
return vec4(tempData, outColor);
}