NVlabs / nvdiffrast

Nvdiffrast - Modular Primitives for High-Performance Differentiable Rendering
Other
1.43k stars 158 forks source link

question about antialias #69

Closed l1346792580123 closed 2 years ago

l1346792580123 commented 2 years ago

It seems that antialias operation is used to get correct gradient when generating silhouette. My question is should I need to use antialias operation for attribute interpolation map? I use CookTorrance rendering model, and the properties of vertices such as diffuse, specular need to be interpolated. Should I add antialias operation after interpolate?

s-laine commented 2 years ago

You should antialias the final pixel colors, but not any of the intermediate buffers containing interpolated attributes, texture coordinates, and so on.

Antialiasing these intermediate buffers would produce values that don't correspond to any surface point. For example, antialiasing texture coordinates would blend them towards zero at the silhouette, which makes no sense. The same applies to the inputs or intermediate values of any shading setup, including the Cook-Torrance model.

l1346792580123 commented 2 years ago

Thanks for you explanation.

l1346792580123 commented 2 years ago

You should antialias the final pixel colors, but not any of the intermediate buffers containing interpolated attributes, texture coordinates, and so on.

Antialiasing these intermediate buffers would produce values that don't correspond to any surface point. For example, antialiasing texture coordinates would blend them towards zero at the silhouette, which makes no sense. The same applies to the inputs or intermediate values of any shading setup, including the Cook-Torrance model.

Sorry for opening this issue again. Due to the limitation of GPU memory, my actual behavior is to take out the valid interpolated attributes to calculate BRDF and final color according to the result of rasterize (rast_out[:,:,:,3] > 0). And I put the color value back to the image according to the index to get the final result. The other value in the final result is initialized to zero manually. Finally, I perform antialias on the final result. Is the pipeline correct?

s-laine commented 2 years ago

I'm not sure I completely understand your pipeline, but if the antialiasing is performed on an image where all shading has been done, it should be correct.

l1346792580123 commented 2 years ago

I'm not sure I completely understand your pipeline, but if the antialiasing is performed on an image where all shading has been done, it should be correct.

I interpolate the attributes of points to get the attribute map. Then I take out the valid attributes according to rast_out[:,:,:,3] > 0 and compute the final color. The shading only has been done on part of the image.

s-laine commented 2 years ago

This sounds perfectly fine. As long as you reconstruct the image by putting the shading results into the same pixel indices where the attributes came from, you can do the antialiasing operation on this image.

l1346792580123 commented 2 years ago

Thanks for your answer! I put the shading results back according to indices and the other pixel values are set to zero.