Trying to debug the motion vector

This commit is contained in:
Sam Gateau 2017-08-21 23:51:29 -07:00
parent 767cccbbb2
commit 97c6b2a60f
4 changed files with 33 additions and 5 deletions

View file

@ -162,7 +162,7 @@ const gpu::PipelinePointer& VelocityBufferPass::getCameraMotionPipeline() {
PrepareStencil::testShape(*state);
state->setColorWriteMask(true, true, false, false);
// Good to go add the brand new pipeline
_cameraMotionPipeline = gpu::Pipeline::create(program, state);
}

View file

@ -22,7 +22,7 @@ void main() {
vec3 currentColor = texture(colorMap, varTexCoord0).xyz;
vec2 pixVelocity = texture(velocityMap, varTexCoord0).xy;
vec2 velocity = params.motionScale * pixVelocity * getInvWidthHeight();
vec2 velocity = params.motionScale * pixVelocity;// *getInvWidthHeight();
vec2 prevTexCoord = varTexCoord0 - velocity;
vec3 prevColor = currentColor;

View file

@ -27,7 +27,7 @@ void main(void) {
vec2 imageSize = getWidthHeight(0);
vec2 pixPos = varTexCoord0 * imageSize;
vec2 pixVelocity = texture(velocityMap, varTexCoord0).xy;
vec2 pixVelocity = imageSize * texture(velocityMap, varTexCoord0).xy;
float pixVelocityLength = length(pixVelocity);
vec2 velocity = params.motionScale * pixVelocity * getInvWidthHeight();
vec2 prevTexCoord = varTexCoord0 - velocity;
@ -37,6 +37,8 @@ void main(void) {
vec2 cursorUV = getDebugCursorTexcoord();
vec2 cursorPixelPos = cursorUV * imageSize;
vec2 cursorVelocity = texture(velocityMap, cursorUV).xy;
vec2 cursorPrevUV = cursorUV - cursorVelocity;
cursorVelocity *= imageSize;
float cursorVelocityLength = length(cursorVelocity);
vec2 cursorToFragVec = pixPos - cursorPixelPos;
@ -55,6 +57,32 @@ void main(void) {
}
}
float tenPercentHeight = 0.1 * imageSize.y;
float centerWidth = imageSize.x * 0.5;
vec2 prevOrbPos = vec2(centerWidth - tenPercentHeight, imageSize.y - tenPercentHeight);
vec2 prevOrbPosToPix = pixPos - prevOrbPos;
if (dot(prevOrbPosToPix, prevOrbPosToPix) < tenPercentHeight * tenPercentHeight) {
vec2 prevOrbPosToPix_uv = cursorPrevUV + prevOrbPosToPix * getInvWidthHeight() * 0.5;
vec3 preOrbColor = vec3(0.0);
if (!(any(lessThan(prevOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(prevOrbPosToPix_uv, vec2(1.0))))) {
preOrbColor = texture(historyMap, prevOrbPosToPix_uv).xyz;
}
outFragColor = vec4(preOrbColor, 1.0);
return;
}
vec2 nextOrbPos = vec2(centerWidth + tenPercentHeight, imageSize.y - tenPercentHeight);
vec2 nextOrbPosToPix = pixPos - nextOrbPos;
if (dot(nextOrbPosToPix, nextOrbPosToPix) < tenPercentHeight * tenPercentHeight) {
vec2 nextOrbPosToPix_uv = cursorUV + nextOrbPosToPix * getInvWidthHeight() * 0.5;
vec3 nextOrbColor = vec3(0.0);
if (!(any(lessThan(nextOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(nextOrbPosToPix_uv, vec2(1.0))))) {
nextOrbColor = texture(colorMap, nextOrbPosToPix_uv).xyz;
}
outFragColor = vec4(nextOrbColor, 1.0);
return;
}
// Debug region before debugX
if (varTexCoord0.x > params.debugX) {
return;

View file

@ -35,11 +35,11 @@ void main(void) {
// The position of the pixel fragment in Eye space then in world space
vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos);
vec3 worldPos = (frameTransform._viewInverse * vec4(eyePos, 1.0)).xyz;
vec3 prevEyePos = (frameTransform._prevView * 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);
vec2 imageSize = getWidthHeight(0);
vec2 imageSize = vec2(1.0, 1.0); // getWidthHeight(0);
outFragColor = vec4( ((texcoordPos - prevUV) * imageSize), 0.0, 0.0);
}