X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=derivatives.frag;h=0e2fd687c9cd483ba2f33d5ca40f40046c0eea80;hb=3795723be95f2fe82f3c8b8b45b1a905b2c811fd;hp=e5e355700f56e1197d1ca3cd2326ae346d98a651;hpb=24c21cf229d7e273ecc0e7ad0dc93bcb9fe466e3;p=nageru diff --git a/derivatives.frag b/derivatives.frag index e5e3557..0e2fd68 100644 --- a/derivatives.frag +++ b/derivatives.frag @@ -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); }