]> git.sesse.net Git - nageru/blobdiff - derivatives.frag
Allow symlinked frame files. Useful for testing.
[nageru] / derivatives.frag
index e5e355700f56e1197d1ca3cd2326ae346d98a651..0e2fd687c9cd483ba2f33d5ca40f40046c0eea80 100644 (file)
@@ -1,9 +1,10 @@
 #version 450 core
 
-in vec2 tc;
+in vec3 tc;
 out vec2 derivatives;
+out float beta_0;
 
-uniform sampler2D tex;
+uniform sampler2DArray tex;
 
 void main()
 {
@@ -19,4 +20,13 @@ void main()
 
        derivatives.x = (x_p1 - x_m1) * (2.0/3.0) + (x_m2 - x_p2) * (1.0/12.0);
        derivatives.y = (y_p1 - y_m1) * (2.0/3.0) + (y_m2 - y_p2) * (1.0/12.0);
+
+       // The nudge term in the square root in the DeepFlow paper is ζ² = 0.1² = 0.01.
+       // But this is assuming a 0..255 level. Given the nonlinearities in the expression
+       // where β_0 appears, there's no 100% equivalent way to adjust this
+       // constant that I can see, but taking it to (0.1/255)² ~= 1.53e-7 ~=
+       // 1e-7 ought to be good enough. I guess the basic idea is that it
+       // will only matter for near-zero derivatives anyway. I am a tiny
+       // bit worried about fp16 precision when storing these numbers, but OK.
+       beta_0 = 1.0 / (derivatives.x * derivatives.x + derivatives.y * derivatives.y + 1e-7);
 }