TAA is working on HMD! Still some issues when game rate is low

This commit is contained in:
Olivier Prat 2018-02-21 17:34:51 +01:00
parent 093a1491cd
commit dca7b7aaba
6 changed files with 42 additions and 20 deletions

View file

@ -330,7 +330,6 @@ void HmdDisplayPlugin::updateFrameData() {
}
}
if (newFrameIndex != INVALID_FRAME) {
_previousPresentFrameInfo = _currentPresentFrameInfo;
_currentPresentFrameInfo = _frameInfos[newFrameIndex];
}
});
@ -344,6 +343,8 @@ void HmdDisplayPlugin::updateFrameData() {
auto correction = invBatchPose * _currentPresentFrameInfo.presentPose;
auto prevCorrection = invPrevBatchPose * _previousPresentFrameInfo.presentPose;
getGLBackend()->setCameraCorrection(correction, prevCorrection);
_previousPresentFrameInfo = _currentPresentFrameInfo;
}
}

View file

@ -89,7 +89,11 @@ mat4 getViewInverse() {
}
mat4 getView() {
return frameTransform._view * cameraCorrection._correctionInverse;
return cameraCorrection._correctionInverse * frameTransform._view;
}
mat4 getPreviousView() {
return cameraCorrection._prevCorrectionInverse * frameTransform._prevView;
}
bool isStereo() {

View file

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

View file

@ -225,12 +225,37 @@ vec3 taa_fetchVelocityMapBest(vec2 uv) {
return vec3(best.xy, taa_fetchDepth(uv));
}
vec2 taa_fromFragUVToEyeUVAndSide(vec2 fragUV, out int stereoSide) {
vec2 eyeUV = fragUV;
stereoSide = 0;
if (isStereo()) {
if (eyeUV.x > 0.5) {
eyeUV.x -= 0.5;
stereoSide = 1;
}
eyeUV.x *= 2.0;
}
return eyeUV;
}
vec2 taa_fromEyeUVToFragUV(vec2 eyeUV, int stereoSide) {
vec2 fragUV = eyeUV;
if (isStereo()) {
fragUV.x *= 0.5;
fragUV.x += stereoSide*0.5;
}
return fragUV;
}
vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, out vec3 sourceColor, out vec3 historyColor) {
sourceColor = taa_fetchSourceMap(fragUV).xyz;
int stereoSide = 0;
vec2 eyeUV = taa_fromFragUVToEyeUVAndSide(fragUV, stereoSide);
vec2 prevEyeUV = eyeUV - fragVelocity;
vec2 prevFragUV = fragUV - fragVelocity;
historyColor = sourceColor;
if (!(any(lessThan(prevFragUV, vec2(0.0))) || any(greaterThan(prevFragUV, vec2(1.0))))) {
vec2 prevFragUV = taa_fromEyeUVToFragUV(prevEyeUV, stereoSide);
if (!(any(lessThan(prevEyeUV, vec2(0.0))) || any(greaterThan(prevEyeUV, vec2(1.0))))) {
historyColor = taa_fetchHistoryMap(prevFragUV).xyz;
}
return prevFragUV;

View file

@ -32,7 +32,9 @@ void main(void) {
vec2 pixVelocity = imageSize * texture(velocityMap, varTexCoord0).xy;
float pixVelocityLength = length(pixVelocity);
vec2 velocity = pixVelocity * texelSize;
vec2 prevTexCoord = varTexCoord0 - velocity;
int stereoSide = 0;
vec2 prevTexCoord = taa_fromFragUVToEyeUVAndSide(varTexCoord0, stereoSide) - velocity;
prevTexCoord = taa_fromEyeUVToFragUV(prevTexCoord, stereoSide);
vec2 prevPix = prevTexCoord * imageSize;
// Pixel Debugged
@ -43,7 +45,7 @@ void main(void) {
vec2 cursorUV = cursorUVRaw;
vec2 cursorPos = cursorUV * imageSize;
vec2 cursorVelocity = texture(velocityMap, cursorUV).xy;
vec2 cursorPrevUV = cursorUV - cursorVelocity;
vec2 cursorPrevUV = taa_fromFragUVToEyeUVAndSide(cursorUV, stereoSide) - cursorVelocity;
cursorVelocity *= imageSize;
float cursorVelocityLength = length(cursorVelocity);
vec2 cursorVelocityDir = cursorVelocity / cursorVelocityLength;
@ -143,13 +145,11 @@ void main(void) {
if (!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0))))) {
prevColor = texture(historyMap, prevTexCoord).xyz;
}
outFragColor.xyz = prevColor;
outFragColor.xyz = mix(prevColor, vec3(1,0,1), clamp(distance(prevColor, nextColor) - 0.01, 0, 1));
if (pixVelocityLength > params.debugShowVelocityThreshold) {
vec3 speedColor = taa_getVelocityColorAboveThreshold(pixVelocityLength);
outFragColor = vec4(0.0, 1.0, 1.0, 1.0);
}
}

View file

@ -26,17 +26,12 @@ void main(void) {
ivec2 framePixelPos = getPixelPosTexcoordPosAndSide(gl_FragCoord.xy, pixelPos, texcoordPos, stereoSide);
float Zdb = texelFetch(depthMap, ivec2(gl_FragCoord.xy), 0).x;
/* float Zeye = evalZeyeFromZdb(Zdb);
if (Zeye <= -getPosLinearDepthFar()) {
outFragColor = vec4(0.5, 0.5, 0.0, 0.0);
return;
}*/
// The position of the pixel fragment in Eye space then in world space
vec3 eyePos = evalEyePositionFromZdb(stereoSide.x, Zdb, texcoordPos);
vec3 worldPos = (frameTransform._viewInverse * cameraCorrection._correction * vec4(eyePos, 1.0)).xyz;
vec3 worldPos = (getViewInverse() * vec4(eyePos, 1.0)).xyz;
vec3 prevEyePos = (cameraCorrection._prevCorrectionInverse * frameTransform._prevView * vec4(worldPos, 1.0)).xyz;
vec3 prevEyePos = (getPreviousView() * vec4(worldPos, 1.0)).xyz;
vec4 prevClipPos = (frameTransform._projection[stereoSide.x] * vec4(prevEyePos, 1.0));
vec2 prevUV = 0.5 * (prevClipPos.xy / prevClipPos.w) + vec2(0.5);