COmparing against fxaa

This commit is contained in:
samcake 2017-08-31 18:27:47 -07:00
parent f031bf5661
commit ddb598203e
7 changed files with 132 additions and 27 deletions

View file

@ -291,7 +291,9 @@ void Antialiasing::configure(const Config& config) {
_params.edit().debugShowVelocityThreshold = config.debugShowVelocityThreshold; _params.edit().debugShowVelocityThreshold = config.debugShowVelocityThreshold;
_params.edit().debugX = config.debugX; _params.edit().regionInfo.x = config.debugX;
_params.edit().regionInfo.z = config.debugFXAAX;
_params.edit().setDebug(config.debug); _params.edit().setDebug(config.debug);
_params.edit().setShowDebugCursor(config.showCursorPixel); _params.edit().setShowDebugCursor(config.showCursorPixel);
_params.edit().setDebugCursor(config.debugCursorTexcoord); _params.edit().setDebugCursor(config.debugCursorTexcoord);

View file

@ -88,6 +88,7 @@ class AntialiasingConfig : public render::Job::Config {
Q_PROPERTY(bool debug MEMBER debug NOTIFY dirty) Q_PROPERTY(bool debug MEMBER debug NOTIFY dirty)
Q_PROPERTY(float debugX MEMBER debugX NOTIFY dirty) Q_PROPERTY(float debugX MEMBER debugX NOTIFY dirty)
Q_PROPERTY(float debugFXAAX MEMBER debugFXAAX NOTIFY dirty)
Q_PROPERTY(float debugShowVelocityThreshold MEMBER debugShowVelocityThreshold NOTIFY dirty) Q_PROPERTY(float debugShowVelocityThreshold MEMBER debugShowVelocityThreshold NOTIFY dirty)
Q_PROPERTY(bool showCursorPixel MEMBER showCursorPixel NOTIFY dirty) Q_PROPERTY(bool showCursorPixel MEMBER showCursorPixel NOTIFY dirty)
Q_PROPERTY(glm::vec2 debugCursorTexcoord MEMBER debugCursorTexcoord NOTIFY dirty) Q_PROPERTY(glm::vec2 debugCursorTexcoord MEMBER debugCursorTexcoord NOTIFY dirty)
@ -103,6 +104,7 @@ public:
float velocityScale{ 1.0f }; float velocityScale{ 1.0f };
float debugX{ 0.0f }; float debugX{ 0.0f };
float debugFXAAX{ 1.0f };
float debugShowVelocityThreshold{ 1.0f }; float debugShowVelocityThreshold{ 1.0f };
glm::vec2 debugCursorTexcoord{ 0.5f, 0.5f }; glm::vec2 debugCursorTexcoord{ 0.5f, 0.5f };
float debugOrbZoom{ 2.0f }; float debugOrbZoom{ 2.0f };
@ -123,25 +125,26 @@ signals:
#define GET_BIT(bitfield, bitIndex) ((bitfield) & (1 << (bitIndex))) #define GET_BIT(bitfield, bitIndex) ((bitfield) & (1 << (bitIndex)))
struct TAAParams { struct TAAParams {
float debugX{ 0.0f }; float nope{ 0.0f };
float blend{ 0.1f }; float blend{ 0.1f };
float velocityScale{ 1.0f }; float velocityScale{ 1.0f };
float debugShowVelocityThreshold{ 1.0f }; float debugShowVelocityThreshold{ 1.0f };
glm::ivec4 debug{ 0 }; glm::ivec4 flags{ 0 };
glm::vec4 pixelInfo{ 0.5f, 0.5f, 2.0f, 0.0f }; glm::vec4 pixelInfo{ 0.5f, 0.5f, 2.0f, 0.0f };
glm::vec4 regionInfo{ 0.0f, 0.0f, 1.0f, 0.0f };
void setUnjitter(bool enabled) { SET_BIT(debug.y, 0, enabled); } void setUnjitter(bool enabled) { SET_BIT(flags.y, 0, enabled); }
bool isUnjitter() const { return (bool)GET_BIT(debug.y, 0); } bool isUnjitter() const { return (bool)GET_BIT(flags.y, 0); }
void setConstrainColor(bool enabled) { SET_BIT(debug.y, 1, enabled); } void setConstrainColor(bool enabled) { SET_BIT(flags.y, 1, enabled); }
bool isConstrainColor() const { return (bool)GET_BIT(debug.y, 1); } bool isConstrainColor() const { return (bool)GET_BIT(flags.y, 1); }
void setDebug(bool enabled) { SET_BIT(debug.x, 0, enabled); } void setDebug(bool enabled) { SET_BIT(flags.x, 0, enabled); }
bool isDebug() const { return (bool) GET_BIT(debug.x, 0); } bool isDebug() const { return (bool) GET_BIT(flags.x, 0); }
void setShowDebugCursor(bool enabled) { SET_BIT(debug.x, 1, enabled); } void setShowDebugCursor(bool enabled) { SET_BIT(flags.x, 1, enabled); }
bool showDebugCursor() const { return (bool)GET_BIT(debug.x, 1); } bool showDebugCursor() const { return (bool)GET_BIT(flags.x, 1); }
void setDebugCursor(glm::vec2 debugCursor) { pixelInfo.x = debugCursor.x; pixelInfo.y = debugCursor.y; } void setDebugCursor(glm::vec2 debugCursor) { pixelInfo.x = debugCursor.x; pixelInfo.y = debugCursor.y; }
glm::vec2 getDebugCursor() const { return glm::vec2(pixelInfo.x, pixelInfo.y); } glm::vec2 getDebugCursor() const { return glm::vec2(pixelInfo.x, pixelInfo.y); }
@ -149,8 +152,8 @@ struct TAAParams {
void setDebugOrbZoom(float orbZoom) { pixelInfo.z = orbZoom; } void setDebugOrbZoom(float orbZoom) { pixelInfo.z = orbZoom; }
float getDebugOrbZoom() const { return pixelInfo.z; } float getDebugOrbZoom() const { return pixelInfo.z; }
void setShowJitterSequence(bool enabled) { SET_BIT(debug.x, 2, enabled); } void setShowJitterSequence(bool enabled) { SET_BIT(flags.x, 2, enabled); }
void setShowClosestFragment(bool enabled) { SET_BIT(debug.x, 3, enabled); } void setShowClosestFragment(bool enabled) { SET_BIT(flags.x, 3, enabled); }
}; };

View file

@ -20,6 +20,8 @@ layout(location = 0) out vec4 outFragColor;
void main() { void main() {
vec2 fragUV = varTexCoord0; vec2 fragUV = varTexCoord0;
vec2 texelSize = getInvWidthHeight(); vec2 texelSize = getInvWidthHeight();
vec2 fragJitterPix = taa_getCurrentJitterSample(); vec2 fragJitterPix = taa_getCurrentJitterSample();
@ -27,6 +29,13 @@ void main() {
fragUV -= fragJitterPix * texelSize; fragUV -= fragJitterPix * texelSize;
} }
// Debug region before debug or fxaa region X
float distToRegionFXAA = fragUV.x - taa_getRegionFXAA().x;
if (distToRegionFXAA > 0.0) {
outFragColor = vec4(taa_evalTXAA(fragUV), 1.0);
return;
}
vec3 nearFragUV = taa_findClosestFragment3x3(fragUV); vec3 nearFragUV = taa_findClosestFragment3x3(fragUV);
vec2 fragVel = taa_fetchVelocityMap(nearFragUV.xy); vec2 fragVel = taa_fetchVelocityMap(nearFragUV.xy);

View file

@ -47,12 +47,13 @@ uniform sampler2D nextMap;
struct TAAParams struct TAAParams
{ {
float debugX; float none;
float blend; float blend;
float motionScale; float motionScale;
float debugShowVelocityThreshold; float debugShowVelocityThreshold;
ivec4 debug; ivec4 flags;
vec4 pixelInfo_orbZoom; vec4 pixelInfo_orbZoom;
vec4 regionInfo;
}; };
layout(std140) uniform taaParamsBuffer { layout(std140) uniform taaParamsBuffer {
@ -62,23 +63,23 @@ layout(std140) uniform taaParamsBuffer {
#define GET_BIT(bitfield, bitIndex) bool((bitfield) & (1 << (bitIndex))) #define GET_BIT(bitfield, bitIndex) bool((bitfield) & (1 << (bitIndex)))
bool taa_showDebugCursor() { bool taa_showDebugCursor() {
return GET_BIT(params.debug.x, 1); return GET_BIT(params.flags.x, 1);
} }
bool taa_showJitterSequence() { bool taa_showJitterSequence() {
return GET_BIT(params.debug.x, 2); return GET_BIT(params.flags.x, 2);
} }
bool taa_showClosestFragment() { bool taa_showClosestFragment() {
return GET_BIT(params.debug.x, 3); return GET_BIT(params.flags.x, 3);
} }
bool taa_unjitter() { bool taa_unjitter() {
return GET_BIT(params.debug.y, 0); return GET_BIT(params.flags.y, 0);
} }
bool taa_constrainColor() { bool taa_constrainColor() {
return GET_BIT(params.debug.y, 1); return GET_BIT(params.flags.y, 1);
} }
vec2 taa_getDebugCursorTexcoord() { vec2 taa_getDebugCursorTexcoord() {
@ -89,6 +90,14 @@ float taa_getDebugOrbZoom() {
return params.pixelInfo_orbZoom.z; return params.pixelInfo_orbZoom.z;
} }
vec2 taa_getRegionDebug() {
return params.regionInfo.xy;
}
vec2 taa_getRegionFXAA() {
return params.regionInfo.zw;
}
vec4 taa_fetchColor(sampler2D map, vec2 uv) { vec4 taa_fetchColor(sampler2D map, vec2 uv) {
#if USE_YCOCG #if USE_YCOCG
vec4 c = texture(map, uv); vec4 c = texture(map, uv);
@ -274,3 +283,71 @@ vec3 taa_getVelocityColorRelative(float velocityPixLength) {
vec3 taa_getVelocityColorAboveThreshold(float velocityPixLength) { vec3 taa_getVelocityColorAboveThreshold(float velocityPixLength) {
return colorRamp((velocityPixLength - params.debugShowVelocityThreshold)/params.debugShowVelocityThreshold); return colorRamp((velocityPixLength - params.debugShowVelocityThreshold)/params.debugShowVelocityThreshold);
} }
vec3 taa_evalTXAA(vec2 fragUV) {
vec2 texelSize = getInvWidthHeight();
// filter width limit for dependent "two-tap" texture samples
float FXAA_SPAN_MAX = 8.0;
// local contrast multiplier for performing AA
// higher = sharper, but setting this value too high will cause near-vertical and near-horizontal edges to fail
// see "fxaaQualityEdgeThreshold"
float FXAA_REDUCE_MUL = 1.0 / 8.0;
// luminance threshold for processing dark colors
// see "fxaaQualityEdgeThresholdMin"
float FXAA_REDUCE_MIN = 1.0 / 128.0;
// fetch raw RGB values for nearby locations
// sampling pattern is "five on a die" (each diagonal direction and the center)
// computing the coordinates for these texture reads could be moved to the vertex shader for speed if needed
vec3 rgbNW = texture(sourceMap, fragUV + (vec2(-1.0, -1.0) * texelSize)).xyz;
vec3 rgbNE = texture(sourceMap, fragUV + (vec2(+1.0, -1.0) * texelSize)).xyz;
vec3 rgbSW = texture(sourceMap, fragUV + (vec2(-1.0, +1.0) * texelSize)).xyz;
vec3 rgbSE = texture(sourceMap, fragUV + (vec2(+1.0, +1.0) * texelSize)).xyz;
vec3 rgbM = texture(sourceMap, fragUV).xyz;
// convert RGB values to luminance
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);
// luma range of local neighborhood
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
// direction perpendicular to local luma gradient
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
// compute clamped direction offset for additional "two-tap" samples
// longer vector = blurry, shorter vector = sharp
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)) * texelSize;
// perform additional texture sampling perpendicular to gradient
vec3 rgbA = (1.0 / 2.0) * (
texture(sourceMap, fragUV + dir * (1.0 / 3.0 - 0.5)).xyz +
texture(sourceMap, fragUV + dir * (2.0 / 3.0 - 0.5)).xyz);
vec3 rgbB = rgbA * (1.0 / 2.0) + (1.0 / 4.0) * (
texture(sourceMap, fragUV + dir * (0.0 / 3.0 - 0.5)).xyz +
texture(sourceMap, fragUV + dir * (3.0 / 3.0 - 0.5)).xyz);
float lumaB = dot(rgbB, luma);
// compare luma of new samples to the luma range of the original neighborhood
// if the new samples exceed this range, just use the first two samples instead of all four
if (lumaB < lumaMin || lumaB > lumaMax) {
return rgbA;
} else {
return rgbB;
}
}

View file

@ -125,7 +125,8 @@ void main(void) {
float niceDotR2 = 4.0; float niceDotR2 = 4.0;
int sequenceLength = taa_getJitterSequenceLength(); //int sequenceLength = taa_getJitterSequenceLength();
int sequenceLength = SEQUENCE_LENGTH;
for (int s = 0; s < sequenceLength; s++) { for (int s = 0; s < sequenceLength; s++) {
vec2 pixToSampleVec = jitterRegionPos - (vec2(0.5) + taa_getJitterSample(s)) * jitterRegionSize; vec2 pixToSampleVec = jitterRegionPos - (vec2(0.5) + taa_getJitterSample(s)) * jitterRegionSize;
float radius2 = (s == taa_getCurrentJitterIndex() ? 4.0 * niceDotR2 : niceDotR2); float radius2 = (s == taa_getCurrentJitterIndex() ? 4.0 * niceDotR2 : niceDotR2);
@ -139,18 +140,23 @@ void main(void) {
} }
} }
// Debug region before debugX // Debug region before debug or fxaa region X
if (varTexCoord0.x > params.debugX) { float distToRegionDebug = varTexCoord0.x - taa_getRegionDebug().x;
float distToRegionFXAA = varTexCoord0.x - taa_getRegionFXAA().x;
if ((distToRegionFXAA < 0.0) && (distToRegionDebug > 0.0)) {
return; return;
} }
// draw a region splitter // draw region splitter
if (abs(varTexCoord0.x - params.debugX) < getInvWidthHeight().x) { if ((abs(distToRegionDebug) < getInvWidthHeight().x) || (abs(distToRegionFXAA) < getInvWidthHeight().x)) {
outFragColor.rgb = vec3(1.0, 1.0, 0.0); outFragColor.rgb = vec3(1.0, 1.0, 0.0);
return; return;
} }
if (distToRegionFXAA > 0.0) {
outFragColor.rgb = taa_evalTXAA();
return;
}
if (taa_showClosestFragment()) { if (taa_showClosestFragment()) {
vec3 fragUV = taa_findClosestFragment3x3(varTexCoord0); vec3 fragUV = taa_findClosestFragment3x3(varTexCoord0);

View file

@ -93,13 +93,21 @@ Rectangle {
} }
} }
ConfigSlider { ConfigSlider {
label: qsTr("Debug X") label: qsTr("Debug Region <")
integral: false integral: false
config: Render.getConfig("RenderMainView.Antialiasing") config: Render.getConfig("RenderMainView.Antialiasing")
property: "debugX" property: "debugX"
max: 1.0 max: 1.0
min: 0.0 min: 0.0
} }
ConfigSlider {
label: qsTr("FXAA Region >")
integral: false
config: Render.getConfig("RenderMainView.Antialiasing")
property: "debugFXAAX"
max: 1.0
min: 0.0
}
Row { Row {
CheckBox { CheckBox {
text: "Jitter Sequence" text: "Jitter Sequence"