Moved velocity buffer job just before antialiasing job to be sure tablet model in HMD writes correct velocity and gets properly antialiased

This commit is contained in:
Olivier Prat 2018-02-26 18:07:44 +01:00
parent d3114cbc67
commit d288ebe79e
6 changed files with 64 additions and 154 deletions

View file

@ -287,8 +287,6 @@ void Antialiasing::configure(const Config& config) {
_params.edit().covarianceGamma = config.covarianceGamma;
_params.edit().setConstrainColor(config.constrainColor);
_params.edit().setCovarianceClipColor(config.covarianceClipColor);
_params.edit().setClipExactColor(config.clipExactColor);
_params.edit().setFeedbackColor(config.feedbackColor);
_params.edit().debugShowVelocityThreshold = config.debugShowVelocityThreshold;
@ -349,6 +347,7 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
batch.setResourceFramebufferSwapChainTexture(AntialiasingPass_HistoryMapSlot, _antialiasingBuffers, 0);
batch.setResourceTexture(AntialiasingPass_SourceMapSlot, sourceBuffer->getRenderBuffer(0));
batch.setResourceTexture(AntialiasingPass_VelocityMapSlot, velocityBuffer->getVelocityTexture());
// This is only used during debug
batch.setResourceTexture(AntialiasingPass_DepthMapSlot, linearDepthBuffer->getLinearDepthTexture());
batch.setUniformBuffer(AntialiasingPass_ParamsSlot, _params);

View file

@ -90,8 +90,6 @@ class AntialiasingConfig : public render::Job::Config {
Q_PROPERTY(float covarianceGamma MEMBER covarianceGamma NOTIFY dirty)
Q_PROPERTY(bool constrainColor MEMBER constrainColor NOTIFY dirty)
Q_PROPERTY(bool covarianceClipColor MEMBER covarianceClipColor NOTIFY dirty)
Q_PROPERTY(bool clipExactColor MEMBER clipExactColor NOTIFY dirty)
Q_PROPERTY(bool feedbackColor MEMBER feedbackColor NOTIFY dirty)
Q_PROPERTY(bool debug MEMBER debug NOTIFY dirty)
@ -111,9 +109,7 @@ public:
float sharpen{ 0.15f };
bool constrainColor{ true };
bool covarianceClipColor{ true };
float covarianceGamma{ 0.9f };
bool clipExactColor{ false };
bool feedbackColor{ false };
float debugX{ 0.0f };
@ -146,12 +142,6 @@ struct TAAParams {
void setConstrainColor(bool enabled) { SET_BIT(flags.y, 1, enabled); }
bool isConstrainColor() const { return (bool)GET_BIT(flags.y, 1); }
void setCovarianceClipColor(bool enabled) { SET_BIT(flags.y, 2, enabled); }
bool isCovarianceClipColor() const { return (bool)GET_BIT(flags.y, 2); }
void setClipExactColor(bool enabled) { SET_BIT(flags.y, 3, enabled); }
bool isClipExactColor() const { return (bool)GET_BIT(flags.y, 3); }
void setFeedbackColor(bool enabled) { SET_BIT(flags.y, 4, enabled); }
bool isFeedbackColor() const { return (bool)GET_BIT(flags.y, 4); }

View file

@ -146,11 +146,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
const auto ambientOcclusionFramebuffer = ambientOcclusionOutputs.getN<AmbientOcclusionEffect::Outputs>(0);
const auto ambientOcclusionUniforms = ambientOcclusionOutputs.getN<AmbientOcclusionEffect::Outputs>(1);
// Velocity
const auto velocityBufferInputs = VelocityBufferPass::Inputs(deferredFrameTransform, deferredFramebuffer).asVarying();
const auto velocityBufferOutputs = task.addJob<VelocityBufferPass>("VelocityBuffer", velocityBufferInputs);
const auto velocityBuffer = velocityBufferOutputs.getN<VelocityBufferPass::Outputs>(0);
// Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now.
task.addJob<DrawLight>("DrawLight", lights);
@ -246,6 +241,11 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
task.addJob<DrawBounds>("DrawOverlayInFrontTransparentBounds", overlaysInFrontTransparent);
}
// Velocity
const auto velocityBufferInputs = VelocityBufferPass::Inputs(deferredFrameTransform, deferredFramebuffer).asVarying();
const auto velocityBufferOutputs = task.addJob<VelocityBufferPass>("VelocityBuffer", velocityBufferInputs);
const auto velocityBuffer = velocityBufferOutputs.getN<VelocityBufferPass::Outputs>(0);
// AA job to be revisited
const auto antialiasingInputs = Antialiasing::Inputs(deferredFrameTransform, primaryFramebuffer, linearDepthTarget, velocityBuffer).asVarying();
task.addJob<Antialiasing>("Antialiasing", antialiasingInputs);

View file

@ -28,9 +28,7 @@ void main() {
return;
}
vec3 fragVelAndZ = taa_fetchVelocityMapBest(fragUV);
vec2 fragVel = fragVelAndZ.xy;
float fragDepth = fragVelAndZ.z;
vec2 fragVel = taa_fetchVelocityMapBest(fragUV).xy;
vec3 sourceColor;
vec3 historyColor;
@ -40,7 +38,7 @@ void main() {
if (taa_constrainColor()) {
// clamp history to neighbourhood of current sample
historyColor = taa_evalConstrainColor(sourceColor, fragUV, fragVel, fragDepth, historyColor);
historyColor = taa_evalConstrainColor(sourceColor, fragUV, fragVel, historyColor);
}
if (taa_feedbackColor()) {

View file

@ -54,14 +54,6 @@ bool taa_constrainColor() {
return GET_BIT(params.flags.y, 1);
}
bool taa_covarianceClipColor() {
return GET_BIT(params.flags.y, 2);
}
bool taa_clipExactColor() {
return GET_BIT(params.flags.y, 3);
}
bool taa_feedbackColor() {
return GET_BIT(params.flags.y, 4);
}
@ -187,7 +179,7 @@ vec3 taa_findClosestFragment3x3(vec2 uv)
return vec3(uv + dd.xy * dmin.xy, dmin.z);
}
vec3 taa_fetchVelocityMapBest(vec2 uv) {
vec2 taa_fetchVelocityMapBest(vec2 uv) {
vec2 dd = abs(taa_getTexelSize());
vec2 du = vec2(dd.x, 0.0);
vec2 dv = vec2(0.0, dd.y);
@ -225,8 +217,7 @@ vec3 taa_fetchVelocityMapBest(vec2 uv) {
testSpeed = dot(dbr,dbr);
if (testSpeed > best.z) { best = vec3(dbr, testSpeed); }
return vec3(best.xy, taa_fetchDepth(uv));
return best.xy;
}
vec2 taa_fromFragUVToEyeUVAndSide(vec2 fragUV, out int stereoSide) {
@ -276,7 +267,7 @@ float Luminance(vec3 rgb) {
#define MINMAX_3X3_ROUNDED 1
mat3 taa_evalNeighbourColorVariance(vec3 sourceColor, vec2 fragUV, vec2 fragVelocity, float fragZe) {
mat3 taa_evalNeighbourColorVariance(vec3 sourceColor, vec2 fragUV, vec2 fragVelocity) {
vec2 texelSize = taa_getTexelSize();
@ -412,69 +403,25 @@ vec3 taa_clampColor(vec3 colorMin, vec3 colorMax, vec3 colorSource, vec3 color)
const float eps = 0.00001;
vec3 p = colorSource;
vec3 q = color;
if (taa_clipExactColor()) {
vec3 r = q - p;
vec3 rmax = colorMax - p.xyz;
vec3 rmin = colorMin - p.xyz;
// note: only clips towards aabb center (but fast!)
vec3 p_clip = 0.5 * (colorMax + colorMin);
vec3 e_clip = 0.5 * (colorMax - colorMin) + vec3(eps);
/* bvec3 over = (greaterThan(r, rmax + vec3(eps)));
bvec3 under = (lessThan(r, rmin - vec3(eps)));
vec3 v_clip = q - 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));
float minScale = 1.0;
if (over.x || under.x)
minScale = (float(over.x) * rmax.x + float(under.x) * rmin.x) / r.x;
if (over.y || under.y)
minScale = min(minScale, (float(over.y) * rmax.y + float(under.y) * rmin.y) / r.y);
if (over.z || under.z)
minScale = min(minScale, (float(over.z) * rmax.z + float(under.z) * rmin.z) / r.z);
r *= minScale;
*/
if (r.x > rmax.x + eps)
r *= (rmax.x / r.x);
if (r.y > rmax.y + eps)
r *= (rmax.y / r.y);
if (r.z > rmax.z + eps)
r *= (rmax.z / r.z);
if (r.x < rmin.x - eps)
r *= (rmin.x / r.x);
if (r.y < rmin.y - eps)
r *= (rmin.y / r.y);
if (r.z < rmin.z - eps)
r *= (rmin.z / r.z);
return clamp(p + r, vec3(0.0), vec3(1.0));
} else {
// note: only clips towards aabb center (but fast!)
vec3 p_clip = 0.5 * (colorMax + colorMin);
vec3 e_clip = 0.5 * (colorMax - colorMin) + vec3(eps);
vec3 v_clip = q - 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 p_clip + v_clip / ma_unit;
else
return q;// point inside aabb
}
// Not using clamp at all
// else {
// return clamp(color, colorMin, colorMax);
//}
if (ma_unit > 1.0)
return p_clip + v_clip / ma_unit;
else
return q;// point inside aabb
}
vec3 taa_evalConstrainColor(vec3 sourceColor, vec2 sourceUV, vec2 sourceVel, float sourceZe, vec3 candidateColor) {
vec3 taa_evalConstrainColor(vec3 sourceColor, vec2 sourceUV, vec2 sourceVel, vec3 candidateColor) {
mat3 colorMinMaxAvg;
if (taa_covarianceClipColor()) {
colorMinMaxAvg = taa_evalNeighbourColorVariance(sourceColor, sourceUV, sourceVel, sourceZe);
} else {
colorMinMaxAvg = taa_evalNeighbourColorRegion(sourceColor, sourceUV, sourceVel, sourceZe);
}
colorMinMaxAvg = taa_evalNeighbourColorVariance(sourceColor, sourceUV, sourceVel);
// clamp history to neighbourhood of current sample
return taa_clampColor(colorMinMaxAvg[0], colorMinMaxAvg[1], sourceColor, candidateColor);

View file

@ -31,12 +31,11 @@ Rectangle {
padding: 10
Column{
spacing: 10
spacing: 10
Row {
spacing: 10
id: fxaaOnOff
id: fxaaOnOff
property bool debugFXAA: false
HifiControls.Button {
text: {
@ -86,67 +85,44 @@ Rectangle {
}
}
Separator {}
Column {
spacing: 10
Row {
spacing: 10
HifiControls.CheckBox {
boxSize: 20
text: "Constrain color"
checked: Render.getConfig("RenderMainView.Antialiasing")["constrainColor"]
onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["constrainColor"] = checked }
}
Column {
spacing: 10
HifiControls.CheckBox {
boxSize: 20
text: "Covariance Min Max"
checked: Render.getConfig("RenderMainView.Antialiasing")["covarianceClipColor"]
onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["covarianceClipColor"] = checked }
}
HifiControls.CheckBox {
boxSize: 20
text: "Clip exact color"
checked: Render.getConfig("RenderMainView.Antialiasing")["clipExactColor"]
onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["clipExactColor"] = checked }
}
}
}
ConfigSlider {
label: qsTr("Covariance gamma")
integral: false
config: Render.getConfig("RenderMainView.Antialiasing")
property: "covarianceGamma"
max: 1.5
min: 0.5
}
Separator {}
HifiControls.CheckBox {
boxSize: 20
text: "Feedback history color"
checked: Render.getConfig("RenderMainView.Antialiasing")["feedbackColor"]
onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["feedbackColor"] = checked }
}
ConfigSlider {
label: qsTr("Source blend")
integral: false
config: Render.getConfig("RenderMainView.Antialiasing")
property: "blend"
max: 1.0
min: 0.0
}
ConfigSlider {
label: qsTr("Post sharpen")
integral: false
config: Render.getConfig("RenderMainView.Antialiasing")
property: "sharpen"
max: 1.0
min: 0.0
}
HifiControls.CheckBox {
boxSize: 20
text: "Constrain color"
checked: Render.getConfig("RenderMainView.Antialiasing")["constrainColor"]
onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["constrainColor"] = checked }
}
ConfigSlider {
label: qsTr("Covariance gamma")
integral: false
config: Render.getConfig("RenderMainView.Antialiasing")
property: "covarianceGamma"
max: 1.5
min: 0.5
}
Separator {}
HifiControls.CheckBox {
boxSize: 20
text: "Feedback history color"
checked: Render.getConfig("RenderMainView.Antialiasing")["feedbackColor"]
onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["feedbackColor"] = checked }
}
ConfigSlider {
label: qsTr("Source blend")
integral: false
config: Render.getConfig("RenderMainView.Antialiasing")
property: "blend"
max: 1.0
min: 0.0
}
ConfigSlider {
label: qsTr("Post sharpen")
integral: false
config: Render.getConfig("RenderMainView.Antialiasing")
property: "sharpen"
max: 1.0
min: 0.0
}
Separator {}
Row {