Closed mworchel closed 1 year ago
Thanks for the bug report, and sorry for the delayed answer. You're correct, this is not the intended behavior and there is a bug in the zero boundary code.
The bug occurs only when the texture has minibatch dimension greater than 1, i.e., you don't rely on broadcasting the texture tensor along the minibatch axis. That is probably why it hasn't been noticed before. For example, if you removed the .repeat((uv.shape[0], 1, 1, 1))
in the reproducer, the bug doesn't trigger.
As a quick fix, you can replace the following block in nvdiffrast/common/texture.cu
, lines 450–455, in your installation:
iu0 += tz * w * h;
iu1 += tz * w * h;
tcOut.x = iu0 + w * iv0;
tcOut.y = iu1 + w * iv0;
tcOut.z = iu0 + w * iv1;
tcOut.w = iu1 + w * iv1;
with
int iu0z = iu0 + tz * w * h;
int iu1z = iu1 + tz * w * h;
tcOut.x = iu0z + w * iv0;
tcOut.y = iu1z + w * iv0;
tcOut.z = iu0z + w * iv1;
tcOut.w = iu1z + w * iv1;
I'll include a fix in the next release and leave this issue open until then. Again, big thanks for the report and the repro.
Awesome, looking forward to the next release and thanks for the intermediate fix.
Agreed, this setting is probably very uncommon. I need the functionality for (differentiable) shadow mapping with a batch of lights, so at least this fix will be useful in a real scenario (replacing a workaround using torch's grid_sample
function).
Thanks again for looking into it.
Fixed in v0.3.1, closing the issue.
Hi,
I have encountered unexpected behavior when I tried to sample multiple textures (![grafik](https://github.com/NVlabs/nvdiffrast/assets/9449513/a52adcce-8f1c-4df4-aa39-733e6f7cb71a)
dr.texture
) withfilter_mode='linear'
andboundary_mode='zero'
: the sampling succeeds for the first texture in the minibatch but outputs zero images for the remaining textures. I have verified that this only occurs for this combination of filter and boundary mode. My minimal reproducer attached at the end generates the following output:I assume this is not the expected behavior?
I am using nvdiffrast version 0.3.0, pytorch 1.12.1 on Windows 10.
Minimal reproducer: