 			cudaBoundaryModeTrap);
 	}
 
+	auto centerViewPos = computeViewSpace(ix, iy, centerDepth, width, height, &mtxC2V);
+
 	float4 centerMoment = aovs[idx].moments;
 
 	int frame = (int)centerMoment.w;

		//varianceEstimation << <1, 1 >> > (
			outputSurf,
			curaov.ptr(),
			width, height);

		checkCudaKernel(varianceEstimation);

		{
			for (int u = -radius; u <= radius; u++)
			{
				if (IS_IN_BOUND(ix + u, 0, width)
					&& IS_IN_BOUND(iy + v, 0, height))
				{
					auto sampleaov = sampleAov(aovs, ix + u, iy + v, width, height);

					auto moment = sampleaov->moments;
					moment /= moment.w;

					auto sampleNml = sampleaov->normal;

					float sampleDepth = sampleaov->depth;
					int sampleMeshId = sampleaov->meshid;

#if 0
					float n = 1 - dot(sampleNml, centerNormal);
					float Wn = exp(-0.5f * n * n / (sigmaN * sigmaN));

					float d = 1 - min(centerDepth, sampleDepth) / max(centerDepth, sampleDepth);
					float Wd = exp(-0.5f * d * d / (sigmaD * sigmaD));

					float Ws = exp(-0.5f * (u * u + v * v) / (sigmaS * sigmaS));
#else
					float Wn = 1.0f;
					{
						float normalCloseness = dot(sampleNml, centerNormal);
						normalCloseness = normalCloseness * normalCloseness;
						normalCloseness = normalCloseness * normalCloseness;
						float normalError = (1.0f - normalCloseness);
						Wn = max((1.0f - normalError), 0.0f);
					}

					float Wd = max(0.0f, 1.0f - abs(centerDepth - sampleDepth));

					float Ws = 1.0f;
					{
						auto sampleViewPos = computeViewSpace(ix + u, iy + v, sampleDepth, width, height, &mtxC2V);

						// Change in position in camera space.
						auto dq = centerViewPos - sampleViewPos;

						// How far away is this point from the original sample in camera space? (Max value is unbounded).
						auto dist2 = dot(dq, dq);

						// How far off the expected plane (on the perpendicular) is this point?  Max value is unbounded.
						float err = max(abs(dot(dq, sampleNml)), abs(dot(dq, centerNormal)));

						Ws = (dist2 < 0.001f)
							? 1.0
							: pow(max(0.0, 1.0 - 2.0 * err / sqrt(dist2)), 2.0);
					}
#endif

					float Wm = centerMeshId == sampleMeshId ? 1.0f : 0.0f;

					float W = Ws * Wn * Wd * Wm;
					sum += moment * W;
					weight += W;
				}
			}
		}

